Converter: separate missing properties and class types to their own grids.

git-svn-id: trunk@25994 -
This commit is contained in:
juha 2010-06-08 21:46:17 +00:00
parent c6f133de70
commit bc2773b52f
4 changed files with 150 additions and 63 deletions

View File

@ -1,13 +1,14 @@
object FixLFMDialog: TFixLFMDialog object FixLFMDialog: TFixLFMDialog
Left = 280 Left = 366
Height = 536 Height = 637
Top = 233 Top = 94
Width = 756 Width = 756
ActiveControl = LFMSynEdit ActiveControl = LFMSynEdit
Caption = 'Fix LFM file' Caption = 'Fix LFM file'
ClientHeight = 536 ClientHeight = 637
ClientWidth = 756 ClientWidth = 756
OnCreate = CheckLFMDialogCreate OnCreate = CheckLFMDialogCreate
Position = poScreenCenter
LCLVersion = '0.9.29' LCLVersion = '0.9.29'
object NoteLabel: TLabel object NoteLabel: TLabel
Left = 0 Left = 0
@ -21,17 +22,17 @@ object FixLFMDialog: TFixLFMDialog
end end
object LFMGroupBox: TGroupBox object LFMGroupBox: TGroupBox
Left = 0 Left = 0
Height = 368 Height = 469
Top = 16 Top = 16
Width = 408 Width = 408
Align = alLeft Align = alLeft
Caption = 'LFM file' Caption = 'LFM file'
ClientHeight = 349 ClientHeight = 450
ClientWidth = 404 ClientWidth = 404
TabOrder = 0 TabOrder = 0
inline LFMSynEdit: TSynEdit inline LFMSynEdit: TSynEdit
Left = 0 Left = 0
Height = 349 Height = 450
Top = 0 Top = 0
Width = 404 Width = 404
Align = alClient Align = alClient
@ -629,7 +630,7 @@ object FixLFMDialog: TFixLFMDialog
object ErrorsGroupBox: TGroupBox object ErrorsGroupBox: TGroupBox
Left = 0 Left = 0
Height = 104 Height = 104
Top = 384 Top = 490
Width = 756 Width = 756
Align = alBottom Align = alBottom
Caption = 'Errors' Caption = 'Errors'
@ -649,20 +650,20 @@ object FixLFMDialog: TFixLFMDialog
end end
object BtnPanel: TPanel object BtnPanel: TPanel
Left = 0 Left = 0
Height = 48 Height = 43
Top = 488 Top = 594
Width = 756 Width = 756
Align = alBottom Align = alBottom
AutoSize = True AutoSize = True
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 48 ClientHeight = 43
ClientWidth = 756 ClientWidth = 756
TabOrder = 2 TabOrder = 2
object CancelButton: TBitBtn object CancelButton: TBitBtn
Left = 669 Left = 670
Height = 36 Height = 31
Top = 6 Top = 6
Width = 81 Width = 80
Align = alRight Align = alRight
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
@ -675,12 +676,12 @@ object FixLFMDialog: TFixLFMDialog
end end
object ReplaceAllButton: TBitBtn object ReplaceAllButton: TBitBtn
Left = 6 Left = 6
Height = 25 Height = 26
Top = 6 Top = 6
Width = 230 Width = 193
AutoSize = True AutoSize = True
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Replace unknown types and properties' Caption = 'Fix unknown properties and types'
NumGlyphs = 0 NumGlyphs = 0
OnClick = ReplaceAllButtonClick OnClick = ReplaceAllButtonClick
TabOrder = 1 TabOrder = 1
@ -688,29 +689,29 @@ object FixLFMDialog: TFixLFMDialog
end end
object PropertyReplaceGroupBox: TGroupBox object PropertyReplaceGroupBox: TGroupBox
Left = 413 Left = 413
Height = 368 Height = 469
Top = 16 Top = 16
Width = 343 Width = 343
Align = alClient Align = alClient
Caption = 'Properties and Types to replace' Caption = 'Replacements'
ClientHeight = 349 ClientHeight = 450
ClientWidth = 339 ClientWidth = 339
TabOrder = 3 TabOrder = 3
object PropertyReplaceGrid: TStringGrid object PropReplaceGrid: TStringGrid
Left = 0 Left = 0
Height = 349 Height = 187
Top = 0 Top = 17
Width = 339 Width = 339
Align = alClient Align = alTop
AutoFillColumns = True AutoFillColumns = True
ColCount = 2 ColCount = 2
Columns = < Columns = <
item item
Title.Caption = 'Delphi name' Title.Caption = 'Delphi Property'
Width = 167 Width = 167
end end
item item
Title.Caption = 'New name' Title.Caption = 'New Property'
Width = 168 Width = 168
end> end>
FixedCols = 0 FixedCols = 0
@ -722,13 +723,77 @@ object FixLFMDialog: TFixLFMDialog
168 168
) )
end end
object PropertiesText: TStaticText
Left = 0
Height = 17
Top = 0
Width = 339
Align = alTop
BorderStyle = sbsSunken
Caption = 'Properties'
TabOrder = 1
end
object Splitter3: TSplitter
Cursor = crVSplit
Left = 0
Height = 5
Top = 204
Width = 339
Align = alTop
ResizeAnchor = akTop
end
object TypeReplaceGrid: TStringGrid
Left = 0
Height = 224
Top = 226
Width = 339
Align = alClient
AutoFillColumns = True
ColCount = 2
Columns = <
item
Title.Caption = 'Delphi Type'
Width = 167
end
item
Title.Caption = 'New Type'
Width = 168
end>
FixedCols = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goSmoothScroll]
RowCount = 2
TabOrder = 3
ColWidths = (
167
168
)
end
object TypesText: TStaticText
Left = 0
Height = 17
Top = 209
Width = 339
Align = alTop
BorderStyle = sbsSunken
Caption = 'Types'
TabOrder = 4
end
end end
object Splitter1: TSplitter object Splitter1: TSplitter
Left = 408 Left = 408
Height = 368 Height = 469
Top = 16 Top = 16
Width = 5 Width = 5
end end
object Splitter2: TSplitter
Cursor = crVSplit
Left = 0
Height = 5
Top = 485
Width = 756
Align = alBottom
ResizeAnchor = akBottom
end
object SynLFMSyn1: TSynLFMSyn object SynLFMSyn1: TSynLFMSyn
DefaultFilter = 'Lazarus Form Files (*.lfm)|*.lfm' DefaultFilter = 'Lazarus Form Files (*.lfm)|*.lfm'
Enabled = False Enabled = False

View File

@ -72,9 +72,10 @@ type
fHasMissingObjectTypes: Boolean; fHasMissingObjectTypes: Boolean;
// References to controls in UI: // References to controls in UI:
fPropReplaceGrid: TStringGrid; fPropReplaceGrid: TStringGrid;
fTypeReplaceGrid: TStringGrid;
function ReplaceAndRemoveAll: TModalResult; function ReplaceAndRemoveAll: TModalResult;
// Fill StringGrid with missing properties from fLFMTree. // Fill StringGrids with missing properties and types from fLFMTree.
procedure FillPropReplaceList; procedure FillReplaceGrids;
protected protected
procedure LoadLFM; procedure LoadLFM;
function ShowRepairLFMWizard: TModalResult; override; function ShowRepairLFMWizard: TModalResult; override;
@ -94,6 +95,7 @@ type
CancelButton: TBitBtn; CancelButton: TBitBtn;
ErrorsGroupBox: TGroupBox; ErrorsGroupBox: TGroupBox;
ErrorsListBox: TListBox; ErrorsListBox: TListBox;
TypeReplaceGrid: TStringGrid;
PropertyReplaceGroupBox: TGroupBox; PropertyReplaceGroupBox: TGroupBox;
NoteLabel: TLabel; NoteLabel: TLabel;
LFMGroupBox: TGroupBox; LFMGroupBox: TGroupBox;
@ -101,7 +103,11 @@ type
BtnPanel: TPanel; BtnPanel: TPanel;
ReplaceAllButton: TBitBtn; ReplaceAllButton: TBitBtn;
Splitter1: TSplitter; Splitter1: TSplitter;
PropertyReplaceGrid: TStringGrid; PropReplaceGrid: TStringGrid;
Splitter2: TSplitter;
Splitter3: TSplitter;
PropertiesText: TStaticText;
TypesText: TStaticText;
SynLFMSyn1: TSynLFMSyn; SynLFMSyn1: TSynLFMSyn;
procedure ErrorsListBoxClick(Sender: TObject); procedure ErrorsListBoxClick(Sender: TObject);
procedure ReplaceAllButtonClick(Sender: TObject); procedure ReplaceAllButtonClick(Sender: TObject);
@ -246,21 +252,27 @@ var
CurError: TLFMError; CurError: TLFMError;
TheNode: TLFMTreeNode; TheNode: TLFMTreeNode;
ObjNode: TLFMObjectNode; ObjNode: TLFMObjectNode;
// Type name --> replacement name. // Property / Type name --> replacement name.
NameReplacements: TStringToStringTree; PropReplacements: TStringToStringTree;
TypeReplacements: TStringToStringTree;
// List of TLFMChangeEntry objects. // List of TLFMChangeEntry objects.
ChgEntryRepl: TObjectList; ChgEntryRepl: TObjectList;
GridUpdater: TGridUpdater; // Updater moves data between grid and map.
PropUpdater: TGridUpdater;
TypeUpdater: TGridUpdater;
OldIdent, NewIdent: string; OldIdent, NewIdent: string;
StartPos, EndPos: integer; StartPos, EndPos: integer;
begin begin
Result:=mrOK; Result:=mrOK;
ChgEntryRepl:=TObjectList.Create; ChgEntryRepl:=TObjectList.Create;
NameReplacements:=TStringToStringTree.Create(false); PropReplacements:=TStringToStringTree.Create(false);
GridUpdater:=TGridUpdater.Create(NameReplacements, fPropReplaceGrid); TypeReplacements:=TStringToStringTree.Create(false);
PropUpdater:=TGridUpdater.Create(PropReplacements, fPropReplaceGrid);
TypeUpdater:=TGridUpdater.Create(TypeReplacements, fTypeReplaceGrid);
try try
// Collect (maybe edited) properties from StringGrid to NameReplacements. // Collect (maybe edited) properties from StringGrid to map.
GridUpdater.GridToMap; PropUpdater.GridToMap;
TypeUpdater.GridToMap;
// Replace each missing property / type or delete it if no replacement. // Replace each missing property / type or delete it if no replacement.
CurError:=fLFMTree.LastError; CurError:=fLFMTree.LastError;
while CurError<>nil do begin while CurError<>nil do begin
@ -270,7 +282,7 @@ begin
// Object type // Object type
ObjNode:=CurError.Node as TLFMObjectNode; ObjNode:=CurError.Node as TLFMObjectNode;
OldIdent:=ObjNode.TypeName; OldIdent:=ObjNode.TypeName;
NewIdent:=NameReplacements[OldIdent]; NewIdent:=TypeReplacements[OldIdent];
// Keep the old class name if no replacement. // Keep the old class name if no replacement.
if NewIdent<>'' then begin if NewIdent<>'' then begin
StartPos:=ObjNode.TypeNamePosition; StartPos:=ObjNode.TypeNamePosition;
@ -284,7 +296,7 @@ begin
TheNode.FindIdentifier(StartPos,EndPos); TheNode.FindIdentifier(StartPos,EndPos);
if StartPos>0 then begin if StartPos>0 then begin
OldIdent:=copy(fLFMBuffer.Source,StartPos,EndPos-StartPos); OldIdent:=copy(fLFMBuffer.Source,StartPos,EndPos-StartPos);
NewIdent:=NameReplacements[OldIdent]; NewIdent:=PropReplacements[OldIdent];
// Delete the whole property line if no replacement. // Delete the whole property line if no replacement.
if NewIdent='' then if NewIdent='' then
FindNiceNodeBounds(TheNode,StartPos,EndPos); FindNiceNodeBounds(TheNode,StartPos,EndPos);
@ -294,56 +306,61 @@ begin
end; end;
CurError:=CurError.PrevError; CurError:=CurError.PrevError;
end; end;
// Apply replacement types also to pascal source. // Apply replacements to LFM.
if not CodeToolBoss.RetypeClassVariables(fPascalBuffer, if not ApplyReplacements(ChgEntryRepl) then begin
TLFMObjectNode(fLFMTree.Root).TypeName, NameReplacements, false)
then begin
Result:=mrCancel; Result:=mrCancel;
exit; exit;
end; end;
// Apply replacements to LFM. // Apply replacement types also to pascal source.
if not ApplyReplacements(ChgEntryRepl) then if not CodeToolBoss.RetypeClassVariables(fPascalBuffer,
TLFMObjectNode(fLFMTree.Root).TypeName, TypeReplacements, false) then
Result:=mrCancel; Result:=mrCancel;
finally finally
GridUpdater.Free; TypeUpdater.Free;
NameReplacements.Free; PropUpdater.Free;
TypeReplacements.Free;
PropReplacements.Free;
ChgEntryRepl.Free; ChgEntryRepl.Free;
end; end;
end; end;
procedure TLFMFixer.FillPropReplaceList; procedure TLFMFixer.FillReplaceGrids;
var var
PropUpdater: TGridUpdater;
TypeUpdater: TGridUpdater;
CurError: TLFMError; CurError: TLFMError;
GridUpdater: TGridUpdater;
OldIdent: string; OldIdent: string;
begin begin
fHasMissingObjectTypes:=false; fHasMissingObjectTypes:=false;
GridUpdater:=TGridUpdater.Create(fSettings.ReplaceTypes, fPropReplaceGrid); // ReplaceTypes is used for properties just in case it will provide some.
PropUpdater:=TGridUpdater.Create(fSettings.ReplaceTypes, fPropReplaceGrid);
TypeUpdater:=TGridUpdater.Create(fSettings.ReplaceTypes, fTypeReplaceGrid);
try try
if fLFMTree<>nil then begin if fLFMTree<>nil then begin
CurError:=fLFMTree.FirstError; CurError:=fLFMTree.FirstError;
while CurError<>nil do begin while CurError<>nil do begin
if CurError.IsMissingObjectType then begin if CurError.IsMissingObjectType then begin
OldIdent:=(CurError.Node as TLFMObjectNode).TypeName; OldIdent:=(CurError.Node as TLFMObjectNode).TypeName;
TypeUpdater.AddUniqueToGrid(OldIdent); // Add a unique type only once.
fHasMissingObjectTypes:=true; fHasMissingObjectTypes:=true;
end end
else else begin
OldIdent:=CurError.Node.GetIdentifier; OldIdent:=CurError.Node.GetIdentifier;
// Add only one instance of each property name. PropUpdater.AddUniqueToGrid(OldIdent); // Add a unique property only once.
GridUpdater.AddUnique(OldIdent); end;
CurError:=CurError.NextError; CurError:=CurError.NextError;
end; end;
end; end;
finally finally
GridUpdater.Free; TypeUpdater.Free;
PropUpdater.Free;
end; end;
end; end;
procedure TLFMFixer.LoadLFM; procedure TLFMFixer.LoadLFM;
begin begin
inherited LoadLFM; inherited LoadLFM;
// Fill PropertyReplaceGrid FillReplaceGrids; // Fill both ReplaceGrids.
FillPropReplaceList;
end; end;
function TLFMFixer.ShowRepairLFMWizard: TModalResult; function TLFMFixer.ShowRepairLFMWizard: TModalResult;
@ -356,7 +373,8 @@ begin
try try
fLFMSynEdit:=FixLFMDialog.LFMSynEdit; fLFMSynEdit:=FixLFMDialog.LFMSynEdit;
fErrorsListBox:=FixLFMDialog.ErrorsListBox; fErrorsListBox:=FixLFMDialog.ErrorsListBox;
fPropReplaceGrid:=FixLFMDialog.PropertyReplaceGrid; fPropReplaceGrid:=FixLFMDialog.PropReplaceGrid;
fTypeReplaceGrid:=FixLFMDialog.TypeReplaceGrid;
LoadLFM; LoadLFM;
if fSettings.AutoRemoveProperties and not fHasMissingObjectTypes then if fSettings.AutoRemoveProperties and not fHasMissingObjectTypes then
Result:=ReplaceAndRemoveAll Result:=ReplaceAndRemoveAll
@ -471,7 +489,9 @@ begin
NoteLabel.Caption:=lisLFMFileContainsInvalidProperties; NoteLabel.Caption:=lisLFMFileContainsInvalidProperties;
ErrorsGroupBox.Caption:=lisErrors; ErrorsGroupBox.Caption:=lisErrors;
LFMGroupBox.Caption:=lisLFMFile; LFMGroupBox.Caption:=lisLFMFile;
PropertyReplaceGroupBox.Caption:=lisReplacementPropTypes; PropertyReplaceGroupBox.Caption:=lisReplacements;
PropertiesText.Caption:=lisProperties;
TypesText.Caption:=lisTypes;
ReplaceAllButton.Caption:=lisReplaceRemoveUnknown; ReplaceAllButton.Caption:=lisReplaceRemoveUnknown;
ReplaceAllButton.LoadGlyphFromLazarusResource('laz_refresh'); ReplaceAllButton.LoadGlyphFromLazarusResource('laz_refresh');
EditorOpts.GetHighlighterSettings(SynLFMSyn1); EditorOpts.GetHighlighterSettings(SynLFMSyn1);

View File

@ -33,7 +33,7 @@ type
public public
constructor Create(AStringMap: TStringToStringTree; AGrid: TStringGrid); constructor Create(AStringMap: TStringToStringTree; AGrid: TStringGrid);
destructor Destroy; override; destructor Destroy; override;
procedure AddUnique(AOldIdent: string); procedure AddUniqueToGrid(AOldIdent: string);
procedure MapToGrid; procedure MapToGrid;
procedure GridToMap; procedure GridToMap;
end; end;
@ -177,7 +177,7 @@ begin
end; end;
end; end;
procedure TGridUpdater.AddUnique(AOldIdent: string); procedure TGridUpdater.AddUniqueToGrid(AOldIdent: string);
// Add a new Delphi -> Lazarus mapping to grid. // Add a new Delphi -> Lazarus mapping to grid.
var var
NewIdent: string; NewIdent: string;
@ -199,7 +199,7 @@ end;
procedure TReplaceNamesForm.FormCreate(Sender: TObject); procedure TReplaceNamesForm.FormCreate(Sender: TObject);
begin begin
Caption:=lisReplacementPropTypes; Caption:=lisReplacements;
IsLasRow:=false; IsLasRow:=false;
end; end;

View File

@ -467,8 +467,10 @@ resourcestring
lisConvTypesToReplace = 'Types to replace'; lisConvTypesToReplace = 'Types to replace';
lisConvUnitReplacements = 'Unit Replacements'; lisConvUnitReplacements = 'Unit Replacements';
lisConvTypeReplacements = 'Type Replacements'; lisConvTypeReplacements = 'Type Replacements';
lisReplacementPropTypes = 'Replacement Properties and Types'; lisReplacements = 'Replacements';
lisReplaceRemoveUnknown = 'Replace unknown types and properties'; lisProperties = 'Properties (replace or delete)';
lisTypes = 'Types (not removed if no replacement)';
lisReplaceRemoveUnknown = 'Fix unknown properties and types';
lisUnableToLoadOldResourceFileTheResourceFileIs = 'Unable to load old ' lisUnableToLoadOldResourceFileTheResourceFileIs = 'Unable to load old '
+'resource file.%sThe resource file is the first include file in the%' +'resource file.%sThe resource file is the first include file in the%'