From 331b05a1476eb03c583be1c6ee80b32c535337ca Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 20 May 2010 21:44:03 +0000 Subject: [PATCH] IDE: started block completion on char git-svn-id: trunk@25556 - --- components/codetools/codetoolmanager.pas | 11 ++++++ components/codetools/stdcodetools.pas | 3 +- ide/sourceeditor.pp | 43 ++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 8df352ef40..fea3f1d83b 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -363,6 +363,7 @@ type function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean; + function CompleteBlock(Code: TCodeBuffer; X,Y: integer): boolean; function CompleteBlock(Code: TCodeBuffer; X,Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean; @@ -3111,6 +3112,16 @@ begin {$ENDIF} end; +function TCodeToolManager.CompleteBlock(Code: TCodeBuffer; X, Y: integer + ): boolean; +var + NewCode: TCodeBuffer; + NewX, NewY, NewTopLine: integer; +begin + Result:=CompleteBlock(Code,X,Y,NewCode,NewX,NewY,NewTopLine); + if (NewCode=nil) and (NewX<0) and (NewY<0) and (NewTopLine<1) then ; +end; + function TCodeToolManager.CompleteBlock(Code: TCodeBuffer; X, Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean; var diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 79aa65e2e6..ac7adb03f3 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -5598,7 +5598,7 @@ var Indent: Integer; CursorBlockInnerIndent, CursorBlockOuterIndent: LongInt; CursorBlock: TBlock; - BehindCursorBlock: Boolean; // atom behind cursor block + BehindCursorBlock: Boolean; // atom is behind cursor block InCursorBlock: Boolean; NeedCompletion: Boolean; InsertPos: LongInt; @@ -5857,7 +5857,6 @@ var InCursorBlock:=(CursorBlockLvl>=0) and (CursorBlockLvl=Stack.Top) and (not BehindCursorBlock); if LineStart and InCursorBlock then begin - Indent:=GetLineIndent(Src,CurPos.StartPos); // atom is in same block as cursor (not sub block) // and first atom of a line // => check indent diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index beeadaa1c1..731fd2e367 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -40,9 +40,9 @@ uses {$IFDEF IDE_MEM_CHECK} MemCheck, {$ENDIF} - Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources, LCLIntf, - FileUtil, Forms, ComCtrls, Dialogs, StdCtrls, Graphics, - Translations, ClipBrd, types, Extctrls, Menus, HelpIntfs, LConvEncoding, LDockCtrl, + Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources, + LCLIntf, FileUtil, Forms, ComCtrls, Dialogs, StdCtrls, Graphics, Translations, + ClipBrd, types, Extctrls, Menus, HelpIntfs, LConvEncoding, LDockCtrl, // codetools BasicCodeTools, CodeBeautifier, CodeToolManager, CodeCache, SourceLog, // synedit @@ -284,6 +284,7 @@ type Category: TAutoCompleteOption): boolean; function AutoBlockCompleteChar(Char: TUTF8Char; var AddChar: boolean; Category: TAutoCompleteOption; aTextPos: TPoint; Line: string): boolean; + function AutoBlockCompleteChar(Char: TUTF8Char): boolean; procedure AutoCompleteBlock; procedure FocusEditor;// called by TSourceNotebook when the Notebook page @@ -3015,6 +3016,12 @@ begin ecNone: ; + ecChar: + begin + if AutoBlockCompleteChar(AChar) then + Handled:=true; + end; + else begin Handled:=false; @@ -3778,6 +3785,36 @@ begin end; end; +function TSourceEditor.AutoBlockCompleteChar(Char: TUTF8Char): boolean; +var + p: TPoint; + x1: integer; + x2: integer; + Line: String; + WordToken: String; +begin + Result:=false; + if (not EditorOpts.AutoBlockCompletion) + or (not (SyntaxHighlighterType in [lshFreePascal,lshDelphi])) then + exit; + if (Char='n') or (Char='N') then begin + p:=GetCursorTextXY; + FEditor.GetWordBoundsAtRowCol(p, x1, x2); + Line:=GetLineText; + WordToken := copy(Line, x1, x2-x1); + if SysUtils.CompareText(WordToken,'begin')<>0 then exit; + debugln(['TSourceEditor.AutoBlockCompleteChar ']); + // user typed 'begin' + if not LazarusIDE.SaveSourceEditorChangesToCodeCache(self) then exit; + {FEditor.BeginUndoBlock; + try + if not CodeToolBoss.CompleteBlock(CodeBuffer,p.X,p.Y) then exit; + finally + FEditor.EndUndoBlock; + end;} + end; +end; + procedure TSourceEditor.AutoCompleteBlock; var XY: TPoint;