Skip to content

Commit

Permalink
Add 1...9 key shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Oct 24, 2021
1 parent 05bad74 commit cf8acbb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ cd Junction
./re.sonny.Junction https://www.gnome.org/
```

Make changes and press `Ctrl+Shift+Q` on the Junction window to restart it.
Make changes and press `<Primary><Shift>Q` on the Junction window to restart it.

Use `Ctrl+Shift+I` to open the inspector.
Use `<Primary><Shift>I` to open the inspector.

To setup development version as default application first install the desktop file with

Expand Down
36 changes: 36 additions & 0 deletions src/ShortcutsWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,42 @@
>Copy to Clipboard</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="accelerator">Right</property>
<property
name="title"
translatable="yes"
>Select next application</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="accelerator">Left</property>
<property
name="title"
translatable="yes"
>Select previous application</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="accelerator">Return space</property>
<property
name="title"
translatable="yes"
>Open with selected application</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="accelerator">1...9</property>
<property
name="title"
translatable="yes"
>Open with application at position</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ GLib.set_application_name("Junction");
Gtk.init();

export default function main(argv, { version, datadir }) {
log(`datadir: ${datadir}`);
bindtextdomain(
"re.sonny.Junction",
GLib.build_filenamev([datadir, "locale"]),
Expand All @@ -20,6 +19,7 @@ export default function main(argv, { version, datadir }) {

const application = Application({ version });

log(`datadir: ${datadir}`);
log("argv " + argv.join(" "));
log(`programInvocationName: ${programInvocationName}`);
log(`_: ${GLib.getenv("_")}`);
Expand Down
24 changes: 24 additions & 0 deletions src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,33 @@ export default function Window({ application, file }) {
entry,
window,
});
appInfo.button = button;
list.append(button);
});

function getAppForKeyval(keyval) {
const keyname = Gdk.keyval_name(keyval);
// Is not 0...9
if (!/^\d$/.test(keyname)) return null;
const appInfo = applications[+keyname - 1];
return appInfo;
}

const eventController = new Gtk.EventControllerKey();
eventController.connect("key-pressed", (self, keyval) => {
const appInfo = getAppForKeyval(keyval);
if (!appInfo) return false;
appInfo.button.grab_focus();
return true;
});
eventController.connect("key-released", (self, keyval) => {
const appInfo = getAppForKeyval(keyval);
if (!appInfo) return false;
appInfo.button.activate();
return true;
});
window.add_controller(eventController);

const copy = new Gio.SimpleAction({
name: "copy",
parameter_type: null,
Expand Down

0 comments on commit cf8acbb

Please sign in to comment.