1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
6
* Copyright (C) 1999, 2000 Red Hat, Inc.
7
* Copyright (C) 2000, 2001 Eazel, Inc.
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License as
11
* published by the Free Software Foundation; either version 2 of the
12
* License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this library; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
* Authors: Elliot Lee <sopwith@redhat.com>
24
* Darin Adler <darin@bentspoon.com>
30
#include <eel/eel-debug.h>
31
#include <eel/eel-gtk-extensions.h>
32
#include <eel/eel-glib-extensions.h>
33
#include <eel/eel-preferences.h>
35
#include <glib/gi18n.h>
36
#include <libnautilus-private/nautilus-bookmark.h>
37
#include <libnautilus-private/nautilus-global-preferences.h>
38
#include <libnautilus-private/nautilus-sidebar-provider.h>
39
#include <libnautilus-private/nautilus-module.h>
40
#include <libnautilus-private/nautilus-signaller.h>
41
#include <libnautilus-private/nautilus-window-info.h>
42
#include <libnautilus-private/nautilus-window-slot-info.h>
44
#include "nautilus-history-sidebar.h"
46
#define NAUTILUS_HISTORY_SIDEBAR_CLASS(klass) \
47
(G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_HISTORY_SIDEBAR, NautilusHistorySidebarClass))
48
#define NAUTILUS_IS_HISTORY_SIDEBAR(obj) \
49
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_HISTORY_SIDEBAR))
50
#define NAUTILUS_IS_HISTORY_SIDEBAR_CLASS(klass) \
51
(G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_HISTORY_SIDEBAR))
54
GtkScrolledWindowClass parent;
55
} NautilusHistorySidebarClass;
59
} NautilusHistorySidebarProvider;
63
} NautilusHistorySidebarProviderClass;
67
HISTORY_SIDEBAR_COLUMN_ICON,
68
HISTORY_SIDEBAR_COLUMN_NAME,
69
HISTORY_SIDEBAR_COLUMN_BOOKMARK,
70
HISTORY_SIDEBAR_COLUMN_COUNT
73
static void nautilus_history_sidebar_iface_init (NautilusSidebarIface *iface);
74
static void sidebar_provider_iface_init (NautilusSidebarProviderIface *iface);
75
static GType nautilus_history_sidebar_provider_get_type (void);
76
static void nautilus_history_sidebar_style_set (GtkWidget *widget,
77
GtkStyle *previous_style);
79
G_DEFINE_TYPE_WITH_CODE (NautilusHistorySidebar, nautilus_history_sidebar, GTK_TYPE_SCROLLED_WINDOW,
80
G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SIDEBAR,
81
nautilus_history_sidebar_iface_init));
83
G_DEFINE_TYPE_WITH_CODE (NautilusHistorySidebarProvider, nautilus_history_sidebar_provider, G_TYPE_OBJECT,
84
G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SIDEBAR_PROVIDER,
85
sidebar_provider_iface_init));
88
update_history (NautilusHistorySidebar *sidebar)
91
GtkTreeSelection *selection;
92
NautilusBookmark *bookmark;
98
store = GTK_LIST_STORE (gtk_tree_view_get_model (sidebar->tree_view));
100
gtk_list_store_clear (store);
102
history = nautilus_window_info_get_history (sidebar->window);
103
for (l = history; l != NULL; l = l->next) {
104
bookmark = nautilus_bookmark_copy (l->data);
106
pixbuf = nautilus_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);
107
name = nautilus_bookmark_get_name (bookmark);
108
gtk_list_store_append (store, &iter);
109
gtk_list_store_set (store, &iter,
110
HISTORY_SIDEBAR_COLUMN_ICON, pixbuf,
111
HISTORY_SIDEBAR_COLUMN_NAME, name,
112
HISTORY_SIDEBAR_COLUMN_BOOKMARK, bookmark,
114
g_object_unref (bookmark);
116
if (pixbuf != NULL) {
117
g_object_unref (pixbuf);
121
eel_g_object_list_free (history);
123
selection = GTK_TREE_SELECTION (gtk_tree_view_get_selection (sidebar->tree_view));
125
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) {
126
gtk_tree_selection_select_iter (selection, &iter);
131
history_changed_callback (GObject *signaller,
132
NautilusHistorySidebar *sidebar)
134
update_history (sidebar);
138
open_selected_item (NautilusHistorySidebar *sidebar,
140
NautilusWindowOpenFlags flags)
142
NautilusWindowSlotInfo *slot;
145
NautilusBookmark *bookmark;
148
model = gtk_tree_view_get_model (sidebar->tree_view);
150
if (!gtk_tree_model_get_iter (model, &iter, path)) {
155
(model, &iter, HISTORY_SIDEBAR_COLUMN_BOOKMARK, &bookmark, -1);
157
/* Navigate to the clicked location. */
158
location = nautilus_bookmark_get_location (NAUTILUS_BOOKMARK (bookmark));
159
slot = nautilus_window_info_get_active_slot (sidebar->window);
160
nautilus_window_slot_info_open_location
162
location, NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE,
164
g_object_unref (location);
168
row_activated_callback (GtkTreeView *tree_view,
170
GtkTreeViewColumn *column,
173
NautilusHistorySidebar *sidebar;
175
sidebar = NAUTILUS_HISTORY_SIDEBAR (user_data);
176
g_assert (sidebar->tree_view == tree_view);
178
open_selected_item (sidebar, path, 0);
182
button_press_event_callback (GtkWidget *widget,
183
GdkEventButton *event,
186
if (event->button == 2 && event->type == GDK_BUTTON_PRESS) {
187
/* Open new tab on middle click. */
188
NautilusHistorySidebar *sidebar;
191
sidebar = NAUTILUS_HISTORY_SIDEBAR (user_data);
192
g_assert (sidebar->tree_view == GTK_TREE_VIEW (widget));
194
if (gtk_tree_view_get_path_at_pos (sidebar->tree_view,
196
&path, NULL, NULL, NULL)) {
197
open_selected_item (sidebar,
199
NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB);
200
gtk_tree_path_free (path);
208
update_click_policy (NautilusHistorySidebar *sidebar)
212
policy = eel_preferences_get_enum (NAUTILUS_PREFERENCES_CLICK_POLICY);
214
eel_gtk_tree_view_set_activate_on_single_click
215
(sidebar->tree_view, policy == NAUTILUS_CLICK_POLICY_SINGLE);
219
click_policy_changed_callback (gpointer user_data)
221
NautilusHistorySidebar *sidebar;
223
sidebar = NAUTILUS_HISTORY_SIDEBAR (user_data);
225
update_click_policy (sidebar);
229
nautilus_history_sidebar_init (NautilusHistorySidebar *sidebar)
231
GtkTreeView *tree_view;
232
GtkTreeViewColumn *col;
233
GtkCellRenderer *cell;
235
GtkTreeSelection *selection;
237
tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
238
gtk_tree_view_set_headers_visible (tree_view, FALSE);
239
gtk_widget_show (GTK_WIDGET (tree_view));
241
col = GTK_TREE_VIEW_COLUMN (gtk_tree_view_column_new ());
243
cell = gtk_cell_renderer_pixbuf_new ();
244
gtk_tree_view_column_pack_start (col, cell, FALSE);
245
gtk_tree_view_column_set_attributes (col, cell,
246
"pixbuf", HISTORY_SIDEBAR_COLUMN_ICON,
249
cell = gtk_cell_renderer_text_new ();
250
gtk_tree_view_column_pack_start (col, cell, TRUE);
251
gtk_tree_view_column_set_attributes (col, cell,
252
"text", HISTORY_SIDEBAR_COLUMN_NAME,
255
gtk_tree_view_column_set_fixed_width (col, NAUTILUS_ICON_SIZE_SMALLER);
256
gtk_tree_view_append_column (tree_view, col);
258
store = gtk_list_store_new (HISTORY_SIDEBAR_COLUMN_COUNT,
261
NAUTILUS_TYPE_BOOKMARK);
263
gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (store));
264
g_object_unref (store);
266
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar),
267
GTK_POLICY_AUTOMATIC,
268
GTK_POLICY_AUTOMATIC);
269
gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (sidebar), NULL);
270
gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (sidebar), NULL);
271
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sidebar), GTK_SHADOW_IN);
272
gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (tree_view));
273
gtk_widget_show (GTK_WIDGET (sidebar));
275
sidebar->tree_view = tree_view;
277
selection = gtk_tree_view_get_selection (tree_view);
278
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
280
g_signal_connect_object
281
(tree_view, "row_activated",
282
G_CALLBACK (row_activated_callback), sidebar, 0);
284
g_signal_connect_object (nautilus_signaller_get_current (),
285
"history_list_changed",
286
G_CALLBACK (history_changed_callback), sidebar, 0);
288
g_signal_connect (tree_view, "button-press-event",
289
G_CALLBACK (button_press_event_callback), sidebar);
291
eel_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
292
click_policy_changed_callback,
294
update_click_policy (sidebar);
298
nautilus_history_sidebar_finalize (GObject *object)
300
NautilusHistorySidebar *sidebar;
302
sidebar = NAUTILUS_HISTORY_SIDEBAR (object);
304
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
305
click_policy_changed_callback,
308
G_OBJECT_CLASS (nautilus_history_sidebar_parent_class)->finalize (object);
312
nautilus_history_sidebar_class_init (NautilusHistorySidebarClass *class)
314
G_OBJECT_CLASS (class)->finalize = nautilus_history_sidebar_finalize;
316
GTK_WIDGET_CLASS (class)->style_set = nautilus_history_sidebar_style_set;
320
nautilus_history_sidebar_get_sidebar_id (NautilusSidebar *sidebar)
322
return NAUTILUS_HISTORY_SIDEBAR_ID;
326
nautilus_history_sidebar_get_tab_label (NautilusSidebar *sidebar)
328
return g_strdup (_("History"));
332
nautilus_history_sidebar_get_tab_tooltip (NautilusSidebar *sidebar)
334
return g_strdup (_("Show History"));
338
nautilus_history_sidebar_get_tab_icon (NautilusSidebar *sidebar)
344
nautilus_history_sidebar_is_visible_changed (NautilusSidebar *sidebar,
351
nautilus_history_sidebar_iface_init (NautilusSidebarIface *iface)
353
iface->get_sidebar_id = nautilus_history_sidebar_get_sidebar_id;
354
iface->get_tab_label = nautilus_history_sidebar_get_tab_label;
355
iface->get_tab_tooltip = nautilus_history_sidebar_get_tab_tooltip;
356
iface->get_tab_icon = nautilus_history_sidebar_get_tab_icon;
357
iface->is_visible_changed = nautilus_history_sidebar_is_visible_changed;
361
nautilus_history_sidebar_set_parent_window (NautilusHistorySidebar *sidebar,
362
NautilusWindowInfo *window)
364
sidebar->window = window;
365
update_history (sidebar);
369
nautilus_history_sidebar_style_set (GtkWidget *widget,
370
GtkStyle *previous_style)
372
NautilusHistorySidebar *sidebar;
374
sidebar = NAUTILUS_HISTORY_SIDEBAR (widget);
376
update_history (sidebar);
379
static NautilusSidebar *
380
nautilus_history_sidebar_create (NautilusSidebarProvider *provider,
381
NautilusWindowInfo *window)
383
NautilusHistorySidebar *sidebar;
385
sidebar = g_object_new (nautilus_history_sidebar_get_type (), NULL);
386
nautilus_history_sidebar_set_parent_window (sidebar, window);
387
g_object_ref_sink (sidebar);
389
return NAUTILUS_SIDEBAR (sidebar);
393
sidebar_provider_iface_init (NautilusSidebarProviderIface *iface)
395
iface->create = nautilus_history_sidebar_create;
399
nautilus_history_sidebar_provider_init (NautilusHistorySidebarProvider *sidebar)
404
nautilus_history_sidebar_provider_class_init (NautilusHistorySidebarProviderClass *class)
409
nautilus_history_sidebar_register (void)
411
nautilus_module_add_type (nautilus_history_sidebar_provider_get_type ());