[gnome-documents] Port fullscreen code to FullscreenAction



commit 7b1a8fdc41ae9525b2c2f4ca421f27a7dbf9e744
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 19 15:13:46 2016 -0700

    Port fullscreen code to FullscreenAction
    
    This also moves the fullscreen action to the view menu instead of the
    app menu.

 data/ui/app-menu.ui     |    4 ----
 data/ui/preview-menu.ui |    5 +++++
 src/application.js      |   21 ---------------------
 src/embed.js            |   20 ++++++++------------
 src/evinceview.js       |   46 +++++++++++++++++++++++++++++++++++++++++-----
 src/mainToolbar.js      |   20 --------------------
 src/mainWindow.js       |   23 ++---------------------
 src/preview.js          |    4 ++++
 src/windowMode.js       |   26 --------------------------
 9 files changed, 60 insertions(+), 109 deletions(-)
---
diff --git a/data/ui/app-menu.ui b/data/ui/app-menu.ui
index 1133224..b778264 100644
--- a/data/ui/app-menu.ui
+++ b/data/ui/app-menu.ui
@@ -2,10 +2,6 @@
   <menu id="app-menu">
     <section>
       <item>
-        <attribute name="action">app.fullscreen</attribute>
-        <attribute name="label" translatable="yes">Fullscreen</attribute>
-      </item>
-      <item>
         <attribute name="action">app.night-mode</attribute>
         <attribute name="label" translatable="yes">Night Mode</attribute>
       </item>
diff --git a/data/ui/preview-menu.ui b/data/ui/preview-menu.ui
index d3c35c0..eddd2b0 100644
--- a/data/ui/preview-menu.ui
+++ b/data/ui/preview-menu.ui
@@ -17,6 +17,11 @@
         <attribute name='hidden-when'>action-missing</attribute>
       </item>
       <item>
+        <attribute name="action">view.fullscreen</attribute>
+        <attribute name="label" translatable="yes">Fullscreen</attribute>
+        <attribute name="accel">F11</attribute>
+      </item>
+      <item>
         <attribute name="action">view.present-current</attribute>
         <attribute name='hidden-when'>action-missing</attribute>
         <attribute name="label" translatable="yes">Present</attribute>
diff --git a/src/application.js b/src/application.js
index afb562c..54a48d5 100644
--- a/src/application.js
+++ b/src/application.js
@@ -168,14 +168,6 @@ const Application = new Lang.Class({
         checkNextFile.apply(this);
     },
 
-    _fullscreenCreateHook: function(action) {
-        modeController.connect('can-fullscreen-changed', Lang.bind(this,
-            function() {
-                let canFullscreen = modeController.getCanFullscreen();
-                action.set_enabled(canFullscreen);
-            }));
-    },
-
     _nightModeCreateHook: function(action) {
         settings.connect('changed::night-mode', Lang.bind(this,
             function() {
@@ -215,13 +207,6 @@ const Application = new Lang.Class({
         settings.set_value('night-mode', GLib.Variant.new('b', !state.get_boolean()));
     },
 
-    _onActionFullscreen: function(action) {
-        let state = action.get_state();
-        let newState = !state.get_boolean();
-        action.change_state(GLib.Variant.new('b', newState));
-        modeController.setFullscreen(newState);
-    },
-
     _connectActionsToMode: function() {
         this._actionEntries.forEach(Lang.bind(this,
             function(actionEntry) {
@@ -443,12 +428,6 @@ const Application = new Lang.Class({
             { name: 'help',
               callback: Lang.bind(this, this._onActionHelp),
               accels: ['F1'] },
-            { name: 'fullscreen',
-              callback: Lang.bind(this, this._onActionFullscreen),
-              state: GLib.Variant.new('b', false),
-              create_hook: Lang.bind(this, this._fullscreenCreateHook),
-              accels: ['F11'],
-              window_mode: WindowMode.WindowMode.PREVIEW_EV },
             { name: 'night-mode',
               callback: Lang.bind(this, this._onActionNightMode),
               create_hook: Lang.bind(this, this._nightModeCreateHook),
diff --git a/src/embed.js b/src/embed.js
index 5014b38..a7e8e54 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -54,8 +54,6 @@ const Embed = new Lang.Class({
 
         Application.modeController.connect('window-mode-changed',
                                            Lang.bind(this, this._onWindowModeChanged));
-        Application.modeController.connect('fullscreen-changed',
-                                           Lang.bind(this, this._onFullscreenChanged));
 
         Application.documentManager.connect('active-changed',
                                             Lang.bind(this, this._onActiveItemChanged));
@@ -73,11 +71,6 @@ const Embed = new Lang.Class({
             this._onWindowModeChanged(Application.modeController, windowMode, WindowMode.WindowMode.NONE);
     },
 
-    _onFullscreenChanged: function(controller, fullscreen) {
-        this._toolbar.visible = !fullscreen;
-        this._toolbar.sensitive = !fullscreen;
-    },
-
     _onSearchChanged: function() {
         // Whenever a search constraint is specified we want to switch to
         // the search mode, and when all constraints have been lifted we
@@ -175,12 +168,15 @@ const Embed = new Lang.Class({
 
     getMainToolbar: function() {
         let windowMode = Application.modeController.getWindowMode();
-        let fullscreen = Application.modeController.getFullscreen();
 
-        if (fullscreen && (windowMode == WindowMode.WindowMode.PREVIEW_EV))
-            return this.getPreview().getFullscreenToolbar();
-        else
-            return this._toolbar;
+        if (windowMode == WindowMode.WindowMode.PREVIEW_EV) {
+            let preview = this.getPreview();
+            let fullscreen = preview.fullscreen;
+            if (fullscreen)
+                return preview.getFullscreenToolbar();
+        }
+
+        return this._toolbar;
     },
 
     getPreview: function() {
diff --git a/src/evinceview.js b/src/evinceview.js
index d4ea883..12b99ee 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -32,6 +32,7 @@ const Mainloop = imports.mainloop;
 
 const Application = imports.application;
 const Documents = imports.documents;
+const FullscreenAction = imports.fullscreenAction;
 const Places = imports.places;
 const Presentation = imports.presentation;
 const Preview = imports.preview;
@@ -56,11 +57,14 @@ const EvinceView = new Lang.Class({
 
         this.parent(overlay, mainWindow);
 
-        Application.modeController.connect('fullscreen-changed', Lang.bind(this,
-            this._onFullscreenChanged));
         Application.modeController.connect('window-mode-changed', Lang.bind(this,
             this._onWindowModeChanged));
 
+        let fullscreenAction = new FullscreenAction.FullscreenAction({ window: mainWindow });
+        fullscreenAction.connect('notify::state', Lang.bind(this, this._onFullscreenChanged));
+        this.actionGroup.add_action(fullscreenAction);
+        Application.application.set_accels_for_action('view.fullscreen', ['F11']);
+
         this.getAction('bookmark-page').enabled = false;
 
         let nightModeId = Application.application.connect('action-state-changed::night-mode',
@@ -69,6 +73,7 @@ const EvinceView = new Lang.Class({
         this.connect('destroy', Lang.bind(this,
             function() {
                 Application.application.disconnect(nightModeId);
+                fullscreenAction.change_state(new GLib.Variant('b', false));
             }));
     },
 
@@ -435,8 +440,11 @@ const EvinceView = new Lang.Class({
         }
     },
 
-    _onFullscreenChanged: function() {
-        let fullscreen = Application.modeController.getFullscreen();
+    _onFullscreenChanged: function(action) {
+        let fullscreen = action.state.get_boolean();
+
+        this._toolbar.visible = !fullscreen;
+        this._toolbar.sensitive = !fullscreen;
 
         if (fullscreen) {
             // create fullscreen toolbar (hidden by default)
@@ -628,6 +636,10 @@ const EvinceView = new Lang.Class({
 
     get evView() {
         return this._evView;
+    },
+
+    get fullscreen() {
+        return this.getAction('fullscreen').state.get_boolean();
     }
 });
 Utils.addJSSignalMethods(EvinceView.prototype);
@@ -682,15 +694,39 @@ const EvinceViewToolbar = new Lang.Class({
         this.preview.getAction('gear-menu').enabled = false;
 
         if (Application.application.isBooks) {
-            this.addFullscreenButton();
+            this._addFullscreenButton();
             this.addNightmodeButton();
         }
 
         this.connect('destroy', Lang.bind(this, function() {
             this._searchAction.enabled = true;
+            if (this._fsStateId > 0)
+                this.preview.getAction('fullscreen').disconnect(this._fsStateId);
         }));
     },
 
+    _addFullscreenButton: function() {
+        this._fullscreenButton = new Gtk.Button({ image: new Gtk.Image ({ icon_name: 
'view-fullscreen-symbolic' }),
+                                                  tooltip_text: _("Fullscreen"),
+                                                  action_name: 'view.fullscreen',
+                                                  visible: true });
+        this.toolbar.pack_end(this._fullscreenButton);
+
+        let action = this.preview.getAction('fullscreen');
+        this._fsStateId = action.connect('notify::state', Lang.bind(this, this._fullscreenStateChanged));
+        this._fullscreenStateChanged();
+    },
+
+    _fullscreenStateChanged: function() {
+        let action = this.preview.getAction('fullscreen');
+        let fullscreen = action.state.get_boolean();
+
+        if (fullscreen)
+            this._fullscreenButton.image.icon_name = 'view-restore-symbolic';
+        else
+            this._fullscreenButton.image.icon_name ='view-fullscreen-symbolic';
+    },
+
     _enableSearch: function() {
         let hasPages = this.preview.hasPages;
         let canFind = true;
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 14772c3..0a8aade 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -94,26 +94,6 @@ const MainToolbar = new Lang.Class({
         return searchButton;
     },
 
-    _onFullscreenStateChanged: function() {
-        let state = Application.application.get_action_state('fullscreen');
-        if (state.get_boolean())
-            this._fullscreenButton.image.icon_name ='view-restore-symbolic';
-        else
-            this._fullscreenButton.image.icon_name ='view-fullscreen-symbolic';
-    },
-
-    addFullscreenButton: function() {
-        let fullscreenButton = new Gtk.Button({ image: new Gtk.Image ({ icon_name: 
'view-fullscreen-symbolic' }),
-                                                tooltip_text: _("Fullscreen"),
-                                                action_name: 'app.fullscreen' });
-        this.toolbar.pack_end(fullscreenButton);
-        Application.application.connect('action-state-changed::fullscreen',
-            Lang.bind(this, this._onFullscreenStateChanged));
-        this._fullscreenButton = fullscreenButton;
-        this._onFullscreenStateChanged();
-        return fullscreenButton;
-    },
-
     addNightmodeButton: function() {
         let nightmodeButton = new Gtk.ToggleButton({ image: new Gtk.Image ({ icon_name: 
'display-brightness-symbolic' }),
                                                      tooltip_text: _("Night Mode"),
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 48a0c8e..b0a079f 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -76,9 +76,6 @@ const MainWindow = new Lang.Class({
         this.connect('configure-event', Lang.bind(this, this._onConfigureEvent));
         this.connect('window-state-event', Lang.bind(this, this._onWindowStateEvent));
 
-        this._fsId = Application.modeController.connect('fullscreen-changed',
-            Lang.bind(this, this._onFullscreenChanged));
-
         this._embed = new Embed.Embed(this);
         this.add(this._embed);
     },
@@ -123,25 +120,10 @@ const MainWindow = new Lang.Class({
     _onWindowStateEvent: function(widget, event) {
         let window = widget.get_window();
         let state = window.get_state();
-
-        if (state & Gdk.WindowState.FULLSCREEN) {
-            Application.modeController.setFullscreen(true);
-            return;
-        }
-
-        Application.modeController.setFullscreen(false);
-
         let maximized = (state & Gdk.WindowState.MAXIMIZED);
         Application.settings.set_boolean('window-maximized', maximized);
     },
 
-    _onFullscreenChanged: function(controller, fullscreen) {
-        if (fullscreen)
-            this.fullscreen();
-        else
-            this.unfullscreen();
-    },
-
     _goBack: function() {
         let windowMode = Application.modeController.getWindowMode();
         let activeCollection = Application.documentManager.getActiveCollection();
@@ -236,9 +218,8 @@ const MainWindow = new Lang.Class({
 
     _handleKeyPreview: function(event) {
         let keyval = event.get_keyval()[1];
-        let fullscreen = Application.modeController.getFullscreen();
-        let def_mod_mask = Gtk.accelerator_get_default_mod_mask();
         let preview = this._embed.getPreview();
+        let def_mod_mask = Gtk.accelerator_get_default_mod_mask();
         let state = event.get_state()[1];
         let windowMode = Application.modeController.getWindowMode();
 
@@ -248,7 +229,7 @@ const MainWindow = new Lang.Class({
 
             if (preview.controlsVisible && (model != null)) {
                 preview.controlsVisible = false;
-            } else if (fullscreen) {
+            } else if (preview.fullscreen) {
                 Application.documentManager.setActiveItem(null);
                 Application.modeController.goBack();
             }
diff --git a/src/preview.js b/src/preview.js
index 6734a22..20f2fc6 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -232,6 +232,10 @@ const Preview = new Lang.Class({
         return false;
     },
 
+    get fullscreen() {
+        return false;
+    },
+
     findPrev: function() {
         throw (new Error('Not implemented'));
     },
diff --git a/src/windowMode.js b/src/windowMode.js
index d8527c5..fcf4e4e 100644
--- a/src/windowMode.js
+++ b/src/windowMode.js
@@ -38,7 +38,6 @@ const ModeController = new Lang.Class({
 
     _init: function() {
         this._mode = WindowMode.NONE;
-        this._fullscreen = false;
         this._history = [];
     },
 
@@ -68,7 +67,6 @@ const ModeController = new Lang.Class({
         oldMode = this._mode;
         this._mode = tmp;
 
-        this._updateFullscreen();
         this.emit('window-mode-changed', this._mode, oldMode);
     },
 
@@ -81,35 +79,11 @@ const ModeController = new Lang.Class({
         this._history.push(oldMode);
         this._mode = mode;
 
-        this._updateFullscreen();
         this.emit('window-mode-changed', this._mode, oldMode);
     },
 
     getWindowMode: function() {
         return this._mode;
-    },
-
-    _updateFullscreen: function() {
-        if (!this.getCanFullscreen() && this._fullscreen)
-            this.setFullscreen(false);
-
-        this.emit('can-fullscreen-changed');
-    },
-
-    setFullscreen: function(fullscreen) {
-        if (this._fullscreen == fullscreen)
-            return;
-
-        this._fullscreen = fullscreen;
-        this.emit('fullscreen-changed', this._fullscreen);
-    },
-
-    getFullscreen: function() {
-        return this._fullscreen;
-    },
-
-    getCanFullscreen: function() {
-        return (this._mode == WindowMode.PREVIEW_EV || this._mode == WindowMode.EDIT);
     }
 });
 Signals.addSignalMethods(ModeController.prototype);


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