From e1ba658ec65e3a68f8c47eea51758f03acc65a3d Mon Sep 17 00:00:00 2001 From: juha Date: Mon, 13 Sep 2010 09:37:06 +0000 Subject: [PATCH] Converter: implemented fully the coordinate offsets. GUI improvements. git-svn-id: trunk@27346 - --- converter/convcodetool.pas | 19 ++--- converter/convertdelphi.pas | 3 +- converter/convertertypes.pas | 121 +++++++++++++++++++++++++++-- converter/convertsettings.lfm | 3 +- converter/convertsettings.pas | 96 ++++++++++++++++------- converter/missingpropertiesdlg.pas | 39 ++++++---- converter/replacefuncsunit.pas | 3 - converter/replacenamesunit.lfm | 2 +- converter/replacenamesunit.pas | 104 ++++++++++++++++++++----- ide/lazarusidestrconsts.pas | 13 ++-- 10 files changed, 312 insertions(+), 91 deletions(-) diff --git a/converter/convcodetool.pas b/converter/convcodetool.pas index 612b02cfe1..ae03a2d9b2 100755 --- a/converter/convcodetool.pas +++ b/converter/convcodetool.pas @@ -66,7 +66,7 @@ type function FixMainClassAncestor(const AClassName: string; AReplaceTypes: TStringToStringTree): boolean; function CheckTopOffsets(LFMBuf: TCodeBuffer; LFMTree: TLFMTree; - ParentOffsets: TStringToStringTree; ValueNodes: TObjectList): boolean; + VisOffsets: TVisualOffsets; ValueNodes: TObjectList): boolean; public property Ask: Boolean read fAsk write fAsk; property HasFormFile: boolean read fHasFormFile write fHasFormFile; @@ -856,11 +856,11 @@ begin end; 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 // a visual container component. An offset will be added to those attributes. // 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. var RootContext: TFindContext; @@ -1077,21 +1077,22 @@ var // ParentContext is the context, where properties are searched. // This can be a class or a property. var - i: Integer; + i, ind: Integer; ValNode: TLFMValueNode; - CurName, GrandName: string; + CurName, GrandName, Prop: string; CurPropertyContext: TFindContext; SearchContext: TFindContext; begin // find complete property name - if LFMProperty.CompleteName='' then exit; - if LFMProperty.CompleteName='Top' then begin + Prop:=LFMProperty.CompleteName; + if Prop='' then exit; + if (Prop='Top') or (Prop='Left') then begin CurName:=ParentContext.Tool.ExtractClassName(ParentContext.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 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; diff --git a/converter/convertdelphi.pas b/converter/convertdelphi.pas index cf6e107180..b386729e1b 100644 --- a/converter/convertdelphi.pas +++ b/converter/convertdelphi.pas @@ -800,8 +800,7 @@ begin end; if not fSettings.AutoReplaceUnits then begin // Edit, then remove or replace units. - Result:=EditMap(MapToEdit, 'Units to replace in '+ExtractFileName(fOrigUnitFilename), - lisConvDelphiName, lisConvNewName); + Result:=EditMap(MapToEdit, 'Units to replace in '+ExtractFileName(fOrigUnitFilename)); if Result<>mrOK then exit; // Iterate the map and rename / remove. Node:=MapToEdit.Tree.FindLowest; diff --git a/converter/convertertypes.pas b/converter/convertertypes.pas index d52bf0966e..349fe36833 100644 --- a/converter/convertertypes.pas +++ b/converter/convertertypes.pas @@ -5,26 +5,61 @@ unit ConverterTypes; interface uses - Classes, SysUtils; + Classes, SysUtils, contnrs; type { TopOffset } // Used when fixing top coordinates of controls inside a visual container. - TTopOffset = class + TSrcPropOffset = class private fParentType: string; fChildType: string; + fPropName: string; fStartPos: integer; public - constructor Create(aParentType, aChildType: string; aStartPos: integer); + constructor Create(aParentType, aChildType, aPropName: string; aStartPos: integer); destructor Destroy; override; property ParentType: string read fParentType; property ChildType: string read fChildType; + property PropName: string read fPropName; property StartPos: integer read fStartPos; 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 { EConverterError } @@ -46,18 +81,94 @@ end; { TopOffset } -constructor TTopOffset.Create(aParentType, aChildType: string; aStartPos: integer); +constructor TSrcPropOffset.Create(aParentType, aChildType, aPropName: string; aStartPos: integer); begin fParentType:=aParentType; fChildType:=aChildType; + fPropName:=aPropName; fStartPos:=aStartPos; end; -destructor TTopOffset.Destroy; +destructor TSrcPropOffset.Destroy; begin inherited Destroy; 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. diff --git a/converter/convertsettings.lfm b/converter/convertsettings.lfm index 1688d7739a..b01d413aa0 100644 --- a/converter/convertsettings.lfm +++ b/converter/convertsettings.lfm @@ -3,6 +3,7 @@ object ConvertSettingsForm: TConvertSettingsForm Height = 483 Top = 298 Width = 637 + ActiveControl = ProjectPathEdit Caption = 'Convert Delphi unit, project or package ' ClientHeight = 483 ClientWidth = 637 @@ -78,7 +79,7 @@ object ConvertSettingsForm: TConvertSettingsForm Hint = 'Some Delphi functions can be replaced with a LCL function' Top = 156 Width = 272 - Caption = 'Top Coordinate Offsets' + Caption = 'Coordinate Offsets' OnClick = VisualOffsButtonClick ParentShowHint = False ShowHint = True diff --git a/converter/convertsettings.pas b/converter/convertsettings.pas index 84054f056e..2b669e0c27 100755 --- a/converter/convertsettings.pas +++ b/converter/convertsettings.pas @@ -31,9 +31,9 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, IDEProcs, - StdCtrls, EditBtn, Buttons, ExtCtrls, DialogProcs, LazarusIDEStrConsts, - CodeToolsStructs, AVL_Tree, BaseIDEIntf, LazConfigStorage, - ButtonPanel, ReplaceNamesUnit, ReplaceFuncsUnit; + StdCtrls, EditBtn, Buttons, ExtCtrls, DialogProcs, ButtonPanel, + LazarusIDEStrConsts, CodeToolsStructs, AVL_Tree, BaseIDEIntf, LazConfigStorage, + ConverterTypes, ReplaceNamesUnit, ReplaceFuncsUnit; type @@ -61,10 +61,10 @@ type fReplaceUnits: TStringToStringTree; // Delphi types mapped to Lazarus types, will be replaced. fReplaceTypes: TStringToStringTree; - // Top coordinate shift of components in a visual container. - fVisualOffsets: TStringToStringTree; // Delphi global function names mapped to FCL/LCL functions. fReplaceFuncs: TFuncsAndCategories; + // Coordinate offsets of components in a visual container. + fVisualOffsets: TVisualOffsets; // Getter / setter: function GetBackupPath: String; procedure SetMainFilename(const AValue: String); @@ -102,8 +102,8 @@ type property EnableVisualOffs: boolean read fEnableVisualOffs; property ReplaceUnits: TStringToStringTree read fReplaceUnits; property ReplaceTypes: TStringToStringTree read fReplaceTypes; - property VisualOffsets: TStringToStringTree read fVisualOffsets; property ReplaceFuncs: TFuncsAndCategories read fReplaceFuncs; + property VisualOffsets: TVisualOffsets read fVisualOffsets; end; @@ -127,9 +127,9 @@ type UnitReplaceButton: TBitBtn; SettingsGroupBox: TGroupBox; MissingStuffGroupBox: TGroupBox; - procedure FuncReplaceButtonClick(Sender: TObject); procedure SameDFMCheckBoxChange(Sender: TObject); procedure TypeReplaceButtonClick(Sender: TObject); + procedure FuncReplaceButtonClick(Sender: TObject); procedure VisualOffsButtonClick(Sender: TObject); procedure UnitReplaceButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); @@ -268,6 +268,47 @@ begin 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 } @@ -297,8 +338,8 @@ begin fMainPath:=''; fReplaceUnits:=TStringToStringTree.Create(false); fReplaceTypes:=TStringToStringTree.Create(false); - fVisualOffsets:=TStringToStringTree.Create(true); fReplaceFuncs:=TFuncsAndCategories.Create; + fVisualOffsets:=TVisualOffsets.Create; // Load settings from ConfigStorage. fConfigStorage:=GetIDEConfigStorage('delphiconverter.xml', true); fBackupFiles :=fConfigStorage.GetValue('BackupFiles', true); @@ -310,8 +351,8 @@ begin fEnableVisualOffs :=fConfigStorage.GetValue('EnableVisualOffs', true); LoadStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits); 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. @@ -354,10 +395,13 @@ begin MapReplacement('^TTnt(.+)LX$', 'T$1'); MapReplacement('^TTnt(.+[^L][^X])$','T$1'); - // Top coordinate offsets for some visual containers. - TheMap:=fVisualOffsets; - MapReplacement('TGroupBox', '10'); - MapReplacement('TPanel', '2'); + // Coordinate offsets for some visual containers. + with fVisualOffsets do begin + AddVisualOffset('TGroupBox' , 10,2); + AddVisualOffset('TPanel', 2,2); + AddVisualOffset('RadioGroup', 10,2); + AddVisualOffset('CheckGroup', 10,2); + end; // Map Delphi function names to FCL/LCL functions. with fReplaceFuncs do begin @@ -412,15 +456,15 @@ begin fConfigStorage.SetDeleteValue('EnableVisualOffs', fEnableVisualOffs, true); SaveStringToStringTree(fConfigStorage, 'UnitReplacements/', fReplaceUnits); SaveStringToStringTree(fConfigStorage, 'TypeReplacements/', fReplaceTypes); - SaveStringToStringTree(fConfigStorage, 'VisualTopOffsets/', fVisualOffsets); - SaveFuncReplacements (fConfigStorage, 'FuncReplacements/', 'Categories/', fReplaceFuncs); + SaveFuncReplacements(fConfigStorage, 'FuncReplacements/', 'Categories/', fReplaceFuncs); + SaveVisualOffsets(fConfigStorage, 'VisualOffsets/', fVisualOffsets); // Free stuff fConfigStorage.Free; fReplaceFuncs.Clear; fReplaceFuncs.Free; fReplaceTypes.Free; - fVisualOffsets.Free; fReplaceUnits.Free; + fVisualOffsets.Free; inherited Destroy; end; @@ -590,8 +634,8 @@ begin FuncReplaceButton.Hint:=lisConvFuncReplHint; FuncReplaceEnableCheckBox.Caption:=lisEnable; - VisualOffsButton.Caption:=lisConvTopCoordOffs; - VisualOffsButton.Hint:=lisConvTopCoordHint; + VisualOffsButton.Caption:=lisConvCoordOffs; + VisualOffsButton.Hint:=lisConvCoordHint; VisualOffsEnableCheckBox.Caption:=lisEnable; TargetRadioGroup.Items.Clear; @@ -630,17 +674,12 @@ end; procedure TConvertSettingsForm.UnitReplaceButtonClick(Sender: TObject); begin - EditMap(fSettings.ReplaceUnits, lisConvUnitsToReplace, lisConvDelphiName, lisConvNewName); + EditMap(fSettings.ReplaceUnits, lisConvUnitsToReplace); end; procedure TConvertSettingsForm.TypeReplaceButtonClick(Sender: TObject); begin - EditMap(fSettings.ReplaceTypes, lisConvTypesToReplace, lisConvDelphiName, lisConvNewName); -end; - -procedure TConvertSettingsForm.VisualOffsButtonClick(Sender: TObject); -begin - EditMap(fSettings.VisualOffsets, lisConvTopCoordOffs, lisConvParentContainer, lisConvTopCoordOff); + EditMap(fSettings.ReplaceTypes, lisConvTypesToReplace); end; procedure TConvertSettingsForm.FuncReplaceButtonClick(Sender: TObject); @@ -648,6 +687,11 @@ begin EditFuncReplacements(fSettings.ReplaceFuncs, lisConvFuncsToReplace); end; +procedure TConvertSettingsForm.VisualOffsButtonClick(Sender: TObject); +begin + EditVisualOffsets(fSettings.VisualOffsets, lisConvCoordOffs); +end; + end. diff --git a/converter/missingpropertiesdlg.pas b/converter/missingpropertiesdlg.pas index 87e4dfdd12..628320fcc1 100644 --- a/converter/missingpropertiesdlg.pas +++ b/converter/missingpropertiesdlg.pas @@ -75,7 +75,7 @@ type fPropReplaceGrid: TStringGrid; fTypeReplaceGrid: TStringGrid; function ReplaceAndRemoveAll: TModalResult; - function ReplaceTopOffsets(aOffsetList: TList): TModalResult; + function ReplaceTopOffsets(aSrcOffsets: TList): TModalResult; // Fill StringGrids with missing properties and types from fLFMTree. procedure FillReplaceGrids; protected @@ -328,30 +328,35 @@ begin end; end; -function TLFMFixer.ReplaceTopOffsets(aOffsetList: TList): TModalResult; +function TLFMFixer.ReplaceTopOffsets(aSrcOffsets: TList): TModalResult; // Replace top coordinates of controls in visual containers. // Returns mrOK if no types were changed, and mrCancel if there was an error. var - TopOffset: TTopOffset; - Len, Offs, OldNun, i: integer; - OffsStr, OldText, NewText: string; + TopOffs: TSrcPropOffset; + VisOffs: TVisualOffset; + OldNum, Ofs, NewNum, Len, ind, i: integer; begin Result:=mrOK; // Add offset to top coordinates. - for i := aOffsetList.Count-1 downto 0 do begin - TopOffset:=TTopOffset(aOffsetList[i]); - OffsStr:=fSettings.VisualOffsets[TopOffset.ParentType]; - if OffsStr<>'' then begin + for i := aSrcOffsets.Count-1 downto 0 do begin + TopOffs:=TSrcPropOffset(aSrcOffsets[i]); + if fSettings.VisualOffsets.Find(TopOffs.ParentType, ind) then begin + VisOffs:=fSettings.VisualOffsets[ind]; Len:=0; - while fLFMBuffer.Source[TopOffset.StartPos+Len] in ['-', '0'..'9'] do + while fLFMBuffer.Source[TopOffs.StartPos+Len] in ['-', '0'..'9'] do Inc(Len); - OldText:=Copy(fLFMBuffer.Source, TopOffset.StartPos, Len); - OldNun:=StrToInt(OldText); - Offs:=StrToInt(OffsStr); - NewText:=IntToStr(OldNun+Offs); - fLFMBuffer.Replace(TopOffset.StartPos, Len, NewText); - IDEMessagesWindow.AddMsg(Format('Changed Top coord of %s from "%s" to "%s" inside %s.', - [TopOffset.ChildType, OldText, NewText, TopOffset.ParentType]),'',-1); + try + OldNum:=StrToInt(Copy(fLFMBuffer.Source, TopOffs.StartPos, Len)); + except on EConvertError do + OldNum:=0; + end; + Ofs:=VisOffs.ByProperty(TopOffs.PropName); + 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; diff --git a/converter/replacefuncsunit.pas b/converter/replacefuncsunit.pas index 6789b7f85d..6e9c60a3f5 100644 --- a/converter/replacefuncsunit.pas +++ b/converter/replacefuncsunit.pas @@ -95,9 +95,6 @@ type function FromUIToFuncList(aFuncsAndCateg: TFuncsAndCategories): boolean; end; -var - ReplaceFuncsForm: TReplaceFuncsForm; - function EditFuncReplacements(aFuncsAndCateg: TFuncsAndCategories; aTitle: string): TModalResult; diff --git a/converter/replacenamesunit.lfm b/converter/replacenamesunit.lfm index ad1b4fc3c0..11e625532d 100644 --- a/converter/replacenamesunit.lfm +++ b/converter/replacenamesunit.lfm @@ -1,5 +1,5 @@ -object ReplaceNamesForm: TReplaceNamesForm Left = 314 +object ReplaceForm: TReplaceForm Height = 472 Top = 438 Width = 433 diff --git a/converter/replacenamesunit.pas b/converter/replacenamesunit.pas index 8f90c7f098..7173fd5a52 100644 --- a/converter/replacenamesunit.pas +++ b/converter/replacenamesunit.pas @@ -36,9 +36,9 @@ type function AddUnique(AOldIdent: string): string; end; - { TReplaceNamesForm } + { TReplaceForm } - TReplaceNamesForm = class(TForm) + TReplaceForm = class(TForm) ButtonPanel: TButtonPanel; InsertRow1: TMenuItem; DeleteRow1: TMenuItem; @@ -58,15 +58,12 @@ type end; -//var -// ReplaceNamesForm: TReplaceNamesForm; - function FromMapToGrid(AMap: TStringToStringTree; AGrid: TStringGrid): boolean; function FromGridToMap(AMap: TStringToStringTree; AGrid: TStringGrid; AllowEmptyValues: boolean = true): boolean; -function EditMap(AMap: TStringToStringTree; - AFormTitle, ACol1Title, ACol2Title: string): TModalResult; +function EditMap(AMap: TStringToStringTree; AFormTitle: string): TModalResult; +function EditVisualOffsets(AOffs: TVisualOffsets; aTitle: string): TModalResult; implementation @@ -117,16 +114,15 @@ begin end; end; -function EditMap(AMap: TStringToStringTree; - AFormTitle, ACol1Title, ACol2Title: string): TModalResult; +function EditMap(AMap: TStringToStringTree; AFormTitle: string): TModalResult; var - RNForm: TReplaceNamesForm; + RNForm: TReplaceForm; begin - RNForm:=TReplaceNamesForm.Create(nil); + RNForm:=TReplaceForm.Create(nil); try RNForm.Caption:=AFormTitle; - RNForm.Grid.Columns[0].Title.Caption:=ACol1Title; - RNForm.Grid.Columns[1].Title.Caption:=ACol2Title; + RNForm.Grid.Columns[0].Title.Caption:=lisConvDelphiName; + RNForm.Grid.Columns[1].Title.Caption:=lisConvNewName; FromMapToGrid(AMap, RNForm.Grid); Result:=RNForm.ShowModal; if Result=mrOK then @@ -136,6 +132,72 @@ begin 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'' 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 } @@ -221,9 +283,9 @@ begin end; -{ TReplaceNamesForm } +{ TReplaceForm } -procedure TReplaceNamesForm.FormCreate(Sender: TObject); +procedure TReplaceForm.FormCreate(Sender: TObject); begin Caption:=lisReplacements; ButtonPanel.OKButton.Caption := lisOk; @@ -232,7 +294,7 @@ begin IsLasRow:=false; end; -procedure TReplaceNamesForm.PopupMenu1Popup(Sender: TObject); +procedure TReplaceForm.PopupMenu1Popup(Sender: TObject); var ControlCoord, NewCell: TPoint; begin @@ -242,19 +304,19 @@ begin Grid.Row:=NewCell.Y; end; -procedure TReplaceNamesForm.InsertRow1Click(Sender: TObject); +procedure TReplaceForm.InsertRow1Click(Sender: TObject); begin Grid.InsertColRow(False, Grid.Row); end; -procedure TReplaceNamesForm.DeleteRow1Click(Sender: TObject); +procedure TReplaceForm.DeleteRow1Click(Sender: TObject); begin Grid.DeleteColRow(False, Grid.Row); end; // Add rows automatically to the end of the grid // using OnSetEditText and OnEditingDone handlers and IsLasRow flag. -procedure TReplaceNamesForm.GridEditingDone(Sender: TObject); +procedure TReplaceForm.GridEditingDone(Sender: TObject); var sg: TStringGrid; begin @@ -265,14 +327,14 @@ begin end; end; -procedure TReplaceNamesForm.GridSetEditText(Sender: TObject; ACol, +procedure TReplaceForm.GridSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string); begin if ARow = (Sender as TStringGrid).RowCount-1 then IsLasRow:=Value<>''; end; -procedure TReplaceNamesForm.btnOKClick(Sender: TObject); +procedure TReplaceForm.btnOKClick(Sender: TObject); begin ModalResult:=mrOK; end; diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 455696bcc8..f0b9638912 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -468,21 +468,22 @@ resourcestring lisConvAutoReplace = 'Replace automatically'; lisConvAutoRemove = 'Remove automatically'; lisConvAutoHint = 'If unchecked, there will be interactive dialogs for editing / accepting changes'; - lisConvUnitsToReplace = 'Units to replace'; lisConvTypesToReplace = 'Types to replace'; - lisConvTopCoordOff = 'Top coordinate offset'; - lisConvTopCoordOffs = 'Top coordinate offsets'; - lisConvFuncsToReplace = 'Functions / procedures to replace'; + lisConvTypeReplacements = 'Type Replacements'; + lisConvUnitsToReplace = 'Units to replace'; lisConvUnitReplacements = 'Unit Replacements'; lisConvUnitReplHint = 'Unit names in uses section of a source unit'; - lisConvTypeReplacements = 'Type Replacements'; 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'; lisConvFuncReplHint = 'Some Delphi functions can be replaced with LCL function'; lisConvDelphiName = 'Delphi Name'; lisConvNewName = 'New Name'; lisConvParentContainer = 'Parent Container'; + lisConvTopOff = 'Top offset'; + lisConvLeftOff = 'Left offset'; lisConvDelphiFunc = 'Delphi Function'; lisReplacement = 'Replacement'; lisReplacements = 'Replacements';