From 8c0ad529578d3a1e5f9b097a7af5fb9be0a2c1fc Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 23 Dec 2008 04:10:52 +0000 Subject: [PATCH] jcf: adopt EditorConverter for lazarus git-svn-id: trunk@17891 - --- components/jcf2/ReadWrite/EditorConverter.pas | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/components/jcf2/ReadWrite/EditorConverter.pas b/components/jcf2/ReadWrite/EditorConverter.pas index 6b97c5e5a1..803a6cad45 100644 --- a/components/jcf2/ReadWrite/EditorConverter.pas +++ b/components/jcf2/ReadWrite/EditorConverter.pas @@ -35,8 +35,13 @@ interface uses Classes, - { delphi design time } - ToolsAPI, + {$ifdef fpc} + { lazarus design time } + SrcEditorIntf, + {$else} + { delphi design time } + ToolsAPI, + {$endif} { local } Converter, ConvertTypes; @@ -59,8 +64,13 @@ type function GetOnStatusMessage: TStatusMessageProc; procedure SetOnStatusMessage(const Value: TStatusMessageProc); + {$ifdef fpc} + function ReadFromIDE(const pcUnit: TSourceEditorInterface): string; + procedure WriteToIDE(const pcUnit: TSourceEditorInterface; const psText: string); + {$else} function ReadFromIDE(const pcUnit: IOTASourceEditor): string; procedure WriteToIDE(const pcUnit: IOTASourceEditor; const psText: string); + {$endif} procedure FinalSummary; function OriginalFileName: string; @@ -71,7 +81,11 @@ type constructor Create; destructor Destroy; override; + {$ifdef fpc} + procedure Convert(const pciUnit: TSourceEditorInterface); + {$else} procedure Convert(const pciUnit: IOTASourceEditor); + {$endif} procedure Clear; @@ -107,6 +121,56 @@ begin inherited; end; +{$ifdef fpc} + +procedure TEditorConverter.Convert(const pciUnit: TSourceEditorInterface); +begin + Assert(pciUnit <> nil); + + if not GetRegSettings.HasRead then + GetRegSettings.ReadAll; + + { check for read-only } + if pciUnit <> nil then + begin + if pciUnit.ReadOnly then + begin + SendStatusMessage(pciUnit.FileName, 'Unit is read only. Cannot format ', + mtInputError, -1, -1); + exit; + end; + end; + + fsCurrentUnitName := pciUnit.FileName; + fcConverter.InputCode := ReadFromIDE(pciUnit); + + // now convert + fcConverter.Convert; + + fsCurrentUnitName := ''; + + if not ConvertError then + begin + WriteToIDE(pciUnit, fcConverter.OutputCode); + SendStatusMessage(pciUnit.FileName, 'Formatted unit', mtProgress, -1, -1); + Inc(fiConvertCount); + end; +end; + +function TEditorConverter.ReadFromIDE(const pcUnit: TSourceEditorInterface): string; +begin + Result := pcUnit.Lines.Text; +end; + +procedure TEditorConverter.WriteToIDE(const pcUnit: TSourceEditorInterface; const psText: string); +begin + if pcUnit = nil then + exit; + pcUnit.ReplaceLines(0, pcUnit.LineCount, psText); +end; + +{$else} + procedure TEditorConverter.Convert(const pciUnit: IOTASourceEditor); var lcBuffer: IOTAEditBuffer; @@ -299,6 +363,8 @@ begin end; +{$endif} + procedure TEditorConverter.AfterConvert; begin FinalSummary;