[polari/wip/fmuellner/window-experiments: 11/30] app: Add run-in-background action



commit 04f99bd3f0ffc3abf9023b549f21a871ecd19df1
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jun 24 13:15:03 2016 +0200

    app: Add run-in-background action

 data/org.gnome.Polari.desktop.in |    5 +++++
 data/resources/menus.ui          |    6 ++++++
 src/application.js               |   18 ++++++++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.Polari.desktop.in b/data/org.gnome.Polari.desktop.in
index 9d6d2e5..6a6e1f1 100644
--- a/data/org.gnome.Polari.desktop.in
+++ b/data/org.gnome.Polari.desktop.in
@@ -7,6 +7,11 @@ Type=Application
 MimeType=x-scheme-handler/irc;
 StartupNotify=true
 DBusActivatable=true
+Actions=run-in-background
 X-GNOME-UsesNotifications=true
 Categories=GNOME;GTK;Network;IRCClient;
 Keywords=IRC;Internet;Relay;Chat;
+
+[Desktop Action run-in-background]
+Name=Run in Background
+Exec=gapplication action org.gnome.Polari run-in-background
diff --git a/data/resources/menus.ui b/data/resources/menus.ui
index 22f20e5..eff8d78 100644
--- a/data/resources/menus.ui
+++ b/data/resources/menus.ui
@@ -2,6 +2,12 @@
   <menu id="app-menu">
     <section>
       <item>
+        <attribute name="action">app.run-in-background</attribute>
+        <attribute name="label" translatable="yes">Run in Background</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
         <attribute name="action">win.show-help-overlay</attribute>
         <attribute name="label" translatable="yes">Keyboard Shortcuts</attribute>
       </item>
diff --git a/src/application.js b/src/application.js
index 7df0b07..bd1a089 100644
--- a/src/application.js
+++ b/src/application.js
@@ -39,6 +39,7 @@ const Application = new Lang.Class({
         GLib.set_application_name('Polari');
         this._window = null;
         this._pendingRequests = {};
+        this._startHidden = false;
     },
 
     vfunc_startup: function() {
@@ -92,6 +93,8 @@ const Application = new Lang.Class({
           { name: 'edit-connection',
             activate: Lang.bind(this, this._onEditConnection),
             parameter_type: GLib.VariantType.new('o') },
+          { name: 'run-in-background',
+            activate: Lang.bind(this, this._onRunInBackground) },
           { name: 'help',
             activate: Lang.bind(this, this._onShowHelp),
             accels: ['F1'] },
@@ -149,11 +152,13 @@ const Application = new Lang.Class({
                         this._pendingRequests[id].cancellable.cancel();
                     this.emit('prepare-shutdown');
             }));
-            this._window.show_all();
+            if (!this._startHidden)
+                this._window.present();
 
             this._chatroomManager.lateInit();
+        } else {
+            this._window.present();
         }
-        this._window.present();
     },
 
     vfunc_open: function(files) {
@@ -595,6 +600,15 @@ const Application = new Lang.Class({
         dialog.show();
     },
 
+    _onRunInBackground: function() {
+        if (this._window) {
+            this._window.hide();
+        } else {
+            this._startHidden = true;
+            this.activate();
+        }
+    },
+
     _onShowHelp: function() {
         Utils.openURL('help:org.gnome.Polari', Gtk.get_current_event_time());
     },


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