@@ -154,33 +154,44 @@ TMenuHandler = class
154
154
Item:TMenuItem;
155
155
Action: TProc;
156
156
procedure OnExecute (Sender: TObject);
157
- Constructor Create(aCaption:String; aAction:TProc);
157
+ Constructor Create(aCaption:String; aAction:TProc; aShortcut: String );
158
158
class var
159
159
MenuHandlers : TObjectList<TMenuHandler>;
160
+ FActionList: TActionList;
160
161
public
161
162
destructor Destroy; override;
162
163
class constructor create;
163
164
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 = ' ' );
165
166
end ;
166
167
167
168
class constructor TMenuHandler.Create;
168
169
begin
169
170
MenuHandlers := TObjectList<TMenuHandler>.Create;
171
+ FActionList := TActionList.Create(nil );
170
172
end ;
171
173
172
174
class destructor TMenuHandler.Destroy;
173
175
begin
174
176
MenuHandlers.free;
177
+ FActionList.Free;
175
178
end ;
176
179
177
- Constructor TMenuHandler.Create(aCaption:String; aAction:TProc);
180
+ Constructor TMenuHandler.Create(aCaption:String; aAction:TProc;aShortcut: String);
181
+ var
182
+ MyAction: TAction;
178
183
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;
184
195
end ;
185
196
186
197
destructor TMenuHandler.Destroy;
@@ -196,9 +207,9 @@ procedure TMenuHandler.OnExecute(Sender: TObject);
196
207
end ;
197
208
198
209
199
- class procedure TMenuHandler.AddMenuItem (NTAServices: INTAServices; aCaption:String; aAction:TProc);
210
+ class procedure TMenuHandler.AddMenuItem (NTAServices: INTAServices; aCaption:String; aAction:TProc; aShortcut: String = ' ' );
200
211
begin
201
- var handler := TMenuHandler.Create(aCaption, aAction);
212
+ var handler := TMenuHandler.Create(aCaption, aAction,aShortcut );
202
213
MenuHandlers.Add(handler);
203
214
// I am adding menu items to the top of the Tools menu because all
204
215
// the menu items under "Configure Tools..." get deleted whenever you
@@ -225,7 +236,7 @@ procedure Register;
225
236
procedure
226
237
begin
227
238
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+\ ' );
229
240
end );
230
241
break;
231
242
end ;
0 commit comments