[seahorse/wip/nielsdg/keyboard-nav: 1/2] Add better keyboard navigation with <Alt> modifier
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/wip/nielsdg/keyboard-nav: 1/2] Add better keyboard navigation with <Alt> modifier
- Date: Fri, 19 Jun 2020 09:39:05 +0000 (UTC)
commit 2e13bead8d59d39abeac5dfeed7bec139a57108f
Author: Niels De Graef <nielsdegraef gmail com>
Date: Fri Jun 19 11:08:11 2020 +0200
Add better keyboard navigation with <Alt> modifier
data/gtk/help-overlay.ui | 34 +++++++++++++++++++++++++++++++++
src/key-manager.vala | 49 ++++++++++++++++++++++++++++++++++++++++++------
src/sidebar.vala | 23 +++++++++++++++++++++++
3 files changed, 100 insertions(+), 6 deletions(-)
---
diff --git a/data/gtk/help-overlay.ui b/data/gtk/help-overlay.ui
index a0627301..d0c542f9 100644
--- a/data/gtk/help-overlay.ui
+++ b/data/gtk/help-overlay.ui
@@ -58,6 +58,40 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsGroup">
+ <property name="visible">1</property>
+ <property name="title" translatable="yes" context="shortcut window">Navigation</property>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Alt>Up</property>
+ <property name="title" translatable="yes" context="shortcut window">Select previous
keyring</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Alt>Down</property>
+ <property name="title" translatable="yes" context="shortcut window">Select next
keyring</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Alt>Left</property>
+ <property name="title" translatable="yes" context="shortcut window">Show sidebar (on small
screens)</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Alt>Right</property>
+ <property name="title" translatable="yes" context="shortcut window">Show keyring contents
(on small screens)</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/key-manager.vala b/src/key-manager.vala
index caac9fce..497bce7a 100644
--- a/src/key-manager.vala
+++ b/src/key-manager.vala
@@ -63,12 +63,12 @@ public class Seahorse.KeyManager : Catalog {
}
private const GLib.ActionEntry[] action_entries = {
- { "new-item", on_new_item },
- { "show-search", on_show_search, },
- { "filter-items", on_filter_items, "s", "'any'" },
- { "focus-place", on_focus_place, "s", "'secret-service'" },
- { "import-file", on_import_file },
- { "paste", on_paste, },
+ { "new-item", on_new_item },
+ { "show-search", on_show_search, },
+ { "filter-items", on_filter_items, "s", "'any'" },
+ { "focus-place", on_focus_place, "s", "'secret-service'" },
+ { "import-file", on_import_file },
+ { "paste", on_paste, },
};
public KeyManager(Application app) {
@@ -495,6 +495,43 @@ public class Seahorse.KeyManager : Catalog {
[GtkCallback]
private bool on_key_pressed(Gtk.Widget widget, Gdk.EventKey event) {
+ bool folded = this.content_box.fold == Hdy.Fold.FOLDED;
+
+ switch (event.keyval) {
+ // <Alt>Down and <Alt>Up for easy sidebar navigation
+ case Gdk.Key.Down:
+ if (Gdk.ModifierType.MOD1_MASK in event.state && !folded) {
+ this.sidebar.select_next_place();
+ return true;
+ }
+ break;
+ case Gdk.Key.Up:
+ if (Gdk.ModifierType.MOD1_MASK in event.state && !folded) {
+ this.sidebar.select_previous_place();
+ return true;
+ }
+ break;
+
+ // <Alt>Left to go back to sidebar in folded mode
+ case Gdk.Key.Left:
+ if (Gdk.ModifierType.MOD1_MASK in event.state && folded) {
+ show_sidebar_pane();
+ return true;
+ }
+ break;
+
+ // <Alt>Right to open currently selected element in folded mode
+ case Gdk.Key.Right:
+ if (Gdk.ModifierType.MOD1_MASK in event.state && folded) {
+ show_item_list_pane();
+ return true;
+ }
+ break;
+ default:
+ break;
+ }
+
+ // By default: propagate to the search bar, for search-as-you-type
return this.search_bar.handle_event(event);
}
}
diff --git a/src/sidebar.vala b/src/sidebar.vala
index e712a0a9..098cf876 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -275,6 +275,29 @@ public class Seahorse.Sidebar : Gtk.ListBox {
return false;
}
+ public void select_next_place() {
+ select_relative(1);
+ }
+
+ public void select_previous_place() {
+ select_relative(-1);
+ }
+
+ // Selects the item that is n positions lower/above the current selection
+ private void select_relative(int positions) {
+ var selected = get_selected_row();
+ if (selected == null) {
+ // Select the first row
+ select_row(get_row_at_index(0));
+ return;
+ }
+
+ var next = get_row_at_index(selected.get_index() + positions);
+ // If we're at the top/bottom of the list, don't do anything
+ if (next != null)
+ select_row(next);
+ }
+
public List<weak Backend>? get_backends() {
return this.backends.copy();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]