Converter: implemented fully the coordinate offsets. GUI improvements.

git-svn-id: trunk@27346 -
This commit is contained in:
juha 2010-09-13 09:37:06 +00:00
parent f3fec16c04
commit e1ba658ec6
10 changed files with 312 additions and 91 deletions

View File

@ -66,7 +66,7 @@ type
function FixMainClassAncestor(const AClassName: string; function FixMainClassAncestor(const AClassName: string;
AReplaceTypes: TStringToStringTree): boolean; AReplaceTypes: TStringToStringTree): boolean;
function CheckTopOffsets(LFMBuf: TCodeBuffer; LFMTree: TLFMTree; function CheckTopOffsets(LFMBuf: TCodeBuffer; LFMTree: TLFMTree;
ParentOffsets: TStringToStringTree; ValueNodes: TObjectList): boolean; VisOffsets: TVisualOffsets; ValueNodes: TObjectList): boolean;
public public
property Ask: Boolean read fAsk write fAsk; property Ask: Boolean read fAsk write fAsk;
property HasFormFile: boolean read fHasFormFile write fHasFormFile; property HasFormFile: boolean read fHasFormFile write fHasFormFile;
@ -856,11 +856,11 @@ begin
end; end;
function TConvDelphiCodeTool.CheckTopOffsets(LFMBuf: TCodeBuffer; LFMTree: TLFMTree; function TConvDelphiCodeTool.CheckTopOffsets(LFMBuf: TCodeBuffer; LFMTree: TLFMTree;
ParentOffsets: TStringToStringTree; ValueNodes: TObjectList): boolean; VisOffsets: TVisualOffsets; ValueNodes: TObjectList): boolean;
// Collect a list of Top attributes for components that are inside // Collect a list of Top attributes for components that are inside
// a visual container component. An offset will be added to those attributes. // a visual container component. An offset will be added to those attributes.
// Parameters: ParentOffsets has names of parent visual container types. // Parameters: ParentOffsets has names of parent visual container types.
// ValueNodes - the found Top attributes are added here as TTopOffset objects. // ValueNodes - the found Top attributes are added here as TSrcPropOffset objects.
// Based on function CheckLFM. // Based on function CheckLFM.
var var
RootContext: TFindContext; RootContext: TFindContext;
@ -1077,21 +1077,22 @@ var
// ParentContext is the context, where properties are searched. // ParentContext is the context, where properties are searched.
// This can be a class or a property. // This can be a class or a property.
var var
i: Integer; i, ind: Integer;
ValNode: TLFMValueNode; ValNode: TLFMValueNode;
CurName, GrandName: string; CurName, GrandName, Prop: string;
CurPropertyContext: TFindContext; CurPropertyContext: TFindContext;
SearchContext: TFindContext; SearchContext: TFindContext;
begin begin
// find complete property name // find complete property name
if LFMProperty.CompleteName='' then exit; Prop:=LFMProperty.CompleteName;
if LFMProperty.CompleteName='Top' then begin if Prop='' then exit;
if (Prop='Top') or (Prop='Left') then begin
CurName:=ParentContext.Tool.ExtractClassName(ParentContext.Node, False); CurName:=ParentContext.Tool.ExtractClassName(ParentContext.Node, False);
GrandName:=GrandParentContext.Tool.ExtractClassName(GrandParentContext.Node, False); GrandName:=GrandParentContext.Tool.ExtractClassName(GrandParentContext.Node, False);
if ParentOffsets[GrandName]<>'' then begin if VisOffsets.Find(GrandName, ind) then begin
if LFMProperty.FirstChild is TLFMValueNode then begin if LFMProperty.FirstChild is TLFMValueNode then begin
ValNode:=LFMProperty.FirstChild as TLFMValueNode; ValNode:=LFMProperty.FirstChild as TLFMValueNode;
ValueNodes.Add(TTopOffset.Create(GrandName, CurName, ValNode.StartPos)); ValueNodes.Add(TSrcPropOffset.Create(GrandName,CurName,Prop,ValNode.StartPos));
end; end;
end; end;
end; end;

View File

@ -800,8 +800,7 @@ begin
end; end;
if not fSettings.AutoReplaceUnits then begin if not fSettings.AutoReplaceUnits then begin
// Edit, then remove or replace units. // Edit, then remove or replace units.
Result:=EditMap(MapToEdit, 'Units to replace in '+ExtractFileName(fOrigUnitFilename), Result:=EditMap(MapToEdit, 'Units to replace in '+ExtractFileName(fOrigUnitFilename));
lisConvDelphiName, lisConvNewName);
if Result<>mrOK then exit; if Result<>mrOK then exit;
// Iterate the map and rename / remove. // Iterate the map and rename / remove.
Node:=MapToEdit.Tree.FindLowest; Node:=MapToEdit.Tree.FindLowest;

View File

@ -5,26 +5,61 @@ unit ConverterTypes;
interface interface
uses uses
Classes, SysUtils; Classes, SysUtils, contnrs;
type type
{ TopOffset } { TopOffset }
// Used when fixing top coordinates of controls inside a visual container. // Used when fixing top coordinates of controls inside a visual container.
TTopOffset = class TSrcPropOffset = class
private private
fParentType: string; fParentType: string;
fChildType: string; fChildType: string;
fPropName: string;
fStartPos: integer; fStartPos: integer;
public public
constructor Create(aParentType, aChildType: string; aStartPos: integer); constructor Create(aParentType, aChildType, aPropName: string; aStartPos: integer);
destructor Destroy; override; destructor Destroy; override;
property ParentType: string read fParentType; property ParentType: string read fParentType;
property ChildType: string read fChildType; property ChildType: string read fChildType;
property PropName: string read fPropName;
property StartPos: integer read fStartPos; property StartPos: integer read fStartPos;
end; end;
{ TVisualOffset }
// User defined settings.
TVisualOffset = class
private
fParentType: string;
fTop: Integer;
fLeft: Integer;
public
constructor Create(const aParentType: string; aTop, aLeft: Integer);
destructor Destroy; override;
function ByProperty(aPropName: string): Integer;
public
property ParentType: string read fParentType;
property Top: Integer read fTop;
property Left: Integer read fLeft;
end;
{ TVisualOffsets }
TVisualOffsets = class(TObjectList)
private
function GetVisualOffset(Index: Integer): TVisualOffset;
procedure SetVisualOffset(Index: Integer; const AValue: TVisualOffset);
public
constructor Create;
destructor Destroy; override;
function Find(aParentType: string; var Index: Integer): Boolean;
function AddVisualOffset(const aParentType: string; aTop, aLeft: Integer): integer;
property Items[Index: Integer]: TVisualOffset read GetVisualOffset
write SetVisualOffset; default;
end;
// types for errors // types for errors
{ EConverterError } { EConverterError }
@ -46,18 +81,94 @@ end;
{ TopOffset } { TopOffset }
constructor TTopOffset.Create(aParentType, aChildType: string; aStartPos: integer); constructor TSrcPropOffset.Create(aParentType, aChildType, aPropName: string; aStartPos: integer);
begin begin
fParentType:=aParentType; fParentType:=aParentType;
fChildType:=aChildType; fChildType:=aChildType;
fPropName:=aPropName;
fStartPos:=aStartPos; fStartPos:=aStartPos;
end; end;
destructor TTopOffset.Destroy; destructor TSrcPropOffset.Destroy;
begin begin
inherited Destroy; inherited Destroy;
end; end;
{ TVisualOffset }
constructor TVisualOffset.Create(const aParentType: string; aTop, aLeft: Integer);
begin
fParentType:=aParentType;
fTop:=aTop;
fLeft:=aLeft;
end;
destructor TVisualOffset.Destroy;
begin
inherited Destroy;
end;
function TVisualOffset.ByProperty(aPropName: string): Integer;
begin
if aPropName='Top' then
Result:=Top
else if aPropName='Left' then
Result:=Left
else
Result:=0
end;
{ TVisualOffsets }
constructor TVisualOffsets.Create;
begin
inherited Create;
end;
destructor TVisualOffsets.Destroy;
begin
inherited Destroy;
end;
function TVisualOffsets.Find(aParentType: string; var Index: Integer): Boolean;
var
i: Integer;
begin
Result:=False;
Index:=-1;
for i:=0 to Count-1 do
if Items[i].fParentType = aParentType then begin
Result:=True;
Index:=i;
Break;
end;
end;
function TVisualOffsets.AddVisualOffset(const aParentType: string; aTop, aLeft: Integer): integer;
// This is called when settings are read or when user made changes in GUI.
// Returns index for the added object, or -1 if not added (duplicate).
var
x: integer;
begin
Result:=-1;
if (aParentType<>'') and not Find(aParentType, x) then
Result:=Add(TVisualOffset.Create(aParentType, aTop, aLeft));
end;
// Getter / Setter :
function TVisualOffsets.GetVisualOffset(Index: Integer): TVisualOffset;
begin
Result:=Inherited Items[Index] as TVisualOffset;
end;
procedure TVisualOffsets.SetVisualOffset(Index: Integer; const AValue: TVisualOffset);
begin
Inherited Items[Index]:=AValue;
end;
end. end.

View File

@ -3,6 +3,7 @@ object ConvertSettingsForm: TConvertSettingsForm
Height = 483 Height = 483
Top = 298 Top = 298
Width = 637 Width = 637
ActiveControl = ProjectPathEdit
Caption = 'Convert Delphi unit, project or package ' Caption = 'Convert Delphi unit, project or package '
ClientHeight = 483 ClientHeight = 483
ClientWidth = 637 ClientWidth = 637
@ -78,7 +79,7 @@ object ConvertSettingsForm: TConvertSettingsForm
Hint = 'Some Delphi functions can be replaced with a LCL function' Hint = 'Some Delphi functions can be replaced with a LCL function'
Top = 156 Top = 156
Width = 272 Width = 272
Caption = 'Top Coordinate Offsets' Caption = 'Coordinate Offsets'
OnClick = VisualOffsButtonClick OnClick = VisualOffsButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True

View File

@ -31,9 +31,9 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, IDEProcs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, IDEProcs,
StdCtrls, EditBtn, Buttons, ExtCtrls, DialogProcs, LazarusIDEStrConsts, StdCtrls, EditBtn, Buttons, ExtCtrls, DialogProcs, ButtonPanel,
CodeToolsStructs, AVL_Tree, BaseIDEIntf, LazConfigStorage, LazarusIDEStrConsts, CodeToolsStructs, AVL_Tree, BaseIDEIntf, LazConfigStorage,
ButtonPanel, ReplaceNamesUnit, ReplaceFuncsUnit; ConverterTypes, ReplaceNamesUnit, ReplaceFuncsUnit;
type type
@ -61,10 +61,10 @@ type
fReplaceUnits: TStringToStringTree; fReplaceUnits: TStringToStringTree;
// Delphi types mapped to Lazarus types, will be replaced. // Delphi types mapped to Lazarus types, will be replaced.
fReplaceTypes: TStringToStringTree; fReplaceTypes: TStringToStringTree;
// Top coordinate shift of components in a visual container.
fVisualOffsets: TStringToStringTree;
// Delphi global function names mapped to FCL/LCL functions. // Delphi global function names mapped to FCL/LCL functions.
fReplaceFuncs: TFuncsAndCategories; fReplaceFuncs: TFuncsAndCategories;
// Coordinate offsets of components in a visual container.
fVisualOffsets: TVisualOffsets;
// Getter / setter: // Getter / setter:
function GetBackupPath: String; function GetBackupPath: String;
procedure SetMainFilename(const AValue: String); procedure SetMainFilename(const AValue: String);
@ -102,8 +102,8 @@ type
property EnableVisualOffs: boolean read fEnableVisualOffs; property EnableVisualOffs: boolean read fEnableVisualOffs;
property ReplaceUnits: TStringToStringTree read fReplaceUnits; property ReplaceUnits: TStringToStringTree read fReplaceUnits;
property ReplaceTypes: TStringToStringTree read fReplaceTypes; property ReplaceTypes: TStringToStringTree read fReplaceTypes;
property VisualOffsets: TStringToStringTree read fVisualOffsets;
property ReplaceFuncs: TFuncsAndCategories read fReplaceFuncs; property ReplaceFuncs: TFuncsAndCategories read fReplaceFuncs;
property VisualOffsets: TVisualOffsets read fVisualOffsets;
end; end;
@ -127,9 +127,9 @@ type
UnitReplaceButton: TBitBtn; UnitReplaceButton: TBitBtn;
SettingsGroupBox: TGroupBox; SettingsGroupBox: TGroupBox;
MissingStuffGroupBox: TGroupBox; MissingStuffGroupBox: TGroupBox;
procedure FuncReplaceButtonClick(Sender: TObject);
procedure SameDFMCheckBoxChange(Sender: TObject); procedure SameDFMCheckBoxChange(Sender: TObject);
procedure TypeReplaceButtonClick(Sender: TObject); procedure TypeReplaceButtonClick(Sender: TObject);
procedure FuncReplaceButtonClick(Sender: TObject);
procedure VisualOffsButtonClick(Sender: TObject); procedure VisualOffsButtonClick(Sender: TObject);
procedure UnitReplaceButtonClick(Sender: TObject); procedure UnitReplaceButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
@ -268,6 +268,47 @@ begin
end; end;
end; end;
// Load and store configuration in VisualOffsets :
procedure LoadVisualOffsets(Config: TConfigStorage; const Path: string;
aVisualOffsets: TVisualOffsets);
var
ParentType, SubPath: String;
xTop, xLeft: Integer;
Cnt, i: Integer;
begin
aVisualOffsets.Clear;
Cnt:=Config.GetValue(Path+'Count', 0);
for i:=0 to Cnt-1 do begin
SubPath:=Path+'Item'+IntToStr(i)+'/';
ParentType:=Config.GetValue(SubPath+'ParentType','');
xTop :=Config.GetValue(SubPath+'Top',0);
xLeft:=Config.GetValue(SubPath+'Left',0);
aVisualOffsets.Add(TVisualOffset.Create(ParentType, xTop, xLeft));
end;
end;
procedure SaveVisualOffsets(Config: TConfigStorage; const Path: string;
aVisualOffsets: TVisualOffsets);
var
offs: TVisualOffset;
SubPath: String;
i: Integer;
begin
Config.SetDeleteValue(Path+'Count', aVisualOffsets.Count, 0);
for i:=0 to aVisualOffsets.Count-1 do begin
offs:=aVisualOffsets[i];
SubPath:=Path+'Item'+IntToStr(i)+'/';
Config.SetDeleteValue(SubPath+'ParentType',offs.ParentType,'');
Config.SetDeleteValue(SubPath+'Top' ,offs.Top,0);
Config.SetDeleteValue(SubPath+'Left' ,offs.Left,0);
end;
// Remove leftover items in case the list has become shorter.
for i:=aVisualOffsets.Count to aVisualOffsets.Count+10 do begin
SubPath:=Path+'Item'+IntToStr(i)+'/';
Config.DeletePath(SubPath);
end;
end;
{ TConvertSettings } { TConvertSettings }
@ -297,8 +338,8 @@ begin
fMainPath:=''; fMainPath:='';
fReplaceUnits:=TStringToStringTree.Create(false); fReplaceUnits:=TStringToStringTree.Create(false);
fReplaceTypes:=TStringToStringTree.Create(false); fReplaceTypes:=TStringToStringTree.Create(false);
fVisualOffsets:=TStringToStringTree.Create(true);
fReplaceFuncs:=TFuncsAndCategories.Create; fReplaceFuncs:=TFuncsAndCategories.Create;
fVisualOffsets:=TVisualOffsets.Create;
// Load settings from ConfigStorage. // Load settings from ConfigStorage.
fConfigStorage:=GetIDEConfigStorage('delphiconverter.xml', true); fConfigStorage:=GetIDEConfigStorage('delphiconverter.xml', true);
fBackupFiles :=fConfigStorage.GetValue('BackupFiles', true); fBackupFiles :=fConfigStorage.GetValue('BackupFiles', true);
@ -310,8 +351,8 @@ begin
fEnableVisualOffs :=fConfigStorage.GetValue('EnableVisualOffs', true); fEnableVisualOffs :=fConfigStorage.GetValue('EnableVisualOffs', true);
LoadStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits); LoadStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits);
LoadStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes); LoadStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes);
LoadStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets); LoadFuncReplacements(fConfigStorage, 'FuncReplacements/', 'Categories/', fReplaceFuncs);
LoadFuncReplacements (fConfigStorage, 'FuncReplacements/', 'Categories/', fReplaceFuncs); LoadVisualOffsets(fConfigStorage, 'VisualOffsets/', fVisualOffsets);
// Add default values for configuration if ConfigStorage doesn't have them. // Add default values for configuration if ConfigStorage doesn't have them.
@ -354,10 +395,13 @@ begin
MapReplacement('^TTnt(.+)LX$', 'T$1'); MapReplacement('^TTnt(.+)LX$', 'T$1');
MapReplacement('^TTnt(.+[^L][^X])$','T$1'); MapReplacement('^TTnt(.+[^L][^X])$','T$1');
// Top coordinate offsets for some visual containers. // Coordinate offsets for some visual containers.
TheMap:=fVisualOffsets; with fVisualOffsets do begin
MapReplacement('TGroupBox', '10'); AddVisualOffset('TGroupBox' , 10,2);
MapReplacement('TPanel', '2'); AddVisualOffset('TPanel', 2,2);
AddVisualOffset('RadioGroup', 10,2);
AddVisualOffset('CheckGroup', 10,2);
end;
// Map Delphi function names to FCL/LCL functions. // Map Delphi function names to FCL/LCL functions.
with fReplaceFuncs do begin with fReplaceFuncs do begin
@ -412,15 +456,15 @@ begin
fConfigStorage.SetDeleteValue('EnableVisualOffs', fEnableVisualOffs, true); fConfigStorage.SetDeleteValue('EnableVisualOffs', fEnableVisualOffs, true);
SaveStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits); SaveStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits);
SaveStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes); SaveStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes);
SaveStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets); SaveFuncReplacements(fConfigStorage, 'FuncReplacements/', 'Categories/', fReplaceFuncs);
SaveFuncReplacements (fConfigStorage, 'FuncReplacements/', 'Categories/', fReplaceFuncs); SaveVisualOffsets(fConfigStorage, 'VisualOffsets/', fVisualOffsets);
// Free stuff // Free stuff
fConfigStorage.Free; fConfigStorage.Free;
fReplaceFuncs.Clear; fReplaceFuncs.Clear;
fReplaceFuncs.Free; fReplaceFuncs.Free;
fReplaceTypes.Free; fReplaceTypes.Free;
fVisualOffsets.Free;
fReplaceUnits.Free; fReplaceUnits.Free;
fVisualOffsets.Free;
inherited Destroy; inherited Destroy;
end; end;
@ -590,8 +634,8 @@ begin
FuncReplaceButton.Hint:=lisConvFuncReplHint; FuncReplaceButton.Hint:=lisConvFuncReplHint;
FuncReplaceEnableCheckBox.Caption:=lisEnable; FuncReplaceEnableCheckBox.Caption:=lisEnable;
VisualOffsButton.Caption:=lisConvTopCoordOffs; VisualOffsButton.Caption:=lisConvCoordOffs;
VisualOffsButton.Hint:=lisConvTopCoordHint; VisualOffsButton.Hint:=lisConvCoordHint;
VisualOffsEnableCheckBox.Caption:=lisEnable; VisualOffsEnableCheckBox.Caption:=lisEnable;
TargetRadioGroup.Items.Clear; TargetRadioGroup.Items.Clear;
@ -630,17 +674,12 @@ end;
procedure TConvertSettingsForm.UnitReplaceButtonClick(Sender: TObject); procedure TConvertSettingsForm.UnitReplaceButtonClick(Sender: TObject);
begin begin
EditMap(fSettings.ReplaceUnits, lisConvUnitsToReplace, lisConvDelphiName, lisConvNewName); EditMap(fSettings.ReplaceUnits, lisConvUnitsToReplace);
end; end;
procedure TConvertSettingsForm.TypeReplaceButtonClick(Sender: TObject); procedure TConvertSettingsForm.TypeReplaceButtonClick(Sender: TObject);
begin begin
EditMap(fSettings.ReplaceTypes, lisConvTypesToReplace, lisConvDelphiName, lisConvNewName); EditMap(fSettings.ReplaceTypes, lisConvTypesToReplace);
end;
procedure TConvertSettingsForm.VisualOffsButtonClick(Sender: TObject);
begin
EditMap(fSettings.VisualOffsets, lisConvTopCoordOffs, lisConvParentContainer, lisConvTopCoordOff);
end; end;
procedure TConvertSettingsForm.FuncReplaceButtonClick(Sender: TObject); procedure TConvertSettingsForm.FuncReplaceButtonClick(Sender: TObject);
@ -648,6 +687,11 @@ begin
EditFuncReplacements(fSettings.ReplaceFuncs, lisConvFuncsToReplace); EditFuncReplacements(fSettings.ReplaceFuncs, lisConvFuncsToReplace);
end; end;
procedure TConvertSettingsForm.VisualOffsButtonClick(Sender: TObject);
begin
EditVisualOffsets(fSettings.VisualOffsets, lisConvCoordOffs);
end;
end. end.

View File

@ -75,7 +75,7 @@ type
fPropReplaceGrid: TStringGrid; fPropReplaceGrid: TStringGrid;
fTypeReplaceGrid: TStringGrid; fTypeReplaceGrid: TStringGrid;
function ReplaceAndRemoveAll: TModalResult; function ReplaceAndRemoveAll: TModalResult;
function ReplaceTopOffsets(aOffsetList: TList): TModalResult; function ReplaceTopOffsets(aSrcOffsets: TList): TModalResult;
// Fill StringGrids with missing properties and types from fLFMTree. // Fill StringGrids with missing properties and types from fLFMTree.
procedure FillReplaceGrids; procedure FillReplaceGrids;
protected protected
@ -328,30 +328,35 @@ begin
end; end;
end; end;
function TLFMFixer.ReplaceTopOffsets(aOffsetList: TList): TModalResult; function TLFMFixer.ReplaceTopOffsets(aSrcOffsets: TList): TModalResult;
// Replace top coordinates of controls in visual containers. // Replace top coordinates of controls in visual containers.
// Returns mrOK if no types were changed, and mrCancel if there was an error. // Returns mrOK if no types were changed, and mrCancel if there was an error.
var var
TopOffset: TTopOffset; TopOffs: TSrcPropOffset;
Len, Offs, OldNun, i: integer; VisOffs: TVisualOffset;
OffsStr, OldText, NewText: string; OldNum, Ofs, NewNum, Len, ind, i: integer;
begin begin
Result:=mrOK; Result:=mrOK;
// Add offset to top coordinates. // Add offset to top coordinates.
for i := aOffsetList.Count-1 downto 0 do begin for i := aSrcOffsets.Count-1 downto 0 do begin
TopOffset:=TTopOffset(aOffsetList[i]); TopOffs:=TSrcPropOffset(aSrcOffsets[i]);
OffsStr:=fSettings.VisualOffsets[TopOffset.ParentType]; if fSettings.VisualOffsets.Find(TopOffs.ParentType, ind) then begin
if OffsStr<>'' then begin VisOffs:=fSettings.VisualOffsets[ind];
Len:=0; Len:=0;
while fLFMBuffer.Source[TopOffset.StartPos+Len] in ['-', '0'..'9'] do while fLFMBuffer.Source[TopOffs.StartPos+Len] in ['-', '0'..'9'] do
Inc(Len); Inc(Len);
OldText:=Copy(fLFMBuffer.Source, TopOffset.StartPos, Len); try
OldNun:=StrToInt(OldText); OldNum:=StrToInt(Copy(fLFMBuffer.Source, TopOffs.StartPos, Len));
Offs:=StrToInt(OffsStr); except on EConvertError do
NewText:=IntToStr(OldNun+Offs); OldNum:=0;
fLFMBuffer.Replace(TopOffset.StartPos, Len, NewText); end;
IDEMessagesWindow.AddMsg(Format('Changed Top coord of %s from "%s" to "%s" inside %s.', Ofs:=VisOffs.ByProperty(TopOffs.PropName);
[TopOffset.ChildType, OldText, NewText, TopOffset.ParentType]),'',-1); NewNum:=OldNum-Ofs;
if NewNum<0 then
NewNum:=0;
fLFMBuffer.Replace(TopOffs.StartPos, Len, IntToStr(NewNum));
IDEMessagesWindow.AddMsg(Format('Changed %s coord of %s from "%d" to "%d" inside %s.',
[TopOffs.PropName, TopOffs.ChildType, OldNum, NewNum, TopOffs.ParentType]),'',-1);
end; end;
end; end;
end; end;

View File

@ -95,9 +95,6 @@ type
function FromUIToFuncList(aFuncsAndCateg: TFuncsAndCategories): boolean; function FromUIToFuncList(aFuncsAndCateg: TFuncsAndCategories): boolean;
end; end;
var
ReplaceFuncsForm: TReplaceFuncsForm;
function EditFuncReplacements(aFuncsAndCateg: TFuncsAndCategories; function EditFuncReplacements(aFuncsAndCateg: TFuncsAndCategories;
aTitle: string): TModalResult; aTitle: string): TModalResult;

View File

@ -1,5 +1,5 @@
object ReplaceNamesForm: TReplaceNamesForm
Left = 314 Left = 314
object ReplaceForm: TReplaceForm
Height = 472 Height = 472
Top = 438 Top = 438
Width = 433 Width = 433

View File

@ -36,9 +36,9 @@ type
function AddUnique(AOldIdent: string): string; function AddUnique(AOldIdent: string): string;
end; end;
{ TReplaceNamesForm } { TReplaceForm }
TReplaceNamesForm = class(TForm) TReplaceForm = class(TForm)
ButtonPanel: TButtonPanel; ButtonPanel: TButtonPanel;
InsertRow1: TMenuItem; InsertRow1: TMenuItem;
DeleteRow1: TMenuItem; DeleteRow1: TMenuItem;
@ -58,15 +58,12 @@ type
end; end;
//var
// ReplaceNamesForm: TReplaceNamesForm;
function FromMapToGrid(AMap: TStringToStringTree; AGrid: TStringGrid): boolean; function FromMapToGrid(AMap: TStringToStringTree; AGrid: TStringGrid): boolean;
function FromGridToMap(AMap: TStringToStringTree; AGrid: TStringGrid; function FromGridToMap(AMap: TStringToStringTree; AGrid: TStringGrid;
AllowEmptyValues: boolean = true): boolean; AllowEmptyValues: boolean = true): boolean;
function EditMap(AMap: TStringToStringTree; function EditMap(AMap: TStringToStringTree; AFormTitle: string): TModalResult;
AFormTitle, ACol1Title, ACol2Title: string): TModalResult; function EditVisualOffsets(AOffs: TVisualOffsets; aTitle: string): TModalResult;
implementation implementation
@ -117,16 +114,15 @@ begin
end; end;
end; end;
function EditMap(AMap: TStringToStringTree; function EditMap(AMap: TStringToStringTree; AFormTitle: string): TModalResult;
AFormTitle, ACol1Title, ACol2Title: string): TModalResult;
var var
RNForm: TReplaceNamesForm; RNForm: TReplaceForm;
begin begin
RNForm:=TReplaceNamesForm.Create(nil); RNForm:=TReplaceForm.Create(nil);
try try
RNForm.Caption:=AFormTitle; RNForm.Caption:=AFormTitle;
RNForm.Grid.Columns[0].Title.Caption:=ACol1Title; RNForm.Grid.Columns[0].Title.Caption:=lisConvDelphiName;
RNForm.Grid.Columns[1].Title.Caption:=ACol2Title; RNForm.Grid.Columns[1].Title.Caption:=lisConvNewName;
FromMapToGrid(AMap, RNForm.Grid); FromMapToGrid(AMap, RNForm.Grid);
Result:=RNForm.ShowModal; Result:=RNForm.ShowModal;
if Result=mrOK then if Result=mrOK then
@ -136,6 +132,72 @@ begin
end; end;
end; end;
// Functions for visual offsets values:
function FromListToGrid(AOffs: TVisualOffsets; AGrid: TStringGrid): boolean;
// Copy strings from coordinale list to grid.
var
i: Integer;
begin
Result:=true;
AGrid.BeginUpdate;
for i:=1 to AOffs.Count do begin // Skip the fixed row in grid.
if AGrid.RowCount<i+2 then
AGrid.RowCount:=i+2; // Leave one empty row to the end.
AGrid.Cells[0,i]:=AOffs[i-1].ParentType;
AGrid.Cells[1,i]:=IntToStr(AOffs[i-1].Top);
AGrid.Cells[2,i]:=IntToStr(AOffs[i-1].Left);
end;
AGrid.EndUpdate;
end;
function FromGridToList(AOffs: TVisualOffsets; AGrid: TStringGrid): boolean;
var
ParentType: string;
i, xTop, xLeft: Integer;
begin
Result:=true;
AOffs.Clear;
// Collect (maybe edited) properties from StringGrid to fStringMap.
for i:=1 to AGrid.RowCount-1 do begin // Skip the fixed row.
ParentType:=AGrid.Cells[0,i];
if ParentType<>'' then begin
xTop:=0;
try
xTop:=StrToInt(AGrid.Cells[1,i]);
except on EConvertError do
ShowMessage('Top value must be a number. Now: '+AGrid.Cells[1,i]);
end;
xLeft:=0;
try
xLeft:=StrToInt(AGrid.Cells[2,i]);
except on EConvertError do
ShowMessage('Left value must be a number. Now: '+AGrid.Cells[2,i]);
end;
AOffs.Add(TVisualOffset.Create(ParentType, xTop, xLeft));
end;
end;
end;
function EditVisualOffsets(AOffs: TVisualOffsets; aTitle: string): TModalResult;
var
xForm: TReplaceForm;
begin
xForm:=TReplaceForm.Create(nil);
try
xForm.Caption:=aTitle;
xForm.Grid.Columns[0].Title.Caption:=lisConvParentContainer;
xForm.Grid.Columns[1].Title.Caption:=lisConvTopOff;
xForm.Grid.Columns.Add.Title.Caption:=lisConvLeftOff;
FromListToGrid(AOffs, xForm.Grid);
Result:=xForm.ShowModal;
if Result=mrOK then
FromGridToList(AOffs, xForm.Grid);
finally
xForm.Free;
end;
end;
{ TStringMapUpdater } { TStringMapUpdater }
@ -221,9 +283,9 @@ begin
end; end;
{ TReplaceNamesForm } { TReplaceForm }
procedure TReplaceNamesForm.FormCreate(Sender: TObject); procedure TReplaceForm.FormCreate(Sender: TObject);
begin begin
Caption:=lisReplacements; Caption:=lisReplacements;
ButtonPanel.OKButton.Caption := lisOk; ButtonPanel.OKButton.Caption := lisOk;
@ -232,7 +294,7 @@ begin
IsLasRow:=false; IsLasRow:=false;
end; end;
procedure TReplaceNamesForm.PopupMenu1Popup(Sender: TObject); procedure TReplaceForm.PopupMenu1Popup(Sender: TObject);
var var
ControlCoord, NewCell: TPoint; ControlCoord, NewCell: TPoint;
begin begin
@ -242,19 +304,19 @@ begin
Grid.Row:=NewCell.Y; Grid.Row:=NewCell.Y;
end; end;
procedure TReplaceNamesForm.InsertRow1Click(Sender: TObject); procedure TReplaceForm.InsertRow1Click(Sender: TObject);
begin begin
Grid.InsertColRow(False, Grid.Row); Grid.InsertColRow(False, Grid.Row);
end; end;
procedure TReplaceNamesForm.DeleteRow1Click(Sender: TObject); procedure TReplaceForm.DeleteRow1Click(Sender: TObject);
begin begin
Grid.DeleteColRow(False, Grid.Row); Grid.DeleteColRow(False, Grid.Row);
end; end;
// Add rows automatically to the end of the grid // Add rows automatically to the end of the grid
// using OnSetEditText and OnEditingDone handlers and IsLasRow flag. // using OnSetEditText and OnEditingDone handlers and IsLasRow flag.
procedure TReplaceNamesForm.GridEditingDone(Sender: TObject); procedure TReplaceForm.GridEditingDone(Sender: TObject);
var var
sg: TStringGrid; sg: TStringGrid;
begin begin
@ -265,14 +327,14 @@ begin
end; end;
end; end;
procedure TReplaceNamesForm.GridSetEditText(Sender: TObject; ACol, procedure TReplaceForm.GridSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: string); ARow: Integer; const Value: string);
begin begin
if ARow = (Sender as TStringGrid).RowCount-1 then if ARow = (Sender as TStringGrid).RowCount-1 then
IsLasRow:=Value<>''; IsLasRow:=Value<>'';
end; end;
procedure TReplaceNamesForm.btnOKClick(Sender: TObject); procedure TReplaceForm.btnOKClick(Sender: TObject);
begin begin
ModalResult:=mrOK; ModalResult:=mrOK;
end; end;

View File

@ -468,21 +468,22 @@ resourcestring
lisConvAutoReplace = 'Replace automatically'; lisConvAutoReplace = 'Replace automatically';
lisConvAutoRemove = 'Remove automatically'; lisConvAutoRemove = 'Remove automatically';
lisConvAutoHint = 'If unchecked, there will be interactive dialogs for editing / accepting changes'; lisConvAutoHint = 'If unchecked, there will be interactive dialogs for editing / accepting changes';
lisConvUnitsToReplace = 'Units to replace';
lisConvTypesToReplace = 'Types to replace'; lisConvTypesToReplace = 'Types to replace';
lisConvTopCoordOff = 'Top coordinate offset'; lisConvTypeReplacements = 'Type Replacements';
lisConvTopCoordOffs = 'Top coordinate offsets'; lisConvUnitsToReplace = 'Units to replace';
lisConvFuncsToReplace = 'Functions / procedures to replace';
lisConvUnitReplacements = 'Unit Replacements'; lisConvUnitReplacements = 'Unit Replacements';
lisConvUnitReplHint = 'Unit names in uses section of a source unit'; lisConvUnitReplHint = 'Unit names in uses section of a source unit';
lisConvTypeReplacements = 'Type Replacements';
lisConvTypeReplHint = 'Unknown types in form file (DFM/LFM)'; lisConvTypeReplHint = 'Unknown types in form file (DFM/LFM)';
lisConvTopCoordHint = 'An offset is added to Top coordinate of controls inside visual containers'; lisConvCoordOffs = 'Coordinate offsets';
lisConvCoordHint = 'An offset is added to Top coordinate of controls inside visual containers';
lisConvFuncsToReplace = 'Functions / procedures to replace';
lisConvFuncReplacements = 'Function Replacements'; lisConvFuncReplacements = 'Function Replacements';
lisConvFuncReplHint = 'Some Delphi functions can be replaced with LCL function'; lisConvFuncReplHint = 'Some Delphi functions can be replaced with LCL function';
lisConvDelphiName = 'Delphi Name'; lisConvDelphiName = 'Delphi Name';
lisConvNewName = 'New Name'; lisConvNewName = 'New Name';
lisConvParentContainer = 'Parent Container'; lisConvParentContainer = 'Parent Container';
lisConvTopOff = 'Top offset';
lisConvLeftOff = 'Left offset';
lisConvDelphiFunc = 'Delphi Function'; lisConvDelphiFunc = 'Delphi Function';
lisReplacement = 'Replacement'; lisReplacement = 'Replacement';
lisReplacements = 'Replacements'; lisReplacements = 'Replacements';