[polari] messageDialog: Use template



commit 63857414c39eea0eb6071b475fbb99932b4239be
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Feb 6 17:38:50 2016 +0100

    messageDialog: Use template
    
    As part of our move to consistently use inheritance, the few remaining
    classes that still use GtkBuilder directly need to be migrated to
    templates.

 data/resources/message-user-dialog.ui |   37 ++++++++++----------
 src/mainWindow.js                     |    5 +--
 src/messageDialog.js                  |   60 +++++++++++++++------------------
 3 files changed, 48 insertions(+), 54 deletions(-)
---
diff --git a/data/resources/message-user-dialog.ui b/data/resources/message-user-dialog.ui
index be68b21..87813ad 100644
--- a/data/resources/message-user-dialog.ui
+++ b/data/resources/message-user-dialog.ui
@@ -6,7 +6,7 @@
       <column type="gchararray"/>
     </columns>
   </object>
-  <object class="GtkEntryCompletion" id="name_completion">
+  <object class="GtkEntryCompletion" id="nameCompletion">
     <property name="model">liststore</property>
     <property name="text-column">0</property>
     <property name="inline-completion">True</property>
@@ -18,11 +18,10 @@
       </attributes>
     </child>
   </object>
-  <object class="GtkDialog" id="message_user_dialog">
+  <template class="Gjs_MessageDialog">
     <property name="modal">True</property>
-    <property name="use-header-bar">1</property>
     <child type="action">
-      <object class="GtkButton" id="cancel_button">
+      <object class="GtkButton" id="cancelButton">
         <property name="label" translatable="yes">_Cancel</property>
         <property name="visible">True</property>
         <property name="receives-default">True</property>
@@ -30,13 +29,14 @@
       </object>
     </child>
     <child type="action">
-      <object class="GtkButton" id="message_button">
+      <object class="GtkButton" id="messageButton">
         <property name="label" translatable="yes">_Message</property>
         <property name="visible">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>
+        <property name="sensitive">False</property>
       </object>
     </child>
     <child internal-child="vbox">
@@ -56,29 +56,30 @@
               </object>
             </child>
             <child>
-              <object class="GtkLabel" id="connection_label">
+              <object class="GtkLabel">
                 <property name="visible">True</property>
                 <property name="halign">end</property>
                 <property name="label" translatable="yes">C_onnection</property>
                 <property name="use-underline">True</property>
-                <property name="mnemonic-widget">connection_combo</property>
+                <property name="mnemonic-widget">connectionCombo</property>
               </object>
             </child>
             <child>
-              <object class="GtkComboBoxText" id="connection_combo">
+              <object class="GtkComboBoxText" id="connectionCombo">
                 <property name="visible">True</property>
                 <property name="hexpand">True</property>
+                <property name="sensitive">False</property>
               </object>
             </child>
             <child>
-              <object class="GtkLabel" id="recent_label">
+              <object class="GtkLabel">
                 <property name="visible">True</property>
                 <property name="halign">end</property>
                 <property name="valign">start</property>
                 <property name="margin-top">24</property>
                 <property name="label" translatable="yes">_Recent</property>
                 <property name="use-underline">True</property>
-                <property name="mnemonic-widget">recent_list</property>
+                <property name="mnemonic-widget">recentList</property>
               </object>
               <packing>
                 <property name="left-attach">1</property>
@@ -91,7 +92,7 @@
                 <property name="margin-top">24</property>
                 <property name="shadow-type">in</property>
                 <child>
-                  <object class="GtkListBox" id="recent_list">
+                  <object class="GtkListBox" id="recentList">
                     <property name="visible">True</property>
                     <property name="selection-mode">none</property>
                   </object>
@@ -103,12 +104,12 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="name_label">
+              <object class="GtkLabel">
                 <property name="visible">True</property>
                 <property name="halign">end</property>
                 <property name="label" translatable="yes">_Name</property>
                 <property name="use-underline">True</property>
-                <property name="mnemonic-widget">name_entry</property>
+                <property name="mnemonic-widget">nameEntry</property>
               </object>
               <packing>
                 <property name="left-attach">1</property>
@@ -116,10 +117,10 @@
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="name_entry">
+              <object class="GtkEntry" id="nameEntry">
                 <property name="visible">True</property>
                 <property name="activates-default">True</property>
-                <property name="completion">name_completion</property>
+                <property name="completion">nameCompletion</property>
               </object>
               <packing>
                 <property name="left-attach">2</property>
@@ -131,8 +132,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="cancel">cancel_button</action-widget>
-      <action-widget response="ok">message_button</action-widget>
+      <action-widget response="cancel">cancelButton</action-widget>
+      <action-widget response="ok">messageButton</action-widget>
     </action-widgets>
-  </object>
+  </template>
 </interface>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index f84b038..64c619e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -284,9 +284,8 @@ const MainWindow = new Lang.Class({
     },
 
     showMessageUserDialog: function() {
-        let dialog = new MessageDialog.MessageDialog();
-        dialog.widget.transient_for = this.window;
-        dialog.widget.show();
+        let dialog = new MessageDialog.MessageDialog({ transient_for: this.window });
+        dialog.show();
     },
 
     _updateUserListLabel: function() {
diff --git a/src/messageDialog.js b/src/messageDialog.js
index 4079a74..04067fe 100644
--- a/src/messageDialog.js
+++ b/src/messageDialog.js
@@ -13,9 +13,18 @@ const MAX_RECENT_USERS = 5;
 
 const MessageDialog = new Lang.Class({
     Name: 'MessageDialog',
+    Extends: Gtk.Dialog,
+    Template: 'resource:///org/gnome/Polari/ui/message-user-dialog.ui',
 
-    _init: function() {
-        this._createWidget();
+    InternalChildren: ['messageButton',
+                       'connectionCombo',
+                       'recentList',
+                       'nameEntry',
+                       'nameCompletion'],
+
+    _init: function(params) {
+        params['use-header-bar'] = 1;
+        this.parent(params);
 
         this._accounts = {};
         this._roomManager = ChatroomManager.getDefault();
@@ -35,6 +44,17 @@ const MessageDialog = new Lang.Class({
             this._connectionCombo.append_text(names[i]);
         this._connectionCombo.sensitive = names.length > 1;
 
+        this._connectionCombo.connect('changed',
+                                      Lang.bind(this, this._onAccountChanged));
+
+        this._recentList.connect('row-activated', Lang.bind(this,
+            function(w, row) {
+                this._nameEntry.text = row.name;
+            }));
+
+        this._nameEntry.connect('changed',
+                                Lang.bind(this, this._updateCanConfirm));
+
         let activeRoom = this._roomManager.getActiveRoom();
         let activeIndex = 0;
         if(activeRoom)
@@ -46,40 +66,14 @@ const MessageDialog = new Lang.Class({
 
         this._nameEntry.grab_focus();
 
-        this.widget.connect('response', Lang.bind(this,
+        this.connect('response', Lang.bind(this,
             function(w, response) {
                 if (response == Gtk.ResponseType.OK)
                     this._onMessageClicked();
-                this.widget.destroy();
+                this.destroy();
             }));
     },
 
-    _createWidget: function() {
-        let builder = new Gtk.Builder();
-        builder.add_from_resource('/org/gnome/Polari/ui/message-user-dialog.ui');
-
-        this.widget = builder.get_object('message_user_dialog');
-
-        this._connectionCombo = builder.get_object('connection_combo');
-        this._connectionCombo.connect('changed',
-                                      Lang.bind(this, this._onAccountChanged));
-        this._connectionCombo.sensitive = false;
-
-        this._recentList = builder.get_object('recent_list');
-        this._recentList.connect('row-activated', Lang.bind(this,
-            function(w, row) {
-                this._nameEntry.text = row.name;
-            }));
-        this._nameCompletion = builder.get_object('name_completion');
-
-        this._messageButton = builder.get_object('message_button');
-        this._messageButton.sensitive = false;
-
-        this._nameEntry = builder.get_object('name_entry');
-        this._nameEntry.connect('changed',
-                                Lang.bind(this, this._updateCanConfirm));
-    },
-
     _updateRecentList: function(names) {
         this._recentList.foreach(Lang.bind(this,
             function(row) {
@@ -163,7 +157,7 @@ const MessageDialog = new Lang.Class({
     },
 
     _onMessageClicked: function() {
-        this.widget.hide();
+        this.hide();
 
         let selected = this._connectionCombo.get_active_text();
         let account = this._accounts[selected];
@@ -183,7 +177,7 @@ const MessageDialog = new Lang.Class({
             let sensitive = this._connectionCombo.get_active() > -1  &&
                             this._nameEntry.get_text_length() > 0;
             this._messageButton.sensitive = sensitive;
-            this.widget.set_default_response(sensitive ? Gtk.ResponseType.OK
-                                                       : Gtk.ResponseType.NONE);
+            this.set_default_response(sensitive ? Gtk.ResponseType.OK
+                                                : Gtk.ResponseType.NONE);
     }
 });


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