[gnome-documents] embed: move toolbar handling into view class



commit edca7d3d6a3cdc5818642590bba0ce2fd2b8027c
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Sep 21 12:24:25 2016 -0700

    embed: move toolbar handling into view class
    
    We want to move in the direction of containing all the view details
    inside the view hierarchy. The Embed class still needs details about the
    window mode and pokes into the preview class to fetch the full screen
    toolbar, but we will fix that in a later commit.

 src/embed.js |   32 +++-----------------------------
 src/view.js  |   27 ++++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 34 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index a7e8e54..d6fa2a0 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -42,8 +42,8 @@ const Embed = new Lang.Class({
         this.parent({ orientation: Gtk.Orientation.VERTICAL,
                       visible: true });
 
-        this._titlebar = new Gtk.Grid({ visible: true });
-        mainWindow.set_titlebar(this._titlebar);
+        let titlebar = new Gtk.Grid({ visible: true });
+        mainWindow.set_titlebar(titlebar);
 
         // create the toolbar for selected items, it's hidden by default
         this._selectionToolbar = new Selections.SelectionToolbar();
@@ -103,33 +103,7 @@ const Embed = new Lang.Class({
     },
 
     _onWindowModeChanged: function(object, newMode, oldMode) {
-        let createToolbar = true;
-
-        if (newMode == WindowMode.WindowMode.COLLECTIONS ||
-            newMode == WindowMode.WindowMode.DOCUMENTS ||
-            newMode == WindowMode.WindowMode.SEARCH) {
-            createToolbar = (oldMode != WindowMode.WindowMode.COLLECTIONS &&
-                             oldMode != WindowMode.WindowMode.DOCUMENTS &&
-                             oldMode != WindowMode.WindowMode.SEARCH);
-        }
-
         this._view.windowMode = newMode;
-
-        if (createToolbar) {
-            if (this._toolbar)
-                this._toolbar.destroy();
-
-            // pack the toolbar
-            this._toolbar = this._view.createToolbar();
-            if (this._toolbar.searchbar)
-                this._toolbar.searchbar.connectJS('activate-result',
-                                                  Lang.bind(this, this._onActivateResult));
-            this._titlebar.add(this._toolbar);
-        }
-    },
-
-    _onActivateResult: function() {
-        this._view.activateResult();
     },
 
     _restoreSearch: function() {
@@ -176,7 +150,7 @@ const Embed = new Lang.Class({
                 return preview.getFullscreenToolbar();
         }
 
-        return this._toolbar;
+        return this._view.toolbar;
     },
 
     getPreview: function() {
diff --git a/src/view.js b/src/view.js
index f60c645..fb99987 100644
--- a/src/view.js
+++ b/src/view.js
@@ -729,6 +729,7 @@ const View = new Lang.Class({
     Extends: Gtk.Overlay,
 
     _init: function(window) {
+        this._toolbar = null;
         this._window = window;
 
         this.parent();
@@ -802,15 +803,12 @@ const View = new Lang.Class({
         this._stack.add_named(this._preview, 'preview');
     },
 
-    activateResult: function() {
+    _onActivateResult: function() {
         this.view.activateResult();
     },
 
-    createToolbar: function() {
-        return this.view.createToolbar(this._stack);
-    },
-
     set windowMode(mode) {
+        let fromPreview = !!this._preview;
         this._clearPreview();
 
         let visibleChild;
@@ -838,6 +836,25 @@ const View = new Lang.Class({
 
         this._stack.set_visible_child(visibleChild);
         this._window.insert_action_group('view', visibleChild.actionGroup);
+
+        let createToolbar = true;
+        if (!this._preview)
+            createToolbar = fromPreview || !this._toolbar;
+
+        if (createToolbar) {
+            if (this._toolbar)
+                this._toolbar.destroy();
+
+            this._toolbar = this.view.createToolbar(this._stack);
+            if (this._toolbar.searchbar)
+                this._toolbar.searchbar.connectJS('activate-result',
+                                                  Lang.bind(this, this._onActivateResult));
+            this._window.get_titlebar().add(this._toolbar);
+        }
+    },
+
+    get toolbar() {
+        return this._toolbar;
     },
 
     get view() {


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