[gnome-weather] Add a "new" action to the app menu
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] Add a "new" action to the app menu
- Date: Sat, 9 Mar 2013 11:24:39 +0000 (UTC)
commit 71660d1866e1d111308dae9c5d26b6b10aedda30
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"><Primary>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 c74e94b..6783e6b 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 71ae7df..6d82688 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]