[gnome-documents] sidebar: move sidebar visibility control to SideFilterController



commit 4216073f2822b17d553362120862b4b4107d294d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 31 21:49:15 2011 -0400

    sidebar: move sidebar visibility control to SideFilterController
    
    Makes it easier to wire to a GSetting later, and cleans up for the next
    commit.

 src/filters.js    |   14 ++++++++++++++
 src/mainWindow.js |    3 ++-
 src/sidebar.js    |   14 ++++++++------
 3 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/src/filters.js b/src/filters.js
index 5a626e4..45cd7b2 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -100,6 +100,8 @@ SideFilterController.prototype = {
     _init: function() {
         // intialize to last category
         this._whereItem = Global.categoryManager.getActiveItem();
+
+        this._sidebarVisible = true;
     },
 
     setActiveItem: function(controller, item) {
@@ -112,6 +114,18 @@ SideFilterController.prototype = {
         this.emit('changed', this._whereItem);
     },
 
+    setSidebarVisible: function(visible) {
+        if (this._sidebarVisible == visible)
+            return;
+
+        this._sidebarVisible = visible;
+        this.emit('sidebar-visible-changed', this._sidebarVisible);
+    },
+
+    getSidebarVisible: function() {
+        return this._sidebarVisible;
+    },
+
     getWhere: function() {
         if (!this._whereItem)
             return '';
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 8249a1f..23e8ab2 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -256,7 +256,8 @@ MainWindow.prototype = {
         let keyval = event.get_keyval()[1];
 
         if (keyval == Gdk.KEY_F9) {
-            this._sidebar.toggleVisibility();
+            let visible = Global.sideFilterController.getSidebarVisible();
+            Global.sideFilterController.setSidebarVisible(!visible);
             return true;
         }
 
diff --git a/src/sidebar.js b/src/sidebar.js
index 5bd0938..20cf6b0 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -362,8 +362,6 @@ function Sidebar() {
 
 Sidebar.prototype = {
     _init: function() {
-        this._sidebarVisible = true;
-
         this.widget = new Gtk.Notebook({ show_tabs: false,
                                          width_request: _SIDEBAR_WIDTH_REQUEST });
         this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_SIDEBAR);
@@ -376,6 +374,10 @@ Sidebar.prototype = {
 
         Global.modeController.connect('window-mode-changed',
                                       Lang.bind(this, this._onWindowModeChanged));
+        Global.sideFilterController.connect('sidebar-visible-changed',
+                                            Lang.bind(this, this._onSidebarVisible));
+
+        this._onSidebarVisible();
     },
 
     _moveOut: function() {
@@ -394,14 +396,14 @@ Sidebar.prototype = {
         if (mode == WindowMode.WindowMode.PREVIEW) {
             this._moveOut();
         } else if (mode == WindowMode.WindowMode.OVERVIEW) {
-            if (this._sidebarVisible)
+            if (Global.sideFilterController.getSidebarVisible())
                 this._moveIn();
         }
     },
 
-    toggleVisibility: function() {
-        this._sidebarVisible = !this._sidebarVisible;
-        if (this._sidebarVisible)
+    _onSidebarVisible: function() {
+        let visible = Global.sideFilterController.getSidebarVisible();
+        if (visible)
             this._moveIn();
         else
             this._moveOut();



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