From 2131e510163d966b5ce16406a36c38534b2d197a Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 6 Dec 2015 06:52:10 +0100 Subject: [PATCH] JumToDefinition and completion menu shortcuts are customizables using the option editor widget --- src/ce_editor.lfm | 1 - src/ce_editor.pas | 7 ++++--- src/ce_synmemo.pas | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/ce_editor.lfm b/src/ce_editor.lfm index 7fb439db..2d98ace8 100644 --- a/src/ce_editor.lfm +++ b/src/ce_editor.lfm @@ -93,7 +93,6 @@ inherited CEEditorWidget: TCEEditorWidget end object mnuedJum2Decl: TMenuItem Caption = 'Jump to declaration' - ShortCut = 24614 OnClick = mnuedJum2DeclClick end object mnuedCallTip: TMenuItem diff --git a/src/ce_editor.pas b/src/ce_editor.pas index 4ae636a0..7c1fa559 100644 --- a/src/ce_editor.pas +++ b/src/ce_editor.pas @@ -299,9 +299,7 @@ begin VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT: updateImperative; end; if fKeyChanged then - beginDelayedUpdate - else if (Key = VK_UP) and (shift = [ssShift,ssCtrl]) then - getSymbolLoc; + beginDelayedUpdate; end; procedure TCEEditorWidget.memoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); @@ -314,6 +312,9 @@ end; procedure TCEEditorWidget.memoCmdProcessed(Sender: TObject; var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer); begin fLastCommand := Command; + // + if Command = ecJumpToDefinition then + getSymbolLoc; end; procedure TCEEditorWidget.memoKeyPress(Sender: TObject; var Key: char); diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index c4023dcc..344854e0 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -143,6 +143,8 @@ type procedure removeBreakPoint(line: integer); function findBreakPoint(line: integer): boolean; protected + procedure DoOnProcessCommand(var Command: TSynEditorCommand; var AChar: TUTF8Char; + Data: pointer); override; procedure MouseLeave; override; procedure SetVisible(Value: Boolean); override; procedure SetHighlighter(const Value: TSynCustomHighlighter); override; @@ -196,6 +198,13 @@ type procedure SetDefaultCoeditKeystrokes(ed: TSynEdit); + function CustomStringToCommand(const Ident: string; var Int: Longint): Boolean; + function CustomCommandToSstring(Int: Longint; var Ident: string): Boolean; + +const + ecCompletionMenu = ecUserFirst + 1; + ecJumpToDefinition = ecUserFirst + 2; + var D2Syn: TSynD2Syn; // used as model to set the options when no editor exists. LfmSyn: TSynLfmSyn; // used to highlight the native project format. @@ -460,6 +469,7 @@ begin fCompletion.CaseSensitive:=false; fCompletion.LongLineHintType:=sclpNone; fCompletion.TheForm.ShowInTaskBar:=stNever; + fCompletion.ShortCut:=0; // MouseLinkColor.Style:= [fsUnderline]; with MouseActions.Add do begin @@ -612,7 +622,6 @@ begin fDDocWin.Hide; end; - procedure TCESynMemo.getCallTips(); begin showCallTips; @@ -641,6 +650,17 @@ begin getCompletionList; end; +procedure TCESynMemo.DoOnProcessCommand(var Command: TSynEditorCommand; + var AChar: TUTF8Char; Data: pointer); +begin + inherited; + if Command = ecCompletionMenu then + begin + fCanAutoDot:=false; + fCompletion.Execute('', ClientToScreen(point(CaretXPix, CaretYPix + Font.Size))); + end; +end; + procedure TCESynMemo.getCompletionList; begin if not DcdWrapper.available then exit; @@ -977,8 +997,29 @@ begin AddKey(ecColSelEditorBottom, VK_END, [ssAlt, ssShift,ssCtrl], 0, []); AddKey(ecSynPSyncroEdStart, ord('E'), [ssCtrl], 0, []); AddKey(ecSynPSyncroEdEscape, ord('E'), [ssCtrl, ssShift], 0, []); + AddKey(ecCompletionMenu, ord(' '), [ssCtrl], 0, []); + AddKey(ecJumpToDefinition, VK_UP, [ssCtrl,ssShift], 0, []); // goto def end; end; + +function CustomStringToCommand(const Ident: string; var Int: Longint): Boolean; +begin + case Ident of + 'ecCompletionMenu': begin Int := ecCompletionMenu; exit(true); end; + 'ecJumpToDeclaration': begin Int := ecJumpToDefinition; exit(true); end; + else exit(false); + end; +end; + +function CustomCommandToSstring(Int: Longint; var Ident: string): Boolean; +begin + case Int of + ecCompletionMenu: begin Ident := 'ecCompletionMenu'; exit(true); end; + ecJumpToDefinition: begin Ident := 'ecJumpToDeclaration'; exit(true); end; + else exit(false); + end; +end; + {$ENDREGION --------------------------------------------------------------------} {$REGION user input ------------------------------------------------------------} @@ -1162,6 +1203,8 @@ initialization LfmSyn.StringAttri.Foreground := clBlue; // TCEEditorHintWindow.FontSize := 10; + // + RegisterKeyCmdIdentProcs(@CustomStringToCommand, @CustomCommandToSstring); finalization D2Syn.Free; LfmSyn.Free;