mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-25 11:19:40 +02:00
jcf: adopt EditorConverter for lazarus
git-svn-id: trunk@17891 -
This commit is contained in:
parent
d578cccfd2
commit
8c0ad52957
@ -35,8 +35,13 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes,
|
Classes,
|
||||||
|
{$ifdef fpc}
|
||||||
|
{ lazarus design time }
|
||||||
|
SrcEditorIntf,
|
||||||
|
{$else}
|
||||||
{ delphi design time }
|
{ delphi design time }
|
||||||
ToolsAPI,
|
ToolsAPI,
|
||||||
|
{$endif}
|
||||||
{ local }
|
{ local }
|
||||||
Converter, ConvertTypes;
|
Converter, ConvertTypes;
|
||||||
|
|
||||||
@ -59,8 +64,13 @@ type
|
|||||||
function GetOnStatusMessage: TStatusMessageProc;
|
function GetOnStatusMessage: TStatusMessageProc;
|
||||||
procedure SetOnStatusMessage(const Value: 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;
|
function ReadFromIDE(const pcUnit: IOTASourceEditor): string;
|
||||||
procedure WriteToIDE(const pcUnit: IOTASourceEditor; const psText: string);
|
procedure WriteToIDE(const pcUnit: IOTASourceEditor; const psText: string);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
procedure FinalSummary;
|
procedure FinalSummary;
|
||||||
function OriginalFileName: string;
|
function OriginalFileName: string;
|
||||||
@ -71,7 +81,11 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
|
{$ifdef fpc}
|
||||||
|
procedure Convert(const pciUnit: TSourceEditorInterface);
|
||||||
|
{$else}
|
||||||
procedure Convert(const pciUnit: IOTASourceEditor);
|
procedure Convert(const pciUnit: IOTASourceEditor);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
procedure Clear;
|
procedure Clear;
|
||||||
|
|
||||||
@ -107,6 +121,56 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
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);
|
procedure TEditorConverter.Convert(const pciUnit: IOTASourceEditor);
|
||||||
var
|
var
|
||||||
lcBuffer: IOTAEditBuffer;
|
lcBuffer: IOTAEditBuffer;
|
||||||
@ -299,6 +363,8 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$endif}
|
||||||
|
|
||||||
procedure TEditorConverter.AfterConvert;
|
procedure TEditorConverter.AfterConvert;
|
||||||
begin
|
begin
|
||||||
FinalSummary;
|
FinalSummary;
|
||||||
|
Loading…
Reference in New Issue
Block a user