1
/* $Id: thunar-window.c 18843 2005-11-14 14:25:58Z benny $ */
3
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License as published by the Free
7
* Software Foundation; either version 2 of the License, or (at your option)
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
* You should have received a copy of the GNU General Public License along with
16
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17
* Place, Suite 330, Boston, MA 02111-1307 USA
24
#include <thunar/thunar-application.h>
25
#include <thunar/thunar-clipboard-manager.h>
26
#include <thunar/thunar-details-view.h>
27
#include <thunar/thunar-dialogs.h>
28
#include <thunar/thunar-favourites-pane.h>
29
#include <thunar/thunar-gtk-extensions.h>
30
#include <thunar/thunar-history.h>
31
#include <thunar/thunar-icon-view.h>
32
#include <thunar/thunar-location-buttons.h>
33
#include <thunar/thunar-location-dialog.h>
34
#include <thunar/thunar-location-entry.h>
35
#include <thunar/thunar-preferences.h>
36
#include <thunar/thunar-statusbar.h>
37
#include <thunar/thunar-window.h>
38
#include <thunar/thunar-window-ui.h>
45
PROP_CURRENT_DIRECTORY,
52
static void thunar_window_class_init (ThunarWindowClass *klass);
53
static void thunar_window_init (ThunarWindow *window);
54
static void thunar_window_dispose (GObject *object);
55
static void thunar_window_finalize (GObject *object);
56
static void thunar_window_get_property (GObject *object,
60
static void thunar_window_set_property (GObject *object,
64
static void thunar_window_realize (GtkWidget *widget);
65
static void thunar_window_unrealize (GtkWidget *widget);
66
static void thunar_window_action_open_new_window (GtkAction *action,
67
ThunarWindow *window);
68
static void thunar_window_action_close_all_windows (GtkAction *action,
69
ThunarWindow *window);
70
static void thunar_window_action_close (GtkAction *action,
71
ThunarWindow *window);
72
static void thunar_window_action_location_bar_changed (GtkRadioAction *action,
73
GtkRadioAction *current,
74
ThunarWindow *window);
75
static void thunar_window_action_side_pane_changed (GtkRadioAction *action,
76
GtkRadioAction *current,
77
ThunarWindow *window);
78
static void thunar_window_action_view_changed (GtkRadioAction *action,
79
GtkRadioAction *current,
80
ThunarWindow *window);
81
static void thunar_window_action_go_up (GtkAction *action,
82
ThunarWindow *window);
83
static void thunar_window_action_open_home (GtkAction *action,
84
ThunarWindow *window);
85
static void thunar_window_action_open_location (GtkAction *action,
86
ThunarWindow *window);
87
static void thunar_window_action_about (GtkAction *action,
88
ThunarWindow *window);
89
static void thunar_window_action_show_hidden (GtkToggleAction *action,
90
ThunarWindow *window);
91
static void thunar_window_current_directory_changed (ThunarFile *current_directory,
92
ThunarWindow *window);
93
static void thunar_window_connect_proxy (GtkUIManager *manager,
96
ThunarWindow *window);
97
static void thunar_window_disconnect_proxy (GtkUIManager *manager,
100
ThunarWindow *window);
101
static void thunar_window_menu_item_selected (GtkWidget *menu_item,
102
ThunarWindow *window);
103
static void thunar_window_menu_item_deselected (GtkWidget *menu_item,
104
ThunarWindow *window);
105
static void thunar_window_notify_loading (ThunarView *view,
107
ThunarWindow *window);
111
struct _ThunarWindowClass
113
GtkWindowClass __parent__;
118
GtkWindow __parent__;
120
ThunarClipboardManager *clipboard;
122
ThunarPreferences *preferences;
124
ThunarIconFactory *icon_factory;
126
GtkActionGroup *action_group;
127
GtkUIManager *ui_manager;
129
/* closures for the menu_item_selected()/menu_item_deselected() callbacks */
130
GClosure *menu_item_selected_closure;
131
GClosure *menu_item_deselected_closure;
132
guint menu_item_tooltip_id;
135
GtkWidget *location_bar;
136
GtkWidget *view_container;
138
GtkWidget *statusbar;
140
ThunarHistory *history;
142
ThunarFile *current_directory;
147
static const GtkActionEntry action_entries[] =
149
{ "file-menu", NULL, N_ ("_File"), NULL, },
150
{ "open-new-window", NULL, N_ ("Open New _Window"), "<control>N", N_ ("Open a new Thunar window for the displayed location"), G_CALLBACK (thunar_window_action_open_new_window), },
151
{ "close-all-windows", NULL, N_ ("Close _All Windows"), "<control><shift>W", N_ ("Close all Thunar windows"), G_CALLBACK (thunar_window_action_close_all_windows), },
152
{ "close", GTK_STOCK_CLOSE, N_ ("_Close"), "<control>W", N_ ("Close this window"), G_CALLBACK (thunar_window_action_close), },
153
{ "edit-menu", NULL, N_ ("_Edit"), NULL, },
154
{ "view-menu", NULL, N_ ("_View"), NULL, },
155
{ "view-location-bar-menu", NULL, N_ ("_Location Bar"), NULL, },
156
{ "view-side-pane-menu", NULL, N_ ("_Side Pane"), NULL, },
157
{ "go-menu", NULL, N_ ("_Go"), NULL, },
158
{ "open-parent", GTK_STOCK_GO_UP, N_ ("Open _Parent"), "<alt>Up", N_ ("Open the parent folder"), G_CALLBACK (thunar_window_action_go_up), },
159
{ "open-home", GTK_STOCK_HOME, N_ ("_Home"), "<alt>Home", N_ ("Open the home folder"), G_CALLBACK (thunar_window_action_open_home), },
160
{ "open-location", NULL, N_ ("Open _Location..."), "<control>L", N_ ("Specify a location to open"), G_CALLBACK (thunar_window_action_open_location), },
161
{ "help-menu", NULL, N_ ("_Help"), NULL, },
162
#if GTK_CHECK_VERSION(2,6,0)
163
{ "about", GTK_STOCK_ABOUT, N_ ("_About"), NULL, N_ ("Display information about Thunar"), G_CALLBACK (thunar_window_action_about), },
165
{ "about", GTK_STOCK_DIALOG_INFO, N_ ("_About"), NULL, N_ ("Display information about Thunar"), G_CALLBACK (thunar_window_action_about), },
169
static const GtkToggleActionEntry toggle_action_entries[] =
171
{ "show-hidden", NULL, N_("Show _Hidden Files"), "<control>H", N_("Toggles the display of hidden files in the current window"), G_CALLBACK (thunar_window_action_show_hidden), FALSE, },
176
G_DEFINE_TYPE (ThunarWindow, thunar_window, GTK_TYPE_WINDOW);
181
thunar_window_class_init (ThunarWindowClass *klass)
183
GtkWidgetClass *gtkwidget_class;
184
GObjectClass *gobject_class;
186
gobject_class = G_OBJECT_CLASS (klass);
187
gobject_class->dispose = thunar_window_dispose;
188
gobject_class->finalize = thunar_window_finalize;
189
gobject_class->get_property = thunar_window_get_property;
190
gobject_class->set_property = thunar_window_set_property;
192
gtkwidget_class = GTK_WIDGET_CLASS (klass);
193
gtkwidget_class->realize = thunar_window_realize;
194
gtkwidget_class->unrealize = thunar_window_unrealize;
197
* ThunarWindow:current-directory:
199
* The directory currently displayed within this #ThunarWindow
202
g_object_class_install_property (gobject_class,
203
PROP_CURRENT_DIRECTORY,
204
g_param_spec_object ("current-directory",
205
_("Current directory"),
206
_("The directory currently displayed within this window"),
208
EXO_PARAM_READWRITE));
211
* ThunarWindow:show-hidden:
213
* Whether to show hidden files in the current window.
215
g_object_class_install_property (gobject_class,
217
g_param_spec_boolean ("show-hidden",
219
_("Whether to display hidden files"),
221
EXO_PARAM_READABLE));
224
* ThunarWindow:ui-manager:
226
* The #GtkUIManager used for this #ThunarWindow. This property
227
* can only be read and is garantied to always contain a valid
228
* #GtkUIManager instance (thus it's never %NULL).
230
g_object_class_install_property (gobject_class,
232
g_param_spec_object ("ui-manager",
234
_("The UI manager used within this window"),
236
EXO_PARAM_READABLE));
242
thunar_window_init (ThunarWindow *window)
244
GtkRadioAction *radio_action;
245
GtkAccelGroup *accel_group;
250
gboolean show_hidden;
255
/* grab a reference on the preferences */
256
window->preferences = thunar_preferences_get ();
258
/* allocate a closure for the menu_item_selected() callback */
259
window->menu_item_selected_closure = g_cclosure_new_object (G_CALLBACK (thunar_window_menu_item_selected), G_OBJECT (window));
260
g_closure_ref (window->menu_item_selected_closure);
261
g_closure_sink (window->menu_item_selected_closure);
263
/* allocate a closure for the menu_item_deselected() callback */
264
window->menu_item_deselected_closure = g_cclosure_new_object (G_CALLBACK (thunar_window_menu_item_deselected), G_OBJECT (window));
265
g_closure_ref (window->menu_item_deselected_closure);
266
g_closure_sink (window->menu_item_deselected_closure);
268
window->icon_factory = thunar_icon_factory_get_default ();
270
/* setup the action group for this window */
271
window->action_group = gtk_action_group_new ("thunar-window");
272
gtk_action_group_set_translation_domain (window->action_group, GETTEXT_PACKAGE);
273
gtk_action_group_add_actions (window->action_group, action_entries, G_N_ELEMENTS (action_entries), GTK_WIDGET (window));
274
gtk_action_group_add_toggle_actions (window->action_group, toggle_action_entries, G_N_ELEMENTS (toggle_action_entries), GTK_WIDGET (window));
276
/* initialize the "show-hidden" action using the default value from the preferences */
277
action = gtk_action_group_get_action (window->action_group, "show-hidden");
278
g_object_get (G_OBJECT (window->preferences), "default-show-hidden", &show_hidden, NULL);
279
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_hidden);
281
/* setup the history support */
282
window->history = g_object_new (THUNAR_TYPE_HISTORY, "action-group", window->action_group, NULL);
283
g_signal_connect_swapped (G_OBJECT (window->history), "change-directory", G_CALLBACK (thunar_window_set_current_directory), window);
284
exo_binding_new (G_OBJECT (window), "current-directory", G_OBJECT (window->history), "current-directory");
287
* add the side pane options
289
radio_action = gtk_radio_action_new ("view-side-pane-favourites", _("_Favourites"), NULL, NULL, THUNAR_TYPE_FAVOURITES_PANE);
290
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
291
gtk_radio_action_set_group (radio_action, NULL);
292
group = gtk_radio_action_get_group (radio_action);
293
g_object_unref (G_OBJECT (radio_action));
295
radio_action = gtk_radio_action_new ("view-side-pane-hidden", _("_Hidden"), NULL, NULL, G_TYPE_NONE);
296
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
297
gtk_radio_action_set_group (radio_action, group);
298
group = gtk_radio_action_get_group (radio_action);
299
g_object_unref (G_OBJECT (radio_action));
302
* add the location bar options
304
radio_action = gtk_radio_action_new ("view-location-bar-buttons", _("_Button Style"), NULL, NULL, THUNAR_TYPE_LOCATION_BUTTONS);
305
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
306
gtk_radio_action_set_group (radio_action, NULL);
307
group = gtk_radio_action_get_group (radio_action);
308
g_object_unref (G_OBJECT (radio_action));
310
radio_action = gtk_radio_action_new ("view-location-bar-entry", _("_Traditional Style"), NULL, NULL, THUNAR_TYPE_LOCATION_ENTRY);
311
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
312
gtk_radio_action_set_group (radio_action, group);
313
group = gtk_radio_action_get_group (radio_action);
314
g_object_unref (G_OBJECT (radio_action));
316
radio_action = gtk_radio_action_new ("view-location-bar-hidden", _("_Hidden"), NULL, NULL, G_TYPE_NONE);
317
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
318
gtk_radio_action_set_group (radio_action, group);
319
group = gtk_radio_action_get_group (radio_action);
320
g_object_unref (G_OBJECT (radio_action));
325
radio_action = gtk_radio_action_new ("view-as-icons", _("View as _Icons"), NULL, NULL, THUNAR_TYPE_ICON_VIEW);
326
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
327
gtk_radio_action_set_group (radio_action, NULL);
328
group = gtk_radio_action_get_group (radio_action);
329
g_object_unref (G_OBJECT (radio_action));
331
radio_action = gtk_radio_action_new ("view-as-detailed-list", _("View as _Detailed List"), NULL, NULL, THUNAR_TYPE_DETAILS_VIEW);
332
gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
333
gtk_radio_action_set_group (radio_action, group);
334
group = gtk_radio_action_get_group (radio_action);
335
g_object_unref (G_OBJECT (radio_action));
337
window->ui_manager = gtk_ui_manager_new ();
338
g_signal_connect (G_OBJECT (window->ui_manager), "connect-proxy", G_CALLBACK (thunar_window_connect_proxy), window);
339
g_signal_connect (G_OBJECT (window->ui_manager), "disconnect-proxy", G_CALLBACK (thunar_window_disconnect_proxy), window);
340
gtk_ui_manager_insert_action_group (window->ui_manager, window->action_group, 0);
341
gtk_ui_manager_add_ui_from_string (window->ui_manager, thunar_window_ui, thunar_window_ui_length, NULL);
343
accel_group = gtk_ui_manager_get_accel_group (window->ui_manager);
344
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
346
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
347
gtk_window_set_title (GTK_WINDOW (window), _("Thunar"));
349
vbox = gtk_vbox_new (FALSE, 0);
350
gtk_container_add (GTK_CONTAINER (window), vbox);
351
gtk_widget_show (vbox);
353
menubar = gtk_ui_manager_get_widget (window->ui_manager, "/main-menu");
354
gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0);
355
gtk_widget_show (menubar);
357
window->paned = g_object_new (GTK_TYPE_HPANED, "border-width", 6, NULL);
358
gtk_box_pack_start (GTK_BOX (vbox), window->paned, TRUE, TRUE, 0);
359
gtk_widget_show (window->paned);
361
box = gtk_vbox_new (FALSE, 6);
362
gtk_paned_pack2 (GTK_PANED (window->paned), box, TRUE, FALSE);
363
gtk_widget_show (box);
365
window->location_bar = gtk_alignment_new (0.0f, 0.5f, 1.0f, 1.0f);
366
gtk_box_pack_start (GTK_BOX (box), window->location_bar, FALSE, FALSE, 0);
367
gtk_widget_show (window->location_bar);
369
window->view_container = gtk_alignment_new (0.5f, 0.5f, 1.0f, 1.0f);
370
gtk_box_pack_start (GTK_BOX (box), window->view_container, TRUE, TRUE, 0);
371
gtk_widget_show (window->view_container);
373
window->statusbar = thunar_statusbar_new ();
374
g_signal_connect_swapped (G_OBJECT (window->statusbar), "change-directory",
375
G_CALLBACK (thunar_window_set_current_directory), window);
376
exo_binding_new (G_OBJECT (window), "current-directory", G_OBJECT (window->statusbar), "current-directory");
377
gtk_box_pack_start (GTK_BOX (vbox), window->statusbar, FALSE, FALSE, 0);
378
gtk_widget_show (window->statusbar);
380
/* allocate a statusbar context for displaying tooltips of the selected menu item */
381
window->menu_item_tooltip_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->statusbar), "menu-item-tooltip");
383
/* determine the selected side pane */
384
g_object_get (G_OBJECT (window->preferences), "last-side-pane", &type_name, NULL);
385
type = g_type_from_name (type_name);
388
/* activate the selected side pane */
389
action = gtk_action_group_get_action (window->action_group, "view-side-pane-favourites");
390
exo_gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), g_type_is_a (type, THUNAR_TYPE_SIDE_PANE) ? type : G_TYPE_NONE);
391
g_signal_connect (G_OBJECT (action), "changed", G_CALLBACK (thunar_window_action_side_pane_changed), window);
392
thunar_window_action_side_pane_changed (GTK_RADIO_ACTION (action), GTK_RADIO_ACTION (action), window);
394
/* determine the selected location bar */
395
g_object_get (G_OBJECT (window->preferences), "last-location-bar", &type_name, NULL);
396
type = g_type_from_name (type_name);
399
/* activate the selected location bar */
400
action = gtk_action_group_get_action (window->action_group, "view-location-bar-buttons");
401
exo_gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), g_type_is_a (type, THUNAR_TYPE_LOCATION_BAR) ? type : G_TYPE_NONE);
402
g_signal_connect (G_OBJECT (action), "changed", G_CALLBACK (thunar_window_action_location_bar_changed), window);
403
thunar_window_action_location_bar_changed (GTK_RADIO_ACTION (action), GTK_RADIO_ACTION (action), window);
405
/* determine the selected view */
406
g_object_get (G_OBJECT (window->preferences), "last-view", &type_name, NULL);
407
type = g_type_from_name (type_name);
410
/* activate the selected view */
411
action = gtk_action_group_get_action (window->action_group, "view-as-icons");
412
exo_gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), g_type_is_a (type, THUNAR_TYPE_VIEW) ? type : THUNAR_TYPE_ICON_VIEW);
413
g_signal_connect (G_OBJECT (action), "changed", G_CALLBACK (thunar_window_action_view_changed), window);
414
thunar_window_action_view_changed (GTK_RADIO_ACTION (action), GTK_RADIO_ACTION (action), window);
420
thunar_window_dispose (GObject *object)
422
ThunarWindow *window = THUNAR_WINDOW (object);
424
/* disconnect from the current-directory */
425
thunar_window_set_current_directory (window, NULL);
427
(*G_OBJECT_CLASS (thunar_window_parent_class)->dispose) (object);
433
thunar_window_finalize (GObject *object)
435
ThunarWindow *window = THUNAR_WINDOW (object);
437
/* drop our references on the menu_item_selected()/menu_item_deselected() closures */
438
g_closure_unref (window->menu_item_deselected_closure);
439
g_closure_unref (window->menu_item_selected_closure);
441
/* disconnect from the ui manager */
442
g_signal_handlers_disconnect_matched (G_OBJECT (window->ui_manager), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, window);
443
g_object_unref (G_OBJECT (window->ui_manager));
445
g_object_unref (G_OBJECT (window->action_group));
446
g_object_unref (G_OBJECT (window->icon_factory));
447
g_object_unref (G_OBJECT (window->history));
449
/* release the preferences reference */
450
g_object_unref (G_OBJECT (window->preferences));
452
(*G_OBJECT_CLASS (thunar_window_parent_class)->finalize) (object);
458
thunar_window_get_property (GObject *object,
463
ThunarWindow *window = THUNAR_WINDOW (object);
468
case PROP_CURRENT_DIRECTORY:
469
g_value_set_object (value, thunar_window_get_current_directory (window));
472
case PROP_SHOW_HIDDEN:
473
action = gtk_action_group_get_action (window->action_group, "show-hidden");
474
g_value_set_boolean (value, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
477
case PROP_UI_MANAGER:
478
g_value_set_object (value, window->ui_manager);
482
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
490
thunar_window_set_property (GObject *object,
495
ThunarWindow *window = THUNAR_WINDOW (object);
499
case PROP_CURRENT_DIRECTORY:
500
thunar_window_set_current_directory (window, g_value_get_object (value));
504
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
512
thunar_window_realize (GtkWidget *widget)
514
ThunarWindow *window = THUNAR_WINDOW (widget);
516
/* let the GtkWidget class perform the realize operation */
517
(*GTK_WIDGET_CLASS (thunar_window_parent_class)->realize) (widget);
519
/* connect to the clipboard manager of the new display and be sure to redraw the window
520
* whenever the clipboard contents change to make sure we always display up2date state.
522
window->clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (widget));
523
g_signal_connect_swapped (G_OBJECT (window->clipboard), "changed",
524
G_CALLBACK (gtk_widget_queue_draw), widget);
530
thunar_window_unrealize (GtkWidget *widget)
532
ThunarWindow *window = THUNAR_WINDOW (widget);
534
/* disconnect from the clipboard manager */
535
g_signal_handlers_disconnect_by_func (G_OBJECT (window->clipboard), gtk_widget_queue_draw, widget);
536
g_object_unref (G_OBJECT (window->clipboard));
538
/* let the GtkWidget class unrealize the window */
539
(*GTK_WIDGET_CLASS (thunar_window_parent_class)->unrealize) (widget);
545
thunar_window_action_open_new_window (GtkAction *action,
546
ThunarWindow *window)
548
ThunarApplication *application;
550
application = thunar_application_get ();
551
thunar_application_open_window (application, window->current_directory,
552
gtk_widget_get_screen (GTK_WIDGET (window)));
553
g_object_unref (G_OBJECT (application));
559
thunar_window_action_close_all_windows (GtkAction *action,
560
ThunarWindow *window)
562
ThunarApplication *application;
565
/* query the list of currently open windows */
566
application = thunar_application_get ();
567
windows = thunar_application_get_windows (application);
568
g_object_unref (G_OBJECT (application));
570
/* destroy all open windows */
571
g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL);
572
g_list_free (windows);
578
thunar_window_action_close (GtkAction *action,
579
ThunarWindow *window)
581
gtk_widget_destroy (GTK_WIDGET (window));
587
thunar_window_action_location_bar_changed (GtkRadioAction *action,
588
GtkRadioAction *current,
589
ThunarWindow *window)
594
/* drop the previous location bar (if any) */
595
widget = gtk_bin_get_child (GTK_BIN (window->location_bar));
596
if (G_LIKELY (widget != NULL))
597
gtk_widget_destroy (widget);
599
/* determine the new type of location bar */
600
type = gtk_radio_action_get_current_value (action);
602
/* activate the new location bar */
603
if (G_LIKELY (type != G_TYPE_NONE))
605
/* initialize the new location bar widget */
606
widget = g_object_new (type, NULL);
607
g_signal_connect_swapped (G_OBJECT (widget), "change-directory",
608
G_CALLBACK (thunar_window_set_current_directory), window);
609
exo_binding_new (G_OBJECT (window), "current-directory",
610
G_OBJECT (widget), "current-directory");
611
gtk_container_add (GTK_CONTAINER (window->location_bar), widget);
612
gtk_widget_show (widget);
614
/* display the location bar container */
615
gtk_widget_show (window->location_bar);
619
/* hide the location bar container */
620
gtk_widget_hide (window->location_bar);
623
/* remember the setting */
624
g_object_set (G_OBJECT (window->preferences), "last-location-bar", g_type_name (type), NULL);
630
thunar_window_action_side_pane_changed (GtkRadioAction *action,
631
GtkRadioAction *current,
632
ThunarWindow *window)
637
/* drop the previous side pane (if any) */
638
widget = gtk_paned_get_child1 (GTK_PANED (window->paned));
639
if (G_LIKELY (widget != NULL))
640
gtk_widget_destroy (widget);
642
/* determine the new type of side pane */
643
type = gtk_radio_action_get_current_value (action);
644
if (G_LIKELY (type != G_TYPE_NONE))
646
widget = g_object_new (type, NULL);
647
exo_binding_new (G_OBJECT (window), "current-directory", G_OBJECT (widget), "current-directory");
648
g_signal_connect_swapped (G_OBJECT (widget), "change-directory", G_CALLBACK (thunar_window_set_current_directory), window);
649
gtk_paned_pack1 (GTK_PANED (window->paned), widget, FALSE, FALSE);
650
gtk_widget_show (widget);
653
/* remember the setting */
654
g_object_set (G_OBJECT (window->preferences), "last-side-pane", g_type_name (type), NULL);
660
thunar_window_action_view_changed (GtkRadioAction *action,
661
GtkRadioAction *current,
662
ThunarWindow *window)
666
/* drop the previous view (if any) */
667
if (G_LIKELY (window->view != NULL))
669
/* destroy and disconnect the previous view */
670
gtk_widget_destroy (window->view);
672
/* update the UI (else GtkUIManager will crash on merging) */
673
gtk_ui_manager_ensure_update (window->ui_manager);
676
/* determine the new type of view */
677
type = gtk_radio_action_get_current_value (action);
679
/* allocate a new view of the requested type */
680
if (G_LIKELY (type != G_TYPE_NONE))
682
window->view = g_object_new (type, "ui-manager", window->ui_manager, NULL);
683
g_signal_connect (G_OBJECT (window->view), "notify::loading", G_CALLBACK (thunar_window_notify_loading), window);
684
g_signal_connect_swapped (G_OBJECT (window->view), "change-directory", G_CALLBACK (thunar_window_set_current_directory), window);
685
exo_binding_new (G_OBJECT (window), "current-directory", G_OBJECT (window->view), "current-directory");
686
exo_binding_new (G_OBJECT (window), "show-hidden", G_OBJECT (window->view), "show-hidden");
687
exo_binding_new (G_OBJECT (window->view), "loading", G_OBJECT (window->statusbar), "loading");
688
exo_binding_new (G_OBJECT (window->view), "statusbar-text", G_OBJECT (window->statusbar), "text");
689
gtk_container_add (GTK_CONTAINER (window->view_container), window->view);
690
gtk_widget_grab_focus (window->view);
691
gtk_widget_show (window->view);
695
/* this should not happen under normal conditions */
699
/* remember the setting */
700
g_object_set (G_OBJECT (window->preferences), "last-view", g_type_name (type), NULL);
706
thunar_window_action_go_up (GtkAction *action,
707
ThunarWindow *window)
711
// FIXME: error handling
712
parent = thunar_file_get_parent (window->current_directory, NULL);
713
thunar_window_set_current_directory (window, parent);
714
g_object_unref (G_OBJECT (parent));
720
thunar_window_action_open_home (GtkAction *action,
721
ThunarWindow *window)
723
ThunarVfsPath *home_path;
724
ThunarFile *home_file;
725
GError *error = NULL;
727
g_return_if_fail (GTK_IS_ACTION (action));
728
g_return_if_fail (THUNAR_IS_WINDOW (window));
730
/* determine the path to the home directory */
731
home_path = thunar_vfs_path_get_for_home ();
733
/* determine the file for the home directory */
734
home_file = thunar_file_get_for_path (home_path, &error);
735
if (G_UNLIKELY (home_file == NULL))
737
/* display an error to the user */
738
thunar_dialogs_show_error (GTK_WIDGET (window), error, _("Failed to open home directory"));
739
g_error_free (error);
743
/* open the home folder */
744
thunar_window_set_current_directory (window, home_file);
745
g_object_unref (G_OBJECT (home_file));
748
/* release our reference on the home path */
749
thunar_vfs_path_unref (home_path);
755
thunar_window_action_open_location (GtkAction *action,
756
ThunarWindow *window)
761
/* bring up the "Open Location"-dialog if the window has no location bar or the location bar
762
* in the window does not support text entry by the user.
764
widget = gtk_bin_get_child (GTK_BIN (window->location_bar));
765
if (widget == NULL || !thunar_location_bar_accept_focus (THUNAR_LOCATION_BAR (widget)))
767
dialog = thunar_location_dialog_new ();
768
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
769
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
770
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
771
thunar_location_dialog_set_selected_file (THUNAR_LOCATION_DIALOG (dialog), thunar_window_get_current_directory (window));
772
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
773
thunar_window_set_current_directory (window, thunar_location_dialog_get_selected_file (THUNAR_LOCATION_DIALOG (dialog)));
774
gtk_widget_destroy (dialog);
781
thunar_window_action_about (GtkAction *action,
782
ThunarWindow *window)
784
static const gchar *authors[] =
786
"Benedikt Meurer <benny@xfce.org>",
790
static const gchar license[] =
791
"This program is free software; you can redistribute it and/or modify it\n"
792
"under the terms of the GNU General Public License as published by the Free\n"
793
"Software Foundation; either version 2 of the License, or (at your option)\n"
794
"any later version.\n"
796
"This program is distributed in the hope that it will be useful, but WITHOUT\n"
797
"ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n"
798
"FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\n"
801
"You should have received a copy of the GNU General Public License along with\n"
802
"this program; if not, write to the Free Software Foundation, Inc., 59 Temple\n"
803
"Place, Suite 330, Boston, MA 02111-1307 USA.\n";
807
/* try to load the about logo */
808
logo = gdk_pixbuf_new_from_file (DATADIR "/pixmaps/Thunar/Thunar-about-logo.png", NULL);
810
/* open the about dialog */
811
gtk_about_dialog_set_email_hook ((gpointer) exo_noop, NULL, NULL);
812
gtk_about_dialog_set_url_hook ((gpointer) exo_noop, NULL, NULL);
813
gtk_show_about_dialog (GTK_WINDOW (window),
815
"comments", _("Thunar is a fast and easy to use file manager\nfor the Xfce Desktop Environment."),
816
"copyright", "Copyright \302\251 2004-2005 Benedikt Meurer",
819
"name", PACKAGE_NAME,
820
"translator-credits", _("translator-credits"),
821
"version", PACKAGE_VERSION,
822
"website", "http://thunar.xfce.org/",
825
/* release the about logo (if any) */
826
if (G_LIKELY (logo != NULL))
827
g_object_unref (G_OBJECT (logo));
833
thunar_window_action_show_hidden (GtkToggleAction *action,
834
ThunarWindow *window)
836
g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
837
g_return_if_fail (THUNAR_IS_WINDOW (window));
839
/* just emit the "notify" signal for the "show-hidden"
840
* signal and the view will automatically sync its state.
842
g_object_notify (G_OBJECT (window), "show-hidden");
848
thunar_window_current_directory_changed (ThunarFile *current_directory,
849
ThunarWindow *window)
853
g_return_if_fail (THUNAR_IS_WINDOW (window));
854
g_return_if_fail (THUNAR_IS_FILE (current_directory));
855
g_return_if_fail (window->current_directory == current_directory);
857
/* set window title and icon */
858
icon = thunar_icon_factory_load_file_icon (window->icon_factory, current_directory, THUNAR_FILE_ICON_STATE_DEFAULT, 48);
859
gtk_window_set_title (GTK_WINDOW (window), thunar_file_get_special_name (current_directory));
860
gtk_window_set_icon (GTK_WINDOW (window), icon);
861
g_object_unref (G_OBJECT (icon));
867
thunar_window_connect_proxy (GtkUIManager *manager,
870
ThunarWindow *window)
872
/* we want to get informed when the user hovers a menu item */
873
if (GTK_IS_MENU_ITEM (proxy))
875
g_signal_connect_closure (G_OBJECT (proxy), "select", window->menu_item_selected_closure, FALSE);
876
g_signal_connect_closure (G_OBJECT (proxy), "deselect", window->menu_item_deselected_closure, FALSE);
883
thunar_window_disconnect_proxy (GtkUIManager *manager,
886
ThunarWindow *window)
888
/* undo what we did in connect_proxy() */
889
if (GTK_IS_MENU_ITEM (proxy))
891
g_signal_handlers_disconnect_matched (G_OBJECT (proxy), G_SIGNAL_MATCH_CLOSURE, 0, 0, window->menu_item_selected_closure, NULL, NULL);
892
g_signal_handlers_disconnect_matched (G_OBJECT (proxy), G_SIGNAL_MATCH_CLOSURE, 0, 0, window->menu_item_deselected_closure, NULL, NULL);
899
thunar_window_menu_item_selected (GtkWidget *menu_item,
900
ThunarWindow *window)
905
/* determine the action for the menu item */
906
action = g_object_get_data (G_OBJECT (menu_item), "gtk-action");
907
if (G_UNLIKELY (action == NULL))
910
/* determine the tooltip from the action */
911
g_object_get (G_OBJECT (action), "tooltip", &tooltip, NULL);
912
if (G_LIKELY (tooltip != NULL))
914
gtk_statusbar_push (GTK_STATUSBAR (window->statusbar), window->menu_item_tooltip_id, tooltip);
922
thunar_window_menu_item_deselected (GtkWidget *menu_item,
923
ThunarWindow *window)
925
/* drop the last tooltip from the statusbar */
926
gtk_statusbar_pop (GTK_STATUSBAR (window->statusbar), window->menu_item_tooltip_id);
932
thunar_window_notify_loading (ThunarView *view,
934
ThunarWindow *window)
938
g_return_if_fail (THUNAR_IS_VIEW (view));
939
g_return_if_fail (THUNAR_IS_WINDOW (window));
940
g_return_if_fail (THUNAR_VIEW (window->view) == view);
942
if (GTK_WIDGET_REALIZED (window))
944
/* setup the proper cursor */
945
if (thunar_view_get_loading (view))
947
cursor = gdk_cursor_new (GDK_WATCH);
948
gdk_window_set_cursor (GTK_WIDGET (window)->window, cursor);
949
gdk_cursor_unref (cursor);
953
gdk_window_set_cursor (GTK_WIDGET (window)->window, NULL);
963
* Allocates a new #ThunarWindow instance, which isn't
964
* associated with any directory.
966
* Return value: the newly allocated #ThunarWindow instance.
969
thunar_window_new (void)
971
return g_object_new (THUNAR_TYPE_WINDOW, NULL);
977
* thunar_window_get_current_directory:
978
* @window : a #ThunarWindow instance.
980
* Queries the #ThunarFile instance, which represents the directory
981
* currently displayed within @window. %NULL is returned if @window
982
* is not currently associated with any directory.
984
* Return value: the directory currently displayed within @window or %NULL.
987
thunar_window_get_current_directory (ThunarWindow *window)
989
g_return_val_if_fail (THUNAR_IS_WINDOW (window), NULL);
990
return window->current_directory;
996
* thunar_window_set_current_directory:
997
* @window : a #ThunarWindow instance.
998
* @current_directory : the new directory or %NULL.
1001
thunar_window_set_current_directory (ThunarWindow *window,
1002
ThunarFile *current_directory)
1004
g_return_if_fail (THUNAR_IS_WINDOW (window));
1005
g_return_if_fail (current_directory == NULL || THUNAR_IS_FILE (current_directory));
1007
/* check if we already display the requested directory */
1008
if (G_UNLIKELY (window->current_directory == current_directory))
1011
/* disconnect from the previously active directory */
1012
if (G_LIKELY (window->current_directory != NULL))
1014
g_signal_handlers_disconnect_by_func (G_OBJECT (window->current_directory), thunar_window_current_directory_changed, window);
1015
g_object_unref (G_OBJECT (window->current_directory));
1018
window->current_directory = current_directory;
1020
/* connect to the new directory */
1021
if (G_LIKELY (current_directory != NULL))
1023
/* take a reference on the file and connect the "changed" signal */
1024
g_signal_connect (G_OBJECT (current_directory), "changed", G_CALLBACK (thunar_window_current_directory_changed), window);
1025
g_object_ref (G_OBJECT (current_directory));
1027
/* update window icon and title */
1028
thunar_window_current_directory_changed (current_directory, window);
1031
/* enable the 'Open new window' action if we have a valid directory */
1032
thunar_gtk_action_group_set_action_sensitive (window->action_group, "open-new-window", (current_directory != NULL));
1034
/* enable the 'Up' action if possible for the new directory */
1035
thunar_gtk_action_group_set_action_sensitive (window->action_group, "open-parent", (current_directory != NULL
1036
&& thunar_file_has_parent (current_directory)));
1038
/* tell everybody that we have a new "current-directory",
1039
* we do this first so other widgets display the new
1040
* state already while the folder view is loading.
1042
g_object_notify (G_OBJECT (window), "current-directory");