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



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

    nautilus-window: Use GtkBuilder definition
    
    Use a GtkBuilder definition for the UI of the window. This makes the code
    cleaner and allow us to merge some UI definitions in the same place, like the
    notification.
    This will make easier to hack on the UI in the future, as we plan to do.

 src/nautilus-notification-delete.ui |   71 ---------------
 src/nautilus-toolbar.c              |    6 +-
 src/nautilus-toolbar.h              |    3 +-
 src/nautilus-window.c               |  160 ++++++++++------------------------
 src/nautilus-window.ui              |  135 +++++++++++++++++++++++++++++
 src/nautilus.gresource.xml          |    2 +-
 6 files changed, 187 insertions(+), 190 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 0c12f21..68bb86d 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>
@@ -544,7 +545,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",
@@ -617,10 +618,9 @@ nautilus_toolbar_reset_menus (NautilusToolbar *self)
 }
 
 GtkWidget *
-nautilus_toolbar_new (NautilusWindow *window)
+nautilus_toolbar_new ()
 {
        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 9cc4e92..1a1a90b 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1302,21 +1302,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
@@ -1340,22 +1331,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,11 +1338,7 @@ nautilus_window_hide_sidebar (NautilusWindow *window)
 {
        DEBUG ("Called hide_sidebar()");
 
-       if (window->priv->sidebar == NULL) {
-               return;
-       }
-
-       nautilus_window_tear_down_sidebar (window);
+       gtk_widget_hide (window->priv->sidebar);
 }
 
 void
@@ -1375,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
@@ -1844,22 +1812,19 @@ nautilus_window_get_toolbar (NautilusWindow *window)
        return window->priv->toolbar;
 }
 
-static GtkWidget *
-create_toolbar (NautilusWindow *window)
+static void
+setup_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);
@@ -1867,14 +1832,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
@@ -1961,53 +1925,38 @@ notebook_create_window_cb (GtkNotebook *notebook,
        return GTK_NOTEBOOK (new_window->priv->notebook);
 }
 
-static GtkWidget *
-create_notebook (NautilusWindow *window)
+static void
+setup_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;
-       g_autoptr (GtkBuilder) builder;
 
        window = NAUTILUS_WINDOW (self);
 
@@ -2018,46 +1967,12 @@ 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);
-
-       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);
+       setup_toolbar (window);
 
-       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);
+       setup_notebook (window);
+       nautilus_window_set_up_sidebar (window);
 
-       builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/nautilus-notification-delete.ui");
-       window->priv->notification_delete = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete"));
-       window->priv->notification_delete_label = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete_label"));
-       window->priv->notification_delete_close = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete_close"));
-       window->priv->notification_delete_undo = GTK_WIDGET (gtk_builder_get_object (builder, 
"notification_delete_undo"));
-       gtk_overlay_add_overlay (GTK_OVERLAY (window->priv->main_view),
-                                 window->priv->notification_delete);
-       g_signal_connect_object (window->priv->notification_delete_close, "clicked",
-                                G_CALLBACK (nautilus_window_on_notification_delete_close_clicked), window, 
0);
-       g_signal_connect_object (window->priv->notification_delete_undo, "clicked",
-                                G_CALLBACK (nautilus_window_on_notification_delete_undo_clicked), window, 0);
 
        g_signal_connect_after (nautilus_file_undo_manager_get (), "undo-changed",
                                 G_CALLBACK (nautilus_window_on_undo_changed), self);
@@ -2146,9 +2061,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) {
@@ -2541,16 +2453,25 @@ nautilus_window_init (NautilusWindow *window)
 
        window->priv = nautilus_window_get_instance_private (window);
 
+       g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
+       g_type_ensure (NAUTILUS_TYPE_NOTEBOOK);
+       gtk_widget_init_template (GTK_WIDGET (window));
+
+       g_signal_connect_object (window->priv->notification_delete_close, "clicked",
+                                G_CALLBACK (nautilus_window_on_notification_delete_close_clicked), window, 
0);
+       g_signal_connect_object (window->priv->notification_delete_undo, "clicked",
+                                G_CALLBACK (nautilus_window_on_notification_delete_undo_clicked), window, 0);
+
+       g_object_bind_property (window, "disable-chrome",
+                               window->priv->sidebar, "visible",
+                               G_BINDING_INVERT_BOOLEAN);
+
        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
@@ -2584,6 +2505,19 @@ nautilus_window_class_init (NautilusWindowClass *class)
 
        class->close = real_window_close;
 
+       gtk_widget_class_set_template_from_resource (wclass,
+                                                    "/org/gnome/nautilus/nautilus-window.ui");
+       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);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_label);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_undo);
+       gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_close);
+
        properties[PROP_DISABLE_CHROME] =
                g_param_spec_boolean ("disable-chrome",
                                      "Disable chrome",
diff --git a/src/nautilus-window.ui b/src/nautilus-window.ui
new file mode 100644
index 0000000..d09a0e8
--- /dev/null
+++ b/src/nautilus-window.ui
@@ -0,0 +1,135 @@
+<?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">
+        <!-- We override the title widget so the GtkHeaderBar stop managing the
+        title label automatically, since we use the NautilusPathBar. We need to set it
+        here rather than in the NautilusToolbar definition due to bug 744324 on
+        gtk+ . -->
+        <child type="title">
+          <object class="GtkLabel">
+          </object>
+        </child>
+      </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>
+                <child type="overlay">
+                  <object class="GtkRevealer" id="notification_delete">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">center</property>
+                    <property name="valign">start</property>
+                    <property name="transition_duration">100</property>
+                    <child>
+                      <object class="GtkFrame">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="margin_start">12</property>
+                            <property name="margin_end">12</property>
+                            <property name="margin_top">2</property>
+                            <property name="margin_bottom">2</property>
+                            <child>
+                              <object class="GtkLabel" id="notification_delete_label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="max_width_chars">50</property>
+                                <property name="ellipsize">middle</property>
+                                <property name="margin_end">30</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="notification_delete_undo">
+                                <property name="label" translatable="yes">undo</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="no_show_all">True</property>
+                                <property name="margin_end">6</property>
+                              </object>
+                              <style>
+                                <class name="text-button"/>
+                              </style>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="notification_delete_close">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="relief">none</property>
+                                <property name="focus_on_click">False</property>
+                                <child>
+                                  <object class="GtkImage">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="icon_name">window-close-symbolic</property>
+                                    <property name="icon_size">2</property>
+                                  </object>
+                                </child>
+                                <style>
+                                  <class name="image-button"/>
+                                </style>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <style>
+                          <class name="app-notification"/>
+                        </style>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml
index 2038a9c..c6dc3b8 100644
--- a/src/nautilus.gresource.xml
+++ b/src/nautilus.gresource.xml
@@ -10,7 +10,7 @@
     <file>nautilus-view-context-menus.xml</file>
     <file>nautilus-progress-info-widget.xml</file>
     <file>nautilus-move-to-trash-shortcut-changed.ui</file>
-    <file>nautilus-notification-delete.ui</file>
+    <file>nautilus-window.ui</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]