@@ -137,19 +137,13 @@ export class MenuWindow extends BrowserWindow {
137137 * @param systemIconsChanged True if the system icon theme has changed since the last
138138 * time the menu was shown.
139139 */
140- public showMenu (
141- request : Partial < ShowMenuRequest > ,
142- info : WMInfo ,
143- systemIconsChanged : boolean
144- ) {
140+ public showMenu ( request : ShowMenuRequest , info : WMInfo , systemIconsChanged : boolean ) {
145141 const sameShortcutBehavior = this . kando
146142 . getGeneralSettings ( )
147143 . get ( 'sameShortcutBehavior' ) ;
148144
149145 // If a menu is currently shown and the user presses the same shortcut again we will
150- // either close the menu or show the next one with the same shortcut. There is also
151- // the option to do nothing in this case, but in this case the menu's shortcut will be
152- // inhibited and thus this method will not be called in the first place.
146+ // either close the menu or show the next one with the same shortcut.
153147 if ( this . isVisible ( ) ) {
154148 let isSameMenu = false ;
155149 if ( request . name != null ) {
@@ -206,7 +200,9 @@ export class MenuWindow extends BrowserWindow {
206200 if ( ! this . kando . allShortcutsInhibited ( ) && sameShortcutBehavior === 'nothing' ) {
207201 const useID = ! this . kando . getBackend ( ) . getBackendInfo ( ) . supportsShortcuts ;
208202 const shortcut = useID ? menu . shortcutID : menu . shortcut ;
209- this . kando . getBackend ( ) . inhibitShortcuts ( [ shortcut ] ) ;
203+ if ( shortcut && shortcut . length > 0 ) {
204+ this . kando . getBackend ( ) . inhibitShortcuts ( [ shortcut ] ) ;
205+ }
210206 }
211207
212208 // Store the last menu to be able to execute the selected action later. The WMInfo
@@ -404,21 +400,27 @@ export class MenuWindow extends BrowserWindow {
404400 /**
405401 * This chooses the correct menu depending on the environment.
406402 *
407- * If the request contains a menu name, this menu is chosen. If no menu with the given
408- * name is found, an exception is thrown. If there are multiple menus with the same
409- * name, the first one is chosen. No other conditions are checked in this case.
403+ * If the request contains a custom menu, this menu is returned. No other conditions are
404+ * checked in this case.
410405 *
411- * If the request contains a trigger (shortcut or shortcutID), a list of menus bound to
412- * this trigger is assembled and the menu with the best matching conditions is chosen.
413- * If no menu with the given trigger is found, null is returned .
406+ * If the request contains a trigger (shortcut or shortcutID) or menu name, we first
407+ * check whether there are any menus with the given trigger or name. If none are found,
408+ * an exception is thrown .
414409 *
415- * If neither a menu name nor a trigger is given, null is returned.
410+ * Then, a list of menu candidates is assembled and the menu with the best matching
411+ * conditions is chosen. If no menu with the given trigger or name is found, null is
412+ * returned.
416413 *
417414 * @param request Required information to select correct menu.
418415 * @param info Information about current desktop environment.
419416 * @returns The selected menu or null if no menu was found.
420417 */
421- public chooseMenu ( request : Partial < ShowMenuRequest > , info : WMInfo ) {
418+ public chooseMenu ( request : ShowMenuRequest , info : WMInfo ) {
419+ // If a custom menu is given in the request, we return this menu directly.
420+ if ( request . menu ) {
421+ return request . menu ;
422+ }
423+
422424 // Get list of current menus.
423425 const menus = this . kando . getMenuSettings ( ) . get ( 'menus' ) ;
424426
@@ -427,7 +429,19 @@ export class MenuWindow extends BrowserWindow {
427429 if ( request . name != null ) {
428430 const menu = menus . find ( ( m ) => m . root . name === request . name ) ;
429431 if ( ! menu ) {
430- throw new Error ( `Menu with name "${ request . name } " not found.` ) ;
432+ throw new Error ( `No menu with name "${ request . name } " found.` ) ;
433+ }
434+ }
435+
436+ // We check if the request has a trigger. If no menu with this trigger is found, we
437+ // throw an error.
438+ if ( request . trigger != null ) {
439+ const useID = ! this . kando . getBackend ( ) . getBackendInfo ( ) . supportsShortcuts ;
440+ const menu = menus . find (
441+ ( m ) => ( useID ? m . shortcutID : m . shortcut ) === request . trigger
442+ ) ;
443+ if ( ! menu ) {
444+ throw new Error ( `No menu with trigger "${ request . trigger } " found.` ) ;
431445 }
432446 }
433447
0 commit comments