[nautilus/wip/csoriano/window_gtkbuilder: 3/3] nautilus-window: Use GtkBuilder definition



commit f01175d4d99eeb2a4f48f1c695f9e51192248883
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Feb 11 12:34:04 2015 +0100

    nautilus-window: Use GtkBuilder definition

 src/nautilus-toolbar-ui.xml |    4 +
 src/nautilus-toolbar.c      |   22 ++++++-
 src/nautilus-toolbar.h      |    3 +-
 src/nautilus-window.c       |  132 ++++++++++++-------------------------------
 src/nautilus-window.xml     |   60 +++++++++++++++++++
 src/nautilus.gresource.xml  |    1 +
 6 files changed, 121 insertions(+), 101 deletions(-)
---
diff --git a/src/nautilus-toolbar-ui.xml b/src/nautilus-toolbar-ui.xml
index 160386a..68dfaef 100644
--- a/src/nautilus-toolbar-ui.xml
+++ b/src/nautilus-toolbar-ui.xml
@@ -4,6 +4,7 @@
   <template class="NautilusToolbar" parent="GtkHeaderBar">
     <property name="visible">True</property>
     <property name="show-close-button">True</property>
+    <property name="custom-title">label_null</property>
     <child>
       <object class="GtkBox" id="navigation_box">
         <property name="visible">True</property>
@@ -124,4 +125,7 @@
       </packing>
     </child>
   </template>
+   <object class="GtkButton" id="label_null">
+     <property name="visible">True</property>
+  </object>
 </interface>
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 93b1c1b..7c7bcd6 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -28,6 +28,7 @@
 
 #include "nautilus-location-entry.h"
 #include "nautilus-pathbar.h"
+#include "nautilus-window.h"
 
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <libnautilus-private/nautilus-ui-utilities.h>
@@ -408,10 +409,13 @@ static void
 nautilus_toolbar_init (NautilusToolbar *self)
 {
        GtkBuilder *builder;
+       GtkWidget *null_label;
+       GtkWidget *title;
 
        self->priv = nautilus_toolbar_get_instance_private (self);
        gtk_widget_init_template (GTK_WIDGET (self));
 
+       g_print("init\n");
        self->priv->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL);
        gtk_container_add (GTK_CONTAINER (self->priv->path_bar_container),
                                          self->priv->path_bar);
@@ -498,6 +502,7 @@ nautilus_toolbar_set_property (GObject *object,
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
        }
+  g_print ("set property\n");
 }
 
 static void
@@ -513,6 +518,14 @@ nautilus_toolbar_dispose (GObject *obj)
 }
 
 static void
+nautilus_toolbar_constructed (GObject *object)
+{
+       NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
+
+  g_print ("constructed\n");
+}
+
+static void
 nautilus_toolbar_class_init (NautilusToolbarClass *klass)
 {
        GObjectClass *oclass;
@@ -522,6 +535,7 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
        oclass = G_OBJECT_CLASS (klass);
        oclass->get_property = nautilus_toolbar_get_property;
        oclass->set_property = nautilus_toolbar_set_property;
+       oclass->constructed = nautilus_toolbar_constructed;
        oclass->dispose = nautilus_toolbar_dispose;
 
        properties[PROP_WINDOW] =
@@ -529,7 +543,7 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
                                     "The NautilusWindow",
                                     "The NautilusWindow this toolbar is part of",
                                     NAUTILUS_TYPE_WINDOW,
-                                    G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+                                    G_PARAM_WRITABLE |
                                     G_PARAM_STATIC_STRINGS);
        properties[PROP_SHOW_LOCATION_ENTRY] =
                g_param_spec_boolean ("show-location-entry",
@@ -549,6 +563,8 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
        gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, 
location_entry_container);
        gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, back_button);
        gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, forward_button);
+
+  g_print ("class init\n");
 }
 
 void
@@ -602,10 +618,10 @@ nautilus_toolbar_reset_menus (NautilusToolbar *self)
 }
 
 GtkWidget *
-nautilus_toolbar_new (NautilusWindow *window)
+nautilus_toolbar_new ()
 {
+       g_print ("new called  \n");
        return g_object_new (NAUTILUS_TYPE_TOOLBAR,
-                            "window", window,
                             "show-close-button", TRUE,
                             "custom-title", gtk_label_new (NULL),
                             "valign", GTK_ALIGN_CENTER,
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index 51a1d24..f281b95 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -27,7 +27,6 @@
 
 #include <gtk/gtk.h>
 
-#include "nautilus-window.h"
 
 #define NAUTILUS_TYPE_TOOLBAR nautilus_toolbar_get_type()
 #define NAUTILUS_TOOLBAR(obj) \
@@ -63,7 +62,7 @@ struct _NautilusToolbarClass {
 
 GType nautilus_toolbar_get_type (void);
 
-GtkWidget *nautilus_toolbar_new (NautilusWindow *window);
+GtkWidget *nautilus_toolbar_new (void);
 
 GtkWidget *nautilus_toolbar_get_path_bar (NautilusToolbar *self);
 GtkWidget *nautilus_toolbar_get_location_entry (NautilusToolbar *self);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 997e8eb..f697f01 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1298,21 +1298,12 @@ places_sidebar_populate_popup_cb (GtkPlacesSidebar *sidebar,
 static void
 nautilus_window_set_up_sidebar (NautilusWindow *window)
 {
-       window->priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-       gtk_style_context_add_class (gtk_widget_get_style_context (window->priv->sidebar),
-                                    GTK_STYLE_CLASS_SIDEBAR);
-
-       gtk_paned_pack1 (GTK_PANED (window->priv->content_paned),
-                        GTK_WIDGET (window->priv->sidebar),
-                        FALSE, FALSE);
-
        setup_side_pane_width (window);
        g_signal_connect (window->priv->sidebar,
                          "size-allocate",
                          G_CALLBACK (side_pane_size_allocate_callback),
                          window);
 
-       window->priv->places_sidebar = gtk_places_sidebar_new ();
        gtk_places_sidebar_set_open_flags (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
                                           (GTK_PLACES_OPEN_NORMAL
                                            | GTK_PLACES_OPEN_NEW_TAB
@@ -1336,22 +1327,6 @@ nautilus_window_set_up_sidebar (NautilusWindow *window)
 
        g_signal_connect (window, "loading-uri",
                          G_CALLBACK (window_loading_uri_cb), window);
-
-       gtk_box_pack_start (GTK_BOX (window->priv->sidebar), window->priv->places_sidebar, TRUE, TRUE, 0);
-       gtk_widget_show (window->priv->places_sidebar);
-       gtk_widget_show (window->priv->sidebar);
-}
-
-static void
-nautilus_window_tear_down_sidebar (NautilusWindow *window)
-{
-       DEBUG ("Destroying sidebar");
-
-       if (window->priv->sidebar != NULL) {
-               gtk_widget_destroy (GTK_WIDGET (window->priv->sidebar));
-               window->priv->sidebar = NULL;
-               window->priv->places_sidebar = NULL;
-       }
 }
 
 void
@@ -1363,7 +1338,7 @@ nautilus_window_hide_sidebar (NautilusWindow *window)
                return;
        }
 
-       nautilus_window_tear_down_sidebar (window);
+       gtk_widget_hide (window->priv->sidebar);
 }
 
 void
@@ -1371,15 +1346,12 @@ nautilus_window_show_sidebar (NautilusWindow *window)
 {
        DEBUG ("Called show_sidebar()");
 
-       if (window->priv->sidebar != NULL) {
-               return;
-       }
-
        if (window->priv->disable_chrome) {
                return;
        }
 
-       nautilus_window_set_up_sidebar (window);
+       gtk_widget_show (window->priv->sidebar);
+       setup_side_pane_width (window);
 }
 
 gboolean
@@ -1748,22 +1720,19 @@ nautilus_window_get_toolbar (NautilusWindow *window)
        return window->priv->toolbar;
 }
 
-static GtkWidget *
+static void
 create_toolbar (NautilusWindow *window)
 {
-       GtkWidget *toolbar;
        GtkWidget *path_bar;
        GtkWidget *location_entry;
 
-       /* build the toolbar */
-       toolbar = nautilus_toolbar_new (NAUTILUS_WINDOW (window));
-
+       g_object_set (window->priv->toolbar, "window", window, NULL);
        g_object_bind_property (window, "disable-chrome",
-                               toolbar, "visible",
+                               window->priv->toolbar, "visible",
                                G_BINDING_INVERT_BOOLEAN);
 
        /* connect to the pathbar signals */
-       path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (toolbar));
+       path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->priv->toolbar));
 
        g_signal_connect_object (path_bar, "path-clicked",
                                 G_CALLBACK (path_bar_location_changed_callback), window, 0);
@@ -1771,14 +1740,13 @@ create_toolbar (NautilusWindow *window)
                                 G_CALLBACK (path_bar_path_event_callback), window, 0);
 
        /* connect to the location entry signals */
-       location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (toolbar));
+       location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
 
        g_signal_connect_object (location_entry, "location-changed",
                                 G_CALLBACK (location_entry_location_changed_callback), window, 0);
        g_signal_connect_object (location_entry, "cancel",
                                 G_CALLBACK (location_entry_cancel_callback), window, 0);
 
-       return toolbar;
 }
 
 static void
@@ -1865,50 +1833,36 @@ notebook_create_window_cb (GtkNotebook *notebook,
        return GTK_NOTEBOOK (new_window->priv->notebook);
 }
 
-static GtkWidget *
+static void
 create_notebook (NautilusWindow *window)
 {
-       GtkWidget *notebook;
-
-       notebook = g_object_new (NAUTILUS_TYPE_NOTEBOOK, NULL);
-       g_signal_connect (notebook, "tab-close-request",
+       g_signal_connect (window->priv->notebook, "tab-close-request",
                          G_CALLBACK (notebook_tab_close_requested),
                          window);
-       g_signal_connect (notebook, "popup-menu",
+       g_signal_connect (window->priv->notebook, "popup-menu",
                          G_CALLBACK (notebook_popup_menu_cb),
                          window);
-       g_signal_connect (notebook, "switch-page",
+       g_signal_connect (window->priv->notebook, "switch-page",
                          G_CALLBACK (notebook_switch_page_cb),
                          window);
-       g_signal_connect (notebook, "create-window",
+       g_signal_connect (window->priv->notebook, "create-window",
                          G_CALLBACK (notebook_create_window_cb),
                          window);
-       g_signal_connect (notebook, "page-added",
+       g_signal_connect (window->priv->notebook, "page-added",
                          G_CALLBACK (notebook_page_added_cb),
                          window);
-       g_signal_connect (notebook, "page-removed",
+       g_signal_connect (window->priv->notebook, "page-removed",
                          G_CALLBACK (notebook_page_removed_cb),
                          window);
-       g_signal_connect_after (notebook, "button-press-event",
+       g_signal_connect_after (window->priv->notebook, "button-press-event",
                                G_CALLBACK (notebook_button_press_cb),
                                window);
-
-       gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
-       gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
-       gtk_widget_show (notebook);
-       gtk_container_set_border_width (GTK_CONTAINER (notebook), 0);
-
-       gtk_container_add (GTK_CONTAINER (window->priv->main_view),
-                           notebook);
-
-       return notebook;
 }
 
 static void
 nautilus_window_constructed (GObject *self)
 {
        NautilusWindow *window;
-       GtkWidget *grid;
        NautilusWindowSlot *slot;
        NautilusApplication *application;
 
@@ -1921,34 +1875,11 @@ nautilus_window_constructed (GObject *self)
        application = NAUTILUS_APPLICATION (g_application_get_default ());
        gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (application));
 
-       /* disable automatic menubar handling, since we show our regular
-        * menubar together with the app menu.
-        */
-       gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (self), FALSE);
-
-       grid = gtk_grid_new ();
-       gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
-       gtk_widget_show (grid);
-       gtk_container_add (GTK_CONTAINER (window), grid);
-
-       window->priv->toolbar = create_toolbar (window);
-       gtk_window_set_titlebar (GTK_WINDOW (window), window->priv->toolbar);
+       create_toolbar (window);
 
-       window->priv->content_paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
-       gtk_widget_set_hexpand (window->priv->content_paned, TRUE);
-       gtk_widget_set_vexpand (window->priv->content_paned, TRUE);
-
-       gtk_container_add (GTK_CONTAINER (grid), window->priv->content_paned);
-       gtk_widget_show (window->priv->content_paned);
-
-       window->priv->main_view = gtk_overlay_new ();
-       gtk_paned_pack2 (GTK_PANED (window->priv->content_paned),
-                         window->priv->main_view,
-                         TRUE, FALSE);
-       gtk_widget_show (window->priv->main_view);
-
-       window->priv->notebook = create_notebook (window);
        nautilus_window_set_initial_window_geometry (window);
+       create_notebook (window);
+       nautilus_window_set_up_sidebar (window);
 
        window->priv->notification_manager = GTK_WIDGET (nautilus_notification_manager_new ());
        gtk_overlay_add_overlay (GTK_OVERLAY (window->priv->main_view),
@@ -2040,9 +1971,6 @@ nautilus_window_destroy (GtkWidget *object)
 
        DEBUG ("Destroying window");
 
-       /* close the sidebar first */
-       nautilus_window_tear_down_sidebar (window);
-
        /* close all slots safely */
        slots_copy = g_list_copy (window->priv->slots);
        if (window->priv->active_slot != NULL) {
@@ -2300,6 +2228,7 @@ void
 nautilus_window_sync_title (NautilusWindow *window,
                            NautilusWindowSlot *slot)
 {
+  return;
        if (NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->sync_title != NULL) {
                NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->sync_title (window, slot);
 
@@ -2432,19 +2361,21 @@ static void
 nautilus_window_init (NautilusWindow *window)
 {
        GtkWindowGroup *window_group;
-
        window->priv = nautilus_window_get_instance_private (window);
 
+       g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
+       g_type_ensure (NAUTILUS_TYPE_NOTEBOOK);
+       g_print ("start template generation \n");
+  g_print ("type %s\n", G_OBJECT_TYPE_NAME (window));
+       gtk_widget_init_template (GTK_WIDGET (window));
+       g_print ("end template generation \n");
+
        window->priv->slots = NULL;
        window->priv->active_slot = NULL;
 
        window_group = gtk_window_group_new ();
        gtk_window_group_add_window (window_group, GTK_WINDOW (window));
        g_object_unref (window_group);
-
-       /* Set initial window title */
-       gtk_window_set_title (GTK_WINDOW (window), _("Files"));
-       gtk_window_set_icon_name (GTK_WINDOW (window), "system-file-manager");
 }
 
 static void
@@ -2478,6 +2409,15 @@ nautilus_window_class_init (NautilusWindowClass *class)
 
        class->close = real_window_close;
 
+       gtk_widget_class_set_template_from_resource (wclass,
+                                                    "/org/gnome/nautilus/nautilus-window.xml");
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, toolbar);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, content_paned);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, sidebar);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, places_sidebar);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, main_view);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notebook);
+
        properties[PROP_DISABLE_CHROME] =
                g_param_spec_boolean ("disable-chrome",
                                      "Disable chrome",
diff --git a/src/nautilus-window.xml b/src/nautilus-window.xml
new file mode 100644
index 0000000..cae4f62
--- /dev/null
+++ b/src/nautilus-window.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="NautilusWindow" parent="GtkApplicationWindow">
+    <property name="show-menubar">False</property>
+    <property name="title" translatable="yes">_Files</property>
+    <property name="icon-name">system-file-manager</property>
+    <child type="titlebar">
+      <object class="NautilusToolbar" id="toolbar">
+      </object>
+    </child>
+    <child>
+      <object class="GtkGrid">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkPaned" id="content_paned">
+            <property name="visible">True</property>
+            <property name="vexpand">True</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkBox" id="sidebar">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkPlacesSidebar" id="places_sidebar">
+                    <property name="visible">True</property>
+                  </object>
+                  <packing>
+                    <property name="pack_type">start</property>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+               <property name="resize">False</property>
+               <property name="shrink">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkOverlay" id="main_view">
+                <property name="visible">True</property>
+                <child>
+                  <object class="NautilusNotebook" id="notebook">
+                    <property name="visible">True</property>
+                    <property name="show-tabs">False</property>
+                    <property name="show-border">False</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+     <object class="GtkButton" id="label_null">
+     <property name="visible">True</property>
+  </object>
+</interface>
diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml
index ff0a1ca..b7820df 100644
--- a/src/nautilus.gresource.xml
+++ b/src/nautilus.gresource.xml
@@ -8,6 +8,7 @@
     <file>nautilus-toolbar-view-menu.xml</file>
     <file>nautilus-toolbar-action-menu.xml</file>
     <file>nautilus-view-context-menus.xml</file>
+    <file>nautilus-window.xml</file>
     <file alias="icons/thumbnail_frame.png">../icons/thumbnail_frame.png</file>
     <file alias="icons/filmholes.png">../icons/filmholes.png</file>
     <file alias="icons/knob.png">../icons/knob.png</file>


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