[nautilus/wip/csoriano/flow: 17/55] window: allow to create custom slots in subclasses



commit b24243988c5bb471aacd42f2d78c313e673a2352
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Mar 22 11:30:36 2016 +0100

    window: allow to create custom slots in subclasses
    
    We are not able to create subclasses of window slots, like the one
    we will need for desktop.
    
    So create a vfunc to handle that, and expose the common code in a public
    function so subclasses can use it.

 src/nautilus-window.c |   28 ++++++++++++++++++++--------
 src/nautilus-window.h |    8 ++++++++
 2 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 0ca4f30..b3b2ba7 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -524,14 +524,25 @@ disconnect_slot (NautilusWindow     *window,
 }
 
 static NautilusWindowSlot *
-nautilus_window_create_slot (NautilusWindow             *window,
-                          NautilusWindowOpenFlags flags)
+nautilus_window_create_slot (NautilusWindow *window)
 {
-       NautilusWindowSlot *slot;
+       return NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS(window))->create_slot (window);
+}
+
+static NautilusWindowSlot *
+real_create_slot (NautilusWindow *window)
+{
+        return nautilus_window_slot_new (window);
+}
 
+void
+nautilus_window_initialize_slot (NautilusWindow          *window,
+                                 NautilusWindowSlot      *slot,
+                                 NautilusWindowOpenFlags  flags)
+{
        g_assert (NAUTILUS_IS_WINDOW (window));
+       g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
 
-       slot = nautilus_window_slot_new (window);
         connect_slot (window, slot);
 
        g_signal_handlers_block_by_func (window->priv->notebook,
@@ -549,8 +560,6 @@ nautilus_window_create_slot (NautilusWindow             *window,
 
        window->priv->slots = g_list_append (window->priv->slots, slot);
        g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
-
-       return slot;
 }
 
 void
@@ -573,7 +582,8 @@ nautilus_window_open_location_full (NautilusWindow          *window,
                 if (new_tab_at_end)
                flags |= NAUTILUS_WINDOW_OPEN_SLOT_APPEND;
 
-               target_slot = nautilus_window_create_slot (window, flags);
+               target_slot = nautilus_window_create_slot (window);
+                nautilus_window_initialize_slot (window, target_slot, flags);
        }
 
        if (target_slot == NULL) {
@@ -2129,7 +2139,8 @@ nautilus_window_constructed (GObject *self)
         * some actions trigger UI widgets to show/hide. */
        nautilus_window_initialize_actions (window);
 
-       slot = nautilus_window_create_slot (window, 0);
+       slot = nautilus_window_create_slot (window);
+        nautilus_window_initialize_slot (window, slot, 0);
        nautilus_window_set_active_slot (window, slot);
 
        window->priv->bookmarks_id =
@@ -2578,6 +2589,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
         wclass->grab_focus = nautilus_window_grab_focus;
 
        class->close = real_window_close;
+       class->create_slot = real_create_slot;
 
        gtk_widget_class_set_template_from_resource (wclass,
                                                     "/org/gnome/nautilus/ui/nautilus-window.ui");
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index ce39b7f..10cc2ba 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -86,6 +86,10 @@ struct NautilusWindowClass {
         void   (* sync_title) (NautilusWindow *window,
                               NautilusWindowSlot *slot);
         void   (* close) (NautilusWindow *window);
+        /* Use this in case your window has a special slot. Also is expected that
+         * the slot is initialized with nautilus_window_initialize_slot.
+         */
+        NautilusWindowSlot * (* create_slot) (NautilusWindow *window);
 };
 
 typedef struct _NautilusWindowPrivate NautilusWindowPrivate;
@@ -149,4 +153,8 @@ void nautilus_window_end_dnd (NautilusWindow *window,
 
 void nautilus_window_search (NautilusWindow *window,
                              const gchar    *text);
+
+void nautilus_window_initialize_slot (NautilusWindow          *window,
+                                      NautilusWindowSlot      *slot,
+                                      NautilusWindowOpenFlags  flags);
 #endif


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