[polari] ui: Update join-dialog/connection-details-dialog



commit 96932bd60fdaf798e5bfd34e12f706e4d53154be
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon May 26 20:03:49 2014 +0200

    ui: Update join-dialog/connection-details-dialog
    
    Update ConnectionDetails to not provide its own action buttons and
    switch the remaining dialogs over to use buttons in the header.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730776

 data/resources/connection-details-dialog.ui |   59 +----------------
 data/resources/join-room-dialog.ui          |   94 +++++++++------------------
 src/connections.js                          |   64 +++++++++---------
 src/joinDialog.js                           |   55 ++++++++++------
 4 files changed, 103 insertions(+), 169 deletions(-)
---
diff --git a/data/resources/connection-details-dialog.ui b/data/resources/connection-details-dialog.ui
index 6416962..7678373 100644
--- a/data/resources/connection-details-dialog.ui
+++ b/data/resources/connection-details-dialog.ui
@@ -28,10 +28,10 @@
           <object class="GtkGrid" id="connection_details_content">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="margin_left">12</property>
-            <property name="margin_right">12</property>
-            <property name="margin_top">36</property>
-            <property name="margin_bottom">0</property>
+            <property name="margin_left">24</property>
+            <property name="margin_right">24</property>
+            <property name="margin_top">24</property>
+            <property name="margin_bottom">24</property>
             <property name="row_spacing">12</property>
             <property name="column_spacing">12</property>
             <child>
@@ -171,53 +171,6 @@
                 <property name="height">1</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButtonBox" id="button_box1">
-                <property name="can_focus">False</property>
-                <property name="visible">True</property>
-                <property name="spacing">12</property>
-                <property name="margin_top">24</property>
-                <property name="vexpand">True</property>
-                <property name="valign">end</property>
-                <property name="layout_style">end</property>
-                <child>
-                  <object class="GtkButton" id="cancel_button">
-                    <property name="label" translatable="yes">_Cancel</property>
-                    <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="use_underline">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkButton" id="confirm_button">
-                    <property name="label" translatable="yes">Cr_eate</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="can_default">True</property>
-                    <property name="has_default">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="use_underline">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-              </object>
-              <packing>
-                <property name="top_attach">4</property>
-                <property name="left_attach">1</property>
-                <property name="width">2</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -227,9 +180,5 @@
         </child>
       </object>
     </child>
-    <action-widgets>
-      <action-widget response="-6">cancel_button</action-widget>
-      <action-widget response="-5">confirm_button</action-widget>
-    </action-widgets>
   </object>
 </interface>
diff --git a/data/resources/join-room-dialog.ui b/data/resources/join-room-dialog.ui
index 8944747..7f75981 100644
--- a/data/resources/join-room-dialog.ui
+++ b/data/resources/join-room-dialog.ui
@@ -18,6 +18,7 @@
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
     <property name="default_width">500</property>
+    <property name="use_header_bar">1</property>
     <child type="titlebar">
       <object class="GtkHeaderBar" id="titlebar">
         <property name="visible">True</property>
@@ -38,6 +39,32 @@
             </child>
           </object>
         </child>
+        <child>
+          <object class="GtkButton" id="cancel_button">
+            <property name="label" translatable="yes">_Cancel</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="confirm_button">
+            <property name="label" translatable="yes">_Join</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="has_default">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
       </object>
     </child>
     <child internal-child="vbox">
@@ -45,18 +72,6 @@
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkStack" id="stack">
             <property name="visible">True</property>
@@ -65,10 +80,10 @@
               <object class="GtkGrid" id="grid1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="margin_left">12</property>
-                <property name="margin_right">12</property>
-                <property name="margin_top">36</property>
-                <property name="margin_bottom">0</property>
+                <property name="margin_left">24</property>
+                <property name="margin_right">24</property>
+                <property name="margin_top">24</property>
+                <property name="margin_bottom">24</property>
                 <property name="row_spacing">12</property>
                 <property name="column_spacing">12</property>
                 <child>
@@ -224,53 +239,6 @@
                     <property name="height">1</property>
                   </packing>
                 </child>
-                <child>
-                  <object class="GtkButtonBox" id="button_box1">
-                    <property name="visible">True</property>
-                    <property name="spacing">12</property>
-                    <property name="margin_top">24</property>
-                    <property name="vexpand">True</property>
-                    <property name="valign">end</property>
-                    <property name="can_focus">False</property>
-                    <property name="layout_style">end</property>
-                    <child>
-                      <object class="GtkButton" id="cancel_button">
-                        <property name="label" translatable="yes">_Cancel</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="use_underline">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkButton" id="join_button">
-                        <property name="label" translatable="yes">_Join</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="can_default">True</property>
-                        <property name="has_default">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="use_underline">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">3</property>
-                    <property name="width">3</property>
-                    <property name="height">1</property>
-                  </packing>
-                </child>
               </object>
               <packing>
                 <property name="name">main</property>
diff --git a/src/connections.js b/src/connections.js
index 7b8d5fd..585de5d 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -190,10 +190,6 @@ const ConnectionDetails = new Lang.Class({
         return params;
     },
 
-    setCancelVisible: function(visible) {
-        this._cancelButton.visible = visible;
-    },
-
     reset: function() {
         this._serverEntry.text = '';
         this._descEntry.text = '';
@@ -212,27 +208,15 @@ const ConnectionDetails = new Lang.Class({
         this._descEntry = builder.get_object('description_entry');
         this._nickEntry = builder.get_object('nickname_entry');
         this._realnameEntry = builder.get_object('realname_entry');
-        this.confirmButton = builder.get_object('confirm_button');
-        this._cancelButton = builder.get_object('cancel_button');
-
-        this.confirmButton.connect('clicked',
-                                    Lang.bind(this, this._onConfirmClicked));
-        this._cancelButton.connect('clicked', Lang.bind(this,
-            function() {
-                this.emit('response', Gtk.ResponseType.CANCEL);
-            }));
 
         this._serverEntry.connect('changed',
-                                  Lang.bind(this, this._updateSensitivity));
+                                  Lang.bind(this, this._onCanConfirmChanged));
         this._nickEntry.connect('changed',
-                                Lang.bind(this, this._updateSensitivity));
-        this._updateSensitivity();
+                                Lang.bind(this, this._onCanConfirmChanged));
     },
 
-    _updateSensitivity: function() {
-        let sensitive = this._serverEntry.get_text_length() > 0 &&
-                        this._nickEntry.get_text_length() > 0;
-        this.confirmButton.sensitive = sensitive;
+    _onCanConfirmChanged: function() {
+        this.emit('can-confirm-changed');
     },
 
     _populateFromAccount: function(account) {
@@ -256,13 +240,19 @@ const ConnectionDetails = new Lang.Class({
             this._descEntry.text = account.display_name;
     },
 
-    _onConfirmClicked: function() {
+    get canConfirm() {
+        return this._serverEntry.get_text_length() > 0 &&
+               this._nickEntry.get_text_length() > 0;
+    },
+
+    save: function() {
+        if (!this.canConfirm)
+            return;
+
         if (this._account)
             this._updateAccount();
         else
             this._createAccount();
-
-        this.emit('response', Gtk.ResponseType.OK);
     },
 
     _createAccount: function() {
@@ -331,17 +321,29 @@ const ConnectionDetailsDialog = new Lang.Class({
                             : _("New Connection");
         this.widget = new Gtk.Dialog({ title: title,
                                        modal: true,
-                                       destroy_with_parent: true });
+                                       destroy_with_parent: true,
+                                       use_header_bar: true });
+        this.widget.connect('response', Lang.bind(this,
+            function(w, response) {
+                if (response == Gtk.ResponseType.OK)
+                    this._details.save();
+            }));
+
+        this.widget.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL);
+
+        let confirmLabel = account ? _("A_pply") : _("Cr_eate");
+        this._confirmButton = this.widget.add_button(confirmLabel,
+                                                     Gtk.ResponseType.OK);
+        this._confirmButton.get_style_context().add_class('suggested-action');
 
         this._details = new ConnectionDetails(account);
+        this._details.connect('can-confirm-changed',
+                              Lang.bind(this, this._updateCanConfirm));
         this.widget.get_content_area().add(this._details.widget);
+        this._updateCanConfirm();
+    },
 
-        this._details.confirmButton.label = account ? _("A_pply")
-                                                    : _("Cr_eate");
-
-        this._details.connect('response', Lang.bind(this,
-            function(details, response) {
-                this.widget.response(response);
-            }));
+    _updateCanConfirm: function() {
+        this._confirmButton.sensitive = this._details.canConfirm;
     }
 });
diff --git a/src/joinDialog.js b/src/joinDialog.js
index a55dd8d..de9aa46 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -64,14 +64,8 @@ const JoinDialog = new Lang.Class({
 
         this._details = new Connections.ConnectionDetails(null);
         this._stack.add_named(this._details.widget, 'connection');
-
-        this._details.confirmButton.label = _("_Save");
-        this._details.setCancelVisible(false);
-
-        this._details.connect('response', Lang.bind(this,
-            function() {
-                this._setPage(DialogPage.MAIN);
-            }));
+        this._details.connect('can-confirm-changed',
+                              Lang.bind(this, this._updateCanConfirm));
 
         this._connectionButton = builder.get_object('add_connection_button');
         this._connectionButton.connect('clicked', Lang.bind(this,
@@ -95,10 +89,11 @@ const JoinDialog = new Lang.Class({
                                       Lang.bind(this, this._onAccountChanged));
         this._connectionCombo.sensitive = false;
 
-        this._joinButton = builder.get_object('join_button');
-        this._joinButton.connect('clicked',
-                                 Lang.bind(this, this._onJoinClicked));
-        this._joinButton.sensitive = false;
+        this._confirmButton = builder.get_object('confirm_button');
+        this._confirmButton.connect('clicked',
+                                    Lang.bind(this, this._onConfirmClicked));
+
+        this._cancelButton = builder.get_object('cancel_button');
 
         this._nameCompletion = builder.get_object('name_completion');
         this._nameEntry = builder.get_object('name_entry');
@@ -138,8 +133,17 @@ const JoinDialog = new Lang.Class({
             }));
     },
 
+    _onConfirmClicked: function() {
+        if (this._page == DialogPage.MAIN) {
+            this._joinRoom();
+            this.widget.response(Gtk.ResponseType.OK);
+        } else {
+            this._details.save();
+            this._setPage(DialogPage.MAIN);
+        }
+    },
 
-    _onJoinClicked: function() {
+    _joinRoom: function() {
         this.widget.hide();
 
         let selected = this._connectionCombo.get_active_text();
@@ -155,7 +159,6 @@ const JoinDialog = new Lang.Class({
                                          [ account.get_object_path(),
                                            room,
                                            TP_CURRENT_TIME ]));
-        this.widget.response(Gtk.ResponseType.OK);
     },
 
     _updateConnectionCombo: function() {
@@ -173,25 +176,37 @@ const JoinDialog = new Lang.Class({
     },
 
     _updateCanConfirm: function() {
+        if (this._page == DialogPage.MAIN) {
             let sensitive = this._connectionCombo.get_active() > -1  &&
                             this._nameEntry.get_text_length() > 0;
-            this._joinButton.sensitive = sensitive;
+            this._confirmButton.sensitive = sensitive;
+        } else {
+            this._confirmButton.sensitive = this._details.canConfirm;
+        }
+    },
+
+    get _page() {
+        if (this._stack.visible_child_name == 'connection')
+            return DialogPage.CONNECTION;
+        else
+            return DialogPage.MAIN;
     },
 
     _setPage: function(page) {
         let isMain = page == DialogPage.MAIN;
 
-        if (isMain) {
+        if (isMain)
             this._details.reset();
 
-            this._joinButton.grab_default();
-        } else {
-            this._details.confirmButton.grab_default();
-        }
+        this._confirmButton.grab_default();
 
         this._backButton.visible = !isMain;
+        this._cancelButton.visible = isMain;
         this._titlebar.title = isMain ? _("Join Chat Room")
                                       : _("Add Connection");
+        this._confirmButton.label = isMain ? _("_Join")
+                                           : _("_Save");
         this._stack.visible_child_name = isMain ? 'main' : 'connection';
+        this._updateCanConfirm();
     }
 });


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