11using System ;
22using System . ComponentModel ;
3- using System . Drawing ;
43using System . IO ;
54using System . Linq ;
65using System . Windows . Forms ;
2019
2120namespace QuickNavigate
2221{
22+ public class ShortcutId
23+ {
24+ public const string TypeExplorer = "QuickNavigate.TypeExplorer" ;
25+ public const string QuickOutline = "QuickNavigate.Outline" ;
26+ public const string ClassHierarchy = "QuickNavigate.ClassHierarchy" ;
27+ public const string RecentFiles = "QuickNavigate.RecentFiles" ;
28+ public const string RecentProjects = "QuickNavigate.RecentProjects" ;
29+ }
30+
2331 public class PluginMain : IPlugin
2432 {
2533 string settingFilename ;
@@ -131,7 +139,7 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority)
131139 /// </summary>
132140 void InitBasics ( )
133141 {
134- string dataPath = Path . Combine ( PathHelper . DataDir , Name ) ;
142+ var dataPath = Path . Combine ( PathHelper . DataDir , Name ) ;
135143 if ( ! Directory . Exists ( dataPath ) ) Directory . CreateDirectory ( dataPath ) ;
136144 settingFilename = Path . Combine ( dataPath , "Settings.fdb" ) ;
137145 }
@@ -156,26 +164,26 @@ void LoadSettings()
156164 /// </summary>
157165 void CreateMenuItems ( )
158166 {
159- ToolStripMenuItem menu = ( ToolStripMenuItem ) PluginBase . MainForm . FindMenuItem ( "SearchMenu" ) ;
160- Image image = PluginBase . MainForm . FindImage ( "99|16|0|0" ) ;
167+ var menu = ( ToolStripMenuItem ) PluginBase . MainForm . FindMenuItem ( "SearchMenu" ) ;
168+ var image = PluginBase . MainForm . FindImage ( "99|16|0|0" ) ;
161169 typeExplorerItem = new ToolStripMenuItem ( "Type Explorer" , image , ShowTypeExplorer ) ;
162- PluginBase . MainForm . RegisterShortcutItem ( $ " { Name } .TypeExplorer" , typeExplorerItem ) ;
170+ PluginBase . MainForm . RegisterShortcutItem ( ShortcutId . TypeExplorer , typeExplorerItem ) ;
163171 menu . DropDownItems . Add ( typeExplorerItem ) ;
164172 image = PluginBase . MainForm . FindImage ( "315|16|0|0" ) ;
165173 quickOutlineItem = new ToolStripMenuItem ( "Quick Outline" , image , ShowQuickOutline ) ;
166- PluginBase . MainForm . RegisterShortcutItem ( $ " { Name } .Outline" , quickOutlineItem ) ;
174+ PluginBase . MainForm . RegisterShortcutItem ( ShortcutId . QuickOutline , quickOutlineItem ) ;
167175 menu . DropDownItems . Add ( quickOutlineItem ) ;
168176 image = PluginBase . MainForm . FindImage ( "99|16|0|0" ) ;
169177 classHierarchyItem = new ToolStripMenuItem ( "Class Hierarchy" , image , ShowClassHierarchy ) ;
170178 menu . DropDownItems . Add ( classHierarchyItem ) ;
171- PluginBase . MainForm . RegisterShortcutItem ( $ " { Name } .ClassHierarchy" , classHierarchyItem ) ;
179+ PluginBase . MainForm . RegisterShortcutItem ( ShortcutId . ClassHierarchy , classHierarchyItem ) ;
172180 editorClassHierarchyItem = new ToolStripMenuItem ( "Class Hierarchy" , image , ShowClassHierarchy ) ;
173181 PluginBase . MainForm . EditorMenu . Items . Insert ( 8 , editorClassHierarchyItem ) ;
174- ToolStripMenuItem item = new ToolStripMenuItem ( "Recent Files" , null , ShowRecentFiles ) ;
175- PluginBase . MainForm . RegisterShortcutItem ( $ " { Name } .RecentFiles" , item ) ;
182+ var item = new ToolStripMenuItem ( "Recent Files" , null , ShowRecentFiles ) ;
183+ PluginBase . MainForm . RegisterShortcutItem ( ShortcutId . RecentFiles , item ) ;
176184 menu . DropDownItems . Add ( item ) ;
177185 item = new ToolStripMenuItem ( "Recent Projects" , null , ShowRecentProjets ) ;
178- PluginBase . MainForm . RegisterShortcutItem ( $ " { Name } .RecentProjects" , item ) ;
186+ PluginBase . MainForm . RegisterShortcutItem ( ShortcutId . RecentProjects , item ) ;
179187 menu . DropDownItems . Add ( item ) ;
180188 }
181189
@@ -196,23 +204,31 @@ void UpdateMenuItems()
196204 /// </summary>
197205 void SaveSettings ( ) => ObjectSerializer . Serialize ( settingFilename , Settings ) ;
198206
199- void ShowRecentFiles ( object sender , EventArgs e )
207+ void ShowRecentFiles ( object sender , EventArgs e ) => ShowRecentFiles ( ) ;
208+
209+ void ShowRecentFiles ( )
200210 {
201- var form = new OpenRecentFilesForm ( ( Settings ) Settings ) ;
211+ var form = new OpenRecentFilesForm ( ( Settings ) Settings ) ;
212+ form . KeyUp += FormOnKeyUp ;
202213 if ( form . ShowDialog ( ) != DialogResult . OK ) return ;
203- var plugin = ( ProjectManager . PluginMain ) PluginBase . MainForm . FindPlugin ( "30018864-fadd-1122-b2a5-779832cbbf23" ) ;
214+ var plugin = ( ProjectManager . PluginMain ) PluginBase . MainForm . FindPlugin ( "30018864-fadd-1122-b2a5-779832cbbf23" ) ;
204215 form . SelectedItems . ForEach ( plugin . OpenFile ) ;
205216 }
206217
207- void ShowRecentProjets ( object sender , EventArgs e )
218+ void ShowRecentProjets ( object sender , EventArgs e ) => ShowRecentProjets ( ) ;
219+
220+ void ShowRecentProjets ( )
208221 {
209222 var form = new OpenRecentProjectsForm ( ( Settings ) Settings ) ;
223+ form . KeyUp += FormOnKeyUp ;
210224 if ( form . ShowDialog ( ) != DialogResult . OK ) return ;
211225 var plugin = ( ProjectManager . PluginMain ) PluginBase . MainForm . FindPlugin ( "30018864-fadd-1122-b2a5-779832cbbf23" ) ;
212226 plugin . OpenFile ( form . SelectedItem ) ;
213227 }
214228
215- void ShowTypeExplorer ( object sender , EventArgs e )
229+ void ShowTypeExplorer ( object sender , EventArgs e ) => ShowTypeExplorer ( ) ;
230+
231+ void ShowTypeExplorer ( )
216232 {
217233 if ( PluginBase . CurrentProject == null ) return ;
218234 var form = new TypeExplorerForm ( ( Settings ) Settings ) ;
@@ -231,7 +247,6 @@ void ShowTypeExplorer(object sender, EventArgs e)
231247 disabledTip = "Show all(Alt+I or left click)" ;
232248 form . AddFilter ( PluginUI . ICON_INTERFACE , FlagType . Interface , Keys . I , enabledTip , disabledTip ) ;
233249 }
234- // Abstracts
235250 if ( features . hasTypeDefs )
236251 {
237252 enabledTip = "Show only typedefs(Alt+T or left click)" ;
@@ -244,33 +259,30 @@ void ShowTypeExplorer(object sender, EventArgs e)
244259 disabledTip = "Show all(Alt+E or left click)" ;
245260 form . AddFilter ( PluginUI . ICON_TYPE , FlagType . Enum , Keys . E , enabledTip , disabledTip ) ;
246261 }
262+ // Abstracts
247263 form . GotoPositionOrLine += OnGotoPositionOrLine ;
248264 form . ShowInQuickOutline += ShowQuickOutline ;
249265 form . ShowInClassHierarchy += ShowClassHierarchy ;
250266 form . ShowInProjectManager += ShowInProjectManager ;
251267 form . ShowInFileExplorer += ShowInFileExplorer ;
268+ form . KeyUp += FormOnKeyUp ;
252269 if ( form . ShowDialog ( ) != DialogResult . OK ) return ;
253270 var node = form . SelectedNode ;
254271 if ( node == null ) return ;
255272 FormHelper . Navigate ( node . Model . InFile . FileName , node ) ;
256273 }
257274
258- void ShowQuickOutline ( object sender , EventArgs e )
259- {
260- var context = ASContext . Context ;
261- ShowOutlineForm ( context . CurrentModel , context . CurrentClass ) ;
262- }
275+ void ShowQuickOutline ( object sender , EventArgs e ) => ShowQuickOutline ( ) ;
276+
277+ void ShowQuickOutline ( ) => ShowQuickOutline ( ASContext . Context . CurrentModel , ASContext . Context . CurrentClass ) ;
263278
264279 void ShowQuickOutline ( Form sender , ClassModel inClass )
265280 {
266281 sender . Close ( ) ;
267- ( ( Control ) PluginBase . MainForm ) . BeginInvoke ( ( MethodInvoker ) delegate
268- {
269- ShowOutlineForm ( inClass . InFile , inClass ) ;
270- } ) ;
282+ ( ( Control ) PluginBase . MainForm ) . BeginInvoke ( ( MethodInvoker ) ( ( ) => ShowQuickOutline ( inClass . InFile , inClass ) ) ) ;
271283 }
272284
273- void ShowOutlineForm ( FileModel inFile , ClassModel inClass )
285+ void ShowQuickOutline ( FileModel inFile , ClassModel inClass )
274286 {
275287 var form = new QuickOutlineForm ( inFile , inClass , ( Settings ) Settings ) ;
276288 form . ShowInClassHierarchy += ShowClassHierarchy ;
@@ -286,11 +298,14 @@ void ShowOutlineForm(FileModel inFile, ClassModel inClass)
286298 enabledTip = "Show only methods(Alt+M or left click)" ;
287299 disabledTip = "Show all(Alt+M or left click)" ;
288300 form . AddFilter ( PluginUI . ICON_FUNCTION , FlagType . Function , Keys . M , enabledTip , disabledTip ) ;
301+ form . KeyUp += FormOnKeyUp ;
289302 if ( form . ShowDialog ( ) != DialogResult . OK ) return ;
290303 FormHelper . Navigate ( inFile . FileName , form . SelectedNode ) ;
291304 }
292305
293- void ShowClassHierarchy ( object sender , EventArgs e )
306+ void ShowClassHierarchy ( object sender , EventArgs e ) => ShowClassHierarchy ( ) ;
307+
308+ void ShowClassHierarchy ( )
294309 {
295310 if ( ! GetCanShowClassHierarchy ( ) ) return ;
296311 var context = ASContext . Context ;
@@ -301,10 +316,7 @@ void ShowClassHierarchy(object sender, EventArgs e)
301316 void ShowClassHierarchy ( Form sender , ClassModel model )
302317 {
303318 sender . Close ( ) ;
304- ( ( Control ) PluginBase . MainForm ) . BeginInvoke ( ( MethodInvoker ) delegate
305- {
306- ShowClassHierarchy ( model ) ;
307- } ) ;
319+ ( ( Control ) PluginBase . MainForm ) . BeginInvoke ( ( MethodInvoker ) ( ( ) => ShowClassHierarchy ( model ) ) ) ;
308320 }
309321
310322 void ShowClassHierarchy ( ClassModel model )
@@ -315,6 +327,7 @@ void ShowClassHierarchy(ClassModel model)
315327 form . ShowInClassHierarchy += ShowClassHierarchy ;
316328 form . ShowInProjectManager += ShowInProjectManager ;
317329 form . ShowInFileExplorer += ShowInFileExplorer ;
330+ form . KeyUp += FormOnKeyUp ;
318331 if ( form . ShowDialog ( ) != DialogResult . OK ) return ;
319332 var node = form . SelectedNode ;
320333 if ( node == null ) return ;
@@ -394,6 +407,35 @@ static void ShowInFileExplorer(Form sender, ClassModel model)
394407 /// </summary>
395408 void OnResolvedContextChanged ( ResolvedContext resolved ) => UpdateMenuItems ( ) ;
396409
410+ void FormOnKeyUp ( object sender , KeyEventArgs e )
411+ {
412+ var shortcutId = PluginBase . MainForm . GetShortcutItemId ( e . KeyData ) ;
413+ if ( string . IsNullOrEmpty ( shortcutId ) ) return ;
414+ MethodInvoker invoker = null ;
415+ switch ( shortcutId )
416+ {
417+ case ShortcutId . ClassHierarchy :
418+ if ( ! ( sender is ClassHierarchyForm ) ) invoker = ShowClassHierarchy ;
419+ break ;
420+ case ShortcutId . QuickOutline :
421+ if ( ! ( sender is QuickOutlineForm ) ) invoker = ShowQuickOutline ;
422+ break ;
423+ case ShortcutId . RecentProjects :
424+ if ( ! ( sender is OpenRecentProjectsForm ) ) invoker = ShowRecentProjets ;
425+ break ;
426+ case ShortcutId . RecentFiles :
427+ if ( ! ( sender is OpenRecentFilesForm ) ) invoker = ShowRecentFiles ;
428+ break ;
429+ case ShortcutId . TypeExplorer :
430+ if ( ! ( sender is TypeExplorerForm ) ) invoker = ShowTypeExplorer ;
431+ break ;
432+ default : return ;
433+ }
434+ if ( invoker == null ) return ;
435+ ( ( Form ) sender ) . Close ( ) ;
436+ ( ( Control ) PluginBase . MainForm ) . BeginInvoke ( invoker ) ;
437+ }
438+
397439 #endregion
398- }
440+ }
399441}
0 commit comments