From bd27789eb28c5c235bd382c00d3f362f20da8273 Mon Sep 17 00:00:00 2001 From: Raymond Date: Wed, 31 Mar 2010 21:40:53 +0200 Subject: [PATCH] Fixed codehints (you can now actually space ;)) --- Projects/SAMufasaGUI/framescript.lfm | 1 + Projects/SAMufasaGUI/framescript.lrs | 71 ++++++++++++++-------------- Projects/SAMufasaGUI/framescript.pas | 21 +++++++- Projects/SAMufasaGUI/testunit.pas | 14 ++++++ Units/Misc/v_autocompleteform.pas | 7 ++- 5 files changed, 75 insertions(+), 39 deletions(-) diff --git a/Projects/SAMufasaGUI/framescript.lfm b/Projects/SAMufasaGUI/framescript.lfm index e46736a..cb8b4e4 100644 --- a/Projects/SAMufasaGUI/framescript.lfm +++ b/Projects/SAMufasaGUI/framescript.lfm @@ -597,6 +597,7 @@ object ScriptFrame: TScriptFrame Options = [eoAutoIndent, eoGroupUndo, eoScrollPastEol, eoSmartTabs, eoTabIndent, eoTabsToSpaces, eoTrimTrailingSpaces, eoBracketHighlight] BracketHighlightStyle = sbhsBoth OnChange = SynEditChange + OnCommandProcessed = SynEditCommandProcessed OnProcessCommand = SynEditProcessCommand OnProcessUserCommand = SynEditProcessUserCommand OnSpecialLineColors = SynEditSpecialLineColors diff --git a/Projects/SAMufasaGUI/framescript.lrs b/Projects/SAMufasaGUI/framescript.lrs index f1a2e42..f103b62 100644 --- a/Projects/SAMufasaGUI/framescript.lrs +++ b/Projects/SAMufasaGUI/framescript.lrs @@ -120,39 +120,40 @@ LazarusResources.Add('TScriptFrame','FORMDATA',[ +'ngs'#1#6#12'program new;'#6#5'begin'#6#4'end.'#0#7'Options'#11#12'eoAutoInd' +'ent'#11'eoGroupUndo'#15'eoScrollPastEol'#11'eoSmartTabs'#11'eoTabIndent'#14 +'eoTabsToSpaces'#20'eoTrimTrailingSpaces'#18'eoBracketHighlight'#0#21'Bracke' - +'tHighlightStyle'#7#8'sbhsBoth'#8'OnChange'#7#13'SynEditChange'#16'OnProcess' - +'Command'#7#21'SynEditProcessCommand'#20'OnProcessUserCommand'#7#25'SynEditP' - +'rocessUserCommand'#19'OnSpecialLineColors'#7#24'SynEditSpecialLineColors'#14 - +'OnStatusChange'#7#19'SynEditStatusChange'#0#244#18'TSynGutterPartList'#0#0 - +#15'TSynGutterMarks'#0#5'Width'#2#23#0#0#20'TSynGutterLineNumber'#0#5'Width' - +#2#17#12'MouseActions'#14#0#21'MarkupInfo.Background'#7#9'clBtnFace'#21'Mark' - +'upInfo.Foreground'#7#6'clNone'#10'DigitCount'#2#2#30'ShowOnlyLineNumbersMul' - +'tiplesOf'#2#1#9'ZeroStart'#8#12'LeadingZeros'#8#0#0#17'TSynGutterChanges'#0 - +#5'Width'#2#4#13'ModifiedColor'#4#252#233#0#0#10'SavedColor'#7#7'clGreen'#0#0 - ,#19'TSynGutterSeparator'#0#5'Width'#2#2#0#0#21'TSynGutterCodeFolding'#0#12'M' - +'ouseActions'#14#1#5'Shift'#11#0#9'ShiftMask'#11#0#6'Button'#7#7'mbRight'#10 - +'ClickCount'#7#8'ccSingle'#8'ClickDir'#7#4'cdUp'#7'Command'#2#16#9'MoveCaret' - +#8#6'Option'#2#0#8'Priority'#2#0#0#1#5'Shift'#11#0#9'ShiftMask'#11#7'ssShift' - +#0#6'Button'#7#8'mbMiddle'#10'ClickCount'#7#5'ccAny'#8'ClickDir'#7#6'cdDown' - +#7'Command'#2#14#9'MoveCaret'#8#6'Option'#2#0#8'Priority'#2#0#0#1#5'Shift'#11 - +#7'ssShift'#0#9'ShiftMask'#11#7'ssShift'#0#6'Button'#7#8'mbMiddle'#10'ClickC' - +'ount'#7#5'ccAny'#8'ClickDir'#7#6'cdDown'#7'Command'#2#14#9'MoveCaret'#8#6'O' - +'ption'#2#1#8'Priority'#2#0#0#1#5'Shift'#11#0#9'ShiftMask'#11#0#6'Button'#7#6 - +'mbLeft'#10'ClickCount'#7#5'ccAny'#8'ClickDir'#7#6'cdDown'#7'Command'#2#0#9 - +'MoveCaret'#8#6'Option'#2#0#8'Priority'#2#0#0#0#21'MarkupInfo.Background'#7#6 - +'clNone'#21'MarkupInfo.Foreground'#7#6'clGray'#20'MouseActionsExpanded'#14#1 - +#5'Shift'#11#0#9'ShiftMask'#11#0#6'Button'#7#6'mbLeft'#10'ClickCount'#7#5'cc' - +'Any'#8'ClickDir'#7#6'cdDown'#7'Command'#2#14#9'MoveCaret'#8#6'Option'#2#0#8 - +'Priority'#2#0#0#0#21'MouseActionsCollapsed'#14#1#5'Shift'#11#6'ssCtrl'#0#9 - +'ShiftMask'#11#6'ssCtrl'#0#6'Button'#7#6'mbLeft'#10'ClickCount'#7#5'ccAny'#8 - +'ClickDir'#7#6'cdDown'#7'Command'#2#15#9'MoveCaret'#8#6'Option'#2#0#8'Priori' - +'ty'#2#0#0#1#5'Shift'#11#0#9'ShiftMask'#11#6'ssCtrl'#0#6'Button'#7#6'mbLeft' - +#10'ClickCount'#7#5'ccAny'#8'ClickDir'#7#6'cdDown'#7'Command'#2#15#9'MoveCar' - +'et'#8#6'Option'#2#1#8'Priority'#2#0#0#0#0#0#0#0#17'TSynFreePascalSyn'#17'Sy' - +'nFreePascalSyn1'#7'Enabled'#8#23'CommentAttri.Foreground'#7#6'clBlue'#18'Co' - +'mmentAttri.Style'#11#6'fsBold'#0#26'IdentifierAttri.Foreground'#7#9'clDefau' - +'lt'#22'NumberAttri.Foreground'#7#6'clNavy'#22'StringAttri.Foreground'#7#6'c' - +'lBlue'#22'SymbolAttri.Foreground'#7#5'clRed'#25'DirectiveAttri.Foreground'#7 - +#5'clRed'#20'DirectiveAttri.Style'#11#6'fsBold'#0#12'CompilerMode'#7#9'pcmOb' - +'jFPC'#14'NestedComments'#9#4'left'#3'@'#1#3'top'#2#16#0#0#0 + +'tHighlightStyle'#7#8'sbhsBoth'#8'OnChange'#7#13'SynEditChange'#18'OnCommand' + +'Processed'#7#23'SynEditCommandProcessed'#16'OnProcessCommand'#7#21'SynEditP' + +'rocessCommand'#20'OnProcessUserCommand'#7#25'SynEditProcessUserCommand'#19 + +'OnSpecialLineColors'#7#24'SynEditSpecialLineColors'#14'OnStatusChange'#7#19 + +'SynEditStatusChange'#0#244#18'TSynGutterPartList'#0#0#15'TSynGutterMarks'#0 + +#5'Width'#2#23#0#0#20'TSynGutterLineNumber'#0#5'Width'#2#17#12'MouseActions' + +#14#0#21'MarkupInfo.Background'#7#9'clBtnFace'#21'MarkupInfo.Foreground'#7#6 + +'clNone'#10'DigitCount'#2#2#30'ShowOnlyLineNumbersMultiplesOf'#2#1#9'ZeroSta' + +'rt'#8#12'LeadingZeros'#8#0#0#17'TSynGutterChanges'#0#5'Width'#2#4#13'Modifi' + ,'edColor'#4#252#233#0#0#10'SavedColor'#7#7'clGreen'#0#0#19'TSynGutterSeparat' + +'or'#0#5'Width'#2#2#0#0#21'TSynGutterCodeFolding'#0#12'MouseActions'#14#1#5 + +'Shift'#11#0#9'ShiftMask'#11#0#6'Button'#7#7'mbRight'#10'ClickCount'#7#8'ccS' + +'ingle'#8'ClickDir'#7#4'cdUp'#7'Command'#2#16#9'MoveCaret'#8#6'Option'#2#0#8 + +'Priority'#2#0#0#1#5'Shift'#11#0#9'ShiftMask'#11#7'ssShift'#0#6'Button'#7#8 + +'mbMiddle'#10'ClickCount'#7#5'ccAny'#8'ClickDir'#7#6'cdDown'#7'Command'#2#14 + +#9'MoveCaret'#8#6'Option'#2#0#8'Priority'#2#0#0#1#5'Shift'#11#7'ssShift'#0#9 + +'ShiftMask'#11#7'ssShift'#0#6'Button'#7#8'mbMiddle'#10'ClickCount'#7#5'ccAny' + +#8'ClickDir'#7#6'cdDown'#7'Command'#2#14#9'MoveCaret'#8#6'Option'#2#1#8'Prio' + +'rity'#2#0#0#1#5'Shift'#11#0#9'ShiftMask'#11#0#6'Button'#7#6'mbLeft'#10'Clic' + +'kCount'#7#5'ccAny'#8'ClickDir'#7#6'cdDown'#7'Command'#2#0#9'MoveCaret'#8#6 + +'Option'#2#0#8'Priority'#2#0#0#0#21'MarkupInfo.Background'#7#6'clNone'#21'Ma' + +'rkupInfo.Foreground'#7#6'clGray'#20'MouseActionsExpanded'#14#1#5'Shift'#11#0 + +#9'ShiftMask'#11#0#6'Button'#7#6'mbLeft'#10'ClickCount'#7#5'ccAny'#8'ClickDi' + +'r'#7#6'cdDown'#7'Command'#2#14#9'MoveCaret'#8#6'Option'#2#0#8'Priority'#2#0 + +#0#0#21'MouseActionsCollapsed'#14#1#5'Shift'#11#6'ssCtrl'#0#9'ShiftMask'#11#6 + +'ssCtrl'#0#6'Button'#7#6'mbLeft'#10'ClickCount'#7#5'ccAny'#8'ClickDir'#7#6'c' + +'dDown'#7'Command'#2#15#9'MoveCaret'#8#6'Option'#2#0#8'Priority'#2#0#0#1#5'S' + +'hift'#11#0#9'ShiftMask'#11#6'ssCtrl'#0#6'Button'#7#6'mbLeft'#10'ClickCount' + +#7#5'ccAny'#8'ClickDir'#7#6'cdDown'#7'Command'#2#15#9'MoveCaret'#8#6'Option' + +#2#1#8'Priority'#2#0#0#0#0#0#0#0#17'TSynFreePascalSyn'#17'SynFreePascalSyn1' + +#7'Enabled'#8#23'CommentAttri.Foreground'#7#6'clBlue'#18'CommentAttri.Style' + +#11#6'fsBold'#0#26'IdentifierAttri.Foreground'#7#9'clDefault'#22'NumberAttri' + +'.Foreground'#7#6'clNavy'#22'StringAttri.Foreground'#7#6'clBlue'#22'SymbolAt' + +'tri.Foreground'#7#5'clRed'#25'DirectiveAttri.Foreground'#7#5'clRed'#20'Dire' + +'ctiveAttri.Style'#11#6'fsBold'#0#12'CompilerMode'#7#9'pcmObjFPC'#14'NestedC' + +'omments'#9#4'left'#3'@'#1#3'top'#2#16#0#0#0 ]); diff --git a/Projects/SAMufasaGUI/framescript.pas b/Projects/SAMufasaGUI/framescript.pas index be99ab4..f816fa3 100644 --- a/Projects/SAMufasaGUI/framescript.pas +++ b/Projects/SAMufasaGUI/framescript.pas @@ -50,6 +50,8 @@ type procedure SynEditChange(Sender: TObject); procedure SynEditClickLink(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); + procedure SynEditCommandProcessed(Sender: TObject; + var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer); procedure SynEditDragDrop(Sender, Source: TObject; X, Y: Integer); procedure SynEditDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); @@ -209,6 +211,18 @@ begin end; end; +procedure TScriptFrame.SynEditCommandProcessed(Sender: TObject; + var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer); +var + Command2 : TSynEditorCommand; +begin + if (Command = ecChar) and (AChar = '(') and (Form1.ParamHint.Visible = false) and (Form1.ShowHintAuto) then + begin + Command2:= ecCodeHints; + SynEditProcessUserCommand(sender,command2,achar,nil); + end; +end; + procedure TScriptFrame.SynEditDragDrop(Sender, Source: TObject; X, Y: Integer); begin if Source is TFunctionListFrame then @@ -377,8 +391,11 @@ begin synedit.Lines.SaveToStream(ms); try Synedit.GetWordBoundsAtRowCol(Synedit.CaretXY, sp, ep); - mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1,true); - + s := SynEdit.Lines[SynEdit.Carety-1]; + if ep > length(s) then //We are outside the real text, go back to the last char + mp.Run(ms, nil, Synedit.SelStart - ep + length(s),true) + else + mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1,true); bcc := 1;bck := 0;cc := 0; s := mp.GetExpressionAtPos(bcc, bck, cc,posi, true); bracketpos := posi + length(s); diff --git a/Projects/SAMufasaGUI/testunit.pas b/Projects/SAMufasaGUI/testunit.pas index 751848d..d9db9a4 100644 --- a/Projects/SAMufasaGUI/testunit.pas +++ b/Projects/SAMufasaGUI/testunit.pas @@ -330,8 +330,10 @@ type function GetFontPath: String; function GetIncludePath: String; function GetScriptState: TScriptState; + function GetShowHintAuto: boolean; procedure SetFontPath(const AValue: String); procedure SetIncludePath(const AValue: String); + procedure SetShowHintAuto(const AValue: boolean); procedure SetScriptState(const State: TScriptState); function LoadSettingDef(Key : string; Def : string) : string; function CreateSetting(Key : string; Value : string) : string; @@ -383,6 +385,7 @@ type procedure InitalizeTMThread(var Thread : TMThread); procedure HandleParameters; procedure OnSaveScript(const Filename : string); + property ShowHintAuto : boolean read GetShowHintAuto write SetShowHintAuto; property IncludePath : String read GetIncludePath write SetIncludePath; property FontPath : String read GetFontPath write SetFontPath; end; @@ -991,6 +994,7 @@ begin CreateSetting('Settings/General/MaxRecentFiles','10'); CreateSetting('Settings/MainForm/NormalSize','739:555'); CreateSetting('Settings/FunctionList/ShowOnStart','True'); + CreateSetting('Settings/CodeHints/ShowAutomatically','True'); CreateSetting('Settings/Updater/RemoteLink',SimbaURL + 'Simba'{$IFDEF WINDOWS} +'.exe'{$ENDIF}); CreateSetting('Settings/Updater/RemoteVersionLink',SimbaURL + 'Version'); @@ -2294,6 +2298,11 @@ begin result := CurrScript.FScriptState; end; +function TForm1.GetShowHintAuto: boolean; +begin + Result := LowerCase(LoadSettingDef('Settings/CodeHints/ShowAutomatically','True')) = 'true'; +end; + procedure TForm1.SetFontPath(const AValue: String); begin SetSetting('Settings/Fonts/Path',AValue); @@ -2407,6 +2416,11 @@ begin UpdatingFonts := False; end; +procedure TForm1.SetShowHintAuto(const AValue: boolean); +begin + SetSetting('Settings/CodeHints/ShowAutomatically',Booltostr(AValue,true)); +end; + {$ifdef mswindows} function GetConsoleWindow: HWND; stdcall; external kernel32 name 'GetConsoleWindow'; diff --git a/Units/Misc/v_autocompleteform.pas b/Units/Misc/v_autocompleteform.pas index cf46c0a..df5e878 100644 --- a/Units/Misc/v_autocompleteform.pas +++ b/Units/Misc/v_autocompleteform.pas @@ -600,11 +600,14 @@ var typedecl : TDeclaration; s,TypeStr,Params : string;// i,ii :integer; + CursorXY : TPoint; begin result := -1; MustHide := True; - Parser := TmwPasLex.Create; - parser.Origin:= PChar( StringListPartToText(Point(FBracketPoint.x,FBracketPoint.y-1),point(min(FSynEdit.LogicalCaretXY.x-1,length(FSynEdit.LineText)),FSynEdit.logicalcaretxy.y-1),FSynEdit.lines)); + Parser := TmwPasLex.Create; //The position of the bracket + parser.Origin:= PChar(StringListPartToText(Point(FBracketPoint.x,FBracketPoint.y-1), + point(min(FSynEdit.CaretX,length(FSynEdit.Lines[FSynEdit.CaretY - 1])),FSynEdit.CaretY-1), + FSynEdit.lines)); bracketcount := 0; ParameterIndex := -1; while parser.TokenID <> tkNull do