From b70be02b90cc86084f41fd453957c50ed11423c5 Mon Sep 17 00:00:00 2001 From: juha Date: Fri, 26 Aug 2016 13:08:06 +0000 Subject: [PATCH] IDEIntf: Add function RemoveShortCut. IDE extension package may want to use a reserved shortcut and remove it. git-svn-id: trunk@52874 - --- components/ideintf/idecommands.pas | 2 ++ ide/keymapping.pp | 38 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/components/ideintf/idecommands.pas b/components/ideintf/idecommands.pas index 0752cf70bd..1a4c41a860 100644 --- a/components/ideintf/idecommands.pas +++ b/components/ideintf/idecommands.pas @@ -636,6 +636,8 @@ type function FindCommandByName(const CommandName: string): TIDECommand; virtual; abstract; function FindCommandsByShortCut(const ShortCutMask: TIDEShortCut; IDEWindowClass: TCustomFormClass = nil): TFPList; virtual; abstract; // list of TIDECommand + function RemoveShortCut(ShortCutMask: TIDEShortCut; + IDEWindowClass: TCustomFormClass = nil): Integer; virtual; abstract; function CategoryCount: integer; virtual; abstract; public procedure StartUpdateEvents; diff --git a/ide/keymapping.pp b/ide/keymapping.pp index 6142740717..bf0d34f736 100644 --- a/ide/keymapping.pp +++ b/ide/keymapping.pp @@ -182,6 +182,8 @@ type function FindCommandByName(const CommandName: string): TIDECommand; override; function FindCommandsByShortCut(const ShortCutMask: TIDEShortCut; IDEWindowClass: TCustomFormClass = nil): TFPList; override; + function RemoveShortCut(ShortCutMask: TIDEShortCut; + IDEWindowClass: TCustomFormClass = nil): Integer; override; function TranslateKey(Key: word; Shift: TShiftState; IDEWindowClass: TCustomFormClass; UseLastKey: boolean = true): word; function IndexOf(ARelation: TKeyCommandRelation): integer; @@ -3936,6 +3938,42 @@ begin end; end; +function TKeyCommandRelationList.RemoveShortCut(ShortCutMask: TIDEShortCut; + IDEWindowClass: TCustomFormClass): Integer; +// Removes the given shortcut from every command. Returns the number deleted. +// An IDE extension package may want to use a reserved shortcut and remove it. + + procedure CheckAndRemove(pShortCut: PIDEShortCut); + begin + if ((pShortCut^.Key1=ShortCutMask.Key1) and (pShortCut^.Shift1=ShortCutMask.Shift1)) + and ((pShortCut^.Key2=VK_UNKNOWN) + or (ShortCutMask.Key2=VK_UNKNOWN) + or ((pShortCut^.Key2=ShortCutMask.Key2) and (pShortCut^.Shift2=ShortCutMask.Shift2))) then + begin + pShortCut^.Key1:=VK_UNKNOWN; + pShortCut^.Shift1:=[]; + pShortCut^.Key2:=VK_UNKNOWN; + pShortCut^.Shift2:=[]; + Inc(Result); + end; + end; + +var + i: Integer; +begin + Result:=0; + if ShortCutMask.Key1=VK_UNKNOWN then + Exit; + for i:=0 to FRelations.Count-1 do + with Relations[i] do + if (IDEWindowClass=nil) or (Category.Scope=nil) + or Category.Scope.HasIDEWindowClass(IDEWindowClass) then + begin + CheckAndRemove(@ShortcutA); + CheckAndRemove(@ShortcutB); + end; +end; + function TKeyCommandRelationList.TranslateKey(Key: word; Shift: TShiftState; IDEWindowClass: TCustomFormClass; UseLastKey: boolean): word; { If UseLastKey = true then only search for commmands with one key.