[gnome-documents] preview: use GResource for the preview toolbar menu
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] preview: use GResource for the preview toolbar menu
- Date: Thu, 19 Jul 2012 21:30:38 +0000 (UTC)
commit ef0da9096f4e346cb0d4d39cff329cc035768726
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu Jul 19 17:27:38 2012 -0400
preview: use GResource for the preview toolbar menu
Instead of manually creating it in JS.
src/Makefile.am | 3 +-
src/gnome-documents.gresource.xml | 1 +
src/preview.js | 38 ++++++++++++------------------------
src/resources/preview-menu.ui | 34 +++++++++++++++++++++++++++++++++
4 files changed, 50 insertions(+), 26 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8eb733a..6aa8651 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,7 +44,8 @@ include Makefile-js.am
gnome-documents.gresource: gnome-documents.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/gnome-documents.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
EXTRA_DIST += gnome-documents.gresource.xml \
- resources/app-menu.ui
+ resources/app-menu.ui \
+ resources/preview-menu.ui
resourcedir = $(pkgdatadir)
resource_DATA = gnome-documents.gresource
diff --git a/src/gnome-documents.gresource.xml b/src/gnome-documents.gresource.xml
index e5f1b74..bd3cff0 100644
--- a/src/gnome-documents.gresource.xml
+++ b/src/gnome-documents.gresource.xml
@@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/documents">
<file alias="app-menu.ui" preprocess="xml-stripblanks">resources/app-menu.ui</file>
+ <file alias="preview-menu.ui" preprocess="xml-stripblanks">resources/preview-menu.ui</file>
</gresource>
</gresources>
diff --git a/src/preview.js b/src/preview.js
index 11c276a..cacf327 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -358,39 +358,27 @@ const PreviewToolbar = new Lang.Class({
this.addSearchButton();
// menu button, on the right of the toolbar
- let menuModel = new Gio.Menu();
-
- let section = new Gio.Menu();
- menuModel.append_section(null, section);
-
- section.append_item(Gio.MenuItem.new(this._getOpenItemLabel(), 'app.open-current'));
- section.append_item(Gio.MenuItem.new(_("Print"), 'app.print-current'));
-
- section = new Gio.Menu();
- menuModel.append_section(null, section);
-
- section.append_item(Gio.MenuItem.new(_("Zoom In"), 'app.zoom-in'));
- section.append_item(Gio.MenuItem.new(_("Zoom Out"), 'app.zoom-out'));
-
- section = new Gio.Menu();
- menuModel.append_section(null, section);
-
- section.append_item(Gio.MenuItem.new(_("Rotate Left"), 'app.rotate-left'));
- section.append_item(Gio.MenuItem.new(_("Rotate Right"), 'app.rotate-right'));
-
+ let previewMenu = this._getPreviewMenu();
let menuButton = this.widget.add_menu('emblem-system-symbolic', null, false);
- menuButton.set_menu_model(menuModel);
+ menuButton.set_menu_model(previewMenu);
this._setToolbarTitle();
this.widget.show_all();
},
- _getOpenItemLabel: function() {
+ _getPreviewMenu: function() {
+ let builder = new Gtk.Builder();
+ builder.add_from_resource('/org/gnome/documents/preview-menu.ui');
+ let menu = builder.get_object('preview-menu');
+
let doc = Global.documentManager.getActiveItem();
- if (!doc || (doc && !doc.defaultAppName))
- return _("Open");
+ if (doc && doc.defaultAppName) {
+ let section = builder.get_object('open-section');
+ section.remove(0);
+ section.prepend(_("Open with %s").format(doc.defaultAppName), 'app.open-current');
+ }
- return _("Open with %s").format(doc.defaultAppName);
+ return menu;
},
createSearchbar: function() {
diff --git a/src/resources/preview-menu.ui b/src/resources/preview-menu.ui
new file mode 100644
index 0000000..7ec4e37
--- /dev/null
+++ b/src/resources/preview-menu.ui
@@ -0,0 +1,34 @@
+<interface>
+ <menu id="preview-menu">
+ <section id="open-section">
+ <item>
+ <attribute name="action">app.open-current</attribute>
+ <attribute name="label" translatable="yes">Open</attribute>
+ </item>
+ <item>
+ <attribute name="action">app.print-current</attribute>
+ <attribute name="label" translatable="yes">Print...</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="action">app.zoom-in</attribute>
+ <attribute name="label" translatable="yes">Zoom In</attribute>
+ </item>
+ <item>
+ <attribute name="action">app.zoom-out</attribute>
+ <attribute name="label" translatable="yes">Zoom Out</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="action">app.rotate-left</attribute>
+ <attribute name="label" translatable="yes">Rotate Left</attribute>
+ </item>
+ <item>
+ <attribute name="action">app.rotate-right</attribute>
+ <attribute name="label" translatable="yes">Rotate Right</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]