[sushi/wip/cosimoc/no-clutter: 66/67] mainWindow: create the GtkToolbar for all renderers



commit 4514c3ab4a054ff2ea540948976b15a9d68da843
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Apr 29 17:06:50 2018 -0700

    mainWindow: create the GtkToolbar for all renderers
    
    De-duplicate this code and avoid having every render create its own
    toolbar.

 src/js/ui/mainWindow.js  |   11 +++++++++--
 src/js/viewers/audio.js  |   23 ++++++++---------------
 src/js/viewers/evince.js |   44 +++++++++++++++++---------------------------
 src/js/viewers/html.js   |   20 ++++++--------------
 src/js/viewers/image.js  |   14 +++-----------
 src/js/viewers/text.js   |   15 +++------------
 6 files changed, 46 insertions(+), 81 deletions(-)
---
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index bf5da29..1c25fde 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -234,8 +234,13 @@ const MainWindow = new Lang.Class({
             this._toolbar = null;
         }
 
-        if (this._renderer.createToolbar) {
-            let rendererToolbar = this._renderer.createToolbar();
+        if (this._renderer.populateToolbar) {
+            let rendererToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
+                                                    halign: Gtk.Align.CENTER,
+                                                    show_arrow: false,
+                                                    visible: true });
+            rendererToolbar.get_style_context().add_class('osd');
+
             this._toolbar = new Gtk.Revealer({ valign: Gtk.Align.END,
                                                hexpand: true,
                                                margin_bottom: Constants.TOOLBAR_SPACING,
@@ -245,6 +250,8 @@ const MainWindow = new Lang.Class({
                                                transition_type: Gtk.RevealerTransitionType.CROSSFADE,
                                                visible: true });
             this._toolbar.add(rendererToolbar);
+
+            this._renderer.populateToolbar(rendererToolbar);
         }
 
         if (!this._toolbar)
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index de5e1a5..67116ac 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -208,7 +208,7 @@ const AudioRenderer = new Lang.Class({
     },
 
     _updateProgressBar : function() {
-        if (!this._mainToolbar)
+        if (!this._progressBar)
             return;
 
         this._isSettingValue = true;
@@ -217,7 +217,7 @@ const AudioRenderer = new Lang.Class({
     },
 
     _updateCurrentLabel : function() {
-        if (!this._mainToolbar)
+        if (!this._currentLabel)
             return;
 
         let currentTime =
@@ -227,7 +227,7 @@ const AudioRenderer = new Lang.Class({
     },
 
     _updateDurationLabel : function() {
-        if (!this._mainToolbar)
+        if (!this._durationLabel)
             return;
 
         let totalTime = this._player.duration;
@@ -263,22 +263,17 @@ const AudioRenderer = new Lang.Class({
         return [ width[1], height[1] ];
     },
 
-    createToolbar : function () {
-        this._mainToolbar = new Gtk.Toolbar();
-        this._mainToolbar.get_style_context().add_class('osd');
-        this._mainToolbar.set_icon_size(Gtk.IconSize.MENU);
-        this._mainToolbar.show();
-
+    populateToolbar : function (toolbar) {
         this._toolbarPlay = new Gtk.ToolButton({ icon_name: 'media-playback-pause-symbolic' });
         this._toolbarPlay.show();
-        this._mainToolbar.insert(this._toolbarPlay, 0);
+        toolbar.insert(this._toolbarPlay, 0);
 
         this._currentLabel = new Gtk.Label({ margin_start: 6,
                                              margin_end: 3 });
         let item = new Gtk.ToolItem();
         item.add(this._currentLabel);
         item.show_all();
-        this._mainToolbar.insert(item, 1);
+        toolbar.insert(item, 1);
 
         this._toolbarPlay.connect('clicked',
                                   Lang.bind(this, function () {
@@ -301,15 +296,13 @@ const AudioRenderer = new Lang.Class({
         item.set_expand(true);
         item.add(this._progressBar);
         item.show_all();
-        this._mainToolbar.insert(item, 2);
+        toolbar.insert(item, 2);
 
         this._durationLabel = new Gtk.Label({ margin_start: 3 });
         item = new Gtk.ToolItem();
         item.add(this._durationLabel);
         item.show_all();
-        this._mainToolbar.insert(item, 3);
-
-        return this._mainToolbar;
+        toolbar.insert(item, 3);
     },
 });
 
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index df1df56..b93b8f8 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -110,46 +110,36 @@ const EvinceRenderer = new Lang.Class({
         return item;
     },
 
-    createToolbar : function() {
-        this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
-                                              halign: Gtk.Align.CENTER });
-        this._mainToolbar.get_style_context().add_class('osd');
-        this._mainToolbar.set_show_arrow(false);
-        this._mainToolbar.show();
-
+    populateToolbar : function(toolbar) {
         this._toolbarBack = new Gtk.ToolButton({ expand: false,
-                                                 icon_name: 'go-previous-symbolic' });
-        this._toolbarBack.show();
-        this._mainToolbar.insert(this._toolbarBack, -1);
+                                                 icon_name: 'go-previous-symbolic',
+                                                 visible: true });
+        toolbar.insert(this._toolbarBack, -1);
 
-        this._toolbarBack.connect('clicked',
-                                  Lang.bind(this, function () {
-                                      this._view.previous_page();
-                                  }));
+        this._toolbarBack.connect('clicked', Lang.bind(this, function () {
+            this._view.previous_page();
+        }));
 
         let labelItem = this._createLabelItem();
-        this._mainToolbar.insert(labelItem, -1);
+        toolbar.insert(labelItem, -1);
 
         this._toolbarForward = new Gtk.ToolButton({ expand: false,
-                                                    icon_name: 'go-next-symbolic' });
-        this._toolbarForward.show();
-        this._mainToolbar.insert(this._toolbarForward, -1);
+                                                    icon_name: 'go-next-symbolic',
+                                                    visible: true });
+        toolbar.insert(this._toolbarForward, -1);
 
-        this._toolbarForward.connect('clicked',
-                                     Lang.bind(this, function () {
-                                         this._view.next_page();
-                                     }));
+        this._toolbarForward.connect('clicked', Lang.bind(this, function () {
+            this._view.next_page();
+        }));
 
         let separator = new Gtk.SeparatorToolItem();
         separator.show();
-        this._mainToolbar.insert(separator, -1);
+        toolbar.insert(separator, -1);
 
-        this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
-        this._mainToolbar.insert(this._toolbarZoom, -1);
+        let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+        toolbar.insert(toolbarZoom, -1);
 
         this._updatePageLabel();
-
-        return this._mainToolbar;
     },
 
     clear : function() {
diff --git a/src/js/viewers/html.js b/src/js/viewers/html.js
index 1070686..a26e4a3 100644
--- a/src/js/viewers/html.js
+++ b/src/js/viewers/html.js
@@ -65,24 +65,16 @@ const HTMLRenderer = new Lang.Class({
         return allocation;
     },
 
-    createToolbar : function() {
-        this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
-                                              halign: Gtk.Align.CENTER });
-        this._mainToolbar.get_style_context().add_class('osd');
-        this._mainToolbar.set_show_arrow(false);
-        this._mainToolbar.show();
-
-        this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
-        this._mainToolbar.insert(this._toolbarZoom, 0);
+    populateToolbar : function(toolbar) {
+        let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+        toolbar.insert(toolbarZoom, 0);
 
         let separator = new Gtk.SeparatorToolItem();
         separator.show();
-        this._mainToolbar.insert(separator, 1);
-
-        this._toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
-        this._mainToolbar.insert(this._toolbarRun, 2);
+        toolbar.insert(separator, 1);
 
-        return this._mainToolbar;
+        let toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
+        toolbar.insert(toolbarRun, 2);
     }
 });
 
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index 22a9b82..f1c90be 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -203,17 +203,9 @@ const ImageRenderer = new Lang.Class({
                                                          this._advanceImage));
     },
 
-    createToolbar : function() {
-        this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
-                                              halign: Gtk.Align.CENTER });
-        this._mainToolbar.get_style_context().add_class('osd');
-        this._mainToolbar.set_show_arrow(false);
-        this._mainToolbar.show();
-
-        this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
-        this._mainToolbar.insert(this._toolbarZoom, 0);
-
-        return this._mainToolbar;
+    populateToolbar : function(toolbar) {
+        let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+        toolbar.insert(toolbarZoom, 0);
     },
 
     destroy : function () {
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index 4a6aa29..6ccbfbd 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -104,18 +104,9 @@ const TextRenderer = new Lang.Class({
         return allocation;
     },
 
-    createToolbar : function() {
-        this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
-                                              halign: Gtk.Align.CENTER });
-        this._mainToolbar.get_style_context().add_class('osd');
-        this._mainToolbar.set_show_arrow(false);
-
-        this._toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
-        this._mainToolbar.insert(this._toolbarRun, 0);
-
-        this._mainToolbar.show();
-
-        return this._mainToolbar;
+    populateToolbar : function(toolbar) {
+        let toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
+        toolbar.insert(toolbarRun, 0);
     }
 });
 


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