nautilus-window-pane.c 4.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-

   nautilus-window-pane.c: Nautilus window pane

   Copyright (C) 2008 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Author: Holger Berndt <berndth@gmx.de>
*/

#include "nautilus-window-pane.h"
26 27 28
#include "nautilus-window-private.h"
#include "nautilus-navigation-window-pane.h"
#include "nautilus-window-manage-views.h"
29
#include <eel/eel-gtk-macros.h>
30

Cosimo Cecchi's avatar
Cosimo Cecchi committed
31
G_DEFINE_TYPE (NautilusWindowPane, nautilus_window_pane,
32 33 34
	       G_TYPE_OBJECT)
#define parent_class nautilus_window_pane_parent_class

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
static inline NautilusWindowSlot *
get_first_inactive_slot (NautilusWindowPane *pane)
{
	GList *l;
	NautilusWindowSlot *slot;

	for (l = pane->slots; l != NULL; l = l->next) {
		slot = NAUTILUS_WINDOW_SLOT (l->data);
		if (slot != pane->active_slot) {
			return slot;
		}
	}

	return NULL;
}

Cosimo Cecchi's avatar
Cosimo Cecchi committed
51 52
static void
nautilus_window_pane_dispose (GObject *object)
53
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
54
	NautilusWindowPane *pane = NAUTILUS_WINDOW_PANE (object);
55

Cosimo Cecchi's avatar
Cosimo Cecchi committed
56
	g_assert (pane->slots == NULL);
57

Cosimo Cecchi's avatar
Cosimo Cecchi committed
58 59
	pane->window = NULL;
	G_OBJECT_CLASS (parent_class)->dispose (object);
60 61
}

62
static void
Cosimo Cecchi's avatar
Cosimo Cecchi committed
63
nautilus_window_pane_class_init (NautilusWindowPaneClass *klass)
64
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
65
	GObjectClass *oclass = G_OBJECT_CLASS (klass);
66

Cosimo Cecchi's avatar
Cosimo Cecchi committed
67
	oclass->dispose = nautilus_window_pane_dispose;
68
}
69

Cosimo Cecchi's avatar
Cosimo Cecchi committed
70 71
static void
nautilus_window_pane_init (NautilusWindowPane *pane)
72
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
73 74 75
	pane->slots = NULL;
	pane->active_slot = NULL;
	pane->is_active = FALSE;
76
}
77

Cosimo Cecchi's avatar
Cosimo Cecchi committed
78 79
NautilusWindowPane *
nautilus_window_pane_new (NautilusWindow *window)
80
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
81
	NautilusWindowPane *pane;
82

Cosimo Cecchi's avatar
Cosimo Cecchi committed
83 84 85
	pane = g_object_new (NAUTILUS_TYPE_WINDOW_PANE, NULL);
	pane->window = window;
	return pane;
86 87
}

Cosimo Cecchi's avatar
Cosimo Cecchi committed
88 89 90
NautilusWindowSlot *
nautilus_window_pane_get_slot_for_content_box (NautilusWindowPane *pane,
					       GtkWidget *content_box)
91
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
92 93
	NautilusWindowSlot *slot;
	GList *l;
94

Cosimo Cecchi's avatar
Cosimo Cecchi committed
95 96
	for (l = pane->slots; l != NULL; l = l->next) {
		slot = NAUTILUS_WINDOW_SLOT (l->data);
Holger Berndt's avatar
Holger Berndt committed
97

Cosimo Cecchi's avatar
Cosimo Cecchi committed
98 99 100 101 102
		if (slot->content_box == content_box) {
			return slot;
		}
	}
	return NULL;
103 104 105
}

void
106 107
nautilus_window_pane_set_active (NautilusWindowPane *pane,
				 gboolean is_active)
108
{
109 110
	NautilusView *view;

111 112 113 114 115
	if (is_active == pane->is_active) {
		return;
	}

	pane->is_active = is_active;
116

117 118 119 120 121
	/* notify the current view about its activity state */
	if (pane->active_slot != NULL) {
		view = nautilus_window_slot_get_current_view (pane->active_slot);
		nautilus_view_set_is_active (view, is_active);
	}
122 123 124

	EEL_CALL_METHOD (NAUTILUS_WINDOW_PANE_CLASS, pane,
			 set_active, (pane, is_active));
125 126
}

Cosimo Cecchi's avatar
Cosimo Cecchi committed
127 128
void
nautilus_window_pane_show (NautilusWindowPane *pane)
129
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
130 131 132
	pane->visible = TRUE;
	EEL_CALL_METHOD (NAUTILUS_WINDOW_PANE_CLASS, pane,
			 show, (pane));
133 134 135
}


Cosimo Cecchi's avatar
Cosimo Cecchi committed
136 137 138 139 140
void
nautilus_window_pane_sync_location_widgets (NautilusWindowPane *pane)
{
	EEL_CALL_METHOD (NAUTILUS_WINDOW_PANE_CLASS, pane,
			 sync_location_widgets, (pane));
141 142
}

Cosimo Cecchi's avatar
Cosimo Cecchi committed
143 144
void
nautilus_window_pane_sync_search_widgets (NautilusWindowPane *pane)
145
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
146 147
	EEL_CALL_METHOD (NAUTILUS_WINDOW_PANE_CLASS, pane,
			 sync_search_widgets, (pane));
148
}
149

Cosimo Cecchi's avatar
Cosimo Cecchi committed
150
void
151 152
nautilus_window_pane_slot_close (NautilusWindowPane *pane,
				 NautilusWindowSlot *slot)
153
{
Cosimo Cecchi's avatar
Cosimo Cecchi committed
154
	NautilusWindowSlot *next_slot;
155

Cosimo Cecchi's avatar
Cosimo Cecchi committed
156 157
	if (pane->window) {
		NautilusWindow *window;
158

Cosimo Cecchi's avatar
Cosimo Cecchi committed
159
		window = pane->window;
160

Cosimo Cecchi's avatar
Cosimo Cecchi committed
161 162 163 164
		if (pane->active_slot == slot) {
			next_slot = get_first_inactive_slot (NAUTILUS_WINDOW_PANE (pane));
			nautilus_window_set_active_slot (window, next_slot);
		}
165

Cosimo Cecchi's avatar
Cosimo Cecchi committed
166
		nautilus_window_close_slot (slot);
167

Cosimo Cecchi's avatar
Cosimo Cecchi committed
168 169 170 171 172 173 174 175 176 177
		/* If that was the last slot in the active pane, close the pane or even the whole window. */
		if (window->details->active_pane->slots == NULL) {
			NautilusWindowPane *next_pane;
			next_pane = nautilus_window_get_next_pane (window);
			
			/* If next_pane is non-NULL, we have more than one pane available. In this
			 * case, close the current pane and switch to the next one. If there is
			 * no next pane, close the window. */
			if(next_pane) {
				nautilus_window_close_pane (pane);
178 179
				nautilus_window_set_active_pane (window, next_pane);

180
				nautilus_navigation_window_update_show_hide_menu_items (NAUTILUS_NAVIGATION_WINDOW (window));
Cosimo Cecchi's avatar
Cosimo Cecchi committed
181 182 183
			} else {
				nautilus_window_close (window);
			}
184 185
		}
	}
Cosimo Cecchi's avatar
Cosimo Cecchi committed
186 187 188 189 190 191 192 193
}

void
nautilus_window_pane_grab_focus (NautilusWindowPane *pane)
{
	if (NAUTILUS_IS_WINDOW_PANE (pane) && pane->active_slot) {
		nautilus_view_grab_focus (pane->active_slot->content_view);
	}	
194
}