cody: ppu list: sort for o file size

git-svn-id: trunk@29457 -
This commit is contained in:
mattias 2011-02-10 22:26:47 +00:00
parent da98b47570
commit c13b98aa11
5 changed files with 149 additions and 37 deletions

View File

@ -32,6 +32,14 @@ interface
resourcestring resourcestring
crsNoProject = 'No project'; crsNoProject = 'No project';
crsPleaseOpenAProjectFirst = 'Please open a project first.'; crsPleaseOpenAProjectFirst = 'Please open a project first.';
crsPPUFilesOfProject = 'PPU files of project "%s"';
crsProjectHasNoMainSourceFile = 'Project has no main source file.';
crsMainSourceFile = 'Main source file: %s';
crsSizeOfPpuFile = 'Size of .ppu file';
crsSizeOfOFile = 'Size of .o file';
crsTotal = 'Total';
crsSearching = 'searching ...';
crsMissing = 'missing ...';
implementation implementation

View File

@ -1,6 +1,14 @@
msgid "" msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8" msgstr "Content-Type: text/plain; charset=UTF-8"
#: codystrconsts.crsmainsourcefile
msgid "Main source file: %s"
msgstr ""
#: codystrconsts.crsmissing
msgid "missing ..."
msgstr ""
#: codystrconsts.crsnoproject #: codystrconsts.crsnoproject
msgid "No project" msgid "No project"
msgstr "" msgstr ""
@ -9,3 +17,27 @@ msgstr ""
msgid "Please open a project first." msgid "Please open a project first."
msgstr "" msgstr ""
#: codystrconsts.crsppufilesofproject
msgid "PPU files of project \"%s\""
msgstr ""
#: codystrconsts.crsprojecthasnomainsourcefile
msgid "Project has no main source file."
msgstr ""
#: codystrconsts.crssearching
msgid "searching ..."
msgstr ""
#: codystrconsts.crssizeofofile
msgid "Size of .o file"
msgstr ""
#: codystrconsts.crssizeofppufile
msgid "Size of .ppu file"
msgstr ""
#: codystrconsts.crstotal
msgid "Total"
msgstr ""

View File

@ -9,6 +9,14 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: codystrconsts.crsmainsourcefile
msgid "Main source file: %s"
msgstr ""
#: codystrconsts.crsmissing
msgid "missing ..."
msgstr ""
#: codystrconsts.crsnoproject #: codystrconsts.crsnoproject
msgid "No project" msgid "No project"
msgstr "Проект отсутствует" msgstr "Проект отсутствует"
@ -17,3 +25,27 @@ msgstr "Проект отсутствует"
msgid "Please open a project first." msgid "Please open a project first."
msgstr "Сначала необходимо открыть проект." msgstr "Сначала необходимо открыть проект."
#: codystrconsts.crsppufilesofproject
msgid "PPU files of project \"%s\""
msgstr ""
#: codystrconsts.crsprojecthasnomainsourcefile
msgid "Project has no main source file."
msgstr ""
#: codystrconsts.crssearching
msgid "searching ..."
msgstr ""
#: codystrconsts.crssizeofofile
msgid "Size of .o file"
msgstr ""
#: codystrconsts.crssizeofppufile
msgid "Size of .ppu file"
msgstr ""
#: codystrconsts.crstotal
msgid "Total"
msgstr ""

View File

@ -40,22 +40,27 @@ object PPUListDialog: TPPUListDialog
BorderSpacing.Around = 6 BorderSpacing.Around = 6
ColCount = 3 ColCount = 3
Columns = < Columns = <
item
Title.Caption = 'Unit'
Width = 173
end
item item
Title.Caption = 'Size of .ppu file' Title.Caption = 'Size of .ppu file'
Width = 227 Width = 173
end end
item item
Title.Caption = 'Size of .o file' Title.Caption = 'Size of .o file'
Width = 228 Width = 173
end> end>
DefaultColWidth = 150 DefaultColWidth = 150
FixedCols = 0
FixedRows = 2 FixedRows = 2
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goColSpanning, goDblClickAutoSize, goSmoothScroll] Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goColSpanning, goDblClickAutoSize, goSmoothScroll]
TabOrder = 1 TabOrder = 1
ColWidths = ( ColWidths = (
64 173
227 173
228 173
) )
end end
object ScopeLabel: TLabel object ScopeLabel: TLabel

View File

@ -30,8 +30,8 @@ unit PPUListDlg;
interface interface
uses uses
Classes, SysUtils, LCLProc, FileUtil, LResources, Forms, Controls, Graphics, Classes, SysUtils, math, LCLProc, FileUtil, LResources, Forms, Controls,
Dialogs, ButtonPanel, Grids, StdCtrls, AvgLvlTree, Graphics, Dialogs, ButtonPanel, Grids, StdCtrls, AvgLvlTree,
// IDEIntf // IDEIntf
IDECommands, MenuIntf, ProjectIntf, LazIDEIntf, IDEDialogs, IDEWindowIntf, IDECommands, MenuIntf, ProjectIntf, LazIDEIntf, IDEDialogs, IDEWindowIntf,
// codetools // codetools
@ -71,11 +71,11 @@ type
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
private private
FAProject: TLazProject; FProject: TLazProject;
FIdleConnected: boolean; FIdleConnected: boolean;
FSearchingItems: TAvgLvlTree; // tree of TPPUListItem sorted for TheUnitName FSearchingItems: TAvgLvlTree; // tree of TPPUListItem sorted for TheUnitName
FItems: TAvgLvlTree; // tree of TPPUListItem sorted for TheUnitName FItems: TAvgLvlTree; // tree of TPPUListItem sorted for TheUnitName
procedure SetAProject(const AValue: TLazProject); procedure SetProject(const AValue: TLazProject);
procedure SetIdleConnected(const AValue: boolean); procedure SetIdleConnected(const AValue: boolean);
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean); procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
procedure AddUses(SrcItem: TPPUListItem; UsedUnits: TStrings); procedure AddUses(SrcItem: TPPUListItem; UsedUnits: TStrings);
@ -83,9 +83,11 @@ type
procedure UpdateAll; procedure UpdateAll;
procedure UpdateUnitsGrid; procedure UpdateUnitsGrid;
function DoubleAsPercentage(const d: double): string; function DoubleAsPercentage(const d: double): string;
function BytesToStr(b: int64): string;
function FindUnitInList(AnUnitName: string; List: TStrings): integer; function FindUnitInList(AnUnitName: string; List: TStrings): integer;
function CompareUnits({%H-}Tree: TAvgLvlTree; Data1, Data2: Pointer): integer;
public public
property AProject: TLazProject read FAProject write SetAProject; property AProject: TLazProject read FProject write SetProject;
property IdleConnected: boolean read FIdleConnected write SetIdleConnected; property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
end; end;
@ -164,7 +166,6 @@ begin
FSearchingItems:=TAvgLvlTree.Create(@ComparePPUListItems); FSearchingItems:=TAvgLvlTree.Create(@ComparePPUListItems);
FItems:=TAvgLvlTree.Create(@ComparePPUListItems); FItems:=TAvgLvlTree.Create(@ComparePPUListItems);
Caption:='Used ppu files of project';
IDEDialogLayoutList.ApplyLayout(Self); IDEDialogLayoutList.ApplyLayout(Self);
end; end;
@ -181,10 +182,10 @@ begin
IDEDialogLayoutList.SaveLayout(Self); IDEDialogLayoutList.SaveLayout(Self);
end; end;
procedure TPPUListDialog.SetAProject(const AValue: TLazProject); procedure TPPUListDialog.SetProject(const AValue: TLazProject);
begin begin
if FAProject=AValue then exit; if FProject=AValue then exit;
FAProject:=AValue; FProject:=AValue;
UpdateAll; UpdateAll;
end; end;
@ -215,14 +216,14 @@ begin
s:=AProject.Title s:=AProject.Title
else else
s:=ExtractFileNameOnly(AProject.ProjectInfoFile); s:=ExtractFileNameOnly(AProject.ProjectInfoFile);
Caption:='PPU files of project "'+dbgstr(s)+'"'; Caption:=Format(crsPPUFilesOfProject, [dbgstr(s)]);
// ScopeLabel // ScopeLabel
MainUnit:=AProject.MainFile; MainUnit:=AProject.MainFile;
if MainUnit=nil then begin if MainUnit=nil then begin
ScopeLabel.Caption:='Project has no main source file.'; ScopeLabel.Caption:=crsProjectHasNoMainSourceFile;
end else begin end else begin
ScopeLabel.Caption:='Main source file: '+MainUnit.Filename; ScopeLabel.Caption:=Format(crsMainSourceFile, [MainUnit.Filename]);
Item:=TPPUListItem.Create; Item:=TPPUListItem.Create;
Item.TheUnitName:=ExtractFileName(MainUnit.Filename); Item.TheUnitName:=ExtractFileName(MainUnit.Filename);
Item.SrcFile:=MainUnit.Filename; Item.SrcFile:=MainUnit.Filename;
@ -248,30 +249,28 @@ procedure TPPUListDialog.UpdateUnitsGrid;
function SizeToStr(TheBytes: int64; ThePercent: double): string; function SizeToStr(TheBytes: int64; ThePercent: double): string;
begin begin
Result:=IntToStr(TheBytes)+' bytes / '+DoubleAsPercentage(ThePercent); Result:=BytesToStr(TheBytes)+' / '+DoubleAsPercentage(ThePercent);
end; end;
var var
Grid: TStringGrid; Grid: TStringGrid;
SortedItems: TFPList;
Node: TAvgLvlTreeNode; Node: TAvgLvlTreeNode;
Item: TPPUListItem; Item: TPPUListItem;
i: Integer;
Row: Integer; Row: Integer;
s: String; s: String;
TotalPPUBytes, TotalOBytes: int64; TotalPPUBytes, TotalOBytes: int64;
SortedItems: TAvgLvlTree;
begin begin
Grid:=UnitsStringGrid; Grid:=UnitsStringGrid;
Grid.BeginUpdate; Grid.BeginUpdate;
Grid.RowCount:=2+FItems.Count;
// header // header
Grid.Cells[0,0]:='Unit'; Grid.Cells[0,0]:='Unit';
Grid.Cells[1,0]:='Size of .ppu file'; Grid.Cells[1, 0]:=crsSizeOfPpuFile;
Grid.Cells[2,0]:='Size of .o file'; Grid.Cells[2, 0]:=crsSizeOfOFile;
SortedItems:=TFPList.Create; SortedItems:=TAvgLvlTree.CreateObjectCompare(@CompareUnits);
try try
Node:=FItems.FindLowest; Node:=FItems.FindLowest;
TotalPPUBytes:=0; TotalPPUBytes:=0;
@ -286,41 +285,42 @@ begin
Node:=FItems.FindSuccessor(Node); Node:=FItems.FindSuccessor(Node);
end; end;
Grid.RowCount:=2+SortedItems.Count;
// total // total
Grid.Cells[0,1]:='Total'; Grid.Cells[0,1]:=crsTotal;
Grid.Cells[1,1]:=SizeToStr(TotalPPUBytes,1.0); Grid.Cells[1,1]:=SizeToStr(TotalPPUBytes,1.0);
Grid.Cells[2,1]:=SizeToStr(TotalOBytes,1.0); Grid.Cells[2,1]:=SizeToStr(TotalOBytes,1.0);
// ToDo: sort // fill grid
Row:=2; Row:=2;
for i:=0 to SortedItems.Count-1 do begin Node:=SortedItems.FindLowest;
Item:=TPPUListItem(SortedItems[i]); while Node<>nil do begin
Item:=TPPUListItem(Node.Data);
Grid.Cells[0,Row]:=Item.TheUnitName; Grid.Cells[0,Row]:=Item.TheUnitName;
// .ppu size // .ppu size
s:=''; s:='';
if Item.PPUFile='' then if Item.PPUFile='' then
s:='searching ...' s:=crsSearching
else if Item.PPUFile=PPUFileNotFound then else if Item.PPUFile=PPUFileNotFound then
s:='missing ...' s:=crsMissing
else else
s:=IntToStr(Item.PPUFileSize)+' bytes / ' s:=SizeToStr(Item.PPUFileSize,double(Item.PPUFileSize)/TotalPPUBytes);
+DoubleAsPercentage(double(Item.PPUFileSize)/TotalPPUBytes);
Grid.Cells[1,Row]:=s; Grid.Cells[1,Row]:=s;
// .o size // .o size
s:=''; s:='';
if Item.OFile='' then if Item.OFile='' then
s:='searching ...' s:=crsSearching
else if Item.OFile=PPUFileNotFound then else if Item.OFile=PPUFileNotFound then
s:='missing ...' s:=crsMissing
else else
s:=IntToStr(Item.OFileSize)+' bytes / ' s:=SizeToStr(Item.OFileSize,double(Item.OFileSize)/TotalOBytes);
+DoubleAsPercentage(double(Item.OFileSize)/TotalOBytes);
Grid.Cells[2,Row]:=s; Grid.Cells[2,Row]:=s;
inc(Row); inc(Row);
Node:=SortedItems.FindSuccessor(Node);
end; end;
finally finally
@ -338,6 +338,24 @@ begin
+DefaultFormatSettings.ThousandSeparator+RightStr(Result,2)+'%'; +DefaultFormatSettings.ThousandSeparator+RightStr(Result,2)+'%';
end; end;
function TPPUListDialog.BytesToStr(b: int64): string;
begin
Result:='';
if b>80000 then begin
Result:='k';
b:=b div 1000;
end;
if b>80000 then begin
Result:='m';
b:=b div 1000;
end;
if b>80000 then begin
Result:='g';
b:=b div 1000;
end;
Result:=IntToStr(b)+' '+Result+'bytes';
end;
function TPPUListDialog.FindUnitInList(AnUnitName: string; List: TStrings function TPPUListDialog.FindUnitInList(AnUnitName: string; List: TStrings
): integer; ): integer;
begin begin
@ -347,6 +365,23 @@ begin
dec(Result); dec(Result);
end; end;
function TPPUListDialog.CompareUnits(Tree: TAvgLvlTree; Data1, Data2: Pointer
): integer;
var
Item1: TPPUListItem absolute Data1;
Item2: TPPUListItem absolute Data2;
Size1: Int64;
Size2: Int64;
begin
// compare size of .o file
Size1:=Max(0,Item1.OFileSize);
Size2:=Max(0,Item2.OFileSize);
if Size1>Size2 then exit(-1)
else if Size1<Size2 then exit(1);
// compare unit name
Result:=-SysUtils.CompareText(Item1.TheUnitName,Item2.TheUnitName);
end;
procedure TPPUListDialog.OnIdle(Sender: TObject; var Done: Boolean); procedure TPPUListDialog.OnIdle(Sender: TObject; var Done: Boolean);
const const
MaxNonIdleTime = (1/86400)/2; MaxNonIdleTime = (1/86400)/2;