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
This commit is contained in:
Rafał Dzięgiel
2021-03-24 14:07:20 +01:00
parent 7a75c6d4ff
commit 58cc45ec7d
2 changed files with 18 additions and 9 deletions

View File

@@ -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);
}
}

View File

@@ -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: ['<Ctrl>O'],
},
openUri: {
run: (window) => new Dialogs.UriDialog(window),
accels: ['<Ctrl>U'],
},
prefs: {
run: (window) => new Dialogs.PrefsDialog(window),
},
about: {
run: (window) => new Dialogs.AboutDialog(window),
},
};
var accels = [
['app.quit', ['q']],
];