[gnome-control-center] window: Move remaining UI declarations to GtkBuilder file



commit 4f40a2fa339933f0c0626b5675bdbc0777e67019
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Jan 21 10:14:12 2018 -0200

    window: Move remaining UI declarations to GtkBuilder file
    
    There were leftover UI declarations in the source code, breaking
    the nice split that it having the UI declared in the GtkBuilder
    file while the logic is programmed.
    
    This commit moves the remaining widgets declared in the source
    code, the connected signals using and the binded properties to
    the GtkBuilder file. This led to a nice cleanup in the source
    code.

 shell/cc-window.c |  108 +++++++++++-----------------------------------------
 shell/window.ui   |   17 ++++++++
 2 files changed, 40 insertions(+), 85 deletions(-)
---
diff --git a/shell/cc-window.c b/shell/cc-window.c
index b3800ac..3d1e0fb 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -87,31 +87,6 @@ enum
   PROP_ACTIVE_PANEL
 };
 
-static void     panel_list_view_changed_cb  (CcPanelList  *panel_list,
-                                             GParamSpec   *pspec,
-                                             CcWindow     *self);
-
-static gboolean set_active_panel_from_id    (CcShell      *shell,
-                                             const gchar  *start_id,
-                                             GVariant     *parameters,
-                                             GError      **error);
-
-static void     show_panel_cb               (CcPanelList  *panel_list,
-                                             const gchar  *panel_id,
-                                             CcWindow     *self);
-
-static void     split_decorations_cb        (GtkSettings  *settings,
-                                             GParamSpec   *pspec,
-                                             CcWindow     *self);
-
-static gboolean window_key_press_event_cb   (GtkWidget    *win,
-                                             GdkEventKey  *event,
-                                             CcWindow     *self);
-
-static gboolean window_button_release_event_cb (GtkWidget      *win,
-                                                GdkEventButton *event,
-                                                CcWindow       *self);
-
 /* Auxiliary methods */
 static const gchar *
 get_icon_name_from_g_icon (GIcon *gicon)
@@ -404,62 +379,6 @@ set_active_panel (CcWindow *shell,
     }
 }
 
-static void
-create_window (CcWindow *self)
-{
-  GtkSettings *settings;
-  AtkObject *accessible;
-
-  /* previous button */
-  accessible = gtk_widget_get_accessible (self->previous_button);
-  atk_object_set_name (accessible, _("All Settings"));
-
-  gtk_window_set_titlebar (GTK_WINDOW (self), self->header_box);
-  gtk_widget_show_all (self->header_box);
-
-  /*
-   * We have to create the listbox here because declaring it in window.ui
-   * and letting GtkBuilder handle it would hit the bug where the focus is
-   * not tracked.
-   */
-  self->panel_list = cc_panel_list_new ();
-
-  g_signal_connect (self->panel_list, "show-panel", G_CALLBACK (show_panel_cb), self);
-  g_signal_connect (self->panel_list, "notify::view", G_CALLBACK (panel_list_view_changed_cb), self);
-
-  g_object_bind_property (self->search_bar,
-                          "search-mode-enabled",
-                          self->panel_list,
-                          "search-mode",
-                          G_BINDING_BIDIRECTIONAL);
-
-  g_object_bind_property (self->search_entry,
-                          "text",
-                          self->panel_list,
-                          "search-query",
-                          G_BINDING_DEFAULT);
-
-  gtk_container_add (GTK_CONTAINER (self->list_scrolled), self->panel_list);
-  gtk_widget_show (self->panel_list);
-
-  setup_model (self);
-
-  /* connect various signals */
-  gtk_widget_add_events (GTK_WIDGET (self), GDK_BUTTON_RELEASE_MASK);
-
-  g_signal_connect_after (self, "key_press_event", G_CALLBACK (window_key_press_event_cb), self);
-  g_signal_connect (self, "button-release-event", G_CALLBACK (window_button_release_event_cb), self);
-
-  /* handle decorations for the split headers. */
-  settings = gtk_settings_get_default ();
-  g_signal_connect (settings,
-                    "notify::gtk-decoration-layout",
-                    G_CALLBACK (split_decorations_cb),
-                    self);
-
-  split_decorations_cb (settings, NULL, self);
-}
-
 /* Callbacks */
 static void
 show_panel_cb (CcPanelList *panel_list,
@@ -769,6 +688,7 @@ cc_window_class_init (CcWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcWindow, list_scrolled);
   gtk_widget_class_bind_template_child (widget_class, CcWindow, lock_button);
   gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_headerbar);
+  gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_list);
   gtk_widget_class_bind_template_child (widget_class, CcWindow, previous_button);
   gtk_widget_class_bind_template_child (widget_class, CcWindow, search_bar);
   gtk_widget_class_bind_template_child (widget_class, CcWindow, search_button);
@@ -776,24 +696,42 @@ cc_window_class_init (CcWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcWindow, stack);
   gtk_widget_class_bind_template_child (widget_class, CcWindow, top_right_box);
 
-  gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, gdk_window_set_cb);
+  gtk_widget_class_bind_template_callback (widget_class, panel_list_view_changed_cb);
+  gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb);
+  gtk_widget_class_bind_template_callback (widget_class, show_panel_cb);
   gtk_widget_class_bind_template_callback (widget_class, update_list_title);
+  gtk_widget_class_bind_template_callback (widget_class, window_button_release_event_cb);
+  gtk_widget_class_bind_template_callback (widget_class, window_key_press_event_cb);
   gtk_widget_class_bind_template_callback (widget_class, window_map_event_cb);
+
+  g_type_ensure (CC_TYPE_PANEL_LIST);
 }
 
 static void
 cc_window_init (CcWindow *self)
 {
+  GtkSettings *settings;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  create_window (self);
+  gtk_widget_add_events (GTK_WIDGET (self), GDK_BUTTON_RELEASE_MASK);
 
-  self->previous_panels = g_queue_new ();
+  /* Handle decorations for the split headers. */
+  settings = gtk_settings_get_default ();
+  g_signal_connect (settings,
+                    "notify::gtk-decoration-layout",
+                    G_CALLBACK (split_decorations_cb),
+                    self);
+
+  split_decorations_cb (settings, NULL, self);
 
-  /* keep a list of custom widgets to unload on panel change */
+  /* Add the panels */
   self->custom_widgets = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+  self->previous_panels = g_queue_new ();
+
+  setup_model (self);
 
   /* After everything is loaded, select the first visible panel */
   cc_panel_list_activate (CC_PANEL_LIST (self->panel_list));
diff --git a/shell/window.ui b/shell/window.ui
index 526405f..92ff197 100644
--- a/shell/window.ui
+++ b/shell/window.ui
@@ -8,6 +8,8 @@
     <property name="default-height">640</property>
     <signal name="notify::window" handler="gdk_window_set_cb" object="CcWindow" swapped="no" />
     <signal name="map-event" handler="window_map_event_cb" object="CcWindow" swapped="no" />
+    <signal name="key-press-event" handler="window_key_press_event_cb" object="CcWindow" swapped="no" 
after="yes" />
+    <signal name="button-release-event" handler="window_button_release_event_cb" object="CcWindow" 
swapped="no" />
     <child>
       <object class="GtkBox" id="main_hbox">
         <property name="visible">True</property>
@@ -55,6 +57,16 @@
                 <style>
                   <class name="view"/>
                 </style>
+                <child>
+                  <object class="CcPanelList" id="panel_list">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="search-mode" bind-source="search_bar" 
bind-property="search-mode-enabled" bind-flags="bidirectional" />
+                    <property name="search-query" bind-source="search_entry" bind-property="text" 
bind-flags="default" />
+                    <signal name="show-panel" handler="show_panel_cb" object="CcWindow" swapped="no" />
+                    <signal name="notify::view" handler="panel_list_view_changed_cb" object="CcWindow" 
swapped="no" />
+                  </object>
+                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -124,6 +136,11 @@
                     <property name="icon_name">go-previous-symbolic</property>
                   </object>
                 </child>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="a11y-button1">
+                    <property name="accessible-name" translatable="yes">All Settings</property>
+                  </object>
+                </child>
                 <style>
                   <class name="image-button"/>
                 </style>


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