mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-02 16:12:35 +02:00
implemented auto ident completion after point plus idle
git-svn-id: trunk@7294 -
This commit is contained in:
parent
3c4f7a315b
commit
a27c24ae41
@ -4657,7 +4657,6 @@ begin
|
||||
Width:=MaxX-Left-Left;
|
||||
Height:=110;
|
||||
Caption:='Automatic features';
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoIdentifierCompletionCheckBox:=TCheckBox.Create(Self);
|
||||
@ -4670,8 +4669,6 @@ begin
|
||||
Height:=20;
|
||||
Caption:=dlgEdIdComlet;
|
||||
Checked:=EditorOpts.AutoIdentifierCompletion;
|
||||
Enabled:=false;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoCodeParametersCheckBox:=TCheckBox.Create(Self);
|
||||
@ -4686,7 +4683,6 @@ begin
|
||||
Caption:=dlgEdCodeParams;
|
||||
Checked:=EditorOpts.AutoCodeParameters;
|
||||
Enabled:=false;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoToolTipExprEvalCheckBox:=TCheckBox.Create(Self);
|
||||
@ -4700,7 +4696,6 @@ begin
|
||||
Caption:=dlgTooltipEval;
|
||||
Checked:=EditorOpts.AutoToolTipExprEval;
|
||||
Enabled:=false;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoToolTipSymbToolsCheckBox:=TCheckBox.Create(Self);
|
||||
@ -4713,7 +4708,6 @@ begin
|
||||
Height:=AutoIdentifierCompletionCheckBox.Height;
|
||||
Caption:=dlgTooltipTools;
|
||||
Checked:=EditorOpts.AutoToolTipSymbTools;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoDelayLabel:=TLabel.Create(Self);
|
||||
@ -4725,7 +4719,6 @@ begin
|
||||
+AutoIdentifierCompletionCheckBox.Width+17;
|
||||
Width:=70;
|
||||
Caption:=dlgEdDelay;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoDelayTrackBar:=TTrackBar.Create(Self);
|
||||
@ -4741,7 +4734,6 @@ begin
|
||||
Height:=10;
|
||||
Position:=EditorOpts.AutoDelayInMSec div 250;
|
||||
TickMarks:=tmBottomRight;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoDelayMinLabel:=TLabel.Create(Self);
|
||||
@ -4753,7 +4745,6 @@ begin
|
||||
+AutoIdentifierCompletionCheckBox.Width+15;
|
||||
Width:=70;
|
||||
Caption:='0.5 ' + DlgTimeSecondUnit;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
AutoDelayMaxLabel:=TLabel.Create(Self);
|
||||
@ -4764,7 +4755,6 @@ begin
|
||||
Left:=AutoDelayTrackBar.Left+AutoDelayTrackBar.Width-30;
|
||||
Width:=70;
|
||||
Caption:='1.5 '+ dlgTimeSecondUnit;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplatesGroupBox:=TGroupBox.Create(Self);
|
||||
@ -4777,7 +4767,6 @@ begin
|
||||
Height:=250;
|
||||
Caption:=dlgEdCodeTempl;
|
||||
OnResize:=@CodeTemplatesGroupBoxResize;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateFileNameLabel:=TLabel.Create(Self);
|
||||
@ -4788,7 +4777,6 @@ begin
|
||||
Left:=7;
|
||||
Width:=110;
|
||||
Caption:=dlgTplFName;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateFileNameComboBox:=TComboBox.Create(Self);
|
||||
@ -4802,7 +4790,6 @@ begin
|
||||
OnChange:=@ComboBoxOnChange;
|
||||
OnKeyDown:=@ComboBoxOnKeyDown;
|
||||
OnExit:=@ComboBoxOnExit;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateFileNameButton:=TButton.Create(Self);
|
||||
@ -4815,7 +4802,6 @@ begin
|
||||
Height:=Width;
|
||||
Caption:='...';
|
||||
OnClick:=@CodeTemplateFileNameButtonClick;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateAddButton:=TButton.Create(Self);
|
||||
@ -4828,7 +4814,6 @@ begin
|
||||
Height:=23;
|
||||
Caption:=dlgEdAdd;
|
||||
OnClick:=@CodeTemplateButtonClick;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateEditButton:=TButton.Create(Self);
|
||||
@ -4841,7 +4826,6 @@ begin
|
||||
Height:=CodeTemplateAddButton.Height;
|
||||
Caption:=dlgEdEdit;
|
||||
OnClick:=@CodeTemplateButtonClick;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateDeleteButton:=TButton.Create(Self);
|
||||
@ -4854,7 +4838,6 @@ begin
|
||||
Height:=CodeTemplateAddButton.Height;
|
||||
Caption:=dlgEdDelete;
|
||||
OnClick:=@CodeTemplateButtonClick;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplatesLabel:=TLabel.Create(Self);
|
||||
@ -4865,7 +4848,6 @@ begin
|
||||
Left:=CodeTemplateAddButton.Left+CodeTemplateAddButton.Width+5;
|
||||
Width:=60;
|
||||
Caption:='Templates';
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateListBox:=TListBox.Create(Self);
|
||||
@ -4877,7 +4859,6 @@ begin
|
||||
Width:=Parent.ClientWidth-8-Left;
|
||||
Height:=80;
|
||||
OnMouseUp:=@CodeTemplateListBoxMouseUp;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateCodeLabel:=TLabel.Create(Self);
|
||||
@ -4889,7 +4870,6 @@ begin
|
||||
Width:=CodeTemplatesLabel.Width;
|
||||
Height:=CodeTemplatesLabel.Height;
|
||||
Caption:='Code';
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateCodePreview:=TPreviewEditor.Create(Self);
|
||||
@ -4902,7 +4882,6 @@ begin
|
||||
Height:=CodeTemplatesGroupBox.ClientHeight-20-Top;
|
||||
Lines.Clear;
|
||||
Gutter.Visible:=false;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CodeTemplateIndentTypeRadioGroup:=TRadioGroup.Create(Self);
|
||||
@ -4920,7 +4899,6 @@ begin
|
||||
Add('Line start');
|
||||
EndUpdate;
|
||||
end;
|
||||
Visible:=true;
|
||||
end;
|
||||
|
||||
CurCodeTemplate:=-1;
|
||||
|
@ -159,24 +159,23 @@ type
|
||||
procedure SetPopupMenu(NewPopupMenu: TPopupMenu);
|
||||
function GetFilename: string;
|
||||
|
||||
Function GotoLine(Value: Integer): Integer;
|
||||
function GotoLine(Value: Integer): Integer;
|
||||
|
||||
Procedure CreateEditor(AOwner: TComponent; AParent: TWinControl);
|
||||
procedure CreateEditor(AOwner: TComponent; AParent: TWinControl);
|
||||
procedure SetVisible(Value: boolean);
|
||||
protected
|
||||
ErrorMsgs: TStrings;
|
||||
Procedure ReParent(AParent: TWinControl);
|
||||
procedure ReParent(AParent: TWinControl);
|
||||
|
||||
Procedure ProcessCommand(Sender: TObject;
|
||||
procedure ProcessCommand(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
||||
Procedure ProcessUserCommand(Sender: TObject;
|
||||
procedure ProcessUserCommand(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
||||
Procedure UserCommandProcessed(Sender: TObject;
|
||||
procedure UserCommandProcessed(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
||||
Procedure ccOnTimer(sender: TObject);
|
||||
Procedure ccAddMessage(Texts: String);
|
||||
procedure ccAddMessage(Texts: String);
|
||||
|
||||
Procedure FocusEditor;// called by TSourceNotebook when the Notebook page
|
||||
procedure FocusEditor;// called by TSourceNotebook when the Notebook page
|
||||
// changes so the editor is focused
|
||||
procedure OnGutterClick(Sender: TObject; X, Y, Line: integer;
|
||||
mark: TSynEditMark);
|
||||
@ -189,6 +188,7 @@ type
|
||||
procedure SetExecutionLine(NewLine: integer);
|
||||
procedure OnCodeBufferChanged(Sender: TSourceLog;
|
||||
SrcLogEntry: TSourceLogEntry);
|
||||
procedure StartIdentCompletion;
|
||||
|
||||
procedure LinesInserted(sender: TObject; FirstLine,Count: Integer);
|
||||
procedure LinesDeleted(sender: TObject; FirstLine,Count: Integer);
|
||||
@ -606,6 +606,7 @@ type
|
||||
AnEditor: TCustomSynEdit; var Index:integer);
|
||||
procedure OnWordCompletionGetSource(
|
||||
var Source: TStrings; SourceIndex: integer);
|
||||
procedure OnIdentCompletionTimer(Sender: TObject);
|
||||
|
||||
procedure FindReplaceDlgKey(Sender: TObject; var Key: Word;
|
||||
Shift:TShiftState; FindDlgComponent: TFindDlgComponent);
|
||||
@ -685,7 +686,7 @@ var
|
||||
// active
|
||||
CurCompletionControl: TSynCompletion;
|
||||
CurrentCompletionType: TCompletionType;
|
||||
IdentCompletionTimer: TTimer;
|
||||
IdentCompletionTimer: TIdleTimer;
|
||||
AWordCompletion: TWordCompletion;
|
||||
|
||||
GotoDialog: TfrmGoto;
|
||||
@ -962,6 +963,8 @@ Procedure TSourceEditor.ProcessCommand(Sender: TObject;
|
||||
// these are normal commands for synedit, define extra actions here
|
||||
// otherwise use ProcessUserCommand
|
||||
begin
|
||||
IdentCompletionTimer.AutoEnabled:=false;
|
||||
|
||||
if (FSourceNoteBook<>nil)
|
||||
and (snIncrementalFind in FSourceNoteBook.States) then begin
|
||||
case Command of
|
||||
@ -1011,13 +1014,21 @@ begin
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
ecChar:
|
||||
begin
|
||||
//debugln('TSourceEditor.ProcessCommand AChar="',AChar,'" AutoIdentifierCompletion=',dbgs(EditorOpts.AutoIdentifierCompletion),' Interval=',dbgs(IdentCompletionTimer.Interval));
|
||||
if (AChar='.') and EditorOpts.AutoIdentifierCompletion then
|
||||
IdentCompletionTimer.AutoEnabled:=true;
|
||||
end;
|
||||
|
||||
end;
|
||||
//debugln('TSourceEditor.ProcessCommand B IdentCompletionTimer.AutoEnabled=',dbgs(IdentCompletionTimer.AutoEnabled));
|
||||
end;
|
||||
|
||||
Procedure TSourceEditor.ProcessUserCommand(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
||||
// define all extra keys here, that should are not handled by synedit
|
||||
// define all extra keys here, that should not be handled by synedit
|
||||
var
|
||||
I: Integer;
|
||||
P: TPoint;
|
||||
@ -1035,24 +1046,7 @@ Begin
|
||||
FindHelpForSourceAtCursor;
|
||||
|
||||
ecIdentCompletion :
|
||||
if not TCustomSynEdit(Sender).ReadOnly then begin
|
||||
CurrentCompletionType:=ctIdentCompletion;
|
||||
TextS := FEditor.LineText;
|
||||
LogCaret:=FEditor.LogicalCaretXY;
|
||||
i := LogCaret.X - 1;
|
||||
if i > length(TextS) then
|
||||
TextS2 := ''
|
||||
else begin
|
||||
while (i > 0) and (TextS[i] in ['a'..'z','A'..'Z','0'..'9','_']) do
|
||||
dec(i);
|
||||
TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1));
|
||||
end;
|
||||
with TCustomSynEdit(Sender) do
|
||||
P := ClientToScreen(Point(CaretXPix - length(TextS2)*CharWidth
|
||||
,CaretYPix + LineHeight));
|
||||
aCompletion.Editor:=TCustomSynEdit(Sender);
|
||||
aCompletion.Execute(TextS2,P.X,P.Y);
|
||||
end;
|
||||
StartIdentCompletion;
|
||||
|
||||
ecWordCompletion :
|
||||
if not TCustomSynEdit(Sender).ReadOnly then begin
|
||||
@ -1619,11 +1613,6 @@ Begin
|
||||
ErrorMsgs.Add(Texts);
|
||||
End;
|
||||
|
||||
Procedure TSourceEditor.ccOnTimer(sender: TObject);
|
||||
Begin
|
||||
IdentCompletionTimer.Enabled := False;
|
||||
End;
|
||||
|
||||
Procedure TSourceEditor.CreateEditor(AOwner: TComponent; AParent: TWinControl);
|
||||
var
|
||||
NewName: string;
|
||||
@ -1780,6 +1769,34 @@ writeln('[TSourceEditor.OnCodeBufferChanged] A ',FIgnoreCodeBufferLock,' ',SrcLo
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceEditor.StartIdentCompletion;
|
||||
var
|
||||
I: Integer;
|
||||
P: TPoint;
|
||||
TextS, TextS2: String;
|
||||
LogCaret: TPoint;
|
||||
begin
|
||||
debugln('TSourceEditor.StartIdentCompletion');
|
||||
if not FEditor.ReadOnly then begin
|
||||
CurrentCompletionType:=ctIdentCompletion;
|
||||
TextS := FEditor.LineText;
|
||||
LogCaret:=FEditor.LogicalCaretXY;
|
||||
i := LogCaret.X - 1;
|
||||
if i > length(TextS) then
|
||||
TextS2 := ''
|
||||
else begin
|
||||
while (i > 0) and (TextS[i] in ['a'..'z','A'..'Z','0'..'9','_']) do
|
||||
dec(i);
|
||||
TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1));
|
||||
end;
|
||||
with FEditor do
|
||||
P := ClientToScreen(Point(CaretXPix - length(TextS2)*CharWidth
|
||||
,CaretYPix + LineHeight));
|
||||
aCompletion.Editor:=FEditor;
|
||||
aCompletion.Execute(TextS2,P.X,P.Y);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceEditor.IncreaseIgnoreCodeBufferLock;
|
||||
begin
|
||||
inc(FIgnoreCodeBufferLock);
|
||||
@ -2194,9 +2211,14 @@ begin
|
||||
end;
|
||||
|
||||
// identifier completion
|
||||
IdentCompletionTimer := TTimer.Create(self);
|
||||
IdentCompletionTimer.Enabled := False;
|
||||
IdentCompletionTimer.Interval := 500;
|
||||
IdentCompletionTimer := TIdleTimer.Create(Self);
|
||||
with IdentCompletionTimer do begin
|
||||
AutoEnabled := False;
|
||||
Enabled := false;
|
||||
Interval := EditorOpts.AutoDelayInMSec;
|
||||
OnTimer := @OnIdentCompletionTimer;
|
||||
end;
|
||||
|
||||
|
||||
// marks
|
||||
SourceEditorMarks:=TSourceMarks.Create(Self);
|
||||
@ -2348,11 +2370,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.OnIdentCompletionTimer(Sender: TObject);
|
||||
var
|
||||
TempEditor: TSourceEditor;
|
||||
begin
|
||||
//debugln('TSourceNotebook.OnIdentCompletionTimer');
|
||||
IdentCompletionTimer.Enabled:=false;
|
||||
IdentCompletionTimer.AutoEnabled:=false;
|
||||
TempEditor:=GetActiveSE;
|
||||
if TempEditor<>nil then TempEditor.StartIdentCompletion;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.OnCodeTemplateTokenNotFound(Sender: TObject;
|
||||
AToken: string; AnEditor: TCustomSynEdit; var Index:integer);
|
||||
var P:TPoint;
|
||||
begin
|
||||
//writeln('RRRRRRRRRRR ',AToken,',',AnEditor.ReadOnly,',',CurrentCompletionType=ctNone);
|
||||
//writeln('TSourceNotebook.OnCodeTemplateTokenNotFound ',AToken,',',AnEditor.ReadOnly,',',CurrentCompletionType=ctNone);
|
||||
if (AnEditor.ReadOnly=false) and (CurrentCompletionType=ctNone) then begin
|
||||
CurrentCompletionType:=ctTemplateCompletion;
|
||||
with AnEditor do
|
||||
@ -2622,6 +2655,7 @@ end;
|
||||
|
||||
Procedure TSourceNotebook.ccExecute(Sender: TObject);
|
||||
// init completion form
|
||||
// called by aCompletion.OnExecute just before showing
|
||||
var
|
||||
S: TStrings;
|
||||
Prefix: String;
|
||||
@ -4662,6 +4696,7 @@ end;
|
||||
procedure TSourceNotebook.OnApplicationUserInput(Sender: TObject; Msg: Cardinal
|
||||
);
|
||||
begin
|
||||
//debugln('TSourceNotebook.OnApplicationUserInput');
|
||||
HideHint;
|
||||
end;
|
||||
|
||||
@ -4689,6 +4724,7 @@ var
|
||||
CurHint: String;
|
||||
begin
|
||||
// hide other hints
|
||||
//debugln('TSourceNotebook.ShowSynEditHint A');
|
||||
Application.HideHint;
|
||||
//
|
||||
ASrcEdit:=GetActiveSE;
|
||||
@ -4918,13 +4954,13 @@ end;
|
||||
procedure TSynEditPlugin1.LinesDeleted(FirstLine, Count: integer);
|
||||
begin
|
||||
if Assigned(OnLinesDeleted) then
|
||||
OnLinesDeleted(self,Firstline,Count);
|
||||
OnLinesDeleted(self,Firstline,Count);
|
||||
end;
|
||||
|
||||
procedure TSynEditPlugin1.LinesInserted(FirstLine, Count: integer);
|
||||
begin
|
||||
if Assigned(OnLinesInserted) then
|
||||
OnLinesInserted(self,Firstline,Count);
|
||||
OnLinesInserted(self,Firstline,Count);
|
||||
end;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -309,10 +309,10 @@ type
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property AutoEnabled: boolean read FAutoEnabled write SetAutoEnabled;
|
||||
property AutoEndEvent: TIdleTimerAutoEvent
|
||||
read FAutoEndEvent write SetAutoEndEvent default itaOnIdle;
|
||||
property AutoStartEvent: TIdleTimerAutoEvent
|
||||
read FAutoStartEvent write SetAutoStartEvent default itaOnUserInput;
|
||||
read FAutoStartEvent write SetAutoStartEvent default itaOnIdle;
|
||||
property AutoEndEvent: TIdleTimerAutoEvent
|
||||
read FAutoEndEvent write SetAutoEndEvent default itaOnUserInput;
|
||||
end;
|
||||
|
||||
|
||||
@ -996,6 +996,9 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.137 2005/06/29 09:24:14 mattias
|
||||
implemented auto ident completion after point plus idle
|
||||
|
||||
Revision 1.136 2005/05/09 14:52:33 vincents
|
||||
also invalidate control, if it is only moved, but not resized.
|
||||
|
||||
|
@ -67,8 +67,8 @@ end;
|
||||
constructor TIdleTimer.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
FAutoEndEvent:=itaOnIdle;
|
||||
FAutoStartEvent:=itaOnUserInput;
|
||||
FAutoStartEvent:=itaOnIdle;
|
||||
FAutoEndEvent:=itaOnUserInput;
|
||||
end;
|
||||
|
||||
destructor TIdleTimer.Destroy;
|
||||
@ -80,7 +80,7 @@ end;
|
||||
procedure TIdleTimer.UpdateHandlers;
|
||||
begin
|
||||
if FAutoEnabled
|
||||
and ([csDesigning,csLoading]*ComponentState=[]) then begin
|
||||
and ([csDesigning,csLoading,csDestroying]*ComponentState=[]) then begin
|
||||
// connect handlers
|
||||
if FHandlersConnected or (Application=nil) then exit;
|
||||
Application.AddOnIdleHandler(@DoOnIdle,true);
|
||||
|
Loading…
Reference in New Issue
Block a user