Skip to content

Commit b9a9e10

Browse files
committed
Now "Open In Visual Studio Code" can be launched also by using the "Ctrl+\" keyboard shortcut
1 parent 8e0dc04 commit b9a9e10

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

DGVisualStudioCodeIntegration.pas

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,33 +154,44 @@ TMenuHandler = class
154154
Item:TMenuItem;
155155
Action: TProc;
156156
procedure OnExecute(Sender: TObject);
157-
Constructor Create(aCaption:String; aAction:TProc);
157+
Constructor Create(aCaption:String; aAction:TProc; aShortcut: String);
158158
class var
159159
MenuHandlers : TObjectList<TMenuHandler>;
160+
FActionList: TActionList;
160161
public
161162
destructor Destroy; override;
162163
class constructor create;
163164
class destructor Destroy;
164-
class procedure AddMenuItem(NTAServices: INTAServices; aCaption:String; aAction:TProc);
165+
class procedure AddMenuItem(NTAServices: INTAServices; aCaption:String; aAction:TProc; aShortcut: String = '');
165166
end;
166167

167168
class constructor TMenuHandler.Create;
168169
begin
169170
MenuHandlers := TObjectList<TMenuHandler>.Create;
171+
FActionList := TActionList.Create(nil);
170172
end;
171173

172174
class destructor TMenuHandler.Destroy;
173175
begin
174176
MenuHandlers.free;
177+
FActionList.Free;
175178
end;
176179

177-
Constructor TMenuHandler.Create(aCaption:String; aAction:TProc);
180+
Constructor TMenuHandler.Create(aCaption:String; aAction:TProc;aShortcut: String);
181+
var
182+
MyAction: TAction;
178183
begin
179-
inherited Create;
180-
Action := aAction;
181-
Item := TMenuItem.Create(nil);
182-
Item.Caption := aCaption;
183-
Item.OnClick := OnExecute;
184+
inherited Create;
185+
Action := aAction;
186+
MyAction := TAction.Create(FActionList);
187+
MyAction.Caption := aCaption;
188+
MyAction.OnExecute := OnExecute;
189+
190+
if aShortcut <> '' then
191+
MyAction.ShortCut := TextToShortCut(aShortcut);
192+
193+
Item := TMenuItem.Create(nil);
194+
Item.Action := MyAction;
184195
end;
185196

186197
destructor TMenuHandler.Destroy;
@@ -196,9 +207,9 @@ procedure TMenuHandler.OnExecute(Sender: TObject);
196207
end;
197208

198209

199-
class procedure TMenuHandler.AddMenuItem(NTAServices: INTAServices; aCaption:String; aAction:TProc);
210+
class procedure TMenuHandler.AddMenuItem(NTAServices: INTAServices; aCaption:String; aAction:TProc; aShortcut: String = '');
200211
begin
201-
var handler := TMenuHandler.Create(aCaption, aAction);
212+
var handler := TMenuHandler.Create(aCaption, aAction,aShortcut);
202213
MenuHandlers.Add(handler);
203214
// I am adding menu items to the top of the Tools menu because all
204215
// the menu items under "Configure Tools..." get deleted whenever you
@@ -225,7 +236,7 @@ procedure Register;
225236
procedure
226237
begin
227238
TMenuHandler.AddMenuItem(NTAServices, '-', nil);
228-
TMenuHandler.AddMenuItem(NTAServices, 'Open in Visual Studio Code', OpenCurrentFileInVisualStudioCode);
239+
TMenuHandler.AddMenuItem(NTAServices, 'Open in Visual Studio Code', OpenCurrentFileInVisualStudioCode, 'Ctrl+\');
229240
end);
230241
break;
231242
end;

0 commit comments

Comments
 (0)