[gnome-calculator] Added keyboard shortcuts window (bgo#772735)



commit 743e265dd37e2289b0792f4a5ec25e536803b87e
Author: Robert Roth <robert roth off gmail com>
Date:   Wed Oct 19 18:44:15 2016 +0300

    Added keyboard shortcuts window (bgo#772735)

 configure.ac                        |    2 +-
 data/Makefile.am                    |    1 +
 data/gnome-calculator.gresource.xml |    1 +
 data/math-shortcuts.ui              |  166 +++++++++++++++++++++++++++++++++++
 data/menu.ui                        |    6 ++
 po/POTFILES.in                      |    1 +
 src/gnome-calculator.vala           |   26 ++++++
 7 files changed, 202 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ac8f412..26f2c09 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ dnl Dependencies
 dnl ###########################################################################
 
 GLIB_REQUIRED=2.40.0
-GTK_REQUIRED=3.11.6
+GTK_REQUIRED=3.19.3
 GTKSOURCEVIEW_REQUIRED=3.15.1
 LIBSOUP_REQUIRED=2.42
 
diff --git a/data/Makefile.am b/data/Makefile.am
index 3ac368e..a8ba11d 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -22,6 +22,7 @@ EXTRA_DIST = \
        history-view.ui \
        math-converter.ui \
        math-window.ui \
+       math-shortcuts.ui \
        menu.ui \
        calculator.css \
        gnome-calculator.gresource.xml \
diff --git a/data/gnome-calculator.gresource.xml b/data/gnome-calculator.gresource.xml
index 15b681c..bec25ea 100644
--- a/data/gnome-calculator.gresource.xml
+++ b/data/gnome-calculator.gresource.xml
@@ -9,6 +9,7 @@
     <file preprocess="xml-stripblanks">history-entry.ui</file>
     <file preprocess="xml-stripblanks">math-converter.ui</file>
     <file preprocess="xml-stripblanks">math-window.ui</file>
+    <file preprocess="xml-stripblanks">math-shortcuts.ui</file>
     <file preprocess="xml-stripblanks">menu.ui</file>
     <file>calculator.css</file>
   </gresource>
diff --git a/data/math-shortcuts.ui b/data/math-shortcuts.ui
new file mode 100644
index 0000000..01c4e4c
--- /dev/null
+++ b/data/math-shortcuts.ui
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.17 -->
+
+  <object class="GtkShortcutsWindow" id="shortcuts-calculator">
+    <property name="modal">1</property>
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="visible">1</property>
+        <property name="section-name">shortcuts</property>
+        <property name="max-height">12</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes">General</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;n</property>
+                <property name="title" translatable="yes">Open a new window</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">F1</property>
+                <property name="title" translatable="yes">Open help</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">Quit the application</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes">Switching modes</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;b</property>
+                <property name="title" translatable="yes">Switch to Basic mode</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;a</property>
+                <property name="title" translatable="yes">Switch to Advanced mode</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;f</property>
+                <property name="title" translatable="yes">Switch to Financial mode</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;p</property>
+                <property name="title" translatable="yes">Switch to Programming mode</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;k</property>
+                <property name="title" translatable="yes">Switch to Keyboard mode</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes">Keyboard entry</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">asterisk</property>
+                <property name="title" translatable="yes">Multiply (×)</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">slash</property>
+                <property name="title" translatable="yes">Divide (÷)</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;R</property>
+                <property name="title" translatable="yes">Square root (√)</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;I</property>
+                <property name="title" translatable="yes">Inverse</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;P</property>
+                <property name="title" translatable="yes">Pi (π)</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;E</property>
+                <property name="title" translatable="yes">Enter numbers in scientific format</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes">Programming mode</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;B</property>
+                <property name="title" translatable="yes">Switch to binary</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;O</property>
+                <property name="title" translatable="yes">Switch to octal</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;D</property>
+                <property name="title" translatable="yes">Switch to decimal</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;H</property>
+                <property name="title" translatable="yes">Switch to hexadecimal</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+
+</interface>
diff --git a/data/menu.ui b/data/menu.ui
index 25f0bf5..954b9b6 100644
--- a/data/menu.ui
+++ b/data/menu.ui
@@ -16,6 +16,12 @@
       </item>
     </section>
     <section>
+      <attribute name="id">help-section</attribute>
+      <item>
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">app.shortcuts</attribute>
+        <attribute name="accel">&lt;Primary&gt;question</attribute>
+      </item>
       <item>
         <attribute name="label" translatable="yes">Help</attribute>
         <attribute name="action">app.help</attribute>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5134961..c393e8a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,6 +9,7 @@ data/gnome-calculator.appdata.xml.in
 data/gnome-calculator.desktop.in
 [type: gettext/glade]data/math-converter.ui
 [type: gettext/glade]data/math-window.ui
+[type: gettext/glade]data/math-shortcuts.ui
 [type: gettext/glade]data/menu.ui
 data/org.gnome.calculator.gschema.xml
 lib/currency.vala
diff --git a/src/gnome-calculator.vala b/src/gnome-calculator.vala
index 112c436..231eec2 100644
--- a/src/gnome-calculator.vala
+++ b/src/gnome-calculator.vala
@@ -14,6 +14,7 @@ public class Calculator : Gtk.Application
     private Settings settings;
     private MathWindow last_opened_window;
     private MathPreferencesDialog preferences_dialog;
+    private Gtk.ShortcutsWindow shortcuts_window;
     private static string program_name = null;
     private static string equation_string = null;
     private static string mode_string = null;
@@ -30,6 +31,7 @@ public class Calculator : Gtk.Application
     {
         { "newwindow", new_window_cb, null, null, null },
         { "preferences", show_preferences_cb, null, null, null },
+        { "shortcuts", keyboard_shortcuts_cb, null, null, null },
         { "help", help_cb, null, null, null },
         { "about", about_cb, null, null, null },
         { "quit", quit_cb, null, null, null },
@@ -241,6 +243,30 @@ public class Calculator : Gtk.Application
         preferences_dialog.present ();
     }
 
+    private void keyboard_shortcuts_cb ()
+    {
+        if (shortcuts_window == null)
+        {
+            var builder = new Gtk.Builder ();
+            try
+            {
+                builder.add_from_resource ("/org/gnome/calculator/math-shortcuts.ui");
+            }
+            catch (Error e)
+            {
+                error ("Error loading shortcuts window UI: %s", e.message);
+            }
+
+            shortcuts_window = builder.get_object ("shortcuts-calculator") as Gtk.ShortcutsWindow;
+            shortcuts_window.destroy.connect ( (event) => { shortcuts_window = null; });
+        }
+
+        if (get_active_window () != shortcuts_window.get_transient_for ())
+            shortcuts_window.set_transient_for (get_active_window ());
+        shortcuts_window.show_all ();
+        shortcuts_window.present ();
+    }
+
     private void help_cb ()
     {
         try


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