[gnome-weather/gnome-3-8] Add a "new" action to the app menu



commit 9d9639d80e0321b2df0aa3dd7055f5bb0317e74e
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Mar 8 18:34:52 2013 +0100

    Add a "new" action to the app menu
    
    This way it is possible to use ctrl+N to show the dialog. It also
    refactors the code to move the "about" action to the window, so that
    we do not need to proxy it manually.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695452

 data/app-menu.ui |    9 ++++++++-
 src/main.js      |    9 +--------
 src/util.js      |    6 +++---
 src/window.js    |    9 ++++++++-
 4 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/data/app-menu.ui b/data/app-menu.ui
index 621b50a..42a16a4 100644
--- a/data/app-menu.ui
+++ b/data/app-menu.ui
@@ -2,9 +2,16 @@
   <menu id="app-menu">
     <section>
       <item>
-        <attribute name="action">app.about</attribute>
+        <attribute name="label" translatable="yes">_New</attribute>
+        <attribute name="action">win.new</attribute>
+        <attribute name="accel">&lt;Primary&gt;n</attribute>
+      </item>
+      <item>
+        <attribute name="action">win.about</attribute>
         <attribute name="label" translatable="yes">About Weather</attribute>
       </item>
+    </section>
+    <section>
       <item>
         <attribute name="action">app.quit</attribute>
         <attribute name="label" translatable="yes">Quit</attribute>
diff --git a/src/main.js b/src/main.js
index 341a333..c6f8eef 100644
--- a/src/main.js
+++ b/src/main.js
@@ -48,11 +48,6 @@ const Application = new Lang.Class({
         this.quit();
     },
 
-    _onAbout: function() {
-        let win = this.get_active_window();
-        win.showAbout();
-    },
-
     _initAppMenu: function() {
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/weather/app-menu.ui');
@@ -76,9 +71,7 @@ const Application = new Lang.Class({
 
         Util.initActions(this,
                          [{ name: 'quit',
-                            callback: this._onQuit },
-                          { name: 'about',
-                            callback: this._onAbout }]);
+                            callback: this._onQuit }]);
 
         this._initAppMenu();
     },
diff --git a/src/util.js b/src/util.js
index f5d3e78..b9cb79e 100644
--- a/src/util.js
+++ b/src/util.js
@@ -44,14 +44,14 @@ function loadStyleSheet(file) {
                                              Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 }
 
-function initActions(app, simpleActionEntries) {
+function initActions(actionMap, simpleActionEntries) {
     simpleActionEntries.forEach(function(entry) {
         let action = new Gio.SimpleAction({ name: entry.name });
 
         if (entry.callback)
-            action.connect('activate', Lang.bind(app, entry.callback));
+            action.connect('activate', Lang.bind(actionMap, entry.callback));
 
-        app.add_action(action);
+        actionMap.add_action(action);
     });
 }
 
diff --git a/src/window.js b/src/window.js
index 4717ddb..fc2fdea 100644
--- a/src/window.js
+++ b/src/window.js
@@ -18,6 +18,7 @@
 
 const City = imports.city;
 const World = imports.world;
+const Util = imports.util;
 
 const Gettext = imports.gettext;
 const Tweener = imports.tweener.tweener;
@@ -100,6 +101,12 @@ const MainWindow = new Lang.Class({
         this._currentPage = Page.WORLD;
         this._pageWidgets = [[],[]];
 
+        Util.initActions(this,
+                         [{ name: 'new',
+                            callback: this._newLocation },
+                          { name: 'about',
+                            callback: this._showAbout }]);
+
         let grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
 
         this._header = new Gd.HeaderBar({ hexpand: true });
@@ -283,7 +290,7 @@ const MainWindow = new Lang.Class({
         dialog.show_all();
     },
 
-    showAbout: function() {
+    _showAbout: function() {
         let aboutDialog = new Gtk.AboutDialog(
             { artists: [ 'Jakub Steiner <jimmac gmail com>' ],
               authors: [ 'Giovanni Campagna <gcampagna src gnome org>' ],


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