From 58cc45ec7d68c34ca96d07fc61b6c6522c60fb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 24 Mar 2021 14:07:20 +0100 Subject: [PATCH] Support accels for menu items Add support for keyboard shortcuts for menu items. Additionally enable a common Ctrl+O for opening new file(s) and Ctrl+U for opening an URI. Closes #45 --- src/appBase.js | 5 ++++- src/menu.js | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/appBase.js b/src/appBase.js index ce0541fc..3faeffce 100644 --- a/src/appBase.js +++ b/src/appBase.js @@ -44,9 +44,12 @@ class ClapperAppBase extends Gtk.Application name: action }); simpleAction.connect( - 'activate', () => Menu.actions[action](this.active_window) + 'activate', () => Menu.actions[action].run(this.active_window) ); this.add_action(simpleAction); + + if(Menu.actions[action].accels) + this.set_accels_for_action(`app.${action}`, Menu.actions[action].accels); } } diff --git a/src/menu.js b/src/menu.js index 38b00323..00609068 100644 --- a/src/menu.js +++ b/src/menu.js @@ -2,12 +2,18 @@ const { GObject, Gtk } = imports.gi; const Dialogs = imports.src.dialogs; var actions = { - openLocal: (window) => new Dialogs.FileChooser(window), - openUri: (window) => new Dialogs.UriDialog(window), - prefs: (window) => new Dialogs.PrefsDialog(window), - about: (window) => new Dialogs.AboutDialog(window), + openLocal: { + run: (window) => new Dialogs.FileChooser(window), + accels: ['O'], + }, + openUri: { + run: (window) => new Dialogs.UriDialog(window), + accels: ['U'], + }, + prefs: { + run: (window) => new Dialogs.PrefsDialog(window), + }, + about: { + run: (window) => new Dialogs.AboutDialog(window), + }, }; - -var accels = [ - ['app.quit', ['q']], -];