[Xfce4-commits] <postler:master> Implement Shortcuts window listing available actions

Christian Dywan noreply at xfce.org
Mon Feb 28 18:44:03 CET 2011


Updating branch refs/heads/master
         to 8bd267e471124dfb4dd5a523e8544e97b60f8950 (commit)
       from 031f9cc25f3fb371dd6bc42f6ba51355eedbc022 (commit)

commit 8bd267e471124dfb4dd5a523e8544e97b60f8950
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Feb 28 18:39:03 2011 +0100

    Implement Shortcuts window listing available actions

 postler/postler-bureau.vala    |   17 ++++++++++
 postler/postler-shortcuts.vala |   68 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 9b5b1ac..775146f 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -61,6 +61,7 @@ public class Postler.Bureau : Gtk.Window {
                     <menuitem action="Search"/>
                 </menu>
                 <menu action="Help">
+                    <menuitem action="Shortcuts"/>
                     <menuitem action="About"/>
                 </menu>
             </menubar>
@@ -83,6 +84,7 @@ public class Postler.Bureau : Gtk.Window {
                 <menuitem action="Fullscreen"/>
                 <menuitem action="AccountNew"/>
                 <menuitem action="ReportBug"/>
+                <menuitem action="Shortcuts"/>
                 <menuitem action="About"/>
             </popup>
             <toolbar name="search_options">
@@ -318,6 +320,19 @@ public class Postler.Bureau : Gtk.Window {
         Postler.App.show_uri (get_screen (), "https://bugs.launchpad.net/postler/+filebug");
     }
 
+    static Gtk.Dialog? shortcuts = null;
+    void action_shortcuts () {
+        if (shortcuts == null) {
+            shortcuts = new Postler.Shortcuts (this, actions);
+            shortcuts.show ();
+            shortcuts.destroy.connect (() => {
+                shortcuts = null;
+            });
+        }
+        else
+            shortcuts.present ();
+    }
+
     void action_view_source () {
         Postler.App.spawn_module ("source", content.last_location);
     }
@@ -434,6 +449,8 @@ public class Postler.Bureau : Gtk.Window {
         { "ReportBug", STOCK_REPORT_BUG, N_("_Report a Problem..."), "",
           N_("Report a Problem..."), action_report_bug },
         { "Help", null, N_("_Help") },
+        { "Shortcuts", null, N_("_Shortcuts"),"F1",
+         N_("View keyboard shortcuts"), action_shortcuts },
         { "About", Gtk.STOCK_ABOUT, null, "",
           N_("Show information about the program"), action_about }
     };
diff --git a/postler/postler-shortcuts.vala b/postler/postler-shortcuts.vala
new file mode 100644
index 0000000..6142689
--- /dev/null
+++ b/postler/postler-shortcuts.vala
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2011 Christian Dywan <christian at twotoasts.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+namespace Postler {
+    public class Shortcuts : Gtk.Dialog {
+        Gtk.ListStore store;
+        Gtk.TreeView treeview;
+
+        public Shortcuts (Gtk.Window parent, Gtk.ActionGroup action_group) {
+            GLib.Object (transient_for: parent,
+                         title: _("Keyboard Shortcuts"),
+                         has_separator: false);
+
+            var screen = get_screen ();
+            Gdk.Rectangle monitor;
+            screen.get_monitor_geometry (0, out monitor);
+            double window_width = monitor.width / 1.7;
+            double window_height = monitor.height / 1.7;
+            set_default_size ((int)window_width, (int)window_height);
+
+            store = new Gtk.ListStore (7, typeof (string), typeof (int),
+                typeof (int), typeof (int), typeof (bool), typeof (string),
+                typeof (Gtk.Action));
+            treeview = new Gtk.TreeView.with_model (store);
+            treeview.set_headers_visible (false);
+            var column = new Gtk.TreeViewColumn ();
+            var renderer = new Gtk.CellRendererText ();
+            column.pack_start (renderer, false);
+            column.add_attribute (renderer, "text", 0);
+            treeview.append_column (column);
+            column = new Gtk.TreeViewColumn ();
+            renderer = new Gtk.CellRendererAccel ();
+            column.pack_start (renderer, false);
+            column.set_attributes (renderer, "accel-key", 1, "accel-mods", 2,
+                "accel-mode", 3, "editable", 4);
+            treeview.append_column (column);
+            var content_area = get_content_area () as Gtk.Box;
+            content_area.pack_start (new Postler.ScrolledWindow (treeview),
+                                     true, true, 0);
+            content_area.show_all ();
+
+            foreach (var action in action_group.list_actions ()) {
+                bool has_key = false;
+                string? path = action.get_accel_path ();
+                var key = new Gtk.AccelKey ();
+                if (path != null)
+                    has_key = Gtk.AccelMap.lookup_entry (path, out key);
+                if (key.accel_key == 0)
+                    continue;
+                store.insert_with_values (null, int.MAX,
+                                          0, action.label,
+                                          1, key.accel_key,
+                                          2, key.accel_mods,
+                                          3, Gtk.CellRendererAccelMode.GTK,
+                                          4, false,
+                                          6, action);
+            }
+        }
+    }
+}



More information about the Xfce4-commits mailing list