mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-03 22:58:22 +02:00
Converter: improved replacement function categories again.
git-svn-id: trunk@26723 -
This commit is contained in:
parent
5d5e183f9d
commit
db08d1db24
@ -710,7 +710,7 @@ var
|
||||
and not fDefinedProcNames.Find(FuncName, x)
|
||||
then begin
|
||||
FuncDefInfo:=fReplaceFuncs.FuncAtInd(i);
|
||||
if fReplaceFuncs.CategoryInUse.Find(FuncDefInfo.Category, x)
|
||||
if fReplaceFuncs.Categories.Find(FuncDefInfo.Category, x)
|
||||
and not (aIsConsoleApp and (FuncDefInfo.Category='UTF8Names'))
|
||||
then begin
|
||||
// Create a new replacement object for params, position and other info.
|
||||
|
@ -188,6 +188,7 @@ procedure LoadFuncReplacements(Config: TConfigStorage;
|
||||
var
|
||||
SubPath: String;
|
||||
xCategory, xDelphiFunc, xReplacement, xPackage, xUnitName: String;
|
||||
CategUsed: Boolean;
|
||||
Cnt, i: Integer;
|
||||
begin
|
||||
aFuncsAndCateg.Clear;
|
||||
@ -207,7 +208,8 @@ begin
|
||||
for i:=0 to Cnt-1 do begin
|
||||
SubPath:=CategPath+'Item'+IntToStr(i)+'/';
|
||||
xCategory:=Config.GetValue(SubPath+'Name','');
|
||||
aFuncsAndCateg.AddCategory(xCategory);
|
||||
CategUsed:=Config.GetValue(SubPath+'InUse',True);
|
||||
aFuncsAndCateg.AddCategory(xCategory, CategUsed);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -237,15 +239,16 @@ begin
|
||||
Config.DeletePath(SubPath);
|
||||
end;
|
||||
// Categories
|
||||
Config.SetDeleteValue(CategPath+'Count', aFuncsAndCateg.CategoryInUse.Count, 0);
|
||||
for i:=0 to aFuncsAndCateg.CategoryInUse.Count-1 do begin
|
||||
s:=aFuncsAndCateg.CategoryInUse[i];
|
||||
Config.SetDeleteValue(CategPath+'Count', aFuncsAndCateg.Categories.Count, 0);
|
||||
for i:=0 to aFuncsAndCateg.Categories.Count-1 do begin
|
||||
s:=aFuncsAndCateg.Categories[i];
|
||||
if s<>'' then begin
|
||||
SubPath:=CategPath+'Item'+IntToStr(i)+'/';
|
||||
Config.SetDeleteValue(SubPath+'Name',s,'');
|
||||
Config.SetDeleteValue(SubPath+'InUse',aFuncsAndCateg.CategoryIsUsed(i),True);
|
||||
end;
|
||||
end;
|
||||
for i:=aFuncsAndCateg.CategoryInUse.Count to aFuncsAndCateg.CategoryInUse.Count+10 do begin
|
||||
for i:=aFuncsAndCateg.Categories.Count to aFuncsAndCateg.Categories.Count+10 do begin
|
||||
SubPath:=CategPath+'Item'+IntToStr(i)+'/';
|
||||
Config.DeletePath(SubPath);
|
||||
end;
|
||||
@ -259,10 +262,19 @@ var
|
||||
TheMap: TStringToStringTree;
|
||||
Categ: string;
|
||||
|
||||
procedure MapReplacement(ADelphi, ALCL: string);
|
||||
procedure MapReplacement(aDelphi, aLCL: string);
|
||||
begin
|
||||
if not TheMap.Contains(ADelphi) then
|
||||
TheMap[ADelphi]:=ALCL;
|
||||
if not TheMap.Contains(aDelphi) then
|
||||
TheMap[aDelphi]:=aLCL;
|
||||
end;
|
||||
|
||||
procedure AddDefaultCategory(aCategory: string);
|
||||
var
|
||||
x: integer;
|
||||
begin
|
||||
with fReplaceFuncs do
|
||||
if not Categories.Find(aCategory, x) then
|
||||
AddCategory(aCategory, True);
|
||||
end;
|
||||
|
||||
begin
|
||||
@ -328,8 +340,8 @@ begin
|
||||
with fReplaceFuncs do begin
|
||||
// File name encoding.
|
||||
Categ:='UTF8Names';
|
||||
if AddFunc(Categ,'FileExists', 'FileExistsUTF8($1)','LCL','FileUtil')<>-1 then
|
||||
AddCategory(Categ); // Use the category by default if the func was added.
|
||||
AddDefaultCategory(Categ);
|
||||
AddFunc(Categ,'FileExists', 'FileExistsUTF8($1)', 'LCL','FileUtil');
|
||||
AddFunc(Categ,'FileAge', 'FileAgeUTF8($1)', 'LCL','FileUtil');
|
||||
AddFunc(Categ,'DirectoryExists', 'DirectoryExistsUTF8($1)', 'LCL','FileUtil');
|
||||
AddFunc(Categ,'ExpandFileName', 'ExpandFileNameUTF8($1)', 'LCL','FileUtil');
|
||||
@ -352,16 +364,16 @@ begin
|
||||
AddFunc(Categ,'ForceDirectories', 'ForceDirectoriesUTF8($1)', 'LCL','FileUtil');
|
||||
// File functions using a handle.
|
||||
Categ:='FileHandle';
|
||||
if AddFunc(Categ,'CreateFile','FileCreate($1)','','SysUtils')<>-1 then
|
||||
AddCategory(Categ);
|
||||
AddFunc(Categ, 'GetFileSize','FileSize($1)' ,'','SysUtils');
|
||||
AddFunc(Categ, 'ReadFile', 'FileRead($1)' ,'','SysUtils');
|
||||
AddFunc(Categ, 'CloseHandle','FileClose($1)','','SysUtils');
|
||||
AddDefaultCategory(Categ);
|
||||
AddFunc(Categ, 'CreateFile', 'FileCreate($1)','','SysUtils');
|
||||
AddFunc(Categ, 'GetFileSize','FileSize($1)' ,'','SysUtils');
|
||||
AddFunc(Categ, 'ReadFile', 'FileRead($1)' ,'','SysUtils');
|
||||
AddFunc(Categ, 'CloseHandle','FileClose($1)' ,'','SysUtils');
|
||||
// Others
|
||||
Categ:='Other';
|
||||
if AddFunc(Categ, 'ShellExecute',
|
||||
'if $3 match ":/" then OpenURL($3); OpenDocument($3)', '', '')<>-1 then
|
||||
AddCategory(Categ);
|
||||
AddDefaultCategory(Categ);
|
||||
AddFunc(Categ, 'ShellExecute',
|
||||
'if $3 match ":/" then OpenURL($3); OpenDocument($3)', '', '');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -50,18 +50,21 @@ type
|
||||
|
||||
TFuncsAndCategories = class
|
||||
private
|
||||
fFuncs: TStringList; // Objects property has TFuncReplacement items.
|
||||
fCategInUse: TStringList; // Categories to be replaced.
|
||||
// Delphi func names, objects property has TFuncReplacement items.
|
||||
fFuncs: TStringList;
|
||||
// Category names, objects property has boolean info Used/Not used.
|
||||
fCategories: TStringList;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
function AddFunc(aCategory, aDelphiFunc, aReplaceFunc, aPackage, aUnitName: string): integer;
|
||||
function AddCategory(aCategory: string): integer;
|
||||
function FuncAtInd(Ind: integer): TFuncReplacement;
|
||||
function AddCategory(aCategory: string; aUsed: Boolean): integer;
|
||||
function CategoryIsUsed(Ind: integer): Boolean;
|
||||
public
|
||||
property Funcs: TStringList read fFuncs;
|
||||
property CategoryInUse: TStringList read fCategInUse;
|
||||
property Categories: TStringList read fCategories;
|
||||
end;
|
||||
|
||||
{ TReplaceFuncsForm }
|
||||
@ -280,14 +283,14 @@ begin
|
||||
fFuncs:=TStringList.Create;
|
||||
fFuncs.Sorted:=True;
|
||||
fFuncs.CaseSensitive:=False;
|
||||
fCategInUse:=TStringList.Create;
|
||||
fCategInUse.Sorted:=True;
|
||||
fCategInUse.Duplicates:=dupIgnore;
|
||||
fCategories:=TStringList.Create;
|
||||
fCategories.Sorted:=True;
|
||||
fCategories.Duplicates:=dupIgnore;
|
||||
end;
|
||||
|
||||
destructor TFuncsAndCategories.Destroy;
|
||||
begin
|
||||
fCategInUse.Free;
|
||||
fCategories.Free;
|
||||
fFuncs.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
@ -299,7 +302,7 @@ begin
|
||||
for i := 0 to fFuncs.Count-1 do
|
||||
fFuncs.Objects[i].Free;
|
||||
fFuncs.Clear;
|
||||
fCategInUse.Clear;
|
||||
fCategories.Clear;
|
||||
end;
|
||||
|
||||
function TFuncsAndCategories.AddFunc(
|
||||
@ -318,11 +321,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TFuncsAndCategories.AddCategory(aCategory: string): integer;
|
||||
begin
|
||||
Result:=fCategInUse.Add(aCategory);
|
||||
end;
|
||||
|
||||
function TFuncsAndCategories.FuncAtInd(Ind: integer): TFuncReplacement;
|
||||
begin
|
||||
Result:=nil;
|
||||
@ -330,6 +328,26 @@ begin
|
||||
Result:=TFuncReplacement(fFuncs.Objects[Ind]);
|
||||
end;
|
||||
|
||||
function TFuncsAndCategories.AddCategory(aCategory: string; aUsed: Boolean): integer;
|
||||
var
|
||||
CategUsed: PtrInt;
|
||||
begin
|
||||
CategUsed:=0;
|
||||
if aUsed then
|
||||
CategUsed:=1;
|
||||
Result:=fCategories.AddObject(aCategory, TObject(CategUsed));
|
||||
end;
|
||||
|
||||
function TFuncsAndCategories.CategoryIsUsed(Ind: integer): Boolean;
|
||||
var
|
||||
CategUsed: PtrInt;
|
||||
begin
|
||||
CategUsed:=0;
|
||||
if fCategories[Ind]<>'' then
|
||||
CategUsed:=PtrInt(fCategories.Objects[Ind]);
|
||||
Result:=CategUsed=1;
|
||||
end;
|
||||
|
||||
|
||||
{ TReplaceFuncsForm }
|
||||
|
||||
@ -391,35 +409,25 @@ function TReplaceFuncsForm.FromFuncListToUI(aFuncsAndCateg: TFuncsAndCategories)
|
||||
// Copy strings from Map to Grid.
|
||||
var
|
||||
FuncRepl: TFuncReplacement;
|
||||
NewCategories: TStringList;
|
||||
i, x: Integer;
|
||||
NewCatInd: longint;
|
||||
i: Integer;
|
||||
begin
|
||||
Result:=true;
|
||||
NewCategories:=TStringList.Create;
|
||||
NewCategories.Sorted:=True;
|
||||
try
|
||||
Grid.BeginUpdate; // Skip the fixed row in grid.
|
||||
for i:=1 to aFuncsAndCateg.fFuncs.Count do begin
|
||||
if Grid.RowCount<i+2 then
|
||||
Grid.RowCount:=i+2; // Leave one empty row to the end.
|
||||
FuncRepl:=TFuncReplacement(aFuncsAndCateg.fFuncs.Objects[i-1]);
|
||||
Grid.Cells[0,i]:=FuncRepl.fCategory;
|
||||
Grid.Cells[1,i]:=aFuncsAndCateg.fFuncs[i-1]; // Delphi function name
|
||||
Grid.Cells[2,i]:=FuncRepl.fReplClause;
|
||||
Grid.Cells[3,i]:=FuncRepl.PackageName;
|
||||
Grid.Cells[4,i]:=FuncRepl.fUnitName;
|
||||
if not NewCategories.Find(FuncRepl.fCategory, x) then begin
|
||||
CategoryListBox.Items.Add(FuncRepl.fCategory);
|
||||
NewCatInd:=NewCategories.Add(FuncRepl.fCategory);
|
||||
CategoryListBox.Checked[NewCatInd]:=
|
||||
aFuncsAndCateg.fCategInUse.Find(FuncRepl.fCategory, x);
|
||||
end;
|
||||
end;
|
||||
Grid.EndUpdate;
|
||||
finally
|
||||
NewCategories.Free;
|
||||
Grid.BeginUpdate; // Skip the fixed row in grid.
|
||||
for i:=1 to aFuncsAndCateg.fFuncs.Count do begin
|
||||
if Grid.RowCount<i+2 then
|
||||
Grid.RowCount:=i+2; // Leave one empty row to the end.
|
||||
FuncRepl:=TFuncReplacement(aFuncsAndCateg.fFuncs.Objects[i-1]);
|
||||
Grid.Cells[0,i]:=FuncRepl.fCategory;
|
||||
Grid.Cells[1,i]:=aFuncsAndCateg.fFuncs[i-1]; // Delphi function name
|
||||
Grid.Cells[2,i]:=FuncRepl.fReplClause;
|
||||
Grid.Cells[3,i]:=FuncRepl.PackageName;
|
||||
Grid.Cells[4,i]:=FuncRepl.fUnitName;
|
||||
end;
|
||||
for i:=0 to aFuncsAndCateg.fCategories.Count-1 do begin
|
||||
CategoryListBox.Items.Add(aFuncsAndCateg.fCategories[i]);
|
||||
CategoryListBox.Checked[i]:=aFuncsAndCateg.CategoryIsUsed(i);
|
||||
end;
|
||||
Grid.EndUpdate;
|
||||
end;
|
||||
|
||||
function TReplaceFuncsForm.FromUIToFuncList(aFuncsAndCateg: TFuncsAndCategories): boolean;
|
||||
@ -438,8 +446,7 @@ begin
|
||||
Grid.Cells[4,i]);
|
||||
// Copy checked (used) categories.
|
||||
for i:=0 to CategoryListBox.Count-1 do
|
||||
if CategoryListBox.Checked[i] then
|
||||
aFuncsAndCateg.AddCategory(CategoryListBox.Items[i]);
|
||||
aFuncsAndCateg.AddCategory(CategoryListBox.Items[i], CategoryListBox.Checked[i]);
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user