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