Merge branch 'IDE/PPUListDlg' into 'main'

Improvement "PPU files" dialog

See merge request freepascal.org/lazarus/lazarus!307
This commit is contained in:
Maxim Ganetsky 2024-07-18 14:47:15 +00:00
commit ce1b29b466
3 changed files with 235 additions and 215 deletions

View File

@ -52,9 +52,9 @@ resourcestring
crsFile = 'File'; crsFile = 'File';
crsFlags = 'Flags'; crsFlags = 'Flags';
crsPackage = 'Package'; crsPackage = 'Package';
crsKbytes = 'kbytes'; crsKbytes = 'KB';
crsMbytes = 'Mbytes'; crsMbytes = 'MB';
crsGbytes = 'Gbytes'; crsGbytes = 'GB';
crsByFpcCfg = 'by fpc.cfg'; crsByFpcCfg = 'by fpc.cfg';
crsNoUnitSelected = 'No unit selected'; crsNoUnitSelected = 'No unit selected';
crsUnit2 = 'Unit: %s'; crsUnit2 = 'Unit: %s';

View File

@ -6,10 +6,12 @@ object PPUListDialog: TPPUListDialog
Caption = 'PPUListDialog' Caption = 'PPUListDialog'
ClientHeight = 531 ClientHeight = 531
ClientWidth = 740 ClientWidth = 740
KeyPreview = True
OnClose = FormClose OnClose = FormClose
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy
Position = poScreenCenter OnKeyDown = FormKeyDown
Position = poWorkAreaCenter
LCLVersion = '3.99.0.0' LCLVersion = '3.99.0.0'
object ButtonPanel1: TButtonPanel object ButtonPanel1: TButtonPanel
Left = 6 Left = 6
@ -56,54 +58,59 @@ object PPUListDialog: TPPUListDialog
Height = 209 Height = 209
Top = 6 Top = 6
Width = 724 Width = 724
Align = alTop Align = alClient
AutoFillColumns = True AutoFillColumns = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
ColCount = 6 ColCount = 6
Columns = < Columns = <
item item
SizePriority = 10 SizePriority = 1
Title.Caption = 'Unit' Title.Caption = 'Unit'
Width = 120 Width = 120
end end
item item
SizePriority = 10 SizePriority = 0
Title.Caption = 'Size of .ppu file' Title.Caption = 'Size of .ppu file'
Width = 120 Width = 130
end end
item item
SizePriority = 10 SizePriority = 0
Title.Caption = 'Size of .o file' Title.Caption = 'Size of .o file'
Width = 120 Width = 130
end end
item item
SizePriority = 5 SizePriority = 0
Title.Caption = 'Uses' Title.Caption = 'Uses'
Width = 120 Width = 100
end end
item item
SizePriority = 5 SizePriority = 0
Title.Caption = 'Used by' Title.Caption = 'Used by'
Width = 120 Width = 100
end end
item item
Title.Caption = 'Package' Title.Caption = 'Package'
Width = 120 Width = 119
end> end>
DefaultColWidth = 150 DefaultColWidth = 150
FixedCols = 0 FixedCols = 0
FixedRows = 2 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 TabOrder = 0
OnMouseDown = UnitsStringGridMouseDown OnMouseDown = UnitsStringGridMouseDown
OnSelectCell = UnitsStringGridSelectCell OnSelectCell = UnitsStringGridSelectCell
ColWidths = ( ColWidths = (
120 120
120 120
120 119
120 119
120 119
120 119
) )
end end
object Splitter1: TSplitter object Splitter1: TSplitter
@ -112,15 +119,15 @@ object PPUListDialog: TPPUListDialog
Height = 5 Height = 5
Top = 221 Top = 221
Width = 736 Width = 736
Align = alTop Align = alBottom
ResizeAnchor = akTop ResizeAnchor = akBottom
end end
object UnitGroupBox: TGroupBox object UnitGroupBox: TGroupBox
Left = 6 Left = 6
Height = 179 Height = 179
Top = 232 Top = 232
Width = 724 Width = 724
Align = alClient Align = alBottom
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'UnitGroupBox' Caption = 'UnitGroupBox'
ClientHeight = 149 ClientHeight = 149
@ -170,18 +177,24 @@ object PPUListDialog: TPPUListDialog
Width = 716 Width = 716
Align = alClient Align = alClient
AutoFillColumns = True AutoFillColumns = True
BorderSpacing.Around = 6
ColCount = 1 ColCount = 1
Columns = < Columns = <
item item
Title.Caption = 'Unit' Title.Caption = 'Unit'
Width = 712 Width = 704
end> end>
FixedCols = 0 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 TabOrder = 0
OnMouseDown = UnitStringGridMouseDown OnMouseDown = UnitStringGridMouseDown
ColWidths = ( ColWidths = (
712 704
) )
end end
end end
@ -196,18 +209,24 @@ object PPUListDialog: TPPUListDialog
Width = 716 Width = 716
Align = alClient Align = alClient
AutoFillColumns = True AutoFillColumns = True
BorderSpacing.Around = 6
ColCount = 1 ColCount = 1
Columns = < Columns = <
item item
Title.Caption = 'Unit' Title.Caption = 'Unit'
Width = 712 Width = 704
end> end>
FixedCols = 0 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 TabOrder = 0
OnMouseDown = UnitStringGridMouseDown OnMouseDown = UnitStringGridMouseDown
ColWidths = ( ColWidths = (
712 704
) )
end end
end end
@ -222,18 +241,24 @@ object PPUListDialog: TPPUListDialog
Width = 716 Width = 716
Align = alClient Align = alClient
AutoFillColumns = True AutoFillColumns = True
BorderSpacing.Around = 6
ColCount = 1 ColCount = 1
Columns = < Columns = <
item item
Title.Caption = 'Unit' Title.Caption = 'Unit'
Width = 712 Width = 704
end> end>
FixedCols = 0 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 TabOrder = 0
OnMouseDown = UnitStringGridMouseDown OnMouseDown = UnitStringGridMouseDown
ColWidths = ( ColWidths = (
712 704
) )
end end
end end
@ -248,27 +273,34 @@ object PPUListDialog: TPPUListDialog
Width = 716 Width = 716
Align = alClient Align = alClient
AutoFillColumns = True AutoFillColumns = True
BorderSpacing.Around = 6
ColCount = 3 ColCount = 3
Columns = < Columns = <
item item
Title.Caption = 'Type' Title.Caption = 'Type'
Width = 231 Width = 235
end end
item item
Title.Caption = 'File' Title.Caption = 'File'
Width = 230 Width = 235
end end
item item
SizePriority = 0
Title.Caption = 'Flags' Title.Caption = 'Flags'
Width = 230 Width = 160
end> end>
FixedCols = 0 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 TabOrder = 0
ColWidths = ( ColWidths = (
231 235
230 235
230 234
) )
end end
end end

View File

@ -33,7 +33,7 @@ uses
Classes, SysUtils, contnrs, math, AVL_Tree, Classes, SysUtils, contnrs, math, AVL_Tree,
// LCL // LCL
FileUtil, Forms, Controls, Dialogs, ButtonPanel, Grids, StdCtrls, FileUtil, Forms, Controls, Dialogs, ButtonPanel, Grids, StdCtrls,
ExtCtrls, ComCtrls, ExtCtrls, ComCtrls, LCLType,
// LazUtils // LazUtils
AvgLvlTree, LazUTF8, AvgLvlTree, LazUTF8,
// BuildIntf // BuildIntf
@ -121,6 +121,7 @@ type
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure LinkedFilesTreeViewDblClick(Sender: TObject); procedure LinkedFilesTreeViewDblClick(Sender: TObject);
procedure UnitsStringGridMouseDown(Sender: TObject; {%H-}Button: TMouseButton; procedure UnitsStringGridMouseDown(Sender: TObject; {%H-}Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
@ -135,7 +136,7 @@ type
FIdleConnected: boolean; FIdleConnected: boolean;
FSearchingItems: TAvlTree; // tree of TPPUDlgListItem sorted for TheUnitName FSearchingItems: TAvlTree; // tree of TPPUDlgListItem sorted for TheUnitName
FItems: 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 FDlgLinkedFiles: TAvlTree; // tree of TPPUDlgLinkedFile sorted for ID, file, flags
procedure SetProject(const AValue: TLazProject); procedure SetProject(const AValue: TLazProject);
procedure SetIdleConnected(const AValue: boolean); procedure SetIdleConnected(const AValue: boolean);
@ -163,9 +164,6 @@ type
// linked files // linked files
procedure UpdateLinkedFilesTreeView; procedure UpdateLinkedFilesTreeView;
function DoubleAsPercentage(const d: double): string;
function BytesToStr(b: int64): string;
public public
property AProject: TLazProject read FProject write SetProject; property AProject: TLazProject read FProject write SetProject;
property IdleConnected: boolean read FIdleConnected write SetIdleConnected; property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
@ -181,20 +179,19 @@ implementation
{$R *.lfm} {$R *.lfm}
procedure ShowPPUList(Sender: TObject); procedure ShowPPUList(Sender: TObject);
var
Dlg: TPPUListDialog;
begin begin
if LazarusIDE.ActiveProject=nil then begin if LazarusIDE.ActiveProject=nil then begin
IDEMessageDialog(crsNoProject, crsPleaseOpenAProjectFirst, mtError, [mbCancel]); IDEMessageDialog(crsNoProject, crsPleaseOpenAProjectFirst, mtError, [mbCancel]);
exit; exit;
end; end;
Dlg:=TPPUListDialog.Create(nil);
try with TPPUListDialog.Create(nil) do
Dlg.AProject:=LazarusIDE.ActiveProject; try
Dlg.ShowModal; AProject:=LazarusIDE.ActiveProject;
finally ShowModal;
Dlg.Free; finally
end; Free;
end;
end; end;
function ComparePPUListItems(Item1, Item2: Pointer): integer; function ComparePPUListItems(Item1, Item2: Pointer): integer;
@ -262,24 +259,27 @@ begin
FItems:=TAvlTree.Create(@ComparePPUListItems); FItems:=TAvlTree.Create(@ComparePPUListItems);
FDlgLinkedFiles:=TAvlTree.Create(@ComparePPULinkedFiles); FDlgLinkedFiles:=TAvlTree.Create(@ComparePPULinkedFiles);
FSort[1].Category:=plsOSize; FColumnSortPrior[1].Category:=plsOSize;
FSort[2].Category:=plsName; FColumnSortPrior[2].Category:=plsName;
FSort[3].Category:=plsPPUSize; FColumnSortPrior[3].Category:=plsPPUSize;
FSort[4].Category:=plsUsedByCount; FColumnSortPrior[4].Category:=plsUsedByCount;
FSort[5].Category:=plsUsesCount; FColumnSortPrior[5].Category:=plsUsesCount;
FSort[6].Category:=plsPackage; FColumnSortPrior[6].Category:=plsPackage;
PageControl1.PageIndex:=0; PageControl1.PageIndex:=0;
UnitsTabSheet.Caption:=crsUnits; UnitsTabSheet.Caption:=crsUnits;
// UnitsStringGrid header // UnitsStringGrid header
UnitsStringGrid.Columns[0].Title.Caption:=crsUnit; with UnitsStringGrid do
UnitsStringGrid.Columns[1].Title.Caption:=crsSizeOfPpuFile; begin
UnitsStringGrid.Columns[2].Title.Caption:=crsSizeOfOFile; Columns[0].Title.Caption:=crsUnit;
UnitsStringGrid.Columns[3].Title.Caption:=crsUses; Columns[1].Title.Caption:=crsSizeOfPpuFile;
UnitsStringGrid.Columns[4].Title.Caption:=crsUsedBy; Columns[2].Title.Caption:=crsSizeOfOFile;
UnitsStringGrid.Columns[5].Title.Caption:=crsPackage; Columns[3].Title.Caption:=crsUses;
Columns[4].Title.Caption:=crsUsedBy;
Columns[5].Title.Caption:=crsPackage;
end;
InfoTabSheet.Caption:=crsCOGeneral; InfoTabSheet.Caption:=crsCOGeneral;
@ -293,9 +293,12 @@ begin
UsesPathStringGrid.Columns[0].Title.Caption:=crsUnit; UsesPathStringGrid.Columns[0].Title.Caption:=crsUnit;
UnitLinkedFilesTabSheet.Caption:=crsLinkedFiles; UnitLinkedFilesTabSheet.Caption:=crsLinkedFiles;
UnitLinkedFilesStringGrid.Columns[0].Title.Caption:=crsType; with UnitLinkedFilesStringGrid do
UnitLinkedFilesStringGrid.Columns[1].Title.Caption:=crsFile; begin
UnitLinkedFilesStringGrid.Columns[2].Title.Caption:=crsFlags; Columns[0].Title.Caption:=crsType;
Columns[1].Title.Caption:=crsFile;
Columns[2].Title.Caption:=crsFlags;
end;
UnitPageControl.PageIndex:=0; UnitPageControl.PageIndex:=0;
@ -317,17 +320,24 @@ begin
FreeAndNil(FDlgLinkedFiles); FreeAndNil(FDlgLinkedFiles);
end; 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); procedure TPPUListDialog.LinkedFilesTreeViewDblClick(Sender: TObject);
var var
Node: TTreeNode; Node: TTreeNode;
TheUnitName: string;
begin begin
Node:=LinkedFilesTreeView.Selected; Node:=LinkedFilesTreeView.Selected;
if Node=nil then exit; if assigned(Node) then
if Node.Data=nil then begin if Node.Data=nil then // is not category node
TheUnitName:=Node.Text; JumpToUnit(Node.Text);
JumpToUnit(TheUnitName);
end;
end; end;
procedure TPPUListDialog.UnitsStringGridMouseDown(Sender: TObject; procedure TPPUListDialog.UnitsStringGridMouseDown(Sender: TObject;
@ -340,10 +350,8 @@ var
l: Integer; l: Integer;
begin begin
if FItems=nil then exit; if FItems=nil then exit;
Col:=-1;
Row:=-1;
UnitsStringGrid.MouseToCell(X,Y,Col,Row); UnitsStringGrid.MouseToCell(X,Y,Col,Row);
if (Row<=1) and (Shift=[ssLeft,ssDouble]) then begin if (Row<UnitsStringGrid.FixedRows) and (Shift=[ssLeft,ssDouble]) then begin
// double left click => sort // double left click => sort
case Col of case Col of
0: s:=plsName; 0: s:=plsName;
@ -354,17 +362,17 @@ begin
5: s:=plsPackage; 5: s:=plsPackage;
else exit; else exit;
end; end;
l:=low(FSort); l:=low(FColumnSortPrior);
if FSort[l].Category=s then begin if FColumnSortPrior[l].Category=s then begin
// reverse direction // reverse direction
FSort[l].Reverse:=not FSort[l].Reverse; FColumnSortPrior[l].Reverse:=not FColumnSortPrior[l].Reverse;
end else begin end else begin
// new primary sort // new primary sort
i:=l; i:=l;
while (i<=High(FSort)) and (FSort[i].Category<>s) do inc(i); while (i<=High(FColumnSortPrior)) and (FColumnSortPrior[i].Category<>s) do inc(i);
System.Move(FSort[l],FSort[succ(l)],(i-l)*SizeOf(FSort[l])); System.Move(FColumnSortPrior[l],FColumnSortPrior[succ(l)],(i-l)*SizeOf(FColumnSortPrior[l]));
FSort[l].Category:=s; FColumnSortPrior[l].Category:=s;
FSort[l].Reverse:=false; FColumnSortPrior[l].Reverse:=false;
end; end;
UpdateUnitsGrid; UpdateUnitsGrid;
end; end;
@ -372,36 +380,30 @@ end;
procedure TPPUListDialog.UnitsStringGridSelectCell(Sender: TObject; aCol, procedure TPPUListDialog.UnitsStringGridSelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean); aRow: Integer; var CanSelect: Boolean);
var
AnUnitName: String;
begin begin
if FItems=nil then exit; if FItems=nil then exit;
if (aRow<2) or (aRow>=UnitsStringGrid.RowCount) then
AnUnitName:='' with UnitsStringGrid do
else if (aRow<FixedRows) or (aRow>=RowCount) then
AnUnitName:=UnitsStringGrid.Cells[0,aRow]; FillUnitsInfo('')
FillUnitsInfo(AnUnitName); else
FillUnitsInfo(Cells[0,aRow]);
end; end;
procedure TPPUListDialog.UnitStringGridMouseDown(Sender: TObject; procedure TPPUListDialog.UnitStringGridMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var var
Grid: TStringGrid; Grid: TStringGrid absolute Sender;
Col: Longint; Col: Longint;
Row: Longint; Row: Longint;
AnUnitName: string;
begin begin
if FItems=nil then exit; if FItems=nil then exit;
Grid:=TStringGrid(Sender);
if Shift=[ssLeft,ssDouble] then begin if Shift=[ssLeft,ssDouble] then begin
Col:=0;
Row:=0;
Grid.MouseToCell(X,Y,Col,Row); Grid.MouseToCell(X,Y,Col,Row);
if (Row<1) or (Row>=Grid.RowCount) then exit; if (Row>=Grid.FixedRows) and (Row<Grid.RowCount) then
if (Col=0) then begin if Col=0 then
AnUnitName:=Grid.Cells[0,Row]; JumpToUnit(Grid.Cells[0,Row]);
JumpToUnit(AnUnitName);
end;
end; end;
end; end;
@ -561,14 +563,38 @@ begin
end; end;
procedure TPPUListDialog.UpdateUnitsGrid; 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 begin
Result:=BytesToStr(TheBytes)+' / '+DoubleAsPercentage(ThePercent); Result:=BytesToStr(TheBytes)+' / '+DoubleAsPercentage(ThePercent);
end; end;
//
var var
Grid: TStringGrid;
Node: TAvlTreeNode; Node: TAvlTreeNode;
Item: TPPUDlgListItem; Item: TPPUDlgListItem;
Row: Integer; Row: Integer;
@ -576,8 +602,7 @@ var
TotalPPUBytes, TotalOBytes: int64; TotalPPUBytes, TotalOBytes: int64;
SortedItems: TAvlTree; SortedItems: TAvlTree;
begin begin
Grid:=UnitsStringGrid; UnitsStringGrid.BeginUpdate;
Grid.BeginUpdate;
SortedItems:=TAvlTree.CreateObjectCompare(@CompareUnits); SortedItems:=TAvlTree.CreateObjectCompare(@CompareUnits);
try try
@ -594,22 +619,22 @@ begin
Node:=FItems.FindSuccessor(Node); Node:=FItems.FindSuccessor(Node);
end; end;
Grid.RowCount:=2+SortedItems.Count; UnitsStringGrid.RowCount:=UnitsStringGrid.FixedRows+SortedItems.Count;
// total // total
Grid.Cells[0,1]:=crsTotal; UnitsStringGrid.Cells[0,1]:=crsTotal;
Grid.Cells[1,1]:=SizeToStr(TotalPPUBytes,1.0); UnitsStringGrid.Cells[1,1]:=SizeToStr(TotalPPUBytes,1.0);
Grid.Cells[2,1]:=SizeToStr(TotalOBytes,1.0); UnitsStringGrid.Cells[2,1]:=SizeToStr(TotalOBytes,1.0);
Grid.Cells[3,1]:=IntToStr(SortedItems.Count); UnitsStringGrid.Cells[3,1]:=IntToStr(SortedItems.Count);
Grid.Cells[4,1]:=''; UnitsStringGrid.Cells[4,1]:='';
Grid.Cells[5,1]:=''; UnitsStringGrid.Cells[5,1]:='';
// fill grid // fill grid
Row:=2; Row:=UnitsStringGrid.FixedRows;
Node:=SortedItems.FindLowest; Node:=SortedItems.FindLowest;
while Node<>nil do begin while Node<>nil do begin
Item:=TPPUDlgListItem(Node.Data); Item:=TPPUDlgListItem(Node.Data);
Grid.Cells[0,Row]:=Item.TheUnitName; UnitsStringGrid.Cells[0,Row]:=Item.TheUnitName;
// .ppu size // .ppu size
s:=''; s:='';
@ -619,7 +644,7 @@ begin
s:=crsMissing s:=crsMissing
else else
s:=SizeToStr(Item.PPUFileSize,double(Item.PPUFileSize)/TotalPPUBytes); s:=SizeToStr(Item.PPUFileSize,double(Item.PPUFileSize)/TotalPPUBytes);
Grid.Cells[1,Row]:=s; UnitsStringGrid.Cells[1,Row]:=s;
// .o size // .o size
s:=''; s:='';
@ -629,16 +654,16 @@ begin
s:=crsMissing s:=crsMissing
else else
s:=SizeToStr(Item.OFileSize,double(Item.OFileSize)/TotalOBytes); s:=SizeToStr(Item.OFileSize,double(Item.OFileSize)/TotalOBytes);
Grid.Cells[2,Row]:=s; UnitsStringGrid.Cells[2,Row]:=s;
// uses // uses
Grid.Cells[3,Row]:=IntToStr(Item.UsesCount); UnitsStringGrid.Cells[3,Row]:=IntToStr(Item.UsesCount);
// used by // used by
Grid.Cells[4,Row]:=IntToStr(Item.UsedByCount); UnitsStringGrid.Cells[4,Row]:=IntToStr(Item.UsedByCount);
// used by // used by
Grid.Cells[5,Row]:=Item.PackageName; UnitsStringGrid.Cells[5,Row]:=Item.PackageName;
inc(Row); inc(Row);
Node:=SortedItems.FindSuccessor(Node); Node:=SortedItems.FindSuccessor(Node);
@ -648,33 +673,7 @@ begin
SortedItems.Free; SortedItems.Free;
end; end;
Grid.EndUpdate; 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; end;
function TPPUListDialog.FindUnitInList(AnUnitName: string; List: TStrings function TPPUListDialog.FindUnitInList(AnUnitName: string; List: TStrings
@ -682,7 +681,7 @@ function TPPUListDialog.FindUnitInList(AnUnitName: string; List: TStrings
begin begin
if List=nil then exit(-1); if List=nil then exit(-1);
Result:=List.Count-1; Result:=List.Count-1;
while (Result>=0) and (SysUtils.CompareText(AnUnitName,List[Result])<>0) do while (Result>=0) and (CompareText(AnUnitName,List[Result])<>0) do
dec(Result); dec(Result);
end; end;
@ -704,41 +703,41 @@ var
i: Integer; i: Integer;
begin begin
Result:=0; Result:=0;
for i:=low(FSort) to High(FSort) do begin for i:=low(FColumnSortPrior) to High(FColumnSortPrior) do begin
case FSort[i].Category of case FColumnSortPrior[i].Category of
plsName: plsName:
begin begin
Result:=SysUtils.CompareText(Item1.TheUnitName,Item2.TheUnitName); Result:=CompareText(Item1.TheUnitName,Item2.TheUnitName);
if FSort[i].Reverse then if FColumnSortPrior[i].Reverse then
Result:=-Result; Result:=-Result;
if Result<>0 then exit; if Result<>0 then exit;
end; end;
plsOSize: plsOSize:
begin begin
Result:=CompareInt(Max(0,Item1.OFileSize),Max(0,Item2.OFileSize), Result:=CompareInt(Max(0,Item1.OFileSize),Max(0,Item2.OFileSize),
FSort[i].Reverse); FColumnSortPrior[i].Reverse);
if Result<>0 then exit; if Result<>0 then exit;
end; end;
plsPPUSize: plsPPUSize:
begin begin
Result:=CompareInt(Max(0,Item1.PPUFileSize),Max(0,Item2.PPUFileSize), Result:=CompareInt(Max(0,Item1.PPUFileSize),Max(0,Item2.PPUFileSize),
FSort[i].Reverse); FColumnSortPrior[i].Reverse);
if Result<>0 then exit; if Result<>0 then exit;
end; end;
plsUsesCount: plsUsesCount:
begin begin
Result:=CompareInt(Item1.UsesCount,Item2.UsesCount,FSort[i].Reverse); Result:=CompareInt(Item1.UsesCount,Item2.UsesCount,FColumnSortPrior[i].Reverse);
if Result<>0 then exit; if Result<>0 then exit;
end; end;
plsUsedByCount: plsUsedByCount:
begin begin
Result:=CompareInt(Item1.UsedByCount,Item2.UsedByCount,FSort[i].Reverse); Result:=CompareInt(Item1.UsedByCount,Item2.UsedByCount,FColumnSortPrior[i].Reverse);
if Result<>0 then exit; if Result<>0 then exit;
end; end;
plsPackage: plsPackage:
begin begin
Result:=SysUtils.CompareText(Item1.PackageName,Item2.PackageName); Result:=CompareText(Item1.PackageName,Item2.PackageName);
if FSort[i].Reverse then if FColumnSortPrior[i].Reverse then
Result:=-Result; Result:=-Result;
if Result<>0 then exit; if Result<>0 then exit;
end; end;
@ -750,36 +749,31 @@ procedure TPPUListDialog.JumpToUnit(TheUnitName: string);
var var
i: Integer; i: Integer;
begin begin
for i:=2 to UnitsStringGrid.RowCount-1 do begin with UnitsStringGrid do
if SysUtils.CompareText(UnitsStringGrid.Cells[0,i],TheUnitName)<>0 then for i:=FixedRows to RowCount-1 do
continue; if CompareText(Cells[0,i],TheUnitName)=0 then begin
PageControl1.PageIndex:=0; PageControl1.PageIndex:=0;
UnitsStringGrid.Row:=i; Row:=i;
UnitsStringGrid.Col:=0; Col:=0;
exit; exit;
end; end;
end; end;
procedure TPPUListDialog.UpdateUnitsInfo; procedure TPPUListDialog.UpdateUnitsInfo;
var
AnUnitName: String;
begin begin
if (UnitsStringGrid.Row<2) or (UnitsStringGrid.Row>=UnitsStringGrid.RowCount) then with UnitsStringGrid do
AnUnitName:='' if (Row<FixedRows) or (Row>=RowCount) then
else FillUnitsInfo('')
AnUnitName:=UnitsStringGrid.Cells[0,UnitsStringGrid.Row]; else
FillUnitsInfo(AnUnitName); FillUnitsInfo(Cells[0,Row]);
end; end;
procedure TPPUListDialog.FillUnitsInfo(AnUnitName: string); procedure TPPUListDialog.FillUnitsInfo(AnUnitName: string);
var var
Item: TPPUDlgListItem; Item: TPPUDlgListItem;
i: Integer; i: Integer;
UsesUnitName: string;
UsedByUnitName: string;
UsesPath: TFPList; UsesPath: TFPList;
LinkedFile: TPPULinkedFile; LinkedFile: TPPULinkedFile;
Grid: TStringGrid;
begin begin
Item:=FindUnit(AnUnitName); Item:=FindUnit(AnUnitName);
if Item=nil then begin if Item=nil then begin
@ -794,49 +788,43 @@ begin
SourceFileLabel.Caption:=Format(crsSource, [Item.SrcFile]); SourceFileLabel.Caption:=Format(crsSource, [Item.SrcFile]);
PPUFileLabel.Caption:=Format(crsPPU, [Item.PPUFile]); PPUFileLabel.Caption:=Format(crsPPU, [Item.PPUFile]);
// uses // uses
if Item.UsesUnits<>nil then begin with UsesStringGrid do
UsesStringGrid.RowCount:=1+Item.UsesUnits.Count; if Item.UsesUnits<>nil then begin
for i:=0 to Item.UsesUnits.Count-1 do begin RowCount:=FixedRows+Item.UsesUnits.Count;
UsesUnitName:=Item.UsesUnits[i]; for i:=0 to Item.UsesUnits.Count-1 do
UsesStringGrid.Cells[0,i+1]:=UsesUnitName; Cells[0,FixedRows+i]:=Item.UsesUnits[i];
end; end else
end else begin RowCount:=FixedRows;
UsesStringGrid.RowCount:=1;
end;
// used by // used by
if Item.UsedByUnits<>nil then begin with UsedByStringGrid do
UsedByStringGrid.RowCount:=1+Item.UsedByUnits.Count; if Item.UsedByUnits<>nil then begin
for i:=0 to Item.UsedByUnits.Count-1 do begin RowCount:=FixedRows+Item.UsedByUnits.Count;
UsedByUnitName:=Item.UsedByUnits[i]; for i:=0 to Item.UsedByUnits.Count-1 do
UsedByStringGrid.Cells[0,i+1]:=UsedByUnitName; Cells[0,FixedRows+i]:=Item.UsedByUnits[i];
end; end else
end else begin RowCount:=FixedRows;
UsedByStringGrid.RowCount:=1;
end;
// uses path // uses path
UsesPath:=FindUsesPath(MainItem,Item); UsesPath:=FindUsesPath(MainItem,Item);
try with UsesPathStringGrid do
UsesPathStringGrid.RowCount:=UsesPath.Count+1; try
for i:=0 to UsesPath.Count-1 do begin RowCount:=FixedRows+UsesPath.Count;
UsesPathStringGrid.Cells[0,i+1]:=TPPUDlgListItem(UsesPath[i]).TheUnitName; for i:=0 to UsesPath.Count-1 do
Cells[0,FixedRows+i]:=TPPUDlgListItem(UsesPath[i]).TheUnitName;
finally
UsesPath.Free;
end; end;
finally
UsesPath.Free;
end;
// linked files // linked files
Grid:=UnitLinkedFilesStringGrid; with UnitLinkedFilesStringGrid do
if Item.LinkedFiles<>nil then begin if Item.LinkedFiles<>nil then begin
Grid.RowCount:=1+Item.LinkedFiles.Count; RowCount:=FixedRows+Item.LinkedFiles.Count;
for i:=0 to Item.LinkedFiles.Count-1 do begin for i:=0 to Item.LinkedFiles.Count-1 do begin
LinkedFile:=TPPULinkedFile(Item.LinkedFiles[i]); LinkedFile:=TPPULinkedFile(Item.LinkedFiles[i]);
Grid.Cells[0,i+1]:=PPUEntryName(LinkedFile.ID); Cells[0,FixedRows+i]:=PPUEntryName(LinkedFile.ID);
Grid.Cells[1,i+1]:=LinkedFile.Filename; Cells[1,FixedRows+i]:=LinkedFile.Filename;
Grid.Cells[2,i+1]:=PPULinkContainerFlagToStr(LinkedFile.Flags); Cells[2,FixedRows+i]:=PPULinkContainerFlagToStr(LinkedFile.Flags);
end; end;
end else begin end else
Grid.RowCount:=1; RowCount:=FixedRows;
end;
end; end;
end; end;