[gnome-documents] mainToolbar: factor out a method to add a back button



commit 3ac2f326b95b028b134126e260c960de1b106009
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Feb 22 13:15:33 2013 -0500

    mainToolbar: factor out a method to add a back button
    
    We copy this code in various places, so make it a method similar to
    addSearchButton().

 src/edit.js        |    7 +------
 src/mainToolbar.js |   17 +++++++++++++----
 src/preview.js     |    7 +------
 3 files changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/src/edit.js b/src/edit.js
index 36ec372..4d3fbab 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -182,12 +182,7 @@ const EditToolbar = new Lang.Class({
         this.parent();
 
         // back button, on the left of the toolbar
-        let iconName =
-            (this.toolbar.get_direction() == Gtk.TextDirection.RTL) ?
-            'go-next-symbolic' : 'go-previous-symbolic';
-        let backButton = new Gd.HeaderSimpleButton({ symbolic_icon_name: iconName,
-                                                     label: _("Back") });
-        this.toolbar.pack_start(backButton);
+        let backButton = this.addBackButton();
         backButton.connect('clicked', Lang.bind(this,
             function() {
                 Application.documentManager.setActiveItem(null);
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index d61909f..273dcc2 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -62,6 +62,17 @@ const MainToolbar = new Lang.Class({
                                                        label: _("Search"),
                                                        action_name: 'app.search' });
         this.toolbar.pack_end(searchButton);
+        return searchButton;
+    },
+
+    addBackButton: function() {
+        let iconName =
+            (this.toolbar.get_direction() == Gtk.TextDirection.RTL) ?
+            'go-next-symbolic' : 'go-previous-symbolic';
+        let backButton = new Gd.HeaderSimpleButton({ symbolic_icon_name: iconName,
+                                                     label: _("Back") });
+        this.toolbar.pack_start(backButton);
+        return backButton;
     }
 });
 
@@ -196,10 +207,8 @@ const OverviewToolbar = new Lang.Class({
         let item = Application.collectionManager.getActiveItem();
 
         if (item && !this._collBackButton) {
-            this._collBackButton = new Gd.HeaderSimpleButton({ symbolic_icon_name: 'go-previous-symbolic',
-                                                               label: _("Back"),
-                                                               visible: true });
-            this.toolbar.pack_start(this._collBackButton);
+            this._collBackButton = this.addBackButton();
+            this._collBackButton.show();
             this._collBackButton.connect('clicked', Lang.bind(this,
                 function() {
                     Application.documentManager.activatePreviousCollection();
diff --git a/src/preview.js b/src/preview.js
index 2db7755..27a4617 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -781,12 +781,7 @@ const PreviewToolbar = new Lang.Class({
         this._gearMenu = Application.application.lookup_action('gear-menu');
 
         // back button, on the left of the toolbar
-        let iconName =
-            (this.toolbar.get_direction() == Gtk.TextDirection.RTL) ?
-            'go-next-symbolic' : 'go-previous-symbolic';
-        let backButton = new Gd.HeaderSimpleButton({ symbolic_icon_name: iconName,
-                                                     label: _("Back") });
-        this.toolbar.pack_start(backButton);
+        let backButton = this.addBackButton();
         backButton.connect('clicked', Lang.bind(this,
             function() {
                 Application.documentManager.setActiveItem(null);


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