window-slot: allow setting the window after construction

Turn the window construct-only property into a construct property, and
add a setter method.
This commit is contained in:
Cosimo Cecchi 2012-08-31 21:10:57 -04:00
parent f56098a6d2
commit 1f9a07a1c3
3 changed files with 45 additions and 18 deletions

View file

@ -279,11 +279,14 @@ viewed_file_changed_callback (NautilusFile *file,
{
GFile *new_location;
gboolean is_in_trash, was_in_trash;
NautilusWindow *window;
g_assert (NAUTILUS_IS_FILE (file));
g_assert (NAUTILUS_IS_WINDOW (slot->window));
g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
g_assert (file == slot->viewed_file);
window = nautilus_window_slot_get_window (slot);
if (!nautilus_file_is_not_yet_confirmed (file)) {
slot->viewed_file_seen = TRUE;
}
@ -348,8 +351,8 @@ viewed_file_changed_callback (NautilusFile *file,
slot->location)) {
g_object_unref (slot->location);
slot->location = new_location;
if (slot == slot->window->details->active_slot) {
nautilus_window_sync_location_widgets (slot->window);
if (slot == nautilus_window_get_active_slot (window)) {
nautilus_window_sync_location_widgets (window);
}
} else {
/* TODO?
@ -925,7 +928,7 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
/* We're missing a previous location (if opened location
* in a new tab) so close it and return */
if (slot->location == NULL) {
nautilus_window_slot_close (slot->window, slot);
nautilus_window_slot_close (window, slot);
} else {
/* We disconnected this, so we need to re-connect it */
viewed_file = nautilus_file_get (slot->location);
@ -1487,11 +1490,11 @@ update_for_new_location (NautilusWindowSlot *slot)
nautilus_window_slot_update_title (slot);
if (slot == slot->window->details->active_slot) {
nautilus_window_sync_location_widgets (slot->window);
if (slot == nautilus_window_get_active_slot (window)) {
nautilus_window_sync_location_widgets (window);
if (location_really_changed) {
nautilus_window_sync_search_widgets (slot->window);
nautilus_window_sync_search_widgets (window);
}
}
}

View file

@ -55,6 +55,10 @@ enum {
NUM_PROPERTIES
};
struct NautilusWindowSlotDetails {
NautilusWindow *window;
};
static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
@ -142,7 +146,7 @@ query_editor_cancel_callback (NautilusQueryEditor *editor,
NautilusWindow *window;
GtkActionGroup *action_group;
window = slot->window;
window = slot->details->window;
action_group = nautilus_window_get_main_action_group (window);
search = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_SEARCH);
@ -252,7 +256,7 @@ real_active (NautilusWindowSlot *slot)
NautilusWindow *window;
int page_num;
window = slot->window;
window = slot->details->window;
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (window->details->notebook),
GTK_WIDGET (slot));
g_assert (page_num >= 0);
@ -301,7 +305,7 @@ nautilus_window_slot_set_property (GObject *object,
switch (property_id) {
case PROP_WINDOW:
slot->window = g_value_get_object (value);
nautilus_window_slot_set_window (slot, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -319,7 +323,7 @@ nautilus_window_slot_get_property (GObject *object,
switch (property_id) {
case PROP_WINDOW:
g_value_set_object (value, slot->window);
g_value_set_object (value, slot->details->window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -371,7 +375,8 @@ nautilus_window_slot_constructed (GObject *object)
static void
nautilus_window_slot_init (NautilusWindowSlot *slot)
{
/* do nothing */
slot->details = G_TYPE_INSTANCE_GET_PRIVATE
(slot, NAUTILUS_TYPE_WINDOW_SLOT, NautilusWindowSlotDetails);
}
static void
@ -431,7 +436,7 @@ nautilus_window_slot_dispose (GObject *object)
slot->find_mount_cancellable = NULL;
}
slot->window = NULL;
slot->details->window = NULL;
g_free (slot->title);
slot->title = NULL;
@ -485,9 +490,10 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
"The NautilusWindow",
"The NautilusWindow this slot is part of",
NAUTILUS_TYPE_WINDOW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
g_type_class_add_private (klass, sizeof (NautilusWindowSlotDetails));
}
GFile *
@ -516,7 +522,20 @@ NautilusWindow *
nautilus_window_slot_get_window (NautilusWindowSlot *slot)
{
g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
return slot->window;
return slot->details->window;
}
void
nautilus_window_slot_set_window (NautilusWindowSlot *slot,
NautilusWindow *window)
{
g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
g_assert (NAUTILUS_IS_WINDOW (window));
if (slot->details->window != window) {
slot->details->window = window;
g_object_notify_by_pspec (G_OBJECT (slot), properties[PROP_WINDOW]);
}
}
/* nautilus_window_slot_update_title:

View file

@ -51,13 +51,15 @@ struct NautilusWindowSlotClass {
void (* inactive) (NautilusWindowSlot *slot);
};
typedef struct NautilusWindowSlotDetails NautilusWindowSlotDetails;
/* Each NautilusWindowSlot corresponds to a location in the window
* for displaying a NautilusView, i.e. a tab.
*/
struct NautilusWindowSlot {
GtkBox parent;
NautilusWindow *window;
NautilusWindowSlotDetails *details;
/* slot contains
* 1) an event box containing extra_location_widgets
@ -119,7 +121,11 @@ struct NautilusWindowSlot {
GType nautilus_window_slot_get_type (void);
NautilusWindowSlot * nautilus_window_slot_new (NautilusWindow *window);
NautilusWindowSlot * nautilus_window_slot_new (NautilusWindow *window);
NautilusWindow * nautilus_window_slot_get_window (NautilusWindowSlot *slot);
void nautilus_window_slot_set_window (NautilusWindowSlot *slot,
NautilusWindow *window);
void nautilus_window_slot_update_title (NautilusWindowSlot *slot);
void nautilus_window_slot_set_query_editor_visible (NautilusWindowSlot *slot,
@ -172,7 +178,6 @@ void nautilus_window_slot_remove_extra_location_widgets (NautilusWindowSlot *
NautilusView * nautilus_window_slot_get_current_view (NautilusWindowSlot *slot);
char * nautilus_window_slot_get_current_uri (NautilusWindowSlot *slot);
NautilusWindow * nautilus_window_slot_get_window (NautilusWindowSlot *slot);
void nautilus_window_slot_clear_forward_list (NautilusWindowSlot *slot);
void nautilus_window_slot_clear_back_list (NautilusWindowSlot *slot);