mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-11 20:40:45 +01:00
SynEdit: refactor, make TSynEditAutoComplete based on plugin
git-svn-id: trunk@35956 -
This commit is contained in:
parent
9b1daa010e
commit
cb3b57701c
@ -45,7 +45,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
LCLIntf, LCLType, LCLProc,
|
LCLIntf, LCLType, LCLProc,
|
||||||
Classes, SynEdit, SynEditKeyCmds,
|
Classes, SynEdit, SynEditKeyCmds, SynEditPlugins,
|
||||||
Controls;
|
Controls;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -65,7 +65,7 @@ type
|
|||||||
|
|
||||||
{ TCustomSynAutoComplete }
|
{ TCustomSynAutoComplete }
|
||||||
|
|
||||||
TCustomSynAutoComplete = class(TComponent)
|
TCustomSynAutoComplete = class(TLazSynMultiEditPlugin)
|
||||||
private
|
private
|
||||||
fOnTokenNotFound: TOnTokenNotFound;
|
fOnTokenNotFound: TOnTokenNotFound;
|
||||||
fIndentToTokenStart: boolean;
|
fIndentToTokenStart: boolean;
|
||||||
@ -87,15 +87,14 @@ type
|
|||||||
function GetCompletions: TStrings;
|
function GetCompletions: TStrings;
|
||||||
function GetCompletionComments: TStrings;
|
function GetCompletionComments: TStrings;
|
||||||
function GetCompletionValues: TStrings;
|
function GetCompletionValues: TStrings;
|
||||||
function GetEditorCount: integer;
|
|
||||||
function GetNthEditor(Index: integer): TCustomSynEdit;
|
|
||||||
procedure ParseCompletionList; virtual;
|
procedure ParseCompletionList; virtual;
|
||||||
procedure SetAutoCompleteList(Value: TStrings); virtual;
|
procedure SetAutoCompleteList(Value: TStrings); virtual;
|
||||||
procedure SetEditor(Value: TCustomSynEdit);
|
|
||||||
procedure SynEditCommandHandler(Sender: TObject; AfterProcessing: boolean;
|
procedure SynEditCommandHandler(Sender: TObject; AfterProcessing: boolean;
|
||||||
var Handled: boolean; var Command: TSynEditorCommand;
|
var Handled: boolean; var Command: TSynEditorCommand;
|
||||||
var AChar: TUTF8Char;
|
var AChar: TUTF8Char;
|
||||||
Data: pointer; HandlerData: pointer);
|
Data: pointer; HandlerData: pointer);
|
||||||
|
procedure DoEditorAdded(AValue: TCustomSynEdit); override;
|
||||||
|
procedure DoEditorRemoving(AValue: TCustomSynEdit); override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -103,14 +102,9 @@ type
|
|||||||
procedure AddCompletion(AToken, AValue, AComment: string;
|
procedure AddCompletion(AToken, AValue, AComment: string;
|
||||||
TheAttributes: TStrings = nil);
|
TheAttributes: TStrings = nil);
|
||||||
procedure DeleteCompletion(Index: integer);
|
procedure DeleteCompletion(Index: integer);
|
||||||
function AddEditor(AEditor: TCustomSynEdit): boolean;
|
|
||||||
procedure Execute(AEditor: TCustomSynEdit); virtual;
|
procedure Execute(AEditor: TCustomSynEdit); virtual;
|
||||||
procedure ExecuteCompletion(AToken: string; AEditor: TCustomSynEdit);
|
procedure ExecuteCompletion(AToken: string; AEditor: TCustomSynEdit);
|
||||||
virtual;
|
virtual;
|
||||||
procedure Loaded; override;
|
|
||||||
procedure Notification(AComponent: TComponent; Operation: TOperation);
|
|
||||||
override;
|
|
||||||
function RemoveEditor(AEditor: TCustomSynEdit): boolean;
|
|
||||||
public
|
public
|
||||||
property AutoCompleteList: TStrings read fAutoCompleteList
|
property AutoCompleteList: TStrings read fAutoCompleteList
|
||||||
write SetAutoCompleteList;
|
write SetAutoCompleteList;
|
||||||
@ -118,9 +112,6 @@ type
|
|||||||
property Completions: TStrings read GetCompletions;
|
property Completions: TStrings read GetCompletions;
|
||||||
property CompletionComments: TStrings read GetCompletionComments;
|
property CompletionComments: TStrings read GetCompletionComments;
|
||||||
property CompletionValues: TStrings read GetCompletionValues;
|
property CompletionValues: TStrings read GetCompletionValues;
|
||||||
property Editor: TCustomSynEdit read fEditor write SetEditor;
|
|
||||||
property EditorCount: integer read GetEditorCount;
|
|
||||||
property Editors[Index: integer]: TCustomSynEdit read GetNthEditor;
|
|
||||||
property EndOfTokenChr: string read fEOTokenChars write fEOTokenChars;
|
property EndOfTokenChr: string read fEOTokenChars write fEOTokenChars;
|
||||||
property CompletionAttributes[Index: integer]: TStrings
|
property CompletionAttributes[Index: integer]: TStrings
|
||||||
read GetCompletionAttributes;
|
read GetCompletionAttributes;
|
||||||
@ -165,23 +156,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSynAutoComplete.AddEditor(AEditor: TCustomSynEdit): boolean;
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
begin
|
|
||||||
if AEditor <> nil then begin
|
|
||||||
i := fEditors.IndexOf(AEditor);
|
|
||||||
if i = -1 then begin
|
|
||||||
AEditor.FreeNotification(Self);
|
|
||||||
fEditors.Add(AEditor);
|
|
||||||
if ComponentState * [csDesigning, csLoading] = [] then
|
|
||||||
AEditor.RegisterCommandHandler({$IFDEF FPC}@{$ENDIF}SynEditCommandHandler, nil);
|
|
||||||
end;
|
|
||||||
Result := TRUE;
|
|
||||||
end else
|
|
||||||
Result := FALSE;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.CompletionListChanged(Sender: TObject);
|
procedure TCustomSynAutoComplete.CompletionListChanged(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
fParsed := FALSE;
|
fParsed := FALSE;
|
||||||
@ -428,46 +402,6 @@ begin
|
|||||||
Result := fCompletionValues;
|
Result := fCompletionValues;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSynAutoComplete.GetEditorCount: integer;
|
|
||||||
begin
|
|
||||||
Result := fEditors.Count;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCustomSynAutoComplete.GetNthEditor(Index: integer): TCustomSynEdit;
|
|
||||||
begin
|
|
||||||
if (Index >= 0) and (Index < fEditors.Count) then
|
|
||||||
Result := TCustomSynEdit(fEditors[Index])
|
|
||||||
else
|
|
||||||
Result := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.Loaded;
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
O: TObject;
|
|
||||||
begin
|
|
||||||
inherited Loaded;
|
|
||||||
for i := 0 to fEditors.Count - 1 do begin
|
|
||||||
O := TObject(fEditors[i]);
|
|
||||||
(O as TCustomSynEdit).RegisterCommandHandler(
|
|
||||||
{$IFDEF FPC}@{$ENDIF}SynEditCommandHandler, nil);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.Notification(AComponent: TComponent;
|
|
||||||
Operation: TOperation);
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
begin
|
|
||||||
inherited Notification(AComponent, Operation);
|
|
||||||
if (Operation = opRemove)
|
|
||||||
and (AComponent is TCustomSynEdit) then begin
|
|
||||||
i := fEditors.IndexOf(AComponent);
|
|
||||||
if i > -1 then
|
|
||||||
RemoveEditor(AComponent as TCustomSynEdit);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.ParseCompletionList;
|
procedure TCustomSynAutoComplete.ParseCompletionList;
|
||||||
|
|
||||||
procedure RemoveFirstLine(var Pattern: string);
|
procedure RemoveFirstLine(var Pattern: string);
|
||||||
@ -605,42 +539,12 @@ begin
|
|||||||
fParsed:=true;
|
fParsed:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSynAutoComplete.RemoveEditor(AEditor: TCustomSynEdit): boolean;
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
begin
|
|
||||||
if AEditor <> nil then begin
|
|
||||||
i := fEditors.IndexOf(AEditor);
|
|
||||||
if i > -1 then begin
|
|
||||||
if fEditor = AEditor then
|
|
||||||
fEditor := nil;
|
|
||||||
fEditors.Delete(i);
|
|
||||||
AEditor.RemoveFreeNotification(Self);
|
|
||||||
if ComponentState * [csDesigning, csLoading] = [] then
|
|
||||||
AEditor.UnregisterCommandHandler(
|
|
||||||
{$IFDEF FPC}@{$ENDIF}SynEditCommandHandler);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Result := FALSE;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.SetAutoCompleteList(Value: TStrings);
|
procedure TCustomSynAutoComplete.SetAutoCompleteList(Value: TStrings);
|
||||||
begin
|
begin
|
||||||
fAutoCompleteList.Assign(Value);
|
fAutoCompleteList.Assign(Value);
|
||||||
fParsed := FALSE;
|
fParsed := FALSE;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.SetEditor(Value: TCustomSynEdit);
|
|
||||||
begin
|
|
||||||
if Value <> fEditor then begin
|
|
||||||
if fEditor <> nil then
|
|
||||||
RemoveEditor(fEditor);
|
|
||||||
fEditor := nil;
|
|
||||||
if (Value <> nil) and AddEditor(Value) then
|
|
||||||
fEditor := Value;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomSynAutoComplete.SynEditCommandHandler(Sender: TObject;
|
procedure TCustomSynAutoComplete.SynEditCommandHandler(Sender: TObject;
|
||||||
AfterProcessing: boolean; var Handled: boolean;
|
AfterProcessing: boolean; var Handled: boolean;
|
||||||
var Command: TSynEditorCommand;
|
var Command: TSynEditorCommand;
|
||||||
@ -654,5 +558,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomSynAutoComplete.DoEditorAdded(AValue: TCustomSynEdit);
|
||||||
|
begin
|
||||||
|
inherited DoEditorAdded(AValue);
|
||||||
|
AValue.RegisterCommandHandler({$IFDEF FPC}@{$ENDIF}SynEditCommandHandler, nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomSynAutoComplete.DoEditorRemoving(AValue: TCustomSynEdit);
|
||||||
|
begin
|
||||||
|
inherited DoEditorRemoving(AValue);
|
||||||
|
AValue.UnregisterCommandHandler({$IFDEF FPC}@{$ENDIF}SynEditCommandHandler);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user