11using System ;
2+ using System . Collections . Concurrent ;
23using System . Collections . Generic ;
34using System . Collections . Specialized ;
45using System . ComponentModel ;
@@ -41,6 +42,7 @@ internal static void Initialize()
4142 _settings . PropertyChanged += Settings_PropertyChanged ;
4243 _settings . CustomPluginHotkeys . CollectionChanged += CustomPluginHotkeys_CollectionChanged ;
4344 PluginManager . PluginHotkeyChanged += PluginManager_PluginHotkeyChanged ;
45+ PluginManager . PluginHotkeyInitialized += PluginManager_PluginHotkeyInitialized ;
4446 }
4547
4648 private static void InitializeRegisteredHotkeys ( )
@@ -109,9 +111,27 @@ private static void InitializeRegisteredHotkeys()
109111 list . Add ( GetRegisteredHotkeyData ( customPluginHotkey ) ) ;
110112 }
111113
112- // Plugin hotkeys
114+ // Add registered hotkeys & Set them
115+ foreach ( var hotkey in list )
116+ {
117+ _settings . RegisteredHotkeys . Add ( hotkey ) ;
118+ if ( hotkey . RegisteredType == RegisteredHotkeyType . DialogJump && ! _settings . EnableDialogJump )
119+ {
120+ // If dialog jump is disabled, do not register the hotkey
121+ continue ;
122+ }
123+ SetHotkey ( hotkey ) ;
124+ }
125+
126+ App . API . LogDebug ( ClassName , $ "Initialize { _settings . RegisteredHotkeys . Count } hotkeys:\n [\n \t { string . Join ( ",\n \t " , _settings . RegisteredHotkeys ) } \n ]") ;
127+ }
128+
129+ private static void PluginManager_PluginHotkeyInitialized ( PluginPair pair )
130+ {
131+ var list = new List < RegisteredHotkeyData > ( ) ;
132+
113133 // Global plugin hotkeys
114- var pluginHotkeyInfos = PluginManager . GetPluginHotkeyInfo ( ) ;
134+ var pluginHotkeyInfos = PluginManager . GetPluginHotkeyInfo ( pair . Metadata . ID ) ;
115135 foreach ( var info in pluginHotkeyInfos )
116136 {
117137 var pluginPair = info . Key ;
@@ -128,7 +148,7 @@ private static void InitializeRegisteredHotkeys()
128148 }
129149
130150 // Window plugin hotkeys
131- var windowPluginHotkeys = PluginManager . GetWindowPluginHotkeys ( ) ;
151+ var windowPluginHotkeys = PluginManager . GetWindowPluginHotkeys ( pair . Metadata . ID ) ;
132152 foreach ( var hotkey in windowPluginHotkeys )
133153 {
134154 var hotkeyModel = hotkey . Key ;
@@ -140,15 +160,10 @@ private static void InitializeRegisteredHotkeys()
140160 foreach ( var hotkey in list )
141161 {
142162 _settings . RegisteredHotkeys . Add ( hotkey ) ;
143- if ( hotkey . RegisteredType == RegisteredHotkeyType . DialogJump && ! _settings . EnableDialogJump )
144- {
145- // If dialog jump is disabled, do not register the hotkey
146- continue ;
147- }
148163 SetHotkey ( hotkey ) ;
149164 }
150165
151- App . API . LogDebug ( ClassName , $ "Initialize { _settings . RegisteredHotkeys . Count } hotkeys:\n [\n \t { string . Join ( ",\n \t " , _settings . RegisteredHotkeys ) } \n ]") ;
166+ App . API . LogDebug ( ClassName , $ "Initialize { list . Count } hotkeys for { pair . Metadata . Name } :\n [\n \t { string . Join ( ",\n \t " , list ) } \n ]") ;
152167 }
153168
154169 #endregion
@@ -359,7 +374,7 @@ private static RegisteredHotkeyData GetRegisteredHotkeyData(HotkeyModel hotkey,
359374 return new ( RegisteredHotkeyType . PluginGlobalHotkey , HotkeyType . Global , hotkey , "pluginHotkey" , GlobalPluginHotkeyCommand , new GlobalPluginHotkeyPair ( metadata , pluginHotkey ) , removeHotkeyAction ) ;
360375 }
361376
362- private static RegisteredHotkeyData GetRegisteredHotkeyData ( HotkeyModel hotkey , List < ( PluginMetadata Metadata , SearchWindowPluginHotkey PluginHotkey ) > windowHotkeys )
377+ private static RegisteredHotkeyData GetRegisteredHotkeyData ( HotkeyModel hotkey , ConcurrentBag < ( PluginMetadata Metadata , SearchWindowPluginHotkey PluginHotkey ) > windowHotkeys )
363378 {
364379 Action removeHotkeysAction = windowHotkeys . All ( h => h . PluginHotkey . Editable ) ?
365380 ( ) =>
@@ -747,12 +762,12 @@ internal static bool CheckAvailability(HotkeyModel currentHotkey)
747762 private static void InitializeActionContextHotkeys ( )
748763 {
749764 // Fixed hotkeys for ActionContext
750- _actionContextRegisteredHotkeys = new List < RegisteredHotkeyData >
751- {
765+ _actionContextRegisteredHotkeys =
766+ [
752767 new ( RegisteredHotkeyType . CtrlShiftEnter , HotkeyType . SearchWindow , "Ctrl+Shift+Enter" , nameof ( Localize . HotkeyCtrlShiftEnterDesc ) , _mainViewModel . OpenResultCommand ) ,
753768 new ( RegisteredHotkeyType . CtrlEnter , HotkeyType . SearchWindow , "Ctrl+Enter" , nameof ( Localize . OpenContainFolderHotkey ) , _mainViewModel . OpenResultCommand ) ,
754769 new ( RegisteredHotkeyType . AltEnter , HotkeyType . SearchWindow , "Alt+Enter" , nameof ( Localize . HotkeyOpenResult ) , _mainViewModel . OpenResultCommand ) ,
755- } ;
770+ ] ;
756771
757772 // Register ActionContext hotkeys and they will be cached and restored in _actionContextHotkeyEvents
758773 foreach ( var hotkey in _actionContextRegisteredHotkeys )
@@ -822,18 +837,12 @@ public GlobalPluginHotkeyPair(PluginMetadata metadata, GlobalPluginHotkey global
822837 }
823838 }
824839
825- private class WindowPluginHotkeyPair
840+ private class WindowPluginHotkeyPair ( HotkeyModel hotkey , ConcurrentBag < ( PluginMetadata Metadata , SearchWindowPluginHotkey PluginHotkey ) > hotkeys )
826841 {
827842 [ Obsolete ( "ActionContext support is deprecated and will be removed in a future release. Please use IPluginHotkey instead." ) ]
828- public HotkeyModel Hotkey { get ; }
843+ public HotkeyModel Hotkey { get ; } = hotkey ;
829844
830- public List < ( PluginMetadata Metadata , SearchWindowPluginHotkey PluginHotkey ) > HotkeyModels { get ; }
831-
832- public WindowPluginHotkeyPair ( HotkeyModel hotkey , List < ( PluginMetadata Metadata , SearchWindowPluginHotkey PluginHotkey ) > hotkeys )
833- {
834- Hotkey = hotkey ;
835- HotkeyModels = hotkeys ;
836- }
845+ public ConcurrentBag < ( PluginMetadata Metadata , SearchWindowPluginHotkey PluginHotkey ) > HotkeyModels { get ; } = hotkeys ;
837846 }
838847
839848 #endregion
0 commit comments