mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 23:59:12 +02:00
Refactored MissingPropertiesDlg.
git-svn-id: trunk@23986 -
This commit is contained in:
parent
b6b87b095a
commit
e8e8dd5595
@ -52,7 +52,7 @@ type
|
|||||||
fAutoMissingProperties: boolean;
|
fAutoMissingProperties: boolean;
|
||||||
fAutoMissingComponents: boolean;
|
fAutoMissingComponents: boolean;
|
||||||
// Replacement properties for Delphi properties.
|
// Replacement properties for Delphi properties.
|
||||||
fReplacementProperties : TStringToStringTree;
|
fReplaceProps: TStringToStringTree;
|
||||||
function GetBackupPath: String;
|
function GetBackupPath: String;
|
||||||
procedure SetMainFilename(const AValue: String);
|
procedure SetMainFilename(const AValue: String);
|
||||||
public
|
public
|
||||||
@ -86,6 +86,7 @@ type
|
|||||||
property FormFileRename: boolean read fFormFileRename;
|
property FormFileRename: boolean read fFormFileRename;
|
||||||
property AutoMissingProperties: boolean read fAutoMissingProperties;
|
property AutoMissingProperties: boolean read fAutoMissingProperties;
|
||||||
property AutoMissingComponents: boolean read fAutoMissingComponents;
|
property AutoMissingComponents: boolean read fAutoMissingComponents;
|
||||||
|
property ReplaceProps: TStringToStringTree read fReplaceProps;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -133,12 +134,18 @@ begin
|
|||||||
fTitle:=ATitle;
|
fTitle:=ATitle;
|
||||||
fMainFilename:='';
|
fMainFilename:='';
|
||||||
fMainPath:='';
|
fMainPath:='';
|
||||||
fReplacementProperties:=TStringToStringTree.Create(false);
|
fReplaceProps:=TStringToStringTree.Create(false);
|
||||||
|
// Now hard-code some values. Later move them to a config file.
|
||||||
|
fReplaceProps['TFlowPanel']:='TPanel';
|
||||||
|
fReplaceProps['TGridPanel']:='TPanel';
|
||||||
|
fReplaceProps['TComboBoxEx']:='TComboBox';
|
||||||
|
fReplaceProps['TCoolBar']:='TPanel';
|
||||||
|
fReplaceProps['TDBRichEdit']:='TDBMemo';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TConvertSettings.Destroy;
|
destructor TConvertSettings.Destroy;
|
||||||
begin
|
begin
|
||||||
fReplacementProperties.Free;
|
fReplaceProps.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -33,21 +33,22 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
// FCL+LCL
|
// FCL+LCL
|
||||||
Classes, SysUtils, Math, TypInfo, LCLProc, Forms, Controls, LResources,
|
Classes, SysUtils, Math, LCLProc, Forms, Controls, //LResources,
|
||||||
Graphics, Dialogs, Buttons, StdCtrls,
|
Graphics, Dialogs, Buttons, StdCtrls,
|
||||||
// components
|
// components
|
||||||
SynHighlighterLFM, SynEdit, BasicCodeTools, CodeCache, CodeToolManager,
|
SynHighlighterLFM, SynEdit, SynEditMiscClasses, LFMTrees,
|
||||||
SynEditMiscClasses, LFMTrees,
|
// codetools
|
||||||
|
BasicCodeTools, CodeCache, CodeToolManager,
|
||||||
// IDE
|
// IDE
|
||||||
PropEdits, IDEDialogs, ComponentReg, PackageIntf, IDEWindowIntf,
|
IDEDialogs, ComponentReg, PackageIntf, IDEWindowIntf, //PropEdits,
|
||||||
CustomFormEditor, LazarusIDEStrConsts, OutputFilter, IDEProcs, IDEOptionDefs,
|
CustomFormEditor, LazarusIDEStrConsts, IDEProcs, OutputFilter, //IDEOptionDefs,
|
||||||
EditorOptions, ExtCtrls, Grids, JITForms, PropEditUtils;
|
EditorOptions, ExtCtrls, Grids, ConvertSettings; //JITForms, PropEditUtils,
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TLfmFixer }
|
{ TLfmChecker }
|
||||||
|
|
||||||
TLfmFixer = class
|
TLfmChecker = class
|
||||||
private
|
private
|
||||||
fPascalBuffer: TCodeBuffer;
|
fPascalBuffer: TCodeBuffer;
|
||||||
fLfmBuffer: TCodeBuffer;
|
fLfmBuffer: TCodeBuffer;
|
||||||
@ -55,19 +56,34 @@ type
|
|||||||
fRootMustBeClassInIntf: boolean;
|
fRootMustBeClassInIntf: boolean;
|
||||||
fObjectsMustExists: boolean;
|
fObjectsMustExists: boolean;
|
||||||
fLfmTree: TLFMTree;
|
fLfmTree: TLFMTree;
|
||||||
|
// References to controls in UI:
|
||||||
|
fLfmSynEdit: TSynEdit;
|
||||||
|
fErrorsListBox: TListBox;
|
||||||
procedure WriteUnitError(Code: TCodeBuffer; x, Y: integer;
|
procedure WriteUnitError(Code: TCodeBuffer; x, Y: integer;
|
||||||
const ErrorMessage: string);
|
const ErrorMessage: string);
|
||||||
procedure WriteCodeToolsError;
|
procedure WriteCodeToolsError;
|
||||||
procedure WriteLFMErrors;
|
procedure WriteLFMErrors;
|
||||||
function FixMissingComponentClasses: TModalResult;
|
function FixMissingComponentClasses: TModalResult;
|
||||||
function CheckUnit: boolean;
|
function CheckUnit: boolean;
|
||||||
function ShowRepairLFMWizard: TModalResult;
|
// Refactored and moved from dialog class:
|
||||||
|
procedure LoadLFM;
|
||||||
|
function RemoveAll: TModalResult;
|
||||||
|
procedure FindNiceNodeBounds(LFMNode: TLFMTreeNode;
|
||||||
|
var StartPos, EndPos: integer);
|
||||||
|
function FindListBoxError: TLFMError;
|
||||||
|
procedure JumpToError(LFMError: TLFMError);
|
||||||
|
procedure AddReplacement(LFMChangeList: TList; StartPos, EndPos: integer;
|
||||||
|
const NewText: string);
|
||||||
|
function ApplyReplacements(LFMChangeList: TList): boolean;
|
||||||
|
protected
|
||||||
|
function ShowRepairLFMWizard: TModalResult; virtual;
|
||||||
public
|
public
|
||||||
constructor Create(APascalBuffer, ALfmBuffer: TCodeBuffer;
|
constructor Create(APascalBuffer, ALfmBuffer: TCodeBuffer;
|
||||||
const AOnOutput: TOnAddFilteredLine);
|
const AOnOutput: TOnAddFilteredLine);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Repair: TModalResult;
|
function Repair: TModalResult;
|
||||||
|
procedure FillErrorsListBox;
|
||||||
|
function AutomaticFixIsPossible: boolean;
|
||||||
public
|
public
|
||||||
property PascalBuffer: TCodeBuffer read fPascalBuffer;
|
property PascalBuffer: TCodeBuffer read fPascalBuffer;
|
||||||
property LfmBuffer: TCodeBuffer read fLfmBuffer;
|
property LfmBuffer: TCodeBuffer read fLfmBuffer;
|
||||||
@ -78,6 +94,21 @@ type
|
|||||||
write fObjectsMustExists;
|
write fObjectsMustExists;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TLfmFixer }
|
||||||
|
|
||||||
|
TLfmFixer = class(TLfmChecker)
|
||||||
|
private
|
||||||
|
// References to controls in UI:
|
||||||
|
fPropReplaceGrid: TStringGrid;
|
||||||
|
protected
|
||||||
|
function ShowRepairLFMWizard: TModalResult; override;
|
||||||
|
public
|
||||||
|
constructor Create(APascalBuffer, ALfmBuffer: TCodeBuffer;
|
||||||
|
const AOnOutput: TOnAddFilteredLine);
|
||||||
|
destructor Destroy; override;
|
||||||
|
function Repair: TModalResult;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TFixLFMDialog }
|
{ TFixLFMDialog }
|
||||||
|
|
||||||
@ -96,30 +127,18 @@ type
|
|||||||
PropertyReplaceGrid: TStringGrid;
|
PropertyReplaceGrid: TStringGrid;
|
||||||
SynLFMSyn1: TSynLFMSyn;
|
SynLFMSyn1: TSynLFMSyn;
|
||||||
procedure ErrorsListBoxClick(Sender: TObject);
|
procedure ErrorsListBoxClick(Sender: TObject);
|
||||||
procedure LFMSynEditSpecialLineMarkup(Sender: TObject; Line: integer;
|
|
||||||
var Special: boolean; AMarkup: TSynSelectedColor);
|
|
||||||
procedure RemoveAllButtonClick(Sender: TObject);
|
procedure RemoveAllButtonClick(Sender: TObject);
|
||||||
procedure CheckLFMDialogCREATE(Sender: TObject);
|
|
||||||
procedure ReplaceAllButtonClick(Sender: TObject);
|
procedure ReplaceAllButtonClick(Sender: TObject);
|
||||||
|
procedure LFMSynEditSpecialLineMarkup(Sender: TObject;
|
||||||
|
Line: integer; var Special: boolean; AMarkup: TSynSelectedColor);
|
||||||
|
procedure CheckLFMDialogCREATE(Sender: TObject);
|
||||||
private
|
private
|
||||||
fLFMSource: TCodeBuffer;
|
// fLfmChecker: TLfmChecker;
|
||||||
fLFMTree: TLFMTree;
|
fLfmFixer: TLfmFixer;
|
||||||
procedure SetLFMSource(const AValue: TCodeBuffer);
|
|
||||||
procedure SetLFMTree(const AValue: TLFMTree);
|
|
||||||
procedure SetupComponents;
|
procedure SetupComponents;
|
||||||
function FindListBoxError: TLFMError;
|
|
||||||
procedure JumpToError(LFMError: TLFMError);
|
|
||||||
procedure FindNiceNodeBounds(LFMNode: TLFMTreeNode;
|
|
||||||
var StartPos, EndPos: integer);
|
|
||||||
procedure AddReplacement(LFMChangeList: TList; StartPos, EndPos: integer;
|
|
||||||
const NewText: string);
|
|
||||||
function ApplyReplacements(LFMChangeList: TList): boolean;
|
|
||||||
public
|
public
|
||||||
procedure LoadLFM;
|
constructor Create(AOwner: TComponent; ALfmFixer: TLfmFixer);
|
||||||
procedure FillErrorsListBox;
|
destructor Destroy; override;
|
||||||
function AutomaticFixIsPossible: boolean;
|
|
||||||
property LFMTree: TLFMTree read fLFMTree write SetLFMTree;
|
|
||||||
property LFMSource: TCodeBuffer read fLFMSource write SetLFMSource;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -134,9 +153,9 @@ type
|
|||||||
NewText: string;
|
NewText: string;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLfmFixer }
|
{ TLfmChecker }
|
||||||
|
|
||||||
constructor TLfmFixer.Create(APascalBuffer, ALfmBuffer: TCodeBuffer;
|
constructor TLfmChecker.Create(APascalBuffer, ALfmBuffer: TCodeBuffer;
|
||||||
const AOnOutput: TOnAddFilteredLine);
|
const AOnOutput: TOnAddFilteredLine);
|
||||||
begin
|
begin
|
||||||
fPascalBuffer:=APascalBuffer;
|
fPascalBuffer:=APascalBuffer;
|
||||||
@ -146,12 +165,35 @@ begin
|
|||||||
fObjectsMustExists:=true;
|
fObjectsMustExists:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TLfmFixer.Destroy;
|
destructor TLfmChecker.Destroy;
|
||||||
begin
|
begin
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLfmFixer.Repair: TModalResult;
|
function TLfmChecker.ShowRepairLFMWizard: TModalResult;
|
||||||
|
//var
|
||||||
|
// FixLFMDialog: TFixLFMDialog;
|
||||||
|
begin
|
||||||
|
Result:=mrCancel;
|
||||||
|
{ FixLFMDialog:=TFixLFMDialog.Create(nil, self);
|
||||||
|
try
|
||||||
|
fLfmSynEdit:=FixLFMDialog.LFMSynEdit;
|
||||||
|
fErrorsListBox:=FixLFMDialog.ErrorsListBox;
|
||||||
|
fPropReplaceGrid:=FixLFMDialog.PropertyReplaceGrid;
|
||||||
|
LoadLFM;
|
||||||
|
Result:=FixLFMDialog.ShowModal;
|
||||||
|
finally
|
||||||
|
FixLFMDialog.Free;
|
||||||
|
end; }
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLfmChecker.LoadLFM;
|
||||||
|
begin
|
||||||
|
fLfmSynEdit.Lines.Text:=fLfmBuffer.Source;
|
||||||
|
FillErrorsListBox;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLfmChecker.Repair: TModalResult;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
if not CheckUnit then begin
|
if not CheckUnit then begin
|
||||||
@ -171,7 +213,7 @@ begin
|
|||||||
Result:=ShowRepairLFMWizard;
|
Result:=ShowRepairLFMWizard;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLfmFixer.WriteUnitError(Code: TCodeBuffer; x, Y: integer;
|
procedure TLfmChecker.WriteUnitError(Code: TCodeBuffer; x, Y: integer;
|
||||||
const ErrorMessage: string);
|
const ErrorMessage: string);
|
||||||
var
|
var
|
||||||
Dir: String;
|
Dir: String;
|
||||||
@ -190,13 +232,13 @@ begin
|
|||||||
fOnOutput(Msg,Dir,-1,nil);
|
fOnOutput(Msg,Dir,-1,nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLfmFixer.WriteCodeToolsError;
|
procedure TLfmChecker.WriteCodeToolsError;
|
||||||
begin
|
begin
|
||||||
WriteUnitError(CodeToolBoss.ErrorCode,CodeToolBoss.ErrorColumn,
|
WriteUnitError(CodeToolBoss.ErrorCode,CodeToolBoss.ErrorColumn,
|
||||||
CodeToolBoss.ErrorLine,CodeToolBoss.ErrorMessage);
|
CodeToolBoss.ErrorLine,CodeToolBoss.ErrorMessage);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLfmFixer.WriteLFMErrors;
|
procedure TLfmChecker.WriteLFMErrors;
|
||||||
var
|
var
|
||||||
CurError: TLFMError;
|
CurError: TLFMError;
|
||||||
Dir: String;
|
Dir: String;
|
||||||
@ -217,7 +259,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLfmFixer.FixMissingComponentClasses: TModalResult;
|
function TLfmChecker.FixMissingComponentClasses: TModalResult;
|
||||||
// returns true, if after adding units to uses section all errors are fixed
|
// returns true, if after adding units to uses section all errors are fixed
|
||||||
var
|
var
|
||||||
CurError: TLFMError;
|
CurError: TLFMError;
|
||||||
@ -270,7 +312,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLfmFixer.CheckUnit: boolean;
|
function TLfmChecker.CheckUnit: boolean;
|
||||||
var
|
var
|
||||||
NewCode: TCodeBuffer;
|
NewCode: TCodeBuffer;
|
||||||
NewX, NewY, NewTopLine: integer;
|
NewX, NewY, NewTopLine: integer;
|
||||||
@ -288,8 +330,7 @@ begin
|
|||||||
// check used units
|
// check used units
|
||||||
MissingUnits:=nil;
|
MissingUnits:=nil;
|
||||||
try
|
try
|
||||||
if not CodeToolBoss.FindMissingUnits(fPascalBuffer,MissingUnits,false,
|
if not CodeToolBoss.FindMissingUnits(fPascalBuffer,MissingUnits,false,false)
|
||||||
false)
|
|
||||||
then begin
|
then begin
|
||||||
WriteCodeToolsError;
|
WriteCodeToolsError;
|
||||||
exit;
|
exit;
|
||||||
@ -306,28 +347,7 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLfmFixer.ShowRepairLFMWizard: TModalResult;
|
function TLfmChecker.RemoveAll: TModalResult;
|
||||||
var
|
|
||||||
FixLFMDialog: TFixLFMDialog;
|
|
||||||
begin
|
|
||||||
Result:=mrCancel;
|
|
||||||
FixLFMDialog:=TFixLFMDialog.Create(nil);
|
|
||||||
FixLFMDialog.LFMTree:=fLfmTree;
|
|
||||||
FixLFMDialog.LFMSource:=fLfmBuffer;
|
|
||||||
FixLFMDialog.LoadLFM;
|
|
||||||
Result:=FixLFMDialog.ShowModal;
|
|
||||||
FixLFMDialog.Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TFixLFMDialog }
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.ReplaceAllButtonClick(Sender: TObject);
|
|
||||||
begin
|
|
||||||
;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.RemoveAllButtonClick(Sender: TObject);
|
|
||||||
var
|
var
|
||||||
CurError: TLFMError;
|
CurError: TLFMError;
|
||||||
DeleteNode: TLFMTreeNode;
|
DeleteNode: TLFMTreeNode;
|
||||||
@ -335,10 +355,11 @@ var
|
|||||||
Replacements: TList;
|
Replacements: TList;
|
||||||
i: integer;
|
i: integer;
|
||||||
begin
|
begin
|
||||||
|
Result:=mrNone;
|
||||||
Replacements:=TList.Create;
|
Replacements:=TList.Create;
|
||||||
try
|
try
|
||||||
// automatically delete each error location
|
// automatically delete each error location
|
||||||
CurError:=LFMTree.LastError;
|
CurError:=fLfmTree.LastError;
|
||||||
while CurError<>nil do begin
|
while CurError<>nil do begin
|
||||||
DeleteNode:=CurError.FindContextNode;
|
DeleteNode:=CurError.FindContextNode;
|
||||||
if (DeleteNode<>nil) and (DeleteNode.Parent<>nil) then begin
|
if (DeleteNode<>nil) and (DeleteNode.Parent<>nil) then begin
|
||||||
@ -347,9 +368,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
CurError:=CurError.PrevError;
|
CurError:=CurError.PrevError;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ApplyReplacements(Replacements) then
|
if ApplyReplacements(Replacements) then
|
||||||
ModalResult:=mrOk;
|
Result:=mrOk;
|
||||||
finally
|
finally
|
||||||
for i := 0 to Replacements.Count - 1 do
|
for i := 0 to Replacements.Count - 1 do
|
||||||
TObject(Replacements[i]).Free;
|
TObject(Replacements[i]).Free;
|
||||||
@ -357,67 +377,25 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFixLFMDialog.ErrorsListBoxClick(Sender: TObject);
|
procedure TLfmChecker.FindNiceNodeBounds(LFMNode: TLFMTreeNode;
|
||||||
begin
|
var StartPos, EndPos: integer);
|
||||||
JumpToError(FindListBoxError);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.LFMSynEditSpecialLineMarkup(Sender: TObject;
|
|
||||||
Line: integer; var Special: boolean; AMarkup: TSynSelectedColor);
|
|
||||||
var
|
var
|
||||||
CurError: TLFMError;
|
Src: String;
|
||||||
begin
|
begin
|
||||||
CurError:=LFMTree.FindErrorAtLine(Line);
|
Src:=fLfmBuffer.Source;
|
||||||
if CurError = nil then Exit;
|
StartPos:=FindLineEndOrCodeInFrontOfPosition(Src,LFMNode.StartPos,1,false,true);
|
||||||
|
EndPos:=FindLineEndOrCodeInFrontOfPosition(Src,LFMNode.EndPos,1,false,true);
|
||||||
Special := True;
|
EndPos:=FindLineEndOrCodeAfterPosition(Src,EndPos,length(Src),false);
|
||||||
EditorOpts.SetMarkupColor(SynLFMSyn1, ahaErrorLine, AMarkup);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFixLFMDialog.CheckLFMDialogCREATE(Sender: TObject);
|
function TLfmChecker.FindListBoxError: TLFMError;
|
||||||
begin
|
|
||||||
Caption:=lisFixLFMFile;
|
|
||||||
Position:=poScreenCenter;
|
|
||||||
IDEDialogLayoutList.ApplyLayout(Self,600,400);
|
|
||||||
SetupComponents;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.SetLFMSource(const AValue: TCodeBuffer);
|
|
||||||
begin
|
|
||||||
if fLFMSource=AValue then exit;
|
|
||||||
fLFMSource:=AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.SetLFMTree(const AValue: TLFMTree);
|
|
||||||
begin
|
|
||||||
if fLFMTree=AValue then exit;
|
|
||||||
fLFMTree:=AValue;
|
|
||||||
RemoveAllButton.Enabled:=AutomaticFixIsPossible;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.SetupComponents;
|
|
||||||
const // Will be moved to LazarusIDEStrConsts
|
|
||||||
lisReplaceAllProperties = 'Replace all properties';
|
|
||||||
begin
|
|
||||||
NoteLabel.Caption:=lisTheLFMLazarusFormFileContainsInvalidPropertiesThis;
|
|
||||||
ErrorsGroupBox.Caption:=lisErrors;
|
|
||||||
LFMGroupBox.Caption:=lisLFMFile;
|
|
||||||
RemoveAllButton.Caption:=lisRemoveAllInvalidProperties;
|
|
||||||
RemoveAllButton.LoadGlyphFromLazarusResource('laz_delete');
|
|
||||||
ReplaceAllButton.Caption:=lisReplaceAllProperties;
|
|
||||||
ReplaceAllButton.LoadGlyphFromLazarusResource('laz_refresh');
|
|
||||||
EditorOpts.GetHighlighterSettings(SynLFMSyn1);
|
|
||||||
EditorOpts.GetSynEditSettings(LFMSynEdit);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TFixLFMDialog.FindListBoxError: TLFMError;
|
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
i:=ErrorsListBox.ItemIndex;
|
i:=fErrorsListBox.ItemIndex;
|
||||||
if (i<0) or (i>=ErrorsListBox.Items.Count) then exit;
|
if (i<0) or (i>=fErrorsListBox.Items.Count) then exit;
|
||||||
Result:=LFMTree.FirstError;
|
Result:=fLfmTree.FirstError;
|
||||||
while Result<>nil do begin
|
while Result<>nil do begin
|
||||||
if i=0 then exit;
|
if i=0 then exit;
|
||||||
Result:=Result.NextError;
|
Result:=Result.NextError;
|
||||||
@ -425,24 +403,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFixLFMDialog.JumpToError(LFMError: TLFMError);
|
procedure TLfmChecker.JumpToError(LFMError: TLFMError);
|
||||||
begin
|
begin
|
||||||
if LFMError=nil then exit;
|
if LFMError=nil then exit;
|
||||||
LFMSynEdit.CaretXY:=LFMError.Caret;
|
fLfmSynEdit.CaretXY:=LFMError.Caret;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFixLFMDialog.FindNiceNodeBounds(LFMNode: TLFMTreeNode;
|
procedure TLfmChecker.AddReplacement(LFMChangeList: TList;
|
||||||
var StartPos, EndPos: integer);
|
|
||||||
var
|
|
||||||
Src: String;
|
|
||||||
begin
|
|
||||||
Src:=LFMSource.Source;
|
|
||||||
StartPos:=FindLineEndOrCodeInFrontOfPosition(Src,LFMNode.StartPos,1,false,true);
|
|
||||||
EndPos:=FindLineEndOrCodeInFrontOfPosition(Src,LFMNode.EndPos,1,false,true);
|
|
||||||
EndPos:=FindLineEndOrCodeAfterPosition(Src,EndPos,length(Src),false);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.AddReplacement(LFMChangeList: TList;
|
|
||||||
StartPos, EndPos: integer; const NewText: string);
|
StartPos, EndPos: integer; const NewText: string);
|
||||||
var
|
var
|
||||||
Entry: TLFMChangeEntry;
|
Entry: TLFMChangeEntry;
|
||||||
@ -480,7 +447,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// insert new entry
|
// insert new entry
|
||||||
NewEntry:=TLFMChangeEntry.Create;
|
NewEntry:=TLFMChangeEntry.Create;
|
||||||
NewEntry.NewText:=NewText;
|
NewEntry.NewText:=NewText;
|
||||||
@ -504,58 +471,52 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFixLFMDialog.ApplyReplacements(LFMChangeList: TList): boolean;
|
function TLfmChecker.ApplyReplacements(LfmChangeList: TList): boolean;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
Entry: TLFMChangeEntry;
|
Entry: TLFMChangeEntry;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
for i:=LFMChangeList.Count-1 downto 0 do begin
|
for i:=LfmChangeList.Count-1 downto 0 do begin
|
||||||
Entry:=TLFMChangeEntry(LFMChangeList[i]);
|
Entry:=TLFMChangeEntry(LfmChangeList[i]);
|
||||||
// DebugLn('TCheckLFMDialog.ApplyReplacements A ',IntToStr(i),' ',
|
// DebugLn('TCheckLFMDialog.ApplyReplacements A ',IntToStr(i),' ',
|
||||||
// IntToStr(Entry.StartPos),',',IntToStr(Entry.EndPos),
|
// IntToStr(Entry.StartPos),',',IntToStr(Entry.EndPos),
|
||||||
// ' "',copy(LFMSource.Source,Entry.StartPos,Entry.EndPos-Entry.StartPos),'" -> "',Entry.NewText,'"');
|
// ' "',copy(fLfmBuffer.Source,Entry.StartPos,Entry.EndPos-Entry.StartPos),'" -> "',Entry.NewText,'"');
|
||||||
LFMSource.Replace(Entry.StartPos,Entry.EndPos-Entry.StartPos,Entry.NewText);
|
fLfmBuffer.Replace(Entry.StartPos,Entry.EndPos-Entry.StartPos,Entry.NewText);
|
||||||
end;
|
end;
|
||||||
//writeln(LFMSource.Source);
|
//writeln(fLfmBuffer.Source);
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFixLFMDialog.LoadLFM;
|
procedure TLfmChecker.FillErrorsListBox;
|
||||||
begin
|
|
||||||
LFMSynEdit.Lines.Text:=LFMSource.Source;
|
|
||||||
FillErrorsListBox;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFixLFMDialog.FillErrorsListBox;
|
|
||||||
var
|
var
|
||||||
CurError: TLFMError;
|
CurError: TLFMError;
|
||||||
Filename: String;
|
Filename: String;
|
||||||
Msg: String;
|
Msg: String;
|
||||||
begin
|
begin
|
||||||
ErrorsListBox.Items.BeginUpdate;
|
fErrorsListBox.Items.BeginUpdate;
|
||||||
ErrorsListBox.Items.Clear;
|
fErrorsListBox.Items.Clear;
|
||||||
if LFMTree<>nil then begin
|
if fLfmTree<>nil then begin
|
||||||
Filename:=ExtractFileName(LFMSource.Filename);
|
Filename:=ExtractFileName(fLfmBuffer.Filename);
|
||||||
CurError:=LFMTree.FirstError;
|
CurError:=fLfmTree.FirstError;
|
||||||
while CurError<>nil do begin
|
while CurError<>nil do begin
|
||||||
Msg:=Filename
|
Msg:=Filename
|
||||||
+'('+IntToStr(CurError.Caret.Y)+','+IntToStr(CurError.Caret.X)+')'
|
+'('+IntToStr(CurError.Caret.Y)+','+IntToStr(CurError.Caret.X)+')'
|
||||||
+' Error: '
|
+' Error: '
|
||||||
+CurError.ErrorMessage;
|
+CurError.ErrorMessage;
|
||||||
ErrorsListBox.Items.Add(Msg);
|
fErrorsListBox.Items.Add(Msg);
|
||||||
CurError:=CurError.NextError;
|
CurError:=CurError.NextError;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
ErrorsListBox.Items.EndUpdate;
|
fErrorsListBox.Items.EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFixLFMDialog.AutomaticFixIsPossible: boolean;
|
function TLfmChecker.AutomaticFixIsPossible: boolean;
|
||||||
var
|
var
|
||||||
CurError: TLFMError;
|
CurError: TLFMError;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
CurError:=LFMTree.FirstError;
|
CurError:=fLfmTree.FirstError;
|
||||||
while CurError<>nil do begin
|
while CurError<>nil do begin
|
||||||
if CurError.ErrorType in [lfmeNoError,lfmeIdentifierNotFound,
|
if CurError.ErrorType in [lfmeNoError,lfmeIdentifierNotFound,
|
||||||
lfmeObjectNameMissing,lfmeObjectIncompatible,lfmePropertyNameMissing,
|
lfmeObjectNameMissing,lfmeObjectIncompatible,lfmePropertyNameMissing,
|
||||||
@ -572,5 +533,118 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TLfmFixer }
|
||||||
|
|
||||||
|
constructor TLfmFixer.Create(APascalBuffer, ALfmBuffer: TCodeBuffer;
|
||||||
|
const AOnOutput: TOnAddFilteredLine);
|
||||||
|
begin
|
||||||
|
inherited Create(APascalBuffer, ALfmBuffer, AOnOutput);
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TLfmFixer.Destroy;
|
||||||
|
begin
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLfmFixer.ShowRepairLFMWizard: TModalResult;
|
||||||
|
var
|
||||||
|
FixLFMDialog: TFixLFMDialog;
|
||||||
|
begin
|
||||||
|
Result:=mrCancel;
|
||||||
|
FixLFMDialog:=TFixLFMDialog.Create(nil, self);
|
||||||
|
try
|
||||||
|
fLfmSynEdit:=FixLFMDialog.LFMSynEdit;
|
||||||
|
fErrorsListBox:=FixLFMDialog.ErrorsListBox;
|
||||||
|
fPropReplaceGrid:=FixLFMDialog.PropertyReplaceGrid;
|
||||||
|
LoadLFM;
|
||||||
|
Result:=FixLFMDialog.ShowModal;
|
||||||
|
finally
|
||||||
|
FixLFMDialog.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLfmFixer.Repair: TModalResult;
|
||||||
|
begin
|
||||||
|
Result:=inherited Repair;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TFixLFMDialog }
|
||||||
|
|
||||||
|
constructor TFixLFMDialog.Create(AOwner: TComponent; ALfmFixer: TLfmFixer);
|
||||||
|
begin
|
||||||
|
inherited Create(AOwner);
|
||||||
|
fLfmFixer:=ALfmFixer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TFixLFMDialog.Destroy;
|
||||||
|
begin
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.ReplaceAllButtonClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.RemoveAllButtonClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
ModalResult:=fLfmFixer.RemoveAll;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.ErrorsListBoxClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
fLfmFixer.JumpToError(fLfmFixer.FindListBoxError);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.LFMSynEditSpecialLineMarkup(Sender: TObject;
|
||||||
|
Line: integer; var Special: boolean; AMarkup: TSynSelectedColor);
|
||||||
|
var
|
||||||
|
CurError: TLFMError;
|
||||||
|
begin
|
||||||
|
CurError:=fLfmFixer.fLfmTree.FindErrorAtLine(Line);
|
||||||
|
if CurError = nil then Exit;
|
||||||
|
Special := True;
|
||||||
|
EditorOpts.SetMarkupColor(SynLFMSyn1, ahaErrorLine, AMarkup);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.CheckLFMDialogCREATE(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Caption:=lisFixLFMFile;
|
||||||
|
Position:=poScreenCenter;
|
||||||
|
IDEDialogLayoutList.ApplyLayout(Self,600,400);
|
||||||
|
SetupComponents;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.SetupComponents;
|
||||||
|
const // Will be moved to LazarusIDEStrConsts
|
||||||
|
lisReplaceAllProperties = 'Replace all properties';
|
||||||
|
begin
|
||||||
|
NoteLabel.Caption:=lisTheLFMLazarusFormFileContainsInvalidPropertiesThis;
|
||||||
|
ErrorsGroupBox.Caption:=lisErrors;
|
||||||
|
LFMGroupBox.Caption:=lisLFMFile;
|
||||||
|
RemoveAllButton.Caption:=lisRemoveAllInvalidProperties;
|
||||||
|
RemoveAllButton.LoadGlyphFromLazarusResource('laz_delete');
|
||||||
|
ReplaceAllButton.Caption:=lisReplaceAllProperties;
|
||||||
|
ReplaceAllButton.LoadGlyphFromLazarusResource('laz_refresh');
|
||||||
|
EditorOpts.GetHighlighterSettings(SynLFMSyn1);
|
||||||
|
EditorOpts.GetSynEditSettings(LFMSynEdit);
|
||||||
|
end;
|
||||||
|
{
|
||||||
|
procedure TFixLFMDialog.SetLfmBuffer(const AValue: TCodeBuffer);
|
||||||
|
begin
|
||||||
|
if fLFMSource=AValue then exit;
|
||||||
|
fLFMSource:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TFixLFMDialog.SetLfmTree(const AValue: TLFMTree);
|
||||||
|
begin
|
||||||
|
if fLFMTree=AValue then exit;
|
||||||
|
fLFMTree:=AValue;
|
||||||
|
RemoveAllButton.Enabled:=AutomaticFixIsPossible;
|
||||||
|
end;
|
||||||
|
}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user