implemented basic Repair broken LFM wizard

git-svn-id: trunk@4891 -
This commit is contained in:
mattias 2003-12-16 13:42:02 +00:00
parent d0e6b3d8d5
commit e758407c49
10 changed files with 952 additions and 549 deletions

View File

@ -215,6 +215,8 @@ type
function AsString: string;
procedure AddToTree(ATree: TLFMTree);
procedure Unbind;
function FindParentError: TLFMError;
function FindContextNode: TLFMTreeNode;
end;
{ TLFMTree }
@ -240,6 +242,8 @@ type
function PositionToCaret(p: integer): TPoint;
procedure AddError(ErrorType: TLFMErrorType; LFMNode: TLFMTreeNode;
const ErrorMessage: string; ErrorPosition: integer);
function FindErrorAtLine(Line: integer): TLFMError;
function FindErrorAtNode(Node: TLFMTreeNode): TLFMError;
end;
const
@ -330,6 +334,24 @@ begin
NewError.AddToTree(Self);
end;
function TLFMTree.FindErrorAtLine(Line: integer): TLFMError;
begin
Result:=FirstError;
while Result<>nil do begin
if (Result.Caret.Y=Line) and (Line>=1) then exit;
Result:=Result.NextError;
end;
end;
function TLFMTree.FindErrorAtNode(Node: TLFMTreeNode): TLFMError;
begin
Result:=FirstError;
while Result<>nil do begin
if (Result.Node=Node) and (Node<>nil) then exit;
Result:=Result.NextError;
end;
end;
procedure TLFMTree.ProcessValue;
var
s: String;
@ -732,6 +754,28 @@ begin
NextError:=nil;
end;
function TLFMError.FindParentError: TLFMError;
var
CurNode: TLFMTreeNode;
begin
Result:=nil;
if (Node=nil) or (Tree=nil) then exit;
CurNode:=Node.Parent;
while CurNode<>nil do begin
Result:=Tree.FindErrorAtNode(CurNode);
if Result<>nil then exit;
CurNode:=CurNode.Parent;
end;
end;
function TLFMError.FindContextNode: TLFMTreeNode;
begin
Result:=Node;
while (Result<>nil)
and (not (Result.TheType in [lfmnProperty,lfmnObject])) do
Result:=Result.Parent;
end;
{ TLFMNameParts }
function TLFMNameParts.GetNamePositions(Index: integer): integer;

View File

@ -1,12 +1,427 @@
object CheckLFMDialog: TCheckLFMDialog
CAPTION = 'CheckLFMDialog'
CLIENTHEIGHT = 414
CLIENTWIDTH = 598
ONCREATE = CheckLFMDialogCREATE
HORZSCROLLBAR.PAGE = 599
VERTSCROLLBAR.PAGE = 415
LEFT = 291
HEIGHT = 414
TOP = 179
WIDTH = 598
Caption = 'Repair LFM file'
ClientHeight = 516
ClientWidth = 458
OnCreate = CheckLFMDialogCreate
HorzScrollBar.Page = 459
VertScrollBar.Page = 517
Left = 368
Height = 516
Top = 200
Width = 458
object CancelButton: TButton
Anchors = [akleft, akbottom]
ModalResult = 2
Caption = 'Cancel'
TabStop = True
TabOrder = 0
Left = 359
Height = 25
Top = 483
Width = 75
end
object RemoveAllButton: TButton
Anchors = [akleft, akbottom]
Caption = 'Remove all invalid properties'
TabStop = True
TabOrder = 1
OnClick = RemoveAllButtonClick
Left = 24
Height = 25
Top = 483
Width = 311
end
object LFMGroupBox: TGroupBox
Anchors = [aktop, akleft, akright, akbottom]
Caption = 'LFM file'
ClientHeight = 266
ClientWidth = 442
Color = -2147483633
ParentColor = True
ParentCtl3D = False
TabOrder = 2
Left = 8
Height = 283
Top = 80
Width = 446
object LFMSynEdit: TSynEdit
Align = alclient
Color = 16777215
Font.Height = -15
Font.Name = 'courier'
Height = 266
Name = 'LFMSynEdit'
ParentCtl3D = False
TabOrder = 0
Width = 442
Highlighter = SynLFMSyn1
Keystrokes = <
item
Command = 3
ShortCut = 38
end
item
Command = 103
ShortCut = 8230
end
item
Command = 211
ShortCut = 16422
end
item
Command = 4
ShortCut = 40
end
item
Command = 104
ShortCut = 8232
end
item
Command = 212
ShortCut = 16424
end
item
Command = 1
ShortCut = 37
end
item
Command = 101
ShortCut = 8229
end
item
Command = 5
ShortCut = 16421
end
item
Command = 105
ShortCut = 24613
end
item
Command = 2
ShortCut = 39
end
item
Command = 102
ShortCut = 8231
end
item
Command = 6
ShortCut = 16423
end
item
Command = 106
ShortCut = 24615
end
item
Command = 10
ShortCut = 34
end
item
Command = 110
ShortCut = 8226
end
item
Command = 14
ShortCut = 16418
end
item
Command = 114
ShortCut = 24610
end
item
Command = 9
ShortCut = 33
end
item
Command = 109
ShortCut = 8225
end
item
Command = 13
ShortCut = 16417
end
item
Command = 113
ShortCut = 24609
end
item
Command = 7
ShortCut = 36
end
item
Command = 107
ShortCut = 8228
end
item
Command = 15
ShortCut = 16420
end
item
Command = 115
ShortCut = 24612
end
item
Command = 8
ShortCut = 35
end
item
Command = 108
ShortCut = 8227
end
item
Command = 16
ShortCut = 16419
end
item
Command = 116
ShortCut = 24611
end
item
Command = 223
ShortCut = 45
end
item
Command = 201
ShortCut = 16429
end
item
Command = 604
ShortCut = 8237
end
item
Command = 502
ShortCut = 46
end
item
Command = 603
ShortCut = 8238
end
item
Command = 501
ShortCut = 8
end
item
Command = 501
ShortCut = 8200
end
item
Command = 504
ShortCut = 16392
end
item
Command = 601
ShortCut = 32776
end
item
Command = 602
ShortCut = 40968
end
item
Command = 509
ShortCut = 13
end
item
Command = 199
ShortCut = 16449
end
item
Command = 201
ShortCut = 16451
end
item
Command = 610
ShortCut = 24649
end
item
Command = 509
ShortCut = 16461
end
item
Command = 510
ShortCut = 16462
end
item
Command = 503
ShortCut = 16468
end
item
Command = 611
ShortCut = 24661
end
item
Command = 604
ShortCut = 16470
end
item
Command = 603
ShortCut = 16472
end
item
Command = 507
ShortCut = 16473
end
item
Command = 506
ShortCut = 24665
end
item
Command = 601
ShortCut = 16474
end
item
Command = 602
ShortCut = 24666
end
item
Command = 301
ShortCut = 16432
end
item
Command = 302
ShortCut = 16433
end
item
Command = 303
ShortCut = 16434
end
item
Command = 304
ShortCut = 16435
end
item
Command = 305
ShortCut = 16436
end
item
Command = 306
ShortCut = 16437
end
item
Command = 307
ShortCut = 16438
end
item
Command = 308
ShortCut = 16439
end
item
Command = 309
ShortCut = 16440
end
item
Command = 310
ShortCut = 16441
end
item
Command = 351
ShortCut = 24624
end
item
Command = 352
ShortCut = 24625
end
item
Command = 353
ShortCut = 24626
end
item
Command = 354
ShortCut = 24627
end
item
Command = 355
ShortCut = 24628
end
item
Command = 356
ShortCut = 24629
end
item
Command = 357
ShortCut = 24630
end
item
Command = 358
ShortCut = 24631
end
item
Command = 359
ShortCut = 24632
end
item
Command = 360
ShortCut = 24633
end
item
Command = 231
ShortCut = 24654
end
item
Command = 232
ShortCut = 24643
end
item
Command = 233
ShortCut = 24652
end
item
Command = 612
ShortCut = 9
end
item
Command = 613
ShortCut = 8201
end
item
Command = 250
ShortCut = 24642
end>
Lines.Strings = (
'LFMSynEdit'
)
OnSpecialLineColors = LFMSynEditSpecialLineColors
Cursor = 65532
Height = 266
Width = 442
end
end
object ErrorsGroupBox: TGroupBox
Anchors = [akleft, akright, akbottom]
Caption = 'Errors'
ClientHeight = 87
ClientWidth = 442
Color = -2147483633
ParentColor = True
ParentCtl3D = False
TabOrder = 3
Left = 8
Height = 104
Top = 371
Width = 446
object ErrorsListBox: TListBox
Align = alclient
OnClick = ErrorsListBoxClick
TabOrder = 0
TabStop = True
TopIndex = -1
Height = 87
Width = 442
end
end
object NoteLabel: TLabel
Caption = 'NoteLabel'
Color = -2147483633
Layout = tltop
WordWrap = True
Left = 8
Height = 65
Top = 8
Width = 441
end
object SynLFMSyn1: TSynLFMSyn
DefaultFilter = 'Lazarus Form Files (*.lfm)|*.lfm'
Enabled = False
left = 129
top = 104
end
end

View File

@ -1,8 +1,76 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TCheckLFMDialog','FORMDATA',[
'TPF0'#15'TCheckLFMDialog'#14'CheckLFMDialog'#7'CAPTION'#6#14'CheckLFMDialog'
+#12'CLIENTHEIGHT'#3#158#1#11'CLIENTWIDTH'#3'V'#2#8'ONCREATE'#7#20'CheckLFMDi'
+'alogCREATE'#18'HORZSCROLLBAR.PAGE'#3'W'#2#18'VERTSCROLLBAR.PAGE'#3#159#1#4
+'LEFT'#3'#'#1#6'HEIGHT'#3#158#1#3'TOP'#3#179#0#5'WIDTH'#3'V'#2#0#0
'TPF0'#15'TCheckLFMDialog'#14'CheckLFMDialog'#7'Caption'#6#15'Repair LFM file'
+#12'ClientHeight'#3#4#2#11'ClientWidth'#3#202#1#8'OnCreate'#7#20'CheckLFMDia'
+'logCreate'#18'HorzScrollBar.Page'#3#203#1#18'VertScrollBar.Page'#3#5#2#4'Le'
+'ft'#3'p'#1#6'Height'#3#4#2#3'Top'#3#200#0#5'Width'#3#202#1#0#7'TButton'#12
+'CancelButton'#7'Anchors'#11#6'akleft'#8'akbottom'#0#11'ModalResult'#2#2#7'C'
+'aption'#6#6'Cancel'#7'TabStop'#9#8'TabOrder'#2#0#4'Left'#3'g'#1#6'Height'#2
+#25#3'Top'#3#227#1#5'Width'#2'K'#0#0#7'TButton'#15'RemoveAllButton'#7'Anchor'
+'s'#11#6'akleft'#8'akbottom'#0#7'Caption'#6#29'Remove all invalid properties'
+#7'TabStop'#9#8'TabOrder'#2#1#7'OnClick'#7#20'RemoveAllButtonClick'#4'Left'#2
+#24#6'Height'#2#25#3'Top'#3#227#1#5'Width'#3'7'#1#0#0#9'TGroupBox'#11'LFMGro'
+'upBox'#7'Anchors'#11#5'aktop'#6'akleft'#7'akright'#8'akbottom'#0#7'Caption'
+#6#8'LFM file'#12'ClientHeight'#3#10#1#11'ClientWidth'#3#186#1#5'Color'#4#15
+#0#0#128#11'ParentColor'#9#11'ParentCtl3D'#8#8'TabOrder'#2#2#4'Left'#2#8#6'H'
+'eight'#3#27#1#3'Top'#2'P'#5'Width'#3#190#1#0#8'TSynEdit'#10'LFMSynEdit'#5'A'
+'lign'#7#8'alclient'#5'Color'#4#255#255#255#0#11'Font.Height'#2#241#9'Font.N'
+'ame'#6#7'courier'#6'Height'#3#10#1#4'Name'#6#10'LFMSynEdit'#11'ParentCtl3D'
+#8#8'TabOrder'#2#0#5'Width'#3#186#1#11'Highlighter'#7#10'SynLFMSyn1'#10'Keys'
+'trokes'#14#1#7'Command'#2#3#8'ShortCut'#2'&'#0#1#7'Command'#2'g'#8'ShortCut'
+#3'& '#0#1#7'Command'#3#211#0#8'ShortCut'#3'&@'#0#1#7'Command'#2#4#8'ShortCu'
+'t'#2'('#0#1#7'Command'#2'h'#8'ShortCut'#3'( '#0#1#7'Command'#3#212#0#8'Shor'
+'tCut'#3'(@'#0#1#7'Command'#2#1#8'ShortCut'#2'%'#0#1#7'Command'#2'e'#8'Short'
+'Cut'#3'% '#0#1#7'Command'#2#5#8'ShortCut'#3'%@'#0#1#7'Command'#2'i'#8'Short'
+'Cut'#3'%`'#0#1#7'Command'#2#2#8'ShortCut'#2''''#0#1#7'Command'#2'f'#8'Short'
+'Cut'#3''' '#0#1#7'Command'#2#6#8'ShortCut'#3'''@'#0#1#7'Command'#2'j'#8'Sho'
+'rtCut'#3'''`'#0#1#7'Command'#2#10#8'ShortCut'#2'"'#0#1#7'Command'#2'n'#8'Sh'
+'ortCut'#3'" '#0#1#7'Command'#2#14#8'ShortCut'#3'"@'#0#1#7'Command'#2'r'#8'S'
+'hortCut'#3'"`'#0#1#7'Command'#2#9#8'ShortCut'#2'!'#0#1#7'Command'#2'm'#8'Sh'
+'ortCut'#3'! '#0#1#7'Command'#2#13#8'ShortCut'#3'!@'#0#1#7'Command'#2'q'#8'S'
+'hortCut'#3'!`'#0#1#7'Command'#2#7#8'ShortCut'#2'$'#0#1#7'Command'#2'k'#8'Sh'
+'ortCut'#3'$ '#0#1#7'Command'#2#15#8'ShortCut'#3'$@'#0#1#7'Command'#2's'#8'S'
+'hortCut'#3'$`'#0#1#7'Command'#2#8#8'ShortCut'#2'#'#0#1#7'Command'#2'l'#8'Sh'
+'ortCut'#3'# '#0#1#7'Command'#2#16#8'ShortCut'#3'#@'#0#1#7'Command'#2't'#8'S'
+'hortCut'#3'#`'#0#1#7'Command'#3#223#0#8'ShortCut'#2'-'#0#1#7'Command'#3#201
+#0#8'ShortCut'#3'-@'#0#1#7'Command'#3'\'#2#8'ShortCut'#3'- '#0#1#7'Command'#3
+#246#1#8'ShortCut'#2'.'#0#1#7'Command'#3'['#2#8'ShortCut'#3'. '#0#1#7'Comman'
+'d'#3#245#1#8'ShortCut'#2#8#0#1#7'Command'#3#245#1#8'ShortCut'#3#8' '#0#1#7
+'Command'#3#248#1#8'ShortCut'#3#8'@'#0#1#7'Command'#3'Y'#2#8'ShortCut'#4#8
+#128#0#0#0#1#7'Command'#3'Z'#2#8'ShortCut'#4#8#160#0#0#0#1#7'Command'#3#253#1
+#8'ShortCut'#2#13#0#1#7'Command'#3#199#0#8'ShortCut'#3'A@'#0#1#7'Command'#3
+#201#0#8'ShortCut'#3'C@'#0#1#7'Command'#3'b'#2#8'ShortCut'#3'I`'#0#1#7'Comma'
+'nd'#3#253#1#8'ShortCut'#3'M@'#0#1#7'Command'#3#254#1#8'ShortCut'#3'N@'#0#1#7
+'Command'#3#247#1#8'ShortCut'#3'T@'#0#1#7'Command'#3'c'#2#8'ShortCut'#3'U`'#0
+#1#7'Command'#3'\'#2#8'ShortCut'#3'V@'#0#1#7'Command'#3'['#2#8'ShortCut'#3'X'
+'@'#0#1#7'Command'#3#251#1#8'ShortCut'#3'Y@'#0#1#7'Command'#3#250#1#8'ShortC'
+'ut'#3'Y`'#0#1#7'Command'#3'Y'#2#8'ShortCut'#3'Z@'#0#1#7'Command'#3'Z'#2#8'S'
+'hortCut'#3'Z`'#0#1#7'Command'#3'-'#1#8'ShortCut'#3'0@'#0#1#7'Command'#3'.'#1
+#8'ShortCut'#3'1@'#0#1#7'Command'#3'/'#1#8'ShortCut'#3'2@'#0#1#7'Command'#3
+'0'#1#8'ShortCut'#3'3@'#0#1#7'Command'#3'1'#1#8'ShortCut'#3'4@'#0#1#7'Comman'
+'d'#3'2'#1#8'ShortCut'#3'5@'#0#1#7'Command'#3'3'#1#8'ShortCut'#3'6@'#0#1#7'C'
+'ommand'#3'4'#1#8'ShortCut'#3'7@'#0#1#7'Command'#3'5'#1#8'ShortCut'#3'8@'#0#1
+#7'Command'#3'6'#1#8'ShortCut'#3'9@'#0#1#7'Command'#3'_'#1#8'ShortCut'#3'0`'
+#0#1#7'Command'#3'`'#1#8'ShortCut'#3'1`'#0#1#7'Command'#3'a'#1#8'ShortCut'#3
+'2`'#0#1#7'Command'#3'b'#1#8'ShortCut'#3'3`'#0#1#7'Command'#3'c'#1#8'ShortCu'
+'t'#3'4`'#0#1#7'Command'#3'd'#1#8'ShortCut'#3'5`'#0#1#7'Command'#3'e'#1#8'Sh'
+'ortCut'#3'6`'#0#1#7'Command'#3'f'#1#8'ShortCut'#3'7`'#0#1#7'Command'#3'g'#1
+#8'ShortCut'#3'8`'#0#1#7'Command'#3'h'#1#8'ShortCut'#3'9`'#0#1#7'Command'#3
+#231#0#8'ShortCut'#3'N`'#0#1#7'Command'#3#232#0#8'ShortCut'#3'C`'#0#1#7'Comm'
+'and'#3#233#0#8'ShortCut'#3'L`'#0#1#7'Command'#3'd'#2#8'ShortCut'#2#9#0#1#7
+'Command'#3'e'#2#8'ShortCut'#3#9' '#0#1#7'Command'#3#250#0#8'ShortCut'#3'B`'
+#0#0#13'Lines.Strings'#1#6#10'LFMSynEdit'#0#19'OnSpecialLineColors'#7#27'LFM'
+'SynEditSpecialLineColors'#6'Cursor'#4#252#255#0#0#6'Height'#3#10#1#5'Width'
+#3#186#1#0#0#0#9'TGroupBox'#14'ErrorsGroupBox'#7'Anchors'#11#6'akleft'#7'akr'
+'ight'#8'akbottom'#0#7'Caption'#6#6'Errors'#12'ClientHeight'#2'W'#11'ClientW'
+'idth'#3#186#1#5'Color'#4#15#0#0#128#11'ParentColor'#9#11'ParentCtl3D'#8#8'T'
,'abOrder'#2#3#4'Left'#2#8#6'Height'#2'h'#3'Top'#3's'#1#5'Width'#3#190#1#0#8
+'TListBox'#13'ErrorsListBox'#5'Align'#7#8'alclient'#7'OnClick'#7#18'ErrorsLi'
+'stBoxClick'#8'TabOrder'#2#0#7'TabStop'#9#8'TopIndex'#2#255#6'Height'#2'W'#5
+'Width'#3#186#1#0#0#0#6'TLabel'#9'NoteLabel'#7'Caption'#6#9'NoteLabel'#5'Col'
+'or'#4#15#0#0#128#6'Layout'#7#5'tltop'#8'WordWrap'#9#4'Left'#2#8#6'Height'#2
+'A'#3'Top'#2#8#5'Width'#3#185#1#0#0#10'TSynLFMSyn'#10'SynLFMSyn1'#13'Default'
+'Filter'#6' Lazarus Form Files (*.lfm)|*.lfm'#7'Enabled'#8#4'left'#3#129#0#3
+'top'#2'h'#0#0#0
]);

View File

@ -32,22 +32,66 @@ unit CheckLFMDlg;
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, CodeCache,
CodeToolManager, LFMTrees, OutputFilter, IDEOptionDefs;
// FCL+LCL
Classes, SysUtils, Math, LResources, Forms, Controls, Graphics, Dialogs,
Buttons, StdCtrls,
// components
SynHighlighterLFM, SynEdit, BasicCodeTools, CodeCache, CodeToolManager,
LFMTrees,
// IDE
OutputFilter, IDEProcs, IDEOptionDefs, EditorOptions;
type
TCheckLFMDialog = class(TForm)
CancelButton: TButton;
ErrorsGroupBox: TGroupBox;
ErrorsListBox: TListBox;
NoteLabel: TLabel;
LFMGroupBox: TGroupBox;
LFMSynEdit: TSynEdit;
RemoveAllButton: TButton;
SynLFMSyn1: TSynLFMSyn;
procedure ErrorsListBoxClick(Sender: TObject);
procedure LFMSynEditSpecialLineColors(Sender: TObject; Line: integer;
var Special: boolean; var FG, BG: TColor);
procedure RemoveAllButtonClick(Sender: TObject);
procedure CheckLFMDialogCREATE(Sender: TObject);
private
FLFMSource: TCodeBuffer;
FLFMTree: TLFMTree;
procedure SetLFMSource(const AValue: TCodeBuffer);
procedure SetLFMTree(const AValue: TLFMTree);
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
procedure LoadLFM;
procedure FillErrorsListBox;
function AutomaticFixIsPossible: boolean;
property LFMTree: TLFMTree read FLFMTree write SetLFMTree;
property LFMSource: TCodeBuffer read FLFMSource write SetLFMSource;
end;
function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
const OnOutput: TOnOutputString): boolean;
function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer;
LFMTree: TLFMTree): boolean;
implementation
type
TLFMChangeEntry = class
public
StartPos, EndPos: integer;
NewText: string;
end;
function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
const OnOutput: TOnOutputString): boolean;
var
@ -80,14 +124,72 @@ begin
try
if Result then exit;
WriteLFMErrors;
// ToDo: open wizard for automatic repair
Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree);
finally
LFMTree.Free;
end;
end;
function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer;
LFMTree: TLFMTree): boolean;
var
CheckLFMDialog: TCheckLFMDialog;
begin
Result:=false;
CheckLFMDialog:=TCheckLFMDialog.Create(Application);
CheckLFMDialog.LFMTree:=LFMTree;
CheckLFMDialog.LFMSource:=LFMBuffer;
CheckLFMDialog.LoadLFM;
if CheckLFMDialog.ShowModal=mrOk then
Result:=true;
CheckLFMDialog.Free;
end;
{ TCheckLFMDialog }
procedure TCheckLFMDialog.RemoveAllButtonClick(Sender: TObject);
var
CurError: TLFMError;
DeleteNode: TLFMTreeNode;
StartPos, EndPos: integer;
Replacements: TList;
begin
Replacements:=TList.Create;
try
// automatically delete each error location
CurError:=LFMTree.LastError;
while CurError<>nil do begin
DeleteNode:=CurError.FindContextNode;
if (DeleteNode<>nil) and (DeleteNode.Parent<>nil) then begin
FindNiceNodeBounds(DeleteNode,StartPos,EndPos);
AddReplacement(Replacements,StartPos,EndPos,'');
end;
CurError:=CurError.PrevError;
end;
if ApplyReplacements(Replacements) then
ModalResult:=mrOk;
finally
Replacements.Free;
end;
end;
procedure TCheckLFMDialog.ErrorsListBoxClick(Sender: TObject);
begin
JumpToError(FindListBoxError);
end;
procedure TCheckLFMDialog.LFMSynEditSpecialLineColors(Sender: TObject;
Line: integer; var Special: boolean; var FG, BG: TColor);
var
CurError: TLFMError;
begin
CurError:=LFMTree.FindErrorAtLine(Line);
if CurError<>nil then begin
EditorOpts.GetSpecialLineColors(SynLFMSyn1,ahaErrorLine,Special,FG,BG);
end;
end;
procedure TCheckLFMDialog.CheckLFMDialogCREATE(Sender: TObject);
begin
Caption:='Fix LFM file';
@ -96,9 +198,204 @@ begin
SetupComponents;
end;
procedure TCheckLFMDialog.SetLFMSource(const AValue: TCodeBuffer);
begin
if FLFMSource=AValue then exit;
FLFMSource:=AValue;
end;
procedure TCheckLFMDialog.SetLFMTree(const AValue: TLFMTree);
begin
if FLFMTree=AValue then exit;
FLFMTree:=AValue;
RemoveAllButton.Enabled:=AutomaticFixIsPossible;
end;
procedure TCheckLFMDialog.SetupComponents;
begin
NoteLabel.Caption:='The LFM (Lazarus form) file contains invalid properties. '
+'This means for example it contains some properties/classes, which do not exist in the current LCL. '
+'The normal fix is to remove these properties from the lfm and fix the pascal code manually.';
CancelButton.Caption:='Cancel';
ErrorsGroupBox.Caption:='Errors';
LFMGroupBox.Caption:='LFM file';
RemoveAllButton.Caption:='Remove all invalid properties';
EditorOpts.GetHighlighterSettings(SynLFMSyn1);
EditorOpts.GetSynEditSettings(LFMSynEdit);
end;
function TCheckLFMDialog.FindListBoxError: TLFMError;
var
i: Integer;
begin
Result:=nil;
i:=ErrorsListBox.ItemIndex;
if (i<0) or (i>=ErrorsListBox.Items.Count) then exit;
Result:=LFMTree.FirstError;
while Result<>nil do begin
if i=0 then exit;
Result:=Result.NextError;
dec(i);
end;
end;
procedure TCheckLFMDialog.JumpToError(LFMError: TLFMError);
begin
if LFMError=nil then exit;
LFMSynEdit.CaretXY:=LFMError.Caret;
end;
procedure TCheckLFMDialog.FindNiceNodeBounds(LFMNode: TLFMTreeNode;
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 TCheckLFMDialog.AddReplacement(LFMChangeList: TList;
StartPos, EndPos: integer; const NewText: string);
var
Entry: TLFMChangeEntry;
NewEntry: TLFMChangeEntry;
NextEntry: TLFMChangeEntry;
i: Integer;
begin
if StartPos>EndPos then
RaiseException('TCheckLFMDialog.AddReplaceMent StartPos>EndPos');
// check for intersection
for i:=0 to LFMChangeList.Count-1 do begin
Entry:=TLFMChangeEntry(LFMChangeList[i]);
if ((Entry.StartPos<EndPos) and (Entry.EndPos>StartPos)) then begin
// New and Entry intersects
if (Entry.NewText='') and (NewText='') then begin
// both are deletes => combine
StartPos:=Min(StartPos,Entry.StartPos);
EndPos:=Max(EndPos,Entry.EndPos);
end else begin
// not allowed
RaiseException('TCheckLFMDialog.AddReplaceMent invalid Intersection');
end;
end;
end;
// combine deletions
if NewText='' then begin
for i:=0 to LFMChangeList.Count-1 do begin
Entry:=TLFMChangeEntry(LFMChangeList[i]);
if ((Entry.StartPos<EndPos) and (Entry.EndPos>StartPos)) then begin
// New and Entry intersects
Entry.StartPos:=Min(StartPos,Entry.StartPos);
Entry.EndPos:=Max(EndPos,Entry.EndPos);
if (i<LFMChangeList.Count-1) then begin
NextEntry:=TLFMChangeEntry(LFMChangeList[i+1]);
if NextEntry.StartPos<EndPos then begin
// next entry can be merged
LFMChangeList.Delete(i+1);
NextEntry.Free;
end;
end;
end;
end;
end;
// insert new entry
NewEntry:=TLFMChangeEntry.Create;
NewEntry.NewText:=NewText;
NewEntry.StartPos:=StartPos;
NewEntry.EndPos:=EndPos;
if LFMChangeList.Count=0 then begin
LFMChangeList.Add(NewEntry);
end else begin
for i:=0 to LFMChangeList.Count-1 do begin
Entry:=TLFMChangeEntry(LFMChangeList[i]);
if Entry.StartPos>EndPos then begin
LFMChangeList.Insert(i,NewEntry);
break;
end else begin
if (i<LFMChangeList.Count-1) then
NextEntry:=TLFMChangeEntry(LFMChangeList[i+1])
else
NextEntry:=nil;
if NextEntry.StartPos>EndPos then begin
LFMChangeList.Insert(i+1,NewEntry);
break;
end;
end;
end;
end;
end;
function TCheckLFMDialog.ApplyReplacements(LFMChangeList: TList): boolean;
var
i: Integer;
Entry: TLFMChangeEntry;
begin
Result:=false;
//writeln(LFMSource.Source);
for i:=LFMChangeList.Count-1 downto 0 do begin
Entry:=TLFMChangeEntry(LFMChangeList[i]);
writeln('TCheckLFMDialog.ApplyReplacements A ',i,' ',Entry.StartPos,',',Entry.EndPos,
' "',copy(LFMSource.Source,Entry.StartPos,Entry.EndPos-Entry.StartPos),'" -> "',Entry.NewText,'"');
LFMSource.Replace(Entry.StartPos,Entry.EndPos-Entry.StartPos,Entry.NewText);
end;
//writeln(LFMSource.Source);
Result:=true;
end;
procedure TCheckLFMDialog.LoadLFM;
begin
LFMSynEdit.Lines.Text:=LFMSource.Source;
FillErrorsListBox;
end;
procedure TCheckLFMDialog.FillErrorsListBox;
var
CurError: TLFMError;
Filename: String;
Msg: String;
begin
ErrorsListBox.Items.BeginUpdate;
ErrorsListBox.Items.Clear;
if LFMTree<>nil then begin
Filename:=ExtractFileName(LFMSource.Filename);
CurError:=LFMTree.FirstError;
while CurError<>nil do begin
Msg:=Filename
+'('+IntToStr(CurError.Caret.Y)+','+IntToStr(CurError.Caret.X)+')'
+' Error: '
+CurError.ErrorMessage;
ErrorsListBox.Items.Add(Msg);
CurError:=CurError.NextError;
end;
end;
ErrorsListBox.Items.EndUpdate;
end;
function TCheckLFMDialog.AutomaticFixIsPossible: boolean;
var
CurError: TLFMError;
begin
Result:=true;
CurError:=LFMTree.FirstError;
while CurError<>nil do begin
if CurError.ErrorType in [lfmeNoError,lfmeIdentifierNotFound,
lfmeObjectNameMissing,lfmeObjectIncompatible,lfmePropertyNameMissing,
lfmePropertyHasNoSubProperties,lfmeIdentifierNotPublished]
then begin
// these things can be fixed automatically
end else begin
// these not
Result:=false;
exit;
end;
CurError:=CurError.NextError;
end;
end;
initialization

View File

@ -1,410 +1,11 @@
object RepairLFMDialog: TRepairLFMDialog
object Delphi2LazarusDialog: TDelphi2LazarusDialog
Caption = 'Repair LFM'
ClientHeight = 425
ClientWidth = 458
HorzScrollBar.Page = 459
VertScrollBar.Page = 426
ClientHeight = 341
ClientWidth = 410
HorzScrollBar.Page = 411
VertScrollBar.Page = 342
Left = 368
Height = 425
Height = 341
Top = 200
Width = 458
object CancelButton: TButton
Anchors = [akleft, akbottom]
ModalResult = 2
Caption = 'Cancel'
TabStop = True
TabOrder = 0
Left = 359
Height = 25
Top = 392
Width = 75
end
object RemoveAllButton: TButton
Anchors = [akleft, akbottom]
Caption = 'Remove all invalid properties'
TabStop = True
TabOrder = 1
OnClick = RemoveAllButtonClick
Left = 24
Height = 25
Top = 392
Width = 311
end
object LFMGroupBox: TGroupBox
Anchors = [aktop, akleft, akright, akbottom]
Caption = 'LFM file'
ClientHeight = 247
ClientWidth = 442
Color = -2147483633
ParentColor = True
ParentCtl3D = False
TabOrder = 2
Left = 8
Height = 264
Top = 8
Width = 446
object LFMSynEdit: TSynEdit
Align = alclient
Color = 16777215
Font.Height = -15
Font.Name = 'courier'
Height = 247
Name = 'LFMSynEdit'
ParentCtl3D = False
TabOrder = 0
Width = 442
BookMarkOptions.OnChange = nil
Gutter.OnChange = nil
Keystrokes = <
item
Command = 3
ShortCut = 38
end
item
Command = 103
ShortCut = 8230
end
item
Command = 211
ShortCut = 16422
end
item
Command = 4
ShortCut = 40
end
item
Command = 104
ShortCut = 8232
end
item
Command = 212
ShortCut = 16424
end
item
Command = 1
ShortCut = 37
end
item
Command = 101
ShortCut = 8229
end
item
Command = 5
ShortCut = 16421
end
item
Command = 105
ShortCut = 24613
end
item
Command = 2
ShortCut = 39
end
item
Command = 102
ShortCut = 8231
end
item
Command = 6
ShortCut = 16423
end
item
Command = 106
ShortCut = 24615
end
item
Command = 10
ShortCut = 34
end
item
Command = 110
ShortCut = 8226
end
item
Command = 14
ShortCut = 16418
end
item
Command = 114
ShortCut = 24610
end
item
Command = 9
ShortCut = 33
end
item
Command = 109
ShortCut = 8225
end
item
Command = 13
ShortCut = 16417
end
item
Command = 113
ShortCut = 24609
end
item
Command = 7
ShortCut = 36
end
item
Command = 107
ShortCut = 8228
end
item
Command = 15
ShortCut = 16420
end
item
Command = 115
ShortCut = 24612
end
item
Command = 8
ShortCut = 35
end
item
Command = 108
ShortCut = 8227
end
item
Command = 16
ShortCut = 16419
end
item
Command = 116
ShortCut = 24611
end
item
Command = 223
ShortCut = 45
end
item
Command = 201
ShortCut = 16429
end
item
Command = 604
ShortCut = 8237
end
item
Command = 502
ShortCut = 46
end
item
Command = 603
ShortCut = 8238
end
item
Command = 501
ShortCut = 8
end
item
Command = 501
ShortCut = 8200
end
item
Command = 504
ShortCut = 16392
end
item
Command = 601
ShortCut = 32776
end
item
Command = 602
ShortCut = 40968
end
item
Command = 509
ShortCut = 13
end
item
Command = 199
ShortCut = 16449
end
item
Command = 201
ShortCut = 16451
end
item
Command = 610
ShortCut = 24649
end
item
Command = 509
ShortCut = 16461
end
item
Command = 510
ShortCut = 16462
end
item
Command = 503
ShortCut = 16468
end
item
Command = 611
ShortCut = 24661
end
item
Command = 604
ShortCut = 16470
end
item
Command = 603
ShortCut = 16472
end
item
Command = 507
ShortCut = 16473
end
item
Command = 506
ShortCut = 24665
end
item
Command = 601
ShortCut = 16474
end
item
Command = 602
ShortCut = 24666
end
item
Command = 301
ShortCut = 16432
end
item
Command = 302
ShortCut = 16433
end
item
Command = 303
ShortCut = 16434
end
item
Command = 304
ShortCut = 16435
end
item
Command = 305
ShortCut = 16436
end
item
Command = 306
ShortCut = 16437
end
item
Command = 307
ShortCut = 16438
end
item
Command = 308
ShortCut = 16439
end
item
Command = 309
ShortCut = 16440
end
item
Command = 310
ShortCut = 16441
end
item
Command = 351
ShortCut = 24624
end
item
Command = 352
ShortCut = 24625
end
item
Command = 353
ShortCut = 24626
end
item
Command = 354
ShortCut = 24627
end
item
Command = 355
ShortCut = 24628
end
item
Command = 356
ShortCut = 24629
end
item
Command = 357
ShortCut = 24630
end
item
Command = 358
ShortCut = 24631
end
item
Command = 359
ShortCut = 24632
end
item
Command = 360
ShortCut = 24633
end
item
Command = 231
ShortCut = 24654
end
item
Command = 232
ShortCut = 24643
end
item
Command = 233
ShortCut = 24652
end
item
Command = 612
ShortCut = 9
end
item
Command = 613
ShortCut = 8201
end
item
Command = 250
ShortCut = 24642
end>
Lines.Strings = (
'LFMSynEdit'
)
SelectedColor.OnChange = nil
Cursor = 65532
Height = 247
Width = 442
end
end
object ErrorsGroupBox: TGroupBox
Anchors = [akleft, akright, akbottom]
Caption = 'Errors'
ClientHeight = 87
ClientWidth = 442
Color = -2147483633
ParentColor = True
ParentCtl3D = False
TabOrder = 3
Left = 8
Height = 104
Top = 280
Width = 446
object ErrorsListBox: TListBox
Align = alclient
TabOrder = 0
TabStop = True
TopIndex = -1
Height = 87
Width = 442
end
end
Width = 410
end

View File

@ -1,71 +1,8 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TRepairLFMDialog','FORMDATA',[
'TPF0'#16'TRepairLFMDialog'#15'RepairLFMDialog'#7'Caption'#6#10'Repair LFM'#12
+'ClientHeight'#3#169#1#11'ClientWidth'#3#202#1#18'HorzScrollBar.Page'#3#203#1
+#18'VertScrollBar.Page'#3#170#1#4'Left'#3'p'#1#6'Height'#3#169#1#3'Top'#3#200
+#0#5'Width'#3#202#1#0#7'TButton'#12'CancelButton'#7'Anchors'#11#6'akleft'#8
+'akbottom'#0#11'ModalResult'#2#2#7'Caption'#6#6'Cancel'#7'TabStop'#9#8'TabOr'
+'der'#2#0#4'Left'#3'g'#1#6'Height'#2#25#3'Top'#3#136#1#5'Width'#2'K'#0#0#7'T'
+'Button'#15'RemoveAllButton'#7'Anchors'#11#6'akleft'#8'akbottom'#0#7'Caption'
+#6#29'Remove all invalid properties'#7'TabStop'#9#8'TabOrder'#2#1#7'OnClick'
+#7#20'RemoveAllButtonClick'#4'Left'#2#24#6'Height'#2#25#3'Top'#3#136#1#5'Wid'
+'th'#3'7'#1#0#0#9'TGroupBox'#11'LFMGroupBox'#7'Anchors'#11#5'aktop'#6'akleft'
+#7'akright'#8'akbottom'#0#7'Caption'#6#8'LFM file'#12'ClientHeight'#3#247#0
+#11'ClientWidth'#3#186#1#5'Color'#4#15#0#0#128#11'ParentColor'#9#11'ParentCt'
+'l3D'#8#8'TabOrder'#2#2#4'Left'#2#8#6'Height'#3#8#1#3'Top'#2#8#5'Width'#3#190
+#1#0#8'TSynEdit'#10'LFMSynEdit'#5'Align'#7#8'alclient'#5'Color'#4#255#255#255
+#0#11'Font.Height'#2#241#9'Font.Name'#6#7'courier'#6'Height'#3#247#0#4'Name'
+#6#10'LFMSynEdit'#11'ParentCtl3D'#8#8'TabOrder'#2#0#5'Width'#3#186#1#24'Book'
+'MarkOptions.OnChange'#13#15'Gutter.OnChange'#13#10'Keystrokes'#14#1#7'Comma'
+'nd'#2#3#8'ShortCut'#2'&'#0#1#7'Command'#2'g'#8'ShortCut'#3'& '#0#1#7'Comman'
+'d'#3#211#0#8'ShortCut'#3'&@'#0#1#7'Command'#2#4#8'ShortCut'#2'('#0#1#7'Comm'
+'and'#2'h'#8'ShortCut'#3'( '#0#1#7'Command'#3#212#0#8'ShortCut'#3'(@'#0#1#7
+'Command'#2#1#8'ShortCut'#2'%'#0#1#7'Command'#2'e'#8'ShortCut'#3'% '#0#1#7'C'
+'ommand'#2#5#8'ShortCut'#3'%@'#0#1#7'Command'#2'i'#8'ShortCut'#3'%`'#0#1#7'C'
+'ommand'#2#2#8'ShortCut'#2''''#0#1#7'Command'#2'f'#8'ShortCut'#3''' '#0#1#7
+'Command'#2#6#8'ShortCut'#3'''@'#0#1#7'Command'#2'j'#8'ShortCut'#3'''`'#0#1#7
+'Command'#2#10#8'ShortCut'#2'"'#0#1#7'Command'#2'n'#8'ShortCut'#3'" '#0#1#7
+'Command'#2#14#8'ShortCut'#3'"@'#0#1#7'Command'#2'r'#8'ShortCut'#3'"`'#0#1#7
+'Command'#2#9#8'ShortCut'#2'!'#0#1#7'Command'#2'm'#8'ShortCut'#3'! '#0#1#7'C'
+'ommand'#2#13#8'ShortCut'#3'!@'#0#1#7'Command'#2'q'#8'ShortCut'#3'!`'#0#1#7
+'Command'#2#7#8'ShortCut'#2'$'#0#1#7'Command'#2'k'#8'ShortCut'#3'$ '#0#1#7'C'
+'ommand'#2#15#8'ShortCut'#3'$@'#0#1#7'Command'#2's'#8'ShortCut'#3'$`'#0#1#7
+'Command'#2#8#8'ShortCut'#2'#'#0#1#7'Command'#2'l'#8'ShortCut'#3'# '#0#1#7'C'
+'ommand'#2#16#8'ShortCut'#3'#@'#0#1#7'Command'#2't'#8'ShortCut'#3'#`'#0#1#7
+'Command'#3#223#0#8'ShortCut'#2'-'#0#1#7'Command'#3#201#0#8'ShortCut'#3'-@'#0
+#1#7'Command'#3'\'#2#8'ShortCut'#3'- '#0#1#7'Command'#3#246#1#8'ShortCut'#2
+'.'#0#1#7'Command'#3'['#2#8'ShortCut'#3'. '#0#1#7'Command'#3#245#1#8'ShortCu'
+'t'#2#8#0#1#7'Command'#3#245#1#8'ShortCut'#3#8' '#0#1#7'Command'#3#248#1#8'S'
+'hortCut'#3#8'@'#0#1#7'Command'#3'Y'#2#8'ShortCut'#4#8#128#0#0#0#1#7'Command'
+#3'Z'#2#8'ShortCut'#4#8#160#0#0#0#1#7'Command'#3#253#1#8'ShortCut'#2#13#0#1#7
+'Command'#3#199#0#8'ShortCut'#3'A@'#0#1#7'Command'#3#201#0#8'ShortCut'#3'C@'
+#0#1#7'Command'#3'b'#2#8'ShortCut'#3'I`'#0#1#7'Command'#3#253#1#8'ShortCut'#3
+'M@'#0#1#7'Command'#3#254#1#8'ShortCut'#3'N@'#0#1#7'Command'#3#247#1#8'Short'
+'Cut'#3'T@'#0#1#7'Command'#3'c'#2#8'ShortCut'#3'U`'#0#1#7'Command'#3'\'#2#8
+'ShortCut'#3'V@'#0#1#7'Command'#3'['#2#8'ShortCut'#3'X@'#0#1#7'Command'#3#251
+#1#8'ShortCut'#3'Y@'#0#1#7'Command'#3#250#1#8'ShortCut'#3'Y`'#0#1#7'Command'
+#3'Y'#2#8'ShortCut'#3'Z@'#0#1#7'Command'#3'Z'#2#8'ShortCut'#3'Z`'#0#1#7'Comm'
+'and'#3'-'#1#8'ShortCut'#3'0@'#0#1#7'Command'#3'.'#1#8'ShortCut'#3'1@'#0#1#7
+'Command'#3'/'#1#8'ShortCut'#3'2@'#0#1#7'Command'#3'0'#1#8'ShortCut'#3'3@'#0
+#1#7'Command'#3'1'#1#8'ShortCut'#3'4@'#0#1#7'Command'#3'2'#1#8'ShortCut'#3'5'
+'@'#0#1#7'Command'#3'3'#1#8'ShortCut'#3'6@'#0#1#7'Command'#3'4'#1#8'ShortCut'
+#3'7@'#0#1#7'Command'#3'5'#1#8'ShortCut'#3'8@'#0#1#7'Command'#3'6'#1#8'Short'
+'Cut'#3'9@'#0#1#7'Command'#3'_'#1#8'ShortCut'#3'0`'#0#1#7'Command'#3'`'#1#8
+'ShortCut'#3'1`'#0#1#7'Command'#3'a'#1#8'ShortCut'#3'2`'#0#1#7'Command'#3'b'
+#1#8'ShortCut'#3'3`'#0#1#7'Command'#3'c'#1#8'ShortCut'#3'4`'#0#1#7'Command'#3
+'d'#1#8'ShortCut'#3'5`'#0#1#7'Command'#3'e'#1#8'ShortCut'#3'6`'#0#1#7'Comman'
+'d'#3'f'#1#8'ShortCut'#3'7`'#0#1#7'Command'#3'g'#1#8'ShortCut'#3'8`'#0#1#7'C'
+'ommand'#3'h'#1#8'ShortCut'#3'9`'#0#1#7'Command'#3#231#0#8'ShortCut'#3'N`'#0
+#1#7'Command'#3#232#0#8'ShortCut'#3'C`'#0#1#7'Command'#3#233#0#8'ShortCut'#3
+'L`'#0#1#7'Command'#3'd'#2#8'ShortCut'#2#9#0#1#7'Command'#3'e'#2#8'ShortCut'
+#3#9' '#0#1#7'Command'#3#250#0#8'ShortCut'#3'B`'#0#0#13'Lines.Strings'#1#6#10
+'LFMSynEdit'#0#22'SelectedColor.OnChange'#13#6'Cursor'#4#252#255#0#0#6'Heigh'
+'t'#3#247#0#5'Width'#3#186#1#0#0#0#9'TGroupBox'#14'ErrorsGroupBox'#7'Anchors'
+#11#6'akleft'#7'akright'#8'akbottom'#0#7'Caption'#6#6'Errors'#12'ClientHeigh'
+'t'#2'W'#11'ClientWidth'#3#186#1#5'Color'#4#15#0#0#128#11'ParentColor'#9#11
+'ParentCtl3D'#8#8'TabOrder'#2#3#4'Left'#2#8#6'Height'#2'h'#3'Top'#3#24#1#5'W'
,'idth'#3#190#1#0#8'TListBox'#13'ErrorsListBox'#5'Align'#7#8'alclient'#8'TabO'
+'rder'#2#0#7'TabStop'#9#8'TopIndex'#2#255#6'Height'#2'W'#5'Width'#3#186#1#0#0
+#0#0
LazarusResources.Add('TDelphi2LazarusDialog','FORMDATA',[
'TPF0'#21'TDelphi2LazarusDialog'#20'Delphi2LazarusDialog'#7'Caption'#6#10'Rep'
+'air LFM'#12'ClientHeight'#3'U'#1#11'ClientWidth'#3#154#1#18'HorzScrollBar.P'
+'age'#3#155#1#18'VertScrollBar.Page'#3'V'#1#4'Left'#3'p'#1#6'Height'#3'U'#1#3
+'Top'#3#200#0#5'Width'#3#154#1#0#0
]);

View File

@ -47,20 +47,13 @@ uses
DialogProcs, IDEProcs, LazarusIDEStrConsts;
type
TRepairLFMDialog = class(TForm)
ErrorsGroupBox: TGroupBox;
LFMGroupBox: TGroupBox;
ErrorsListBox: TListBox;
RemoveAllButton: TButton;
CancelButton: TButton;
LFMSynEdit: TSynEdit;
procedure RemoveAllButtonClick(Sender: TObject);
TDelphi2LazarusDialog = class(TForm)
private
public
end;
var
RepairLFMDialog: TRepairLFMDialog;
Delphi2LazarusDialog: TDelphi2LazarusDialog;
function CheckDelphiFileExt(const Filename: string): TModalResult;
function CheckFilenameForLCLPaths(const Filename: string): TModalResult;
@ -72,6 +65,9 @@ function RenameDelphiUnitToLazarusUnit(const DelphiFilename: string;
function ConvertDFMFileToLFMFile(const DFMFilename: string): TModalResult;
function ConvertDelphiSourceToLazarusSource(const LazarusUnitFilename: string;
AddLRSCode: boolean): TModalResult;
function LoadUnitAndLFMFile(const UnitFileName: string;
var UnitCode, LFMCode: TCodeBuffer): TModalResult;
function ConvertLFMtoLRSfile(const LFMFilename: string): TModalResult;
implementation
@ -226,11 +222,33 @@ begin
Result:=mrOk;
end;
{ TRepairLFMDialog }
procedure TRepairLFMDialog.RemoveAllButtonClick(Sender: TObject);
function LoadUnitAndLFMFile(const UnitFileName: string;
var UnitCode, LFMCode: TCodeBuffer): TModalResult;
var
LFMFilename: string;
begin
UnitCode:=nil;
LFMCode:=nil;
Result:=LoadCodeBuffer(UnitCode,UnitFileName,
[lbfCheckIfText,lbfUpdateFromDisk]);
if Result<>mrOk then exit;
LFMFilename:=ChangeFileExt(UnitFileName,'.lfm');
if FileExists(LFMFilename) then begin
Result:=LoadCodeBuffer(LFMCode,LFMFilename,
[lbfCheckIfText,lbfUpdateFromDisk]);
if Result<>mrOk then exit;
end;
end;
function ConvertLFMtoLRSfile(const LFMFilename: string): TModalResult;
begin
if not LFMtoLRSfile(LFMFilename) then begin
Result:=MessageDlg('Error creating lrs',
'Unable to convert lfm to lrs and write lrs file.',
mtError,[mbCancel],0);
exit;
end;
Result:=mrOk;
end;
initialization

View File

@ -528,6 +528,7 @@ function ShowEditorOptionsDialog:TModalResult;
function StrToLazSyntaxHighlighter(const s: string): TLazSyntaxHighlighter;
function ExtensionToLazSyntaxHighlighter(Ext:string): TLazSyntaxHighlighter;
implementation
@ -1791,45 +1792,48 @@ begin
case AddHilightAttr of
ahaTextBlock:
begin
BG:=clNavy;
FG:=clWhite;
NewBG:=clNavy;
NewFG:=clWhite;
end;
ahaExecutionPoint:
begin
BG:=clDKGray;
FG:=clWhite;
NewBG:=clDKGray;
NewFG:=clWhite;
end;
ahaEnabledBreakpoint:
begin
BG:=clRed;
FG:=clWhite;
NewBG:=clRed;
NewFG:=clWhite;
end;
ahaDisabledBreakpoint:
begin
BG:=clGreen;
FG:=clBlack;
NewBG:=clGreen;
NewFG:=clBlack;
end;
ahaInvalidBreakpoint:
begin
BG:=clOlive;
FG:=clGreen;
NewBG:=clOlive;
NewFG:=clGreen;
end;
ahaUnknownBreakpoint:
begin
BG:=clRed;
FG:=clBlack;
NewBG:=clRed;
NewFG:=clBlack;
end;
ahaErrorLine:
begin
BG:=$50a0ff;
FG:=clBlack;
NewBG:=$50a0ff;
NewFG:=clBlack;
end;
else
begin
BG:=clWhite;
FG:=clBlack;
NewBG:=clWhite;
NewFG:=clBlack;
end;
end;
Special:=(NewFG<>clNone) or (NewBG<>clNone);
if NewFG<>clNone then FG:=NewFG;
if NewBG<>clNone then BG:=NewBG;
end;
procedure TEditorOptions.GetSynEditSelectedColor(ASynEdit:TSynEdit);

View File

@ -6455,32 +6455,33 @@ var
LRSFilename: String;
ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo;
UnitCode, LFMCode: TCodeBuffer;
begin
// check file and directory
writeln('TMainIDE.DoConvertDelphiUnit A');
writeln('TMainIDE.DoConvertDelphiUnit A ',DelphiFilename);
Result:=CheckDelphiFileExt(DelphiFilename);
if Result<>mrOk then exit;
Result:=CheckFilenameForLCLPaths(DelphiFilename);
if Result<>mrOk then exit;
// close Delphi files in editor
writeln('TMainIDE.DoConvertDelphiUnit B ',DelphiFilename);
writeln('TMainIDE.DoConvertDelphiUnit Close files in editor');
Result:=DoCloseEditorFile(DelphiFilename,[cfSaveFirst]);
if Result<>mrOk then exit;
DFMFilename:=FindDFMFileForDelphiUnit(DelphiFilename);
Result:=DoCloseEditorFile(DFMFilename,[cfSaveFirst]);
if Result<>mrOk then exit;
// rename files (.pas,.dfm) lowercase
writeln('TMainIDE.DoConvertDelphiUnit C');
writeln('TMainIDE.DoConvertDelphiUnit Rename files');
Result:=RenameDelphiUnitToLazarusUnit(DelphiFilename,false);
if Result<>mrOk then exit;
// convert .dfm file to .lfm file
writeln('TMainIDE.DoConvertDelphiUnit D ',DFMFilename);
writeln('TMainIDE.DoConvertDelphiUnit Convert dfm to lfm');
if DFMFilename<>'' then begin
Result:=ConvertDFMFileToLFMFile(DFMFilename);
if Result<>mrOk then exit;
end;
// create empty .lrs file
writeln('TMainIDE.DoConvertDelphiUnit E');
writeln('TMainIDE.DoConvertDelphiUnit Create empty lrs');
LazarusUnitFilename:=ConvertDelphiToLazarusFilename(DelphiFilename);
if DFMFilename<>'' then begin
LRSFilename:=ChangeFileExt(LazarusUnitFilename,'.lrs');
@ -6493,7 +6494,7 @@ begin
// remove {$R *.dfm} directive
// add initialization
// add {$i unit.lrs} directive
writeln('TMainIDE.DoConvertDelphiUnit F');
writeln('TMainIDE.DoConvertDelphiUnit Convert delphi source');
FOpenEditorsOnCodeToolChange:=true;
try
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then begin
@ -6507,10 +6508,25 @@ begin
exit;
end;
// ToDo: check lfm
writeln('TMainIDE.DoConvertDelphiUnit G');
// ToDo: convert lfm to lrs
writeln('TMainIDE.DoConvertDelphiUnit H');
// check the LFM file and the pascal unit
writeln('TMainIDE.DoConvertDelphiUnit Check new .lfm and .pas file');
Result:=LoadUnitAndLFMFile(LazarusUnitFilename,UnitCode,LFMCode);
if Result<>mrOk then exit;
if not CheckLFMBuffer(UnitCode,LFMCode,@MessagesView.AddMsg) then
begin
DoJumpToCompilerMessage(-1,true);
exit;
end;
// save LFM file
writeln('TMainIDE.DoConvertDelphiUnit Save LFM');
Result:=DoSaveCodeBufferToFile(LFMCode,LFMCode.Filename,false);
if Result<>mrOk then exit;
// convert lfm to lrs
writeln('TMainIDE.DoConvertDelphiUnit Convert lfm to lrs');
Result:=ConvertLFMtoLRSfile(LFMCode.Filename);
if Result<>mrOk then exit;
finally
FOpenEditorsOnCodeToolChange:=false;
end;
@ -10213,6 +10229,9 @@ end.
{ =============================================================================
$Log$
Revision 1.679 2003/12/16 13:42:02 mattias
implemented basic Repair broken LFM wizard
Revision 1.678 2003/11/28 23:24:57 mattias
implemented Clean Directories

View File

@ -64,11 +64,11 @@ type
function InitLazResourceComponent(Instance: TComponent;
RootAncestor: TClass): Boolean;
procedure BinaryToLazarusResourceCode(BinStream,ResStream:TStream;
ResourceName, ResourceType:AnsiString);
function LFMtoLRSfile(LFMfilename:ansistring):boolean;
procedure BinaryToLazarusResourceCode(BinStream, ResStream: TStream;
const ResourceName, ResourceType: String);
function LFMtoLRSfile(const LFMfilename: string): boolean;
// returns true if successful
function LFMtoLRSstream(LFMStream,LFCStream:TStream):boolean;
function LFMtoLRSstream(LFMStream, LFCStream: TStream): boolean;
// returns true if successful
function FindLFMClassName(LFMStream: TStream):AnsiString;
function CreateLFMFile(AComponent: TComponent; LFMStream: TStream): integer;
@ -102,7 +102,7 @@ begin
end;}
procedure BinaryToLazarusResourceCode(BinStream,ResStream:TStream;
ResourceName, ResourceType:AnsiString);
const ResourceName, ResourceType: String);
{ example ResStream:
LazarusResources.Add('ResourceName','ResourceType',
#123#45#34#78#18#72#45#34#78#18#72#72##45#34#78#45#34#78#184#34#78#145#34#78
@ -212,36 +212,36 @@ begin
Result:='';
end;
function LFMtoLRSfile(LFMfilename:ansistring):boolean;
function LFMtoLRSfile(const LFMfilename: string):boolean;
// returns true if successful
var
LFMFileStream,LFCFileStream:TFileStream;
LFMMemStream,LFCMemStream:TMemoryStream;
LFCfilename,LFMfilenameExt:ansistring;
LFMFileStream, LRSFileStream: TFileStream;
LFMMemStream, LRSMemStream: TMemoryStream;
LRSfilename, LFMfilenameExt: string;
begin
Result:=true;
try
LFMFileStream:=TFileStream.Create(LFMfilename,fmOpenRead);
LFMMemStream:=TMemoryStream.Create;
LFCMemStream:=TMemoryStream.Create;
LRSMemStream:=TMemoryStream.Create;
try
LFMMemStream.CopyFrom(LFMFileStream,LFMFileStream.Size);
LFMMemStream.Position:=0;
LFMfilenameExt:=ExtractFileExt(LFMfilename);
LFCfilename:=copy(LFMfilename,1,
LRSfilename:=copy(LFMfilename,1,
length(LFMfilename)-length(LFMfilenameExt))+'.lrs';
Result:=LFMtoLRSstream(LFMMemStream,LFCMemStream);
Result:=LFMtoLRSstream(LFMMemStream,LRSMemStream);
if not Result then exit;
LFCMemStream.Position:=0;
LFCFileStream:=TFileStream.Create(LFCfilename,fmCreate);
LRSMemStream.Position:=0;
LRSFileStream:=TFileStream.Create(LRSfilename,fmCreate);
try
LFCFileStream.CopyFrom(LFCMemStream,LFCMemStream.Size);
LRSFileStream.CopyFrom(LRSMemStream,LRSMemStream.Size);
finally
LFCFileStream.Free;
LRSFileStream.Free;
end;
finally
LFMMemStream.Free;
LFCMemStream.Free;
LRSMemStream.Free;
LFMFileStream.Free;
end;
except
@ -252,7 +252,7 @@ begin
end;
end;
function LFMtoLRSstream(LFMStream,LFCStream:TStream):boolean;
function LFMtoLRSstream(LFMStream,LRSStream:TStream):boolean;
// returns true if successful
var FormClassName:ansistring;
BinStream:TMemoryStream;
@ -264,14 +264,14 @@ begin
try
ObjectTextToBinary(LFMStream,BinStream);
BinStream.Position:=0;
BinaryToLazarusResourceCode(BinStream,LFCStream,FormClassName
BinaryToLazarusResourceCode(BinStream,LRSStream,FormClassName
,'FORMDATA');
finally
BinStream.Free;
end;
except
on E: Exception do begin
writeln('LFMtoLFCstream ',E.Message);
writeln('LFMtoLRSstream ',E.Message);
Result:=false;
end;
end;