[gnome-photos/wip/abono/gui-refactoring: 4/8] main-toolbar: Port to template



commit fd2bcddeb73562f7590be46646015e4f6c3a2197
Author: Alessandro Bono <abono gnome org>
Date:   Thu Feb 16 23:08:08 2017 +0100

    main-toolbar: Port to template

 src/photos-main-toolbar.c  |   16 +++++++++-------
 src/photos-main-toolbar.ui |   11 +++++++++++
 src/photos.gresource.xml   |    1 +
 3 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index a43584a..d88635d 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -756,16 +756,11 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
-  gtk_widget_show (GTK_WIDGET (self));
-
-  self->header_bar = photos_header_bar_new ();
-  gtk_container_add (GTK_CONTAINER (self), self->header_bar);
-  gtk_widget_show (self->header_bar);
-
   self->gear_menu = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "gear-menu"));
   self->search = g_action_map_lookup_action (G_ACTION_MAP (app), "search");
 
+  gtk_widget_init_template (GTK_WIDGET (self));
+
   builder = gtk_builder_new_from_resource ("/org/gnome/Photos/selection-menu.ui");
 
   selection_menu = G_MENU (gtk_builder_get_object (builder, "selection-menu"));
@@ -814,11 +809,15 @@ static void
 photos_main_toolbar_class_init (PhotosMainToolbarClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class;
 
   object_class->constructed = photos_main_toolbar_constructed;
   object_class->dispose = photos_main_toolbar_dispose;
   object_class->set_property = photos_main_toolbar_set_property;
 
+  widget_class = GTK_WIDGET_CLASS (class);
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/main-toolbar.ui");
+
   g_object_class_install_property (object_class,
                                    PROP_OVERLAY,
                                    g_param_spec_object ("overlay",
@@ -826,6 +825,9 @@ photos_main_toolbar_class_init (PhotosMainToolbarClass *class)
                                                         "The stack overlay widget",
                                                         GTK_TYPE_OVERLAY,
                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+
+  gtk_widget_class_bind_template_child (widget_class, PhotosMainToolbar, header_bar);
 }
 
 
diff --git a/src/photos-main-toolbar.ui b/src/photos-main-toolbar.ui
new file mode 100644
index 0000000..18cdff8
--- /dev/null
+++ b/src/photos-main-toolbar.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <template class="PhotosMainToolbar" parent="GtkBox">
+    <property name="visible">1</property>
+    <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+    <child>
+      <object class="PhotosHeaderBar" id="header_bar"></object>
+    </child>
+  </template>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 5cac26c..8e814c3 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -6,6 +6,7 @@
     <file alias="dnd-counter.svg" preprocess="to-pixdata">../data/dnd-counter.svg</file>
     <file alias="dropdown.ui" preprocess="xml-stripblanks" compressed="true">photos-dropdown.ui</file>
     <file alias="export-dialog.ui" preprocess="xml-stripblanks" 
compressed="true">photos-export-dialog.ui</file>
+    <file alias="main-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-main-toolbar.ui</file>
     <file alias="preview-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-preview-menu.ui</file>
     <file alias="selection-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-menu.ui</file>
     <file alias="selection-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-toolbar.ui</file>


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