From 76ef42ad5beb364c41944bf000c1975d74a06e63 Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Thu, 18 Jul 2024 09:24:49 +0500 Subject: [PATCH 1/5] ppulistdlg: Using FixedRows property instead constant --- components/codetools/ide/ppulistdlg.pas | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/components/codetools/ide/ppulistdlg.pas b/components/codetools/ide/ppulistdlg.pas index 98071729e9..43d47b8b20 100644 --- a/components/codetools/ide/ppulistdlg.pas +++ b/components/codetools/ide/ppulistdlg.pas @@ -343,7 +343,7 @@ begin Col:=-1; Row:=-1; UnitsStringGrid.MouseToCell(X,Y,Col,Row); - if (Row<=1) and (Shift=[ssLeft,ssDouble]) then begin + if (Row sort case Col of 0: s:=plsName; @@ -376,7 +376,7 @@ var AnUnitName: String; begin if FItems=nil then exit; - if (aRow<2) or (aRow>=UnitsStringGrid.RowCount) then + if (aRow=UnitsStringGrid.RowCount) then AnUnitName:='' else AnUnitName:=UnitsStringGrid.Cells[0,aRow]; @@ -397,7 +397,7 @@ begin Col:=0; Row:=0; Grid.MouseToCell(X,Y,Col,Row); - if (Row<1) or (Row>=Grid.RowCount) then exit; + if (Row=Grid.RowCount) then exit; if (Col=0) then begin AnUnitName:=Grid.Cells[0,Row]; JumpToUnit(AnUnitName); @@ -594,7 +594,7 @@ begin Node:=FItems.FindSuccessor(Node); end; - Grid.RowCount:=2+SortedItems.Count; + Grid.RowCount:=Grid.FixedRows+SortedItems.Count; // total Grid.Cells[0,1]:=crsTotal; @@ -605,7 +605,7 @@ begin Grid.Cells[5,1]:=''; // fill grid - Row:=2; + Row:=Grid.FixedRows; Node:=SortedItems.FindLowest; while Node<>nil do begin Item:=TPPUDlgListItem(Node.Data); @@ -750,7 +750,7 @@ procedure TPPUListDialog.JumpToUnit(TheUnitName: string); var i: Integer; begin - for i:=2 to UnitsStringGrid.RowCount-1 do begin + for i:=UnitsStringGrid.FixedRows to UnitsStringGrid.RowCount-1 do begin if SysUtils.CompareText(UnitsStringGrid.Cells[0,i],TheUnitName)<>0 then continue; PageControl1.PageIndex:=0; @@ -764,7 +764,7 @@ procedure TPPUListDialog.UpdateUnitsInfo; var AnUnitName: String; begin - if (UnitsStringGrid.Row<2) or (UnitsStringGrid.Row>=UnitsStringGrid.RowCount) then + if (UnitsStringGrid.Row=UnitsStringGrid.RowCount) then AnUnitName:='' else AnUnitName:=UnitsStringGrid.Cells[0,UnitsStringGrid.Row]; @@ -795,30 +795,30 @@ begin PPUFileLabel.Caption:=Format(crsPPU, [Item.PPUFile]); // uses if Item.UsesUnits<>nil then begin - UsesStringGrid.RowCount:=1+Item.UsesUnits.Count; + UsesStringGrid.RowCount:=UsesStringGrid.FixedRows+Item.UsesUnits.Count; for i:=0 to Item.UsesUnits.Count-1 do begin UsesUnitName:=Item.UsesUnits[i]; - UsesStringGrid.Cells[0,i+1]:=UsesUnitName; + UsesStringGrid.Cells[0,UsesStringGrid.FixedRows+i]:=UsesUnitName; end; end else begin - UsesStringGrid.RowCount:=1; + UsesStringGrid.RowCount:=UsesStringGrid.FixedRows; end; // used by if Item.UsedByUnits<>nil then begin - UsedByStringGrid.RowCount:=1+Item.UsedByUnits.Count; + UsedByStringGrid.RowCount:=UsedByStringGrid.FixedRows+Item.UsedByUnits.Count; for i:=0 to Item.UsedByUnits.Count-1 do begin UsedByUnitName:=Item.UsedByUnits[i]; - UsedByStringGrid.Cells[0,i+1]:=UsedByUnitName; + UsedByStringGrid.Cells[0,UsedByStringGrid.FixedRows+i]:=UsedByUnitName; end; end else begin - UsedByStringGrid.RowCount:=1; + UsedByStringGrid.RowCount:=UsedByStringGrid.FixedRows; end; // uses path UsesPath:=FindUsesPath(MainItem,Item); try - UsesPathStringGrid.RowCount:=UsesPath.Count+1; + UsesPathStringGrid.RowCount:=UsesPathStringGrid.FixedRows+UsesPath.Count; for i:=0 to UsesPath.Count-1 do begin - UsesPathStringGrid.Cells[0,i+1]:=TPPUDlgListItem(UsesPath[i]).TheUnitName; + UsesPathStringGrid.Cells[0,UsesPathStringGrid.FixedRows+i]:=TPPUDlgListItem(UsesPath[i]).TheUnitName; end; finally UsesPath.Free; @@ -827,15 +827,15 @@ begin // linked files Grid:=UnitLinkedFilesStringGrid; if Item.LinkedFiles<>nil then begin - Grid.RowCount:=1+Item.LinkedFiles.Count; + Grid.RowCount:=Grid.FixedRows+Item.LinkedFiles.Count; for i:=0 to Item.LinkedFiles.Count-1 do begin LinkedFile:=TPPULinkedFile(Item.LinkedFiles[i]); - Grid.Cells[0,i+1]:=PPUEntryName(LinkedFile.ID); - Grid.Cells[1,i+1]:=LinkedFile.Filename; - Grid.Cells[2,i+1]:=PPULinkContainerFlagToStr(LinkedFile.Flags); + Grid.Cells[0,Grid.FixedRows+i]:=PPUEntryName(LinkedFile.ID); + Grid.Cells[1,Grid.FixedRows+i]:=LinkedFile.Filename; + Grid.Cells[2,Grid.FixedRows+i]:=PPULinkContainerFlagToStr(LinkedFile.Flags); end; end else begin - Grid.RowCount:=1; + Grid.RowCount:=Grid.FixedRows; end; end; end; From 4a2ce51ec056dfb880341cfdf03c5ff43c3d4108 Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Thu, 18 Jul 2024 09:24:50 +0500 Subject: [PATCH 2/5] ppulistdlg: Removing unnecessary local variables for grids --- components/codetools/ide/ppulistdlg.pas | 49 +++++++++++-------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/components/codetools/ide/ppulistdlg.pas b/components/codetools/ide/ppulistdlg.pas index 43d47b8b20..17d501670f 100644 --- a/components/codetools/ide/ppulistdlg.pas +++ b/components/codetools/ide/ppulistdlg.pas @@ -386,13 +386,12 @@ end; procedure TPPUListDialog.UnitStringGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var - Grid: TStringGrid; + Grid: TStringGrid absolute Sender; Col: Longint; Row: Longint; AnUnitName: string; begin if FItems=nil then exit; - Grid:=TStringGrid(Sender); if Shift=[ssLeft,ssDouble] then begin Col:=0; Row:=0; @@ -568,7 +567,6 @@ procedure TPPUListDialog.UpdateUnitsGrid; end; var - Grid: TStringGrid; Node: TAvlTreeNode; Item: TPPUDlgListItem; Row: Integer; @@ -576,8 +574,7 @@ var TotalPPUBytes, TotalOBytes: int64; SortedItems: TAvlTree; begin - Grid:=UnitsStringGrid; - Grid.BeginUpdate; + UnitsStringGrid.BeginUpdate; SortedItems:=TAvlTree.CreateObjectCompare(@CompareUnits); try @@ -594,22 +591,22 @@ begin Node:=FItems.FindSuccessor(Node); end; - Grid.RowCount:=Grid.FixedRows+SortedItems.Count; + UnitsStringGrid.RowCount:=UnitsStringGrid.FixedRows+SortedItems.Count; // total - Grid.Cells[0,1]:=crsTotal; - Grid.Cells[1,1]:=SizeToStr(TotalPPUBytes,1.0); - Grid.Cells[2,1]:=SizeToStr(TotalOBytes,1.0); - Grid.Cells[3,1]:=IntToStr(SortedItems.Count); - Grid.Cells[4,1]:=''; - Grid.Cells[5,1]:=''; + UnitsStringGrid.Cells[0,1]:=crsTotal; + UnitsStringGrid.Cells[1,1]:=SizeToStr(TotalPPUBytes,1.0); + UnitsStringGrid.Cells[2,1]:=SizeToStr(TotalOBytes,1.0); + UnitsStringGrid.Cells[3,1]:=IntToStr(SortedItems.Count); + UnitsStringGrid.Cells[4,1]:=''; + UnitsStringGrid.Cells[5,1]:=''; // fill grid - Row:=Grid.FixedRows; + Row:=UnitsStringGrid.FixedRows; Node:=SortedItems.FindLowest; while Node<>nil do begin Item:=TPPUDlgListItem(Node.Data); - Grid.Cells[0,Row]:=Item.TheUnitName; + UnitsStringGrid.Cells[0,Row]:=Item.TheUnitName; // .ppu size s:=''; @@ -619,7 +616,7 @@ begin s:=crsMissing else s:=SizeToStr(Item.PPUFileSize,double(Item.PPUFileSize)/TotalPPUBytes); - Grid.Cells[1,Row]:=s; + UnitsStringGrid.Cells[1,Row]:=s; // .o size s:=''; @@ -629,16 +626,16 @@ begin s:=crsMissing else s:=SizeToStr(Item.OFileSize,double(Item.OFileSize)/TotalOBytes); - Grid.Cells[2,Row]:=s; + UnitsStringGrid.Cells[2,Row]:=s; // uses - Grid.Cells[3,Row]:=IntToStr(Item.UsesCount); + UnitsStringGrid.Cells[3,Row]:=IntToStr(Item.UsesCount); // used by - Grid.Cells[4,Row]:=IntToStr(Item.UsedByCount); + UnitsStringGrid.Cells[4,Row]:=IntToStr(Item.UsedByCount); // used by - Grid.Cells[5,Row]:=Item.PackageName; + UnitsStringGrid.Cells[5,Row]:=Item.PackageName; inc(Row); Node:=SortedItems.FindSuccessor(Node); @@ -648,7 +645,7 @@ begin SortedItems.Free; end; - Grid.EndUpdate; + UnitsStringGrid.EndUpdate; end; function TPPUListDialog.DoubleAsPercentage(const d: double): string; @@ -779,7 +776,6 @@ var UsedByUnitName: string; UsesPath: TFPList; LinkedFile: TPPULinkedFile; - Grid: TStringGrid; begin Item:=FindUnit(AnUnitName); if Item=nil then begin @@ -825,17 +821,16 @@ begin end; // linked files - Grid:=UnitLinkedFilesStringGrid; if Item.LinkedFiles<>nil then begin - Grid.RowCount:=Grid.FixedRows+Item.LinkedFiles.Count; + UnitLinkedFilesStringGrid.RowCount:=UnitLinkedFilesStringGrid.FixedRows+Item.LinkedFiles.Count; for i:=0 to Item.LinkedFiles.Count-1 do begin LinkedFile:=TPPULinkedFile(Item.LinkedFiles[i]); - Grid.Cells[0,Grid.FixedRows+i]:=PPUEntryName(LinkedFile.ID); - Grid.Cells[1,Grid.FixedRows+i]:=LinkedFile.Filename; - Grid.Cells[2,Grid.FixedRows+i]:=PPULinkContainerFlagToStr(LinkedFile.Flags); + UnitLinkedFilesStringGrid.Cells[0,UnitLinkedFilesStringGrid.FixedRows+i]:=PPUEntryName(LinkedFile.ID); + UnitLinkedFilesStringGrid.Cells[1,UnitLinkedFilesStringGrid.FixedRows+i]:=LinkedFile.Filename; + UnitLinkedFilesStringGrid.Cells[2,UnitLinkedFilesStringGrid.FixedRows+i]:=PPULinkContainerFlagToStr(LinkedFile.Flags); end; end else begin - Grid.RowCount:=Grid.FixedRows; + UnitLinkedFilesStringGrid.RowCount:=UnitLinkedFilesStringGrid.FixedRows; end; end; end; From cd2d3ae56559843c354ef33c5e5e59938d44222b Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Thu, 18 Jul 2024 09:24:50 +0500 Subject: [PATCH 3/5] ppulistdlg: Minor refactoring and cleanup --- components/codetools/ide/ppulistdlg.pas | 226 +++++++++++------------- 1 file changed, 106 insertions(+), 120 deletions(-) diff --git a/components/codetools/ide/ppulistdlg.pas b/components/codetools/ide/ppulistdlg.pas index 17d501670f..5569fd79ef 100644 --- a/components/codetools/ide/ppulistdlg.pas +++ b/components/codetools/ide/ppulistdlg.pas @@ -135,7 +135,7 @@ type FIdleConnected: boolean; FSearchingItems: TAvlTree; // tree of TPPUDlgListItem sorted for TheUnitName FItems: TAvlTree; // tree of TPPUDlgListItem sorted for TheUnitName - FSort: array[1..6] of TPPUListSortRec; + FColumnSortPrior: array[1..6] of TPPUListSortRec; FDlgLinkedFiles: TAvlTree; // tree of TPPUDlgLinkedFile sorted for ID, file, flags procedure SetProject(const AValue: TLazProject); procedure SetIdleConnected(const AValue: boolean); @@ -181,20 +181,19 @@ implementation {$R *.lfm} procedure ShowPPUList(Sender: TObject); -var - Dlg: TPPUListDialog; begin if LazarusIDE.ActiveProject=nil then begin IDEMessageDialog(crsNoProject, crsPleaseOpenAProjectFirst, mtError, [mbCancel]); exit; end; - Dlg:=TPPUListDialog.Create(nil); - try - Dlg.AProject:=LazarusIDE.ActiveProject; - Dlg.ShowModal; - finally - Dlg.Free; - end; + + with TPPUListDialog.Create(nil) do + try + AProject:=LazarusIDE.ActiveProject; + ShowModal; + finally + Free; + end; end; function ComparePPUListItems(Item1, Item2: Pointer): integer; @@ -262,24 +261,27 @@ begin FItems:=TAvlTree.Create(@ComparePPUListItems); FDlgLinkedFiles:=TAvlTree.Create(@ComparePPULinkedFiles); - FSort[1].Category:=plsOSize; - FSort[2].Category:=plsName; - FSort[3].Category:=plsPPUSize; - FSort[4].Category:=plsUsedByCount; - FSort[5].Category:=plsUsesCount; - FSort[6].Category:=plsPackage; + FColumnSortPrior[1].Category:=plsOSize; + FColumnSortPrior[2].Category:=plsName; + FColumnSortPrior[3].Category:=plsPPUSize; + FColumnSortPrior[4].Category:=plsUsedByCount; + FColumnSortPrior[5].Category:=plsUsesCount; + FColumnSortPrior[6].Category:=plsPackage; PageControl1.PageIndex:=0; UnitsTabSheet.Caption:=crsUnits; // UnitsStringGrid header - UnitsStringGrid.Columns[0].Title.Caption:=crsUnit; - UnitsStringGrid.Columns[1].Title.Caption:=crsSizeOfPpuFile; - UnitsStringGrid.Columns[2].Title.Caption:=crsSizeOfOFile; - UnitsStringGrid.Columns[3].Title.Caption:=crsUses; - UnitsStringGrid.Columns[4].Title.Caption:=crsUsedBy; - UnitsStringGrid.Columns[5].Title.Caption:=crsPackage; + with UnitsStringGrid do + begin + Columns[0].Title.Caption:=crsUnit; + Columns[1].Title.Caption:=crsSizeOfPpuFile; + Columns[2].Title.Caption:=crsSizeOfOFile; + Columns[3].Title.Caption:=crsUses; + Columns[4].Title.Caption:=crsUsedBy; + Columns[5].Title.Caption:=crsPackage; + end; InfoTabSheet.Caption:=crsCOGeneral; @@ -293,9 +295,12 @@ begin UsesPathStringGrid.Columns[0].Title.Caption:=crsUnit; UnitLinkedFilesTabSheet.Caption:=crsLinkedFiles; - UnitLinkedFilesStringGrid.Columns[0].Title.Caption:=crsType; - UnitLinkedFilesStringGrid.Columns[1].Title.Caption:=crsFile; - UnitLinkedFilesStringGrid.Columns[2].Title.Caption:=crsFlags; + with UnitLinkedFilesStringGrid do + begin + Columns[0].Title.Caption:=crsType; + Columns[1].Title.Caption:=crsFile; + Columns[2].Title.Caption:=crsFlags; + end; UnitPageControl.PageIndex:=0; @@ -320,14 +325,11 @@ end; procedure TPPUListDialog.LinkedFilesTreeViewDblClick(Sender: TObject); var Node: TTreeNode; - TheUnitName: string; begin Node:=LinkedFilesTreeView.Selected; - if Node=nil then exit; - if Node.Data=nil then begin - TheUnitName:=Node.Text; - JumpToUnit(TheUnitName); - end; + if assigned(Node) then + if Node.Data=nil then // is not category node + JumpToUnit(Node.Text); end; procedure TPPUListDialog.UnitsStringGridMouseDown(Sender: TObject; @@ -340,8 +342,6 @@ var l: Integer; begin if FItems=nil then exit; - Col:=-1; - Row:=-1; UnitsStringGrid.MouseToCell(X,Y,Col,Row); if (Row sort @@ -354,17 +354,17 @@ begin 5: s:=plsPackage; else exit; end; - l:=low(FSort); - if FSort[l].Category=s then begin + l:=low(FColumnSortPrior); + if FColumnSortPrior[l].Category=s then begin // reverse direction - FSort[l].Reverse:=not FSort[l].Reverse; + FColumnSortPrior[l].Reverse:=not FColumnSortPrior[l].Reverse; end else begin // new primary sort i:=l; - while (i<=High(FSort)) and (FSort[i].Category<>s) do inc(i); - System.Move(FSort[l],FSort[succ(l)],(i-l)*SizeOf(FSort[l])); - FSort[l].Category:=s; - FSort[l].Reverse:=false; + while (i<=High(FColumnSortPrior)) and (FColumnSortPrior[i].Category<>s) do inc(i); + System.Move(FColumnSortPrior[l],FColumnSortPrior[succ(l)],(i-l)*SizeOf(FColumnSortPrior[l])); + FColumnSortPrior[l].Category:=s; + FColumnSortPrior[l].Reverse:=false; end; UpdateUnitsGrid; end; @@ -372,15 +372,14 @@ end; procedure TPPUListDialog.UnitsStringGridSelectCell(Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean); -var - AnUnitName: String; begin if FItems=nil then exit; - if (aRow=UnitsStringGrid.RowCount) then - AnUnitName:='' - else - AnUnitName:=UnitsStringGrid.Cells[0,aRow]; - FillUnitsInfo(AnUnitName); + + with UnitsStringGrid do + if (aRow=RowCount) then + FillUnitsInfo('') + else + FillUnitsInfo(Cells[0,aRow]); end; procedure TPPUListDialog.UnitStringGridMouseDown(Sender: TObject; @@ -389,18 +388,14 @@ var Grid: TStringGrid absolute Sender; Col: Longint; Row: Longint; - AnUnitName: string; begin if FItems=nil then exit; + if Shift=[ssLeft,ssDouble] then begin - Col:=0; - Row:=0; Grid.MouseToCell(X,Y,Col,Row); - if (Row=Grid.RowCount) then exit; - if (Col=0) then begin - AnUnitName:=Grid.Cells[0,Row]; - JumpToUnit(AnUnitName); - end; + if (Row>=Grid.FixedRows) and (Row=0) and (SysUtils.CompareText(AnUnitName,List[Result])<>0) do + while (Result>=0) and (CompareText(AnUnitName,List[Result])<>0) do dec(Result); end; @@ -701,41 +696,41 @@ var i: Integer; begin Result:=0; - for i:=low(FSort) to High(FSort) do begin - case FSort[i].Category of + for i:=low(FColumnSortPrior) to High(FColumnSortPrior) do begin + case FColumnSortPrior[i].Category of plsName: begin - Result:=SysUtils.CompareText(Item1.TheUnitName,Item2.TheUnitName); - if FSort[i].Reverse then + Result:=CompareText(Item1.TheUnitName,Item2.TheUnitName); + if FColumnSortPrior[i].Reverse then Result:=-Result; if Result<>0 then exit; end; plsOSize: begin Result:=CompareInt(Max(0,Item1.OFileSize),Max(0,Item2.OFileSize), - FSort[i].Reverse); + FColumnSortPrior[i].Reverse); if Result<>0 then exit; end; plsPPUSize: begin Result:=CompareInt(Max(0,Item1.PPUFileSize),Max(0,Item2.PPUFileSize), - FSort[i].Reverse); + FColumnSortPrior[i].Reverse); if Result<>0 then exit; end; plsUsesCount: begin - Result:=CompareInt(Item1.UsesCount,Item2.UsesCount,FSort[i].Reverse); + Result:=CompareInt(Item1.UsesCount,Item2.UsesCount,FColumnSortPrior[i].Reverse); if Result<>0 then exit; end; plsUsedByCount: begin - Result:=CompareInt(Item1.UsedByCount,Item2.UsedByCount,FSort[i].Reverse); + Result:=CompareInt(Item1.UsedByCount,Item2.UsedByCount,FColumnSortPrior[i].Reverse); if Result<>0 then exit; end; plsPackage: begin - Result:=SysUtils.CompareText(Item1.PackageName,Item2.PackageName); - if FSort[i].Reverse then + Result:=CompareText(Item1.PackageName,Item2.PackageName); + if FColumnSortPrior[i].Reverse then Result:=-Result; if Result<>0 then exit; end; @@ -747,33 +742,29 @@ procedure TPPUListDialog.JumpToUnit(TheUnitName: string); var i: Integer; begin - for i:=UnitsStringGrid.FixedRows to UnitsStringGrid.RowCount-1 do begin - if SysUtils.CompareText(UnitsStringGrid.Cells[0,i],TheUnitName)<>0 then - continue; - PageControl1.PageIndex:=0; - UnitsStringGrid.Row:=i; - UnitsStringGrid.Col:=0; - exit; - end; + with UnitsStringGrid do + for i:=FixedRows to RowCount-1 do + if CompareText(Cells[0,i],TheUnitName)=0 then begin + PageControl1.PageIndex:=0; + Row:=i; + Col:=0; + exit; + end; end; procedure TPPUListDialog.UpdateUnitsInfo; -var - AnUnitName: String; begin - if (UnitsStringGrid.Row=UnitsStringGrid.RowCount) then - AnUnitName:='' - else - AnUnitName:=UnitsStringGrid.Cells[0,UnitsStringGrid.Row]; - FillUnitsInfo(AnUnitName); + with UnitsStringGrid do + if (Row=RowCount) then + FillUnitsInfo('') + else + FillUnitsInfo(Cells[0,Row]); end; procedure TPPUListDialog.FillUnitsInfo(AnUnitName: string); var Item: TPPUDlgListItem; i: Integer; - UsesUnitName: string; - UsedByUnitName: string; UsesPath: TFPList; LinkedFile: TPPULinkedFile; begin @@ -790,48 +781,43 @@ begin SourceFileLabel.Caption:=Format(crsSource, [Item.SrcFile]); PPUFileLabel.Caption:=Format(crsPPU, [Item.PPUFile]); // uses - if Item.UsesUnits<>nil then begin - UsesStringGrid.RowCount:=UsesStringGrid.FixedRows+Item.UsesUnits.Count; - for i:=0 to Item.UsesUnits.Count-1 do begin - UsesUnitName:=Item.UsesUnits[i]; - UsesStringGrid.Cells[0,UsesStringGrid.FixedRows+i]:=UsesUnitName; - end; - end else begin - UsesStringGrid.RowCount:=UsesStringGrid.FixedRows; - end; + with UsesStringGrid do + if Item.UsesUnits<>nil then begin + RowCount:=FixedRows+Item.UsesUnits.Count; + for i:=0 to Item.UsesUnits.Count-1 do + Cells[0,FixedRows+i]:=Item.UsesUnits[i]; + end else + RowCount:=FixedRows; // used by - if Item.UsedByUnits<>nil then begin - UsedByStringGrid.RowCount:=UsedByStringGrid.FixedRows+Item.UsedByUnits.Count; - for i:=0 to Item.UsedByUnits.Count-1 do begin - UsedByUnitName:=Item.UsedByUnits[i]; - UsedByStringGrid.Cells[0,UsedByStringGrid.FixedRows+i]:=UsedByUnitName; - end; - end else begin - UsedByStringGrid.RowCount:=UsedByStringGrid.FixedRows; - end; + with UsedByStringGrid do + if Item.UsedByUnits<>nil then begin + RowCount:=FixedRows+Item.UsedByUnits.Count; + for i:=0 to Item.UsedByUnits.Count-1 do + Cells[0,FixedRows+i]:=Item.UsedByUnits[i]; + end else + RowCount:=FixedRows; // uses path UsesPath:=FindUsesPath(MainItem,Item); - try - UsesPathStringGrid.RowCount:=UsesPathStringGrid.FixedRows+UsesPath.Count; - for i:=0 to UsesPath.Count-1 do begin - UsesPathStringGrid.Cells[0,UsesPathStringGrid.FixedRows+i]:=TPPUDlgListItem(UsesPath[i]).TheUnitName; + with UsesPathStringGrid do + try + RowCount:=FixedRows+UsesPath.Count; + for i:=0 to UsesPath.Count-1 do + Cells[0,FixedRows+i]:=TPPUDlgListItem(UsesPath[i]).TheUnitName; + finally + UsesPath.Free; end; - finally - UsesPath.Free; - end; - // linked files - if Item.LinkedFiles<>nil then begin - UnitLinkedFilesStringGrid.RowCount:=UnitLinkedFilesStringGrid.FixedRows+Item.LinkedFiles.Count; - for i:=0 to Item.LinkedFiles.Count-1 do begin - LinkedFile:=TPPULinkedFile(Item.LinkedFiles[i]); - UnitLinkedFilesStringGrid.Cells[0,UnitLinkedFilesStringGrid.FixedRows+i]:=PPUEntryName(LinkedFile.ID); - UnitLinkedFilesStringGrid.Cells[1,UnitLinkedFilesStringGrid.FixedRows+i]:=LinkedFile.Filename; - UnitLinkedFilesStringGrid.Cells[2,UnitLinkedFilesStringGrid.FixedRows+i]:=PPULinkContainerFlagToStr(LinkedFile.Flags); - end; - end else begin - UnitLinkedFilesStringGrid.RowCount:=UnitLinkedFilesStringGrid.FixedRows; - end; + with UnitLinkedFilesStringGrid do + if Item.LinkedFiles<>nil then begin + RowCount:=FixedRows+Item.LinkedFiles.Count; + for i:=0 to Item.LinkedFiles.Count-1 do begin + LinkedFile:=TPPULinkedFile(Item.LinkedFiles[i]); + Cells[0,FixedRows+i]:=PPUEntryName(LinkedFile.ID); + Cells[1,FixedRows+i]:=LinkedFile.Filename; + Cells[2,FixedRows+i]:=PPULinkContainerFlagToStr(LinkedFile.Flags); + end; + end else + RowCount:=FixedRows; end; end; From 82d3fdbe130a89d82cb8b5b4417642d29dcef72a Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Thu, 18 Jul 2024 09:24:50 +0500 Subject: [PATCH 4/5] ppulistdlg: Improvement display of numeric values in tables --- components/codetools/ide/codystrconsts.pas | 6 +-- components/codetools/ide/ppulistdlg.pas | 60 ++++++++++------------ 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/components/codetools/ide/codystrconsts.pas b/components/codetools/ide/codystrconsts.pas index 014f0f1036..96252794d7 100644 --- a/components/codetools/ide/codystrconsts.pas +++ b/components/codetools/ide/codystrconsts.pas @@ -52,9 +52,9 @@ resourcestring crsFile = 'File'; crsFlags = 'Flags'; crsPackage = 'Package'; - crsKbytes = 'kbytes'; - crsMbytes = 'Mbytes'; - crsGbytes = 'Gbytes'; + crsKbytes = 'KB'; + crsMbytes = 'MB'; + crsGbytes = 'GB'; crsByFpcCfg = 'by fpc.cfg'; crsNoUnitSelected = 'No unit selected'; crsUnit2 = 'Unit: %s'; diff --git a/components/codetools/ide/ppulistdlg.pas b/components/codetools/ide/ppulistdlg.pas index 5569fd79ef..cb2b6fb9d0 100644 --- a/components/codetools/ide/ppulistdlg.pas +++ b/components/codetools/ide/ppulistdlg.pas @@ -163,9 +163,6 @@ type // linked files procedure UpdateLinkedFilesTreeView; - - function DoubleAsPercentage(const d: double): string; - function BytesToStr(b: int64): string; public property AProject: TLazProject read FProject write SetProject; property IdleConnected: boolean read FIdleConnected write SetIdleConnected; @@ -555,12 +552,37 @@ begin end; procedure TPPUListDialog.UpdateUnitsGrid; - - function SizeToStr(TheBytes: int64; ThePercent: double): string; + // + function BytesToStr(aBytes: double): string; + const + cSizeFactor = 1024.0; + begin + Result:=''; + if aBytes>=cSizeFactor then begin + Result:=crsKbytes; + aBytes:=aBytes/cSizeFactor; + if aBytes>=cSizeFactor then begin + Result:=crsMbytes; + aBytes:=aBytes/cSizeFactor; + if aBytes>=cSizeFactor then begin + Result:=crsGbytes; + aBytes:=aBytes/cSizeFactor; + end; + end; + end; + Result:=FloatToStrF(aBytes,ffFixed,3,2)+' '+Result; + end; + // + function DoubleAsPercentage(const d: double): string; inline; + begin + Result := FloatToStrF(100.0*d,ffFixed,3,2)+'%'; + end; + // + function SizeToStr(TheBytes: int64; ThePercent: double): string; inline; begin Result:=BytesToStr(TheBytes)+' / '+DoubleAsPercentage(ThePercent); end; - + // var Node: TAvlTreeNode; Item: TPPUDlgListItem; @@ -643,32 +665,6 @@ begin UnitsStringGrid.EndUpdate; end; -function TPPUListDialog.DoubleAsPercentage(const d: double): string; -begin - Result:=IntToStr(round(d*10000)); - while length(Result)<3 do Result:='0'+Result; - Result:=copy(Result,1,length(Result)-2) - +DefaultFormatSettings.DecimalSeparator+RightStr(Result,2)+'%'; -end; - -function TPPUListDialog.BytesToStr(b: int64): string; -begin - Result:=''; - if b>80000 then begin - Result:=crsKbytes; - b:=b div 1000; - end; - if b>80000 then begin - Result:=crsMbytes; - b:=b div 1000; - end; - if b>80000 then begin - Result:=crsGbytes; - b:=b div 1000; - end; - Result:=IntToStr(b)+' '+Result; -end; - function TPPUListDialog.FindUnitInList(AnUnitName: string; List: TStrings ): integer; begin From 6078ca4e450f6b10259d19a829a6af2050e4018f Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Thu, 18 Jul 2024 09:24:51 +0500 Subject: [PATCH 5/5] ppulistdlg: Improvement appearance, close the dialog with [Esc] --- components/codetools/ide/ppulistdlg.lfm | 104 ++++++++++++++++-------- components/codetools/ide/ppulistdlg.pas | 13 ++- 2 files changed, 80 insertions(+), 37 deletions(-) diff --git a/components/codetools/ide/ppulistdlg.lfm b/components/codetools/ide/ppulistdlg.lfm index 7cf4feddf0..d3ca50cd23 100644 --- a/components/codetools/ide/ppulistdlg.lfm +++ b/components/codetools/ide/ppulistdlg.lfm @@ -6,10 +6,12 @@ object PPUListDialog: TPPUListDialog Caption = 'PPUListDialog' ClientHeight = 531 ClientWidth = 740 + KeyPreview = True OnClose = FormClose OnCreate = FormCreate OnDestroy = FormDestroy - Position = poScreenCenter + OnKeyDown = FormKeyDown + Position = poWorkAreaCenter LCLVersion = '3.99.0.0' object ButtonPanel1: TButtonPanel Left = 6 @@ -56,54 +58,59 @@ object PPUListDialog: TPPUListDialog Height = 209 Top = 6 Width = 724 - Align = alTop + Align = alClient AutoFillColumns = True BorderSpacing.Around = 6 ColCount = 6 Columns = < item - SizePriority = 10 + SizePriority = 1 Title.Caption = 'Unit' Width = 120 end item - SizePriority = 10 + SizePriority = 0 Title.Caption = 'Size of .ppu file' - Width = 120 + Width = 130 end item - SizePriority = 10 + SizePriority = 0 Title.Caption = 'Size of .o file' - Width = 120 + Width = 130 end item - SizePriority = 5 + SizePriority = 0 Title.Caption = 'Uses' - Width = 120 + Width = 100 end item - SizePriority = 5 + SizePriority = 0 Title.Caption = 'Used by' - Width = 120 + Width = 100 end item Title.Caption = 'Package' - Width = 120 + Width = 119 end> DefaultColWidth = 150 FixedCols = 0 FixedRows = 2 - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goColSizing, goThumbTracking, goColSpanning, goDblClickAutoSize, goSmoothScroll] + FocusRectVisible = False + MouseWheelOption = mwGrid + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goThumbTracking, goDblClickAutoSize, goSmoothScroll, goTruncCellHints, goCellEllipsis, goRowHighlight] + ParentShowHint = False + RowCount = 2 + ShowHint = True TabOrder = 0 OnMouseDown = UnitsStringGridMouseDown OnSelectCell = UnitsStringGridSelectCell ColWidths = ( 120 120 - 120 - 120 - 120 - 120 + 119 + 119 + 119 + 119 ) end object Splitter1: TSplitter @@ -112,15 +119,15 @@ object PPUListDialog: TPPUListDialog Height = 5 Top = 221 Width = 736 - Align = alTop - ResizeAnchor = akTop + Align = alBottom + ResizeAnchor = akBottom end object UnitGroupBox: TGroupBox Left = 6 Height = 179 Top = 232 Width = 724 - Align = alClient + Align = alBottom BorderSpacing.Around = 6 Caption = 'UnitGroupBox' ClientHeight = 149 @@ -170,18 +177,24 @@ object PPUListDialog: TPPUListDialog Width = 716 Align = alClient AutoFillColumns = True + BorderSpacing.Around = 6 ColCount = 1 Columns = < item Title.Caption = 'Unit' - Width = 712 + Width = 704 end> FixedCols = 0 - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goThumbTracking, goSmoothScroll] + FocusRectVisible = False + MouseWheelOption = mwGrid + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goThumbTracking, goSmoothScroll, goTruncCellHints, goCellEllipsis, goRowHighlight] + ParentShowHint = False + RowCount = 1 + ShowHint = True TabOrder = 0 OnMouseDown = UnitStringGridMouseDown ColWidths = ( - 712 + 704 ) end end @@ -196,18 +209,24 @@ object PPUListDialog: TPPUListDialog Width = 716 Align = alClient AutoFillColumns = True + BorderSpacing.Around = 6 ColCount = 1 Columns = < item Title.Caption = 'Unit' - Width = 712 + Width = 704 end> FixedCols = 0 - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goThumbTracking, goSmoothScroll] + FocusRectVisible = False + MouseWheelOption = mwGrid + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goThumbTracking, goSmoothScroll, goTruncCellHints, goCellEllipsis, goRowHighlight] + ParentShowHint = False + RowCount = 1 + ShowHint = True TabOrder = 0 OnMouseDown = UnitStringGridMouseDown ColWidths = ( - 712 + 704 ) end end @@ -222,18 +241,24 @@ object PPUListDialog: TPPUListDialog Width = 716 Align = alClient AutoFillColumns = True + BorderSpacing.Around = 6 ColCount = 1 Columns = < item Title.Caption = 'Unit' - Width = 712 + Width = 704 end> FixedCols = 0 - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goSmoothScroll] + FocusRectVisible = False + MouseWheelOption = mwGrid + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goThumbTracking, goSmoothScroll, goTruncCellHints, goCellEllipsis, goRowHighlight] + ParentShowHint = False + RowCount = 1 + ShowHint = True TabOrder = 0 OnMouseDown = UnitStringGridMouseDown ColWidths = ( - 712 + 704 ) end end @@ -248,27 +273,34 @@ object PPUListDialog: TPPUListDialog Width = 716 Align = alClient AutoFillColumns = True + BorderSpacing.Around = 6 ColCount = 3 Columns = < item Title.Caption = 'Type' - Width = 231 + Width = 235 end item Title.Caption = 'File' - Width = 230 + Width = 235 end item + SizePriority = 0 Title.Caption = 'Flags' - Width = 230 + Width = 160 end> FixedCols = 0 - Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goColSizing, goThumbTracking, goColSpanning, goSmoothScroll] + FocusRectVisible = False + MouseWheelOption = mwGrid + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goThumbTracking, goSmoothScroll, goTruncCellHints, goCellEllipsis, goRowHighlight] + ParentShowHint = False + RowCount = 1 + ShowHint = True TabOrder = 0 ColWidths = ( - 231 - 230 - 230 + 235 + 235 + 234 ) end end diff --git a/components/codetools/ide/ppulistdlg.pas b/components/codetools/ide/ppulistdlg.pas index cb2b6fb9d0..91f3ca15d6 100644 --- a/components/codetools/ide/ppulistdlg.pas +++ b/components/codetools/ide/ppulistdlg.pas @@ -33,7 +33,7 @@ uses Classes, SysUtils, contnrs, math, AVL_Tree, // LCL FileUtil, Forms, Controls, Dialogs, ButtonPanel, Grids, StdCtrls, - ExtCtrls, ComCtrls, + ExtCtrls, ComCtrls, LCLType, // LazUtils AvgLvlTree, LazUTF8, // BuildIntf @@ -121,6 +121,7 @@ type procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); + procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure LinkedFilesTreeViewDblClick(Sender: TObject); procedure UnitsStringGridMouseDown(Sender: TObject; {%H-}Button: TMouseButton; Shift: TShiftState; X, Y: Integer); @@ -319,6 +320,16 @@ begin FreeAndNil(FDlgLinkedFiles); end; +procedure TPPUListDialog.FormKeyDown(Sender: TObject; var Key: Word; + Shift: TShiftState); +begin + if (Key = VK_ESCAPE) and (Shift = []) then + begin + Close; + Key := 0; + end; +end; + procedure TPPUListDialog.LinkedFilesTreeViewDblClick(Sender: TObject); var Node: TTreeNode;