[gnome-calendar/ui-rewrite] window: move to builder's ui file



commit fb4c018c15e2167a98cc2198bdfa580be750e1ad
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Nov 24 23:59:12 2014 -0200

    window: move to builder's ui file
    
    This is way better than programmatically building the entire window interface.

 data/Makefile.am            |    1 +
 data/calendar.gresource.xml |    1 +
 data/ui/window.ui           |  147 +++++++++++++++++++++++++++++++++++++++++++
 src/gcal-window.c           |  121 +++++++----------------------------
 4 files changed, 173 insertions(+), 97 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 17d2faf..41d039c 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -22,6 +22,7 @@ EXTRA_DIST=                     \
   ui/menus.ui                   \
   ui/nav_bar.ui                 \
   ui/new-event.ui               \
+  ui/window.ui                  \
   theme/gtk-styles.css          \
   $(desktop_in_files)           \
   $(gsettingsschema_in_files)
diff --git a/data/calendar.gresource.xml b/data/calendar.gresource.xml
index f4ccefa..a164d37 100644
--- a/data/calendar.gresource.xml
+++ b/data/calendar.gresource.xml
@@ -5,6 +5,7 @@
     <file alias="menus.ui" compressed="true" preprocess="xml-stripblanks">ui/menus.ui</file>
     <file alias="nav_bar.ui" compressed="true" preprocess="xml-stripblanks">ui/nav_bar.ui</file>
     <file alias="new-event.ui" compressed="true" preprocess="xml-stripblanks">ui/new-event.ui</file>
+    <file alias="window.ui" compressed="true" preprocess="xml-stripblanks">ui/window.ui</file>
     <file alias="gtk-styles.css" compressed="true">theme/gtk-styles.css</file>
   </gresource>
 </gresources>
diff --git a/data/ui/window.ui b/data/ui/window.ui
new file mode 100644
index 0000000..5378fc8
--- /dev/null
+++ b/data/ui/window.ui
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.14"/>
+  <template class="GcalWindow" parent="GtkApplicationWindow">
+    <property name="can_focus">False</property>
+    <property name="window_position">center</property>
+    <property name="default_width">800</property>
+    <property name="default_height">600</property>
+    <property name="show_menubar">False</property>
+    <child>
+      <object class="GtkOverlay" id="views_overlay">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkGrid" id="main_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <child>
+              <object class="GtkSearchBar" id="search_bar">
+                <property name="app_paintable">True</property>
+                <property name="can_focus">False</property>
+                <property name="no_show_all">True</property>
+                <property name="hexpand">True</property>
+                <property name="show_close_button">True</property>
+                <child>
+                  <object class="GtkGrid" id="search_entry_grid">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkSearchEntry" id="search_entry">
+                        <property name="width_request">500</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="halign">center</property>
+                        <property name="hexpand">True</property>
+                        <property name="primary_icon_name">edit-find-symbolic</property>
+                        <property name="primary_icon_activatable">False</property>
+                        <property name="primary_icon_sensitive">False</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkStack" id="views_stack">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="transition_duration">250</property>
+                <property name="transition_type">slide-left-right</property>
+                <style>
+                  <class name="views"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GcalNavBar" id="nav_bar">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="header_bar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+        <child>
+          <object class="GtkButton" id="today_button">
+            <property name="label" translatable="yes">Today</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+          </object>
+        </child>
+        <child type="title">
+          <object class="GtkStackSwitcher" id="views_switcher">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="stack">views_stack</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkMenuButton" id="menu_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <child>
+              <object class="GtkImage" id="menu_image">
+                <property name="can_focus">False</property>
+                <property name="icon_name">open-menu-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkToggleButton" id="search_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <child>
+              <object class="GtkImage" id="search_button_image">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">edit-find-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <style>
+      <class name="views"/>
+    </style>
+  </template>
+</interface>
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 40031ed..231fb16 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -67,8 +67,10 @@ typedef struct
   GtkWidget           *popover; /* short-lived */
 
   /* header_bar widets */
-  GtkWidget           *today_button;
+  GtkWidget           *menu_button;
+  GtkWidget           *search_button;
   GtkWidget           *search_entry;
+  GtkWidget           *today_button;
   GtkWidget           *views_switcher;
 
   /* day, week, month, year, list, search */
@@ -926,6 +928,7 @@ gcal_window_class_init(GcalWindowClass *klass)
   widget_class = GTK_WIDGET_CLASS (klass);
   widget_class->configure_event = gcal_window_configure_event;
   widget_class->window_state_event = gcal_window_state_event;
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/window.ui");
 
   g_object_class_install_property (
       object_class,
@@ -964,6 +967,19 @@ gcal_window_class_init(GcalWindowClass *klass)
                             "A weak reference to the app manager object",
                             G_PARAM_CONSTRUCT_ONLY |
                             G_PARAM_READWRITE));
+
+  /* widgets */
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, header_bar);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, main_box);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, menu_button);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, nav_bar);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, search_bar);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, search_button);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, search_entry);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, today_button);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, views_overlay);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, views_stack);
+  gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, views_switcher);
 }
 
 static void
@@ -982,6 +998,8 @@ gcal_window_init (GcalWindow *self)
   priv->save_geometry_timeout_id = 0;
   priv->event_to_delete = NULL;
   priv->open_edit_dialog = FALSE;
+
+  gtk_widget_init_template (GTK_WIDGET (self));
 }
 
 static void
@@ -989,10 +1007,7 @@ gcal_window_constructed (GObject *object)
 {
   GcalWindowPrivate *priv;
 
-  GtkWidget *box;
-  GtkWidget *search_button;
 
-  GtkWidget *menu_button;
   GtkBuilder *builder;
   GMenuModel *winmenu;
 
@@ -1012,34 +1027,14 @@ gcal_window_constructed (GObject *object)
   g_free (clock_format);
   g_object_unref (helper_settings);
 
-  /* ui construction */
-  priv->main_box = gtk_grid_new ();
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->main_box),
-                                  GTK_ORIENTATION_VERTICAL);
-
-  /* header_bar */
-  priv->header_bar = gtk_header_bar_new ();
-
-  /* header_bar: new */
-  priv->today_button = gtk_button_new_with_label (_("Today"));
-  gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->header_bar),
-                             priv->today_button);
-
-  priv->views_switcher = gtk_stack_switcher_new ();
-  g_object_ref_sink (priv->views_switcher);
-  gtk_header_bar_set_custom_title (GTK_HEADER_BAR (priv->header_bar),
-                                   priv->views_switcher);
 
   /* header_bar: menu */
-  menu_button = gtk_menu_button_new ();
-  gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (menu_button),
+  gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (priv->menu_button),
                                    TRUE);
   gtk_button_set_image (
-      GTK_BUTTON (menu_button),
+      GTK_BUTTON (priv->menu_button),
       gtk_image_new_from_icon_name ("open-menu-symbolic",
                                     GTK_ICON_SIZE_MENU));
-  gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header_bar),
-                           menu_button);
 
   builder = gtk_builder_new ();
   gtk_builder_add_from_resource (builder,
@@ -1047,76 +1042,18 @@ gcal_window_constructed (GObject *object)
                                  NULL);
 
   winmenu = (GMenuModel *)gtk_builder_get_object (builder, "winmenu");
-  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_button),
+  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->menu_button),
                                   winmenu);
 
   g_object_unref (builder);
 
-  /* header_bar: search */
-  search_button = gtk_toggle_button_new ();
-  gtk_container_add (
-      GTK_CONTAINER (search_button),
-      gtk_image_new_from_icon_name ("edit-find-symbolic",
-                                    GTK_ICON_SIZE_MENU));
-  gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->header_bar),
-                           search_button);
-
-  gtk_header_bar_set_show_close_button (
-      GTK_HEADER_BAR (priv->header_bar),
-      TRUE);
-
-  gtk_widget_set_hexpand (priv->header_bar, TRUE);
-  gtk_window_set_titlebar (GTK_WINDOW (object), priv->header_bar);
-
-  /* search_bar */
-  priv->search_entry = gtk_search_entry_new ();
-  g_object_set (priv->search_entry,
-                "width-request", 500,
-                "hexpand", TRUE,
-                "halign", GTK_ALIGN_CENTER,
-                NULL);
-
-  box = gtk_grid_new ();
-  gtk_container_add (GTK_CONTAINER (box), priv->search_entry);
-
-  priv->search_bar = gtk_search_bar_new ();
-  gtk_widget_set_no_show_all (priv->search_bar, TRUE);
+  /* search bar */
   gtk_search_bar_connect_entry (GTK_SEARCH_BAR (priv->search_bar),
                                 GTK_ENTRY (priv->search_entry));
-  gtk_widget_set_hexpand (priv->search_bar, TRUE);
-  g_object_bind_property (search_button, "active",
+  g_object_bind_property (priv->search_button, "active",
                           priv->search_bar, "search-mode-enabled",
                           G_BINDING_BIDIRECTIONAL);
-  gtk_container_add (GTK_CONTAINER (priv->search_bar), box);
-  gtk_container_add (GTK_CONTAINER (priv->main_box), priv->search_bar);
-  gtk_widget_show_all (box);
-
-  /* overlay */
-  priv->views_overlay = gtk_overlay_new ();
-  gtk_container_add (GTK_CONTAINER (priv->main_box), priv->views_overlay);
-
-  box = gtk_grid_new ();
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
-                                  GTK_ORIENTATION_VERTICAL);
-  gtk_container_add (GTK_CONTAINER (priv->views_overlay), box);
-
-  /* nav_bar */
-  priv->nav_bar = gcal_nav_bar_new ();
-  gtk_container_add (GTK_CONTAINER (box), priv->nav_bar);
-
-  /* stack widget for holding views */
-  priv->views_stack = gtk_stack_new ();
-  g_object_set (priv->views_stack,
-                "vexpand", TRUE,
-                "hexpand", TRUE,
-                "transition-type", GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT,
-                "transition-duration", 250,
-                NULL);
-  gtk_container_add (GTK_CONTAINER (box), priv->views_stack);
 
-  gtk_style_context_add_class (
-      gtk_widget_get_style_context (priv->views_stack),
-      "views");
 
   priv->views[GCAL_WINDOW_VIEW_WEEK] =
     gcal_week_view_new (priv->manager);
@@ -1154,16 +1091,6 @@ gcal_window_constructed (GObject *object)
                           "active-date",
                           G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
 
-  gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (priv->views_switcher),
-                                GTK_STACK (priv->views_stack));
-
-  gtk_container_add (GTK_CONTAINER (object), priv->main_box);
-  gtk_widget_show_all (priv->main_box);
-
-  gtk_style_context_add_class (
-      gtk_widget_get_style_context (GTK_WIDGET (object)),
-      "views");
-
   /* popover and content */
   priv->popover = gtk_popover_new (GTK_WIDGET(priv->views_stack));
 


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