[gnome-characters/bilelmoussaoui/shortcuts: 3/3] add a shortcuts dialog




commit e65a59895faad58405a6119c10142086e98eaea9
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Fri Feb 19 09:42:46 2021 +0100

    add a shortcuts dialog
    
    was missing from the sidebar split

 data/mainwindow.ui                           |  1 +
 data/org.gnome.Characters.data.gresource.xml |  1 +
 data/shortcuts.ui                            | 47 ++++++++++++++++++++++++++++
 po/POTFILES.in                               |  1 +
 src/main.js                                  |  3 ++
 src/window.js                                | 18 +++++++++--
 6 files changed, 68 insertions(+), 3 deletions(-)
---
diff --git a/data/mainwindow.ui b/data/mainwindow.ui
index 8fac8b1..cc3053e 100644
--- a/data/mainwindow.ui
+++ b/data/mainwindow.ui
@@ -46,6 +46,7 @@
                   <object class="GtkMenuButton">
                     <property name="visible">True</property>
                     <property name="menu-model">primary_menu</property>
+                    <property name="action_name">win.show-primary-menu</property>
                     <child>
                       <object class="GtkImage">
                         <property name="visible">True</property>
diff --git a/data/org.gnome.Characters.data.gresource.xml b/data/org.gnome.Characters.data.gresource.xml
index 6208af3..2298437 100644
--- a/data/org.gnome.Characters.data.gresource.xml
+++ b/data/org.gnome.Characters.data.gresource.xml
@@ -5,6 +5,7 @@
     <file preprocess="xml-stripblanks">mainwindow.ui</file>
     <file preprocess="xml-stripblanks">character.ui</file>
     <file preprocess="xml-stripblanks">characterlist.ui</file>
+    <file preprocess="xml-stripblanks">shortcuts.ui</file>
     <file preprocess="xml-stripblanks">menu.ui</file>
     <file>application.css</file>
   </gresource>
diff --git a/data/shortcuts.ui b/data/shortcuts.ui
new file mode 100644
index 0000000..3ca64c7
--- /dev/null
+++ b/data/shortcuts.ui
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkShortcutsWindow" id="shortcuts">
+    <property name="modal">True</property>
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="visible">1</property>
+        <property name="section-name">shortcuts</property>
+        <property name="max-height">10</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes" context="shortcut window">General</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">F10</property>
+                <property name="title" translatable="yes" context="shortcut window">Open menu</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;F</property>
+                <property name="title" translatable="yes" context="shortcut window">Search</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;question</property>
+                <property name="title" translatable="yes" context="shortcut window">Keyboard 
shortcuts</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;Q</property>
+                <property name="title" translatable="yes" context="shortcut window">Quit</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1690b8e..88385e7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ data/character.ui
 data/mainview.ui
 data/mainwindow.ui
 data/menu.ui
+data/shortcuts.ui
 data/org.gnome.Characters.appdata.xml.in
 data/org.gnome.Characters.desktop.in
 data/org.gnome.Characters.gschema.xml
diff --git a/src/main.js b/src/main.js
index b18b325..66a0d96 100644
--- a/src/main.js
+++ b/src/main.js
@@ -83,6 +83,9 @@ var MyApplication = GObject.registerClass({
                             activate: this._onSearch,
                             parameter_type: new GLib.VariantType('as') }]);
         this.set_accels_for_action('app.quit', ['<Primary>q']);
+        this.set_accels_for_action('win.find', ['<Primary>f']);
+        this.set_accels_for_action('win.show-primary-menu', ['F10']);
+        this.set_accels_for_action('win.show-help-overlay', ['<Primary>question']);
 
         settings = Util.getSettings('org.gnome.Characters',
                                     '/org/gnome/Characters/');
diff --git a/src/window.js b/src/window.js
index bcee339..e23ae8e 100644
--- a/src/window.js
+++ b/src/window.js
@@ -75,9 +75,12 @@ var MainWindow = GObject.registerClass({
                             parameter_type: new GLib.VariantType('s') },
                           { name: 'filter-font',
                             activate: this._filterFont,
-                            parameter_type: new GLib.VariantType('s') }]);
-
-        this.application.set_accels_for_action('win.find', ['<Primary>F']);
+                            parameter_type: new GLib.VariantType('s') },
+                            { 
+                                name: 'show-primary-menu',
+                                activate: this._togglePrimaryMenu,
+                                state: new GLib.Variant('b', false),
+                            }]);
 
         this.bind_property('search-active', this._search_active_button, 'active',
                            GObject.BindingFlags.SYNC_CREATE |
@@ -113,6 +116,10 @@ var MainWindow = GObject.registerClass({
         });
 
         this._container.pack_start(this._mainView, true, true, 0);
+        
+        let builder = Gtk.Builder.new_from_resource('/org/gnome/Characters/shortcuts.ui');
+        let helpOverlay = builder.get_object("shortcuts");
+        this.set_help_overlay(helpOverlay);
 
         // Due to limitations of gobject-introspection wrt GdkEvent
         // and GdkEventKey, this needs to be a signal handler
@@ -124,6 +131,11 @@ var MainWindow = GObject.registerClass({
         this._selectFirstSubcategory();
     }
 
+    _togglePrimaryMenu(action) {
+        let state = action.get_state().get_boolean();
+        action.set_state(GLib.Variant.new_boolean(!state));
+    }
+
     // Select the first subcategory which contains at least one character.
     _selectFirstSubcategory() {
         let categoryList;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]