~ubuntu-branches/debian/experimental/thunar/experimental

« back to all changes in this revision

Viewing changes to thunar/thunar-window.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2006-01-02 23:42:32 UTC
  • Revision ID: james.westby@ubuntu.com-20060102234232-8xeq0lqhyn70syr0
Tags: upstream-0.1.4svn+r18850
ImportĀ upstreamĀ versionĀ 0.1.4svn+r18850

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: thunar-window.c 18843 2005-11-14 14:25:58Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
 
4
 *
 
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)
 
8
 * any later version.
 
9
 *
 
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
 
13
 * more details.
 
14
 *
 
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
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include <config.h>
 
22
#endif
 
23
 
 
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>
 
39
 
 
40
 
 
41
 
 
42
enum
 
43
{
 
44
  PROP_0,
 
45
  PROP_CURRENT_DIRECTORY,
 
46
  PROP_SHOW_HIDDEN,
 
47
  PROP_UI_MANAGER,
 
48
};
 
49
 
 
50
 
 
51
 
 
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,
 
57
                                                           guint               prop_id,
 
58
                                                           GValue             *value,
 
59
                                                           GParamSpec         *pspec);
 
60
static void     thunar_window_set_property                (GObject            *object,
 
61
                                                           guint               prop_id,
 
62
                                                           const GValue       *value,
 
63
                                                           GParamSpec         *pspec);
 
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,
 
94
                                                           GtkAction          *action,
 
95
                                                           GtkWidget          *proxy,
 
96
                                                           ThunarWindow       *window);
 
97
static void     thunar_window_disconnect_proxy            (GtkUIManager       *manager,
 
98
                                                           GtkAction          *action,
 
99
                                                           GtkWidget          *proxy,
 
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,
 
106
                                                           GParamSpec         *pspec,
 
107
                                                           ThunarWindow       *window);
 
108
 
 
109
 
 
110
 
 
111
struct _ThunarWindowClass
 
112
{
 
113
  GtkWindowClass __parent__;
 
114
};
 
115
 
 
116
struct _ThunarWindow
 
117
{
 
118
  GtkWindow __parent__;
 
119
 
 
120
  ThunarClipboardManager *clipboard;
 
121
 
 
122
  ThunarPreferences      *preferences;
 
123
 
 
124
  ThunarIconFactory      *icon_factory;
 
125
 
 
126
  GtkActionGroup         *action_group;
 
127
  GtkUIManager           *ui_manager;
 
128
 
 
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;
 
133
 
 
134
  GtkWidget              *paned;
 
135
  GtkWidget              *location_bar;
 
136
  GtkWidget              *view_container;
 
137
  GtkWidget              *view;
 
138
  GtkWidget              *statusbar;
 
139
 
 
140
  ThunarHistory          *history;
 
141
 
 
142
  ThunarFile             *current_directory;
 
143
};
 
144
 
 
145
 
 
146
 
 
147
static const GtkActionEntry action_entries[] =
 
148
{
 
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), },
 
164
#else
 
165
  { "about", GTK_STOCK_DIALOG_INFO, N_ ("_About"), NULL, N_ ("Display information about Thunar"), G_CALLBACK (thunar_window_action_about), },
 
166
#endif
 
167
};
 
168
 
 
169
static const GtkToggleActionEntry toggle_action_entries[] =
 
170
{
 
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, },
 
172
};
 
173
 
 
174
 
 
175
 
 
176
G_DEFINE_TYPE (ThunarWindow, thunar_window, GTK_TYPE_WINDOW);
 
177
 
 
178
 
 
179
 
 
180
static void
 
181
thunar_window_class_init (ThunarWindowClass *klass)
 
182
{
 
183
  GtkWidgetClass *gtkwidget_class;
 
184
  GObjectClass   *gobject_class;
 
185
 
 
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;
 
191
 
 
192
  gtkwidget_class = GTK_WIDGET_CLASS (klass);
 
193
  gtkwidget_class->realize = thunar_window_realize;
 
194
  gtkwidget_class->unrealize = thunar_window_unrealize;
 
195
 
 
196
  /**
 
197
   * ThunarWindow:current-directory:
 
198
   *
 
199
   * The directory currently displayed within this #ThunarWindow
 
200
   * or %NULL.
 
201
   **/
 
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"),
 
207
                                                        THUNAR_TYPE_FILE,
 
208
                                                        EXO_PARAM_READWRITE));
 
209
 
 
210
  /**
 
211
   * ThunarWindow:show-hidden:
 
212
   *
 
213
   * Whether to show hidden files in the current window.
 
214
   **/
 
215
  g_object_class_install_property (gobject_class,
 
216
                                   PROP_SHOW_HIDDEN,
 
217
                                   g_param_spec_boolean ("show-hidden",
 
218
                                                         _("Show hidden"),
 
219
                                                         _("Whether to display hidden files"),
 
220
                                                         FALSE,
 
221
                                                         EXO_PARAM_READABLE));
 
222
 
 
223
  /**
 
224
   * ThunarWindow:ui-manager:
 
225
   *
 
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).
 
229
   **/
 
230
  g_object_class_install_property (gobject_class,
 
231
                                   PROP_UI_MANAGER,
 
232
                                   g_param_spec_object ("ui-manager",
 
233
                                                        _("UI manager"),
 
234
                                                        _("The UI manager used within this window"),
 
235
                                                        GTK_TYPE_UI_MANAGER,
 
236
                                                        EXO_PARAM_READABLE));
 
237
}
 
238
 
 
239
 
 
240
 
 
241
static void
 
242
thunar_window_init (ThunarWindow *window)
 
243
{
 
244
  GtkRadioAction *radio_action;
 
245
  GtkAccelGroup  *accel_group;
 
246
  GtkAction      *action;
 
247
  GtkWidget      *vbox;
 
248
  GtkWidget      *menubar;
 
249
  GtkWidget      *box;
 
250
  gboolean        show_hidden;
 
251
  GSList         *group;
 
252
  gchar          *type_name;
 
253
  GType           type;
 
254
 
 
255
  /* grab a reference on the preferences */
 
256
  window->preferences = thunar_preferences_get ();
 
257
 
 
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);
 
262
 
 
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);
 
267
 
 
268
  window->icon_factory = thunar_icon_factory_get_default ();
 
269
 
 
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));
 
275
 
 
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);
 
280
 
 
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");
 
285
 
 
286
  /*
 
287
   * add the side pane options
 
288
   */
 
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));
 
294
 
 
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));
 
300
 
 
301
  /*
 
302
   * add the location bar options
 
303
   */
 
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));
 
309
 
 
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));
 
315
 
 
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));
 
321
 
 
322
  /*
 
323
   * add view options
 
324
   */
 
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));
 
330
 
 
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));
 
336
 
 
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);
 
342
 
 
343
  accel_group = gtk_ui_manager_get_accel_group (window->ui_manager);
 
344
  gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
 
345
 
 
346
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
 
347
  gtk_window_set_title (GTK_WINDOW (window), _("Thunar"));
 
348
 
 
349
  vbox = gtk_vbox_new (FALSE, 0);
 
350
  gtk_container_add (GTK_CONTAINER (window), vbox);
 
351
  gtk_widget_show (vbox);
 
352
 
 
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);
 
356
 
 
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);
 
360
 
 
361
  box = gtk_vbox_new (FALSE, 6);
 
362
  gtk_paned_pack2 (GTK_PANED (window->paned), box, TRUE, FALSE);
 
363
  gtk_widget_show (box);
 
364
 
 
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);
 
368
 
 
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);
 
372
 
 
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);
 
379
 
 
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");
 
382
 
 
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);
 
386
  g_free (type_name);
 
387
 
 
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);
 
393
 
 
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);
 
397
  g_free (type_name);
 
398
 
 
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);
 
404
 
 
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);
 
408
  g_free (type_name);
 
409
 
 
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);
 
415
}
 
416
 
 
417
 
 
418
 
 
419
static void
 
420
thunar_window_dispose (GObject *object)
 
421
{
 
422
  ThunarWindow *window = THUNAR_WINDOW (object);
 
423
 
 
424
  /* disconnect from the current-directory */
 
425
  thunar_window_set_current_directory (window, NULL);
 
426
 
 
427
  (*G_OBJECT_CLASS (thunar_window_parent_class)->dispose) (object);
 
428
}
 
429
 
 
430
 
 
431
 
 
432
static void
 
433
thunar_window_finalize (GObject *object)
 
434
{
 
435
  ThunarWindow *window = THUNAR_WINDOW (object);
 
436
 
 
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);
 
440
 
 
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));
 
444
 
 
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));
 
448
 
 
449
  /* release the preferences reference */
 
450
  g_object_unref (G_OBJECT (window->preferences));
 
451
 
 
452
  (*G_OBJECT_CLASS (thunar_window_parent_class)->finalize) (object);
 
453
}
 
454
 
 
455
 
 
456
 
 
457
static void
 
458
thunar_window_get_property (GObject    *object,
 
459
                            guint       prop_id,
 
460
                            GValue     *value,
 
461
                            GParamSpec *pspec)
 
462
{
 
463
  ThunarWindow *window = THUNAR_WINDOW (object);
 
464
  GtkAction    *action;
 
465
 
 
466
  switch (prop_id)
 
467
    {
 
468
    case PROP_CURRENT_DIRECTORY:
 
469
      g_value_set_object (value, thunar_window_get_current_directory (window));
 
470
      break;
 
471
 
 
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)));
 
475
      break;
 
476
 
 
477
    case PROP_UI_MANAGER:
 
478
      g_value_set_object (value, window->ui_manager);
 
479
      break;
 
480
 
 
481
    default:
 
482
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
483
      break;
 
484
    }
 
485
}
 
486
 
 
487
 
 
488
 
 
489
static void
 
490
thunar_window_set_property (GObject            *object,
 
491
                            guint               prop_id,
 
492
                            const GValue       *value,
 
493
                            GParamSpec         *pspec)
 
494
{
 
495
  ThunarWindow *window = THUNAR_WINDOW (object);
 
496
 
 
497
  switch (prop_id)
 
498
    {
 
499
    case PROP_CURRENT_DIRECTORY:
 
500
      thunar_window_set_current_directory (window, g_value_get_object (value));
 
501
      break;
 
502
 
 
503
    default:
 
504
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
505
      break;
 
506
    }
 
507
}
 
508
 
 
509
 
 
510
 
 
511
static void
 
512
thunar_window_realize (GtkWidget *widget)
 
513
{
 
514
  ThunarWindow *window = THUNAR_WINDOW (widget);
 
515
 
 
516
  /* let the GtkWidget class perform the realize operation */
 
517
  (*GTK_WIDGET_CLASS (thunar_window_parent_class)->realize) (widget);
 
518
 
 
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.
 
521
   */
 
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);
 
525
}
 
526
 
 
527
 
 
528
 
 
529
static void
 
530
thunar_window_unrealize (GtkWidget *widget)
 
531
{
 
532
  ThunarWindow *window = THUNAR_WINDOW (widget);
 
533
 
 
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));
 
537
 
 
538
  /* let the GtkWidget class unrealize the window */
 
539
  (*GTK_WIDGET_CLASS (thunar_window_parent_class)->unrealize) (widget);
 
540
}
 
541
 
 
542
 
 
543
 
 
544
static void
 
545
thunar_window_action_open_new_window (GtkAction    *action,
 
546
                                      ThunarWindow *window)
 
547
{
 
548
  ThunarApplication *application;
 
549
 
 
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));
 
554
}
 
555
 
 
556
 
 
557
 
 
558
static void
 
559
thunar_window_action_close_all_windows (GtkAction    *action,
 
560
                                        ThunarWindow *window)
 
561
{
 
562
  ThunarApplication *application;
 
563
  GList             *windows;
 
564
 
 
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));
 
569
 
 
570
  /* destroy all open windows */
 
571
  g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL);
 
572
  g_list_free (windows);
 
573
}
 
574
 
 
575
 
 
576
 
 
577
static void
 
578
thunar_window_action_close (GtkAction    *action,
 
579
                            ThunarWindow *window)
 
580
{
 
581
  gtk_widget_destroy (GTK_WIDGET (window));
 
582
}
 
583
 
 
584
 
 
585
 
 
586
static void
 
587
thunar_window_action_location_bar_changed (GtkRadioAction *action,
 
588
                                           GtkRadioAction *current,
 
589
                                           ThunarWindow   *window)
 
590
{
 
591
  GtkWidget *widget;
 
592
  GType      type;
 
593
 
 
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);
 
598
 
 
599
  /* determine the new type of location bar */
 
600
  type = gtk_radio_action_get_current_value (action);
 
601
 
 
602
  /* activate the new location bar */
 
603
  if (G_LIKELY (type != G_TYPE_NONE))
 
604
    {
 
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);
 
613
 
 
614
      /* display the location bar container */
 
615
      gtk_widget_show (window->location_bar);
 
616
    }
 
617
  else
 
618
    {
 
619
      /* hide the location bar container */
 
620
      gtk_widget_hide (window->location_bar);
 
621
    }
 
622
 
 
623
  /* remember the setting */
 
624
  g_object_set (G_OBJECT (window->preferences), "last-location-bar", g_type_name (type), NULL);
 
625
}
 
626
 
 
627
 
 
628
 
 
629
static void
 
630
thunar_window_action_side_pane_changed (GtkRadioAction *action,
 
631
                                        GtkRadioAction *current,
 
632
                                        ThunarWindow   *window)
 
633
{
 
634
  GtkWidget *widget;
 
635
  GType      type;
 
636
 
 
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);
 
641
 
 
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))
 
645
    {
 
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);
 
651
    }
 
652
 
 
653
  /* remember the setting */
 
654
  g_object_set (G_OBJECT (window->preferences), "last-side-pane", g_type_name (type), NULL);
 
655
}
 
656
 
 
657
 
 
658
 
 
659
static void
 
660
thunar_window_action_view_changed (GtkRadioAction *action,
 
661
                                   GtkRadioAction *current,
 
662
                                   ThunarWindow   *window)
 
663
{
 
664
  GType type;
 
665
 
 
666
  /* drop the previous view (if any) */
 
667
  if (G_LIKELY (window->view != NULL))
 
668
    {
 
669
      /* destroy and disconnect the previous view */
 
670
      gtk_widget_destroy (window->view);
 
671
 
 
672
      /* update the UI (else GtkUIManager will crash on merging) */
 
673
      gtk_ui_manager_ensure_update (window->ui_manager);
 
674
    }
 
675
 
 
676
  /* determine the new type of view */
 
677
  type = gtk_radio_action_get_current_value (action);
 
678
 
 
679
  /* allocate a new view of the requested type */
 
680
  if (G_LIKELY (type != G_TYPE_NONE))
 
681
    {
 
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);
 
692
    }
 
693
  else
 
694
    {
 
695
      /* this should not happen under normal conditions */
 
696
      window->view = NULL;
 
697
    }
 
698
 
 
699
  /* remember the setting */
 
700
  g_object_set (G_OBJECT (window->preferences), "last-view", g_type_name (type), NULL);
 
701
}
 
702
 
 
703
 
 
704
 
 
705
static void
 
706
thunar_window_action_go_up (GtkAction    *action,
 
707
                            ThunarWindow *window)
 
708
{
 
709
  ThunarFile *parent;
 
710
 
 
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));
 
715
}
 
716
 
 
717
 
 
718
 
 
719
static void
 
720
thunar_window_action_open_home (GtkAction    *action,
 
721
                                ThunarWindow *window)
 
722
{
 
723
  ThunarVfsPath *home_path;
 
724
  ThunarFile    *home_file;
 
725
  GError        *error = NULL;
 
726
 
 
727
  g_return_if_fail (GTK_IS_ACTION (action));
 
728
  g_return_if_fail (THUNAR_IS_WINDOW (window));
 
729
 
 
730
  /* determine the path to the home directory */
 
731
  home_path = thunar_vfs_path_get_for_home ();
 
732
 
 
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))
 
736
    {
 
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);
 
740
    }
 
741
  else
 
742
    {
 
743
      /* open the home folder */
 
744
      thunar_window_set_current_directory (window, home_file);
 
745
      g_object_unref (G_OBJECT (home_file));
 
746
    }
 
747
 
 
748
  /* release our reference on the home path */
 
749
  thunar_vfs_path_unref (home_path);
 
750
}
 
751
 
 
752
 
 
753
 
 
754
static void
 
755
thunar_window_action_open_location (GtkAction    *action,
 
756
                                    ThunarWindow *window)
 
757
{
 
758
  GtkWidget *dialog;
 
759
  GtkWidget *widget;
 
760
 
 
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.
 
763
   */
 
764
  widget = gtk_bin_get_child (GTK_BIN (window->location_bar));
 
765
  if (widget == NULL || !thunar_location_bar_accept_focus (THUNAR_LOCATION_BAR (widget)))
 
766
    {
 
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);
 
775
    }
 
776
}
 
777
 
 
778
 
 
779
 
 
780
static void
 
781
thunar_window_action_about (GtkAction    *action,
 
782
                            ThunarWindow *window)
 
783
{
 
784
  static const gchar *authors[] =
 
785
  {
 
786
    "Benedikt Meurer <benny@xfce.org>",
 
787
    NULL,
 
788
  };
 
789
 
 
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"
 
795
    "\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"
 
799
    "more details.\n"
 
800
    "\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";
 
804
 
 
805
  GdkPixbuf *logo;
 
806
  
 
807
  /* try to load the about logo */
 
808
  logo = gdk_pixbuf_new_from_file (DATADIR "/pixmaps/Thunar/Thunar-about-logo.png", NULL);
 
809
 
 
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),
 
814
                         "authors", authors,
 
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",
 
817
                         "license", license,
 
818
                         "logo", logo,
 
819
                         "name", PACKAGE_NAME,
 
820
                         "translator-credits", _("translator-credits"),
 
821
                         "version", PACKAGE_VERSION,
 
822
                         "website", "http://thunar.xfce.org/",
 
823
                         NULL);
 
824
 
 
825
  /* release the about logo (if any) */
 
826
  if (G_LIKELY (logo != NULL))
 
827
    g_object_unref (G_OBJECT (logo));
 
828
}
 
829
 
 
830
 
 
831
 
 
832
static void
 
833
thunar_window_action_show_hidden (GtkToggleAction *action,
 
834
                                  ThunarWindow    *window)
 
835
{
 
836
  g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
 
837
  g_return_if_fail (THUNAR_IS_WINDOW (window));
 
838
 
 
839
  /* just emit the "notify" signal for the "show-hidden"
 
840
   * signal and the view will automatically sync its state.
 
841
   */
 
842
  g_object_notify (G_OBJECT (window), "show-hidden");
 
843
}
 
844
 
 
845
 
 
846
 
 
847
static void
 
848
thunar_window_current_directory_changed (ThunarFile   *current_directory,
 
849
                                         ThunarWindow *window)
 
850
{
 
851
  GdkPixbuf *icon;
 
852
 
 
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);
 
856
 
 
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));
 
862
}
 
863
 
 
864
 
 
865
 
 
866
static void
 
867
thunar_window_connect_proxy (GtkUIManager *manager,
 
868
                             GtkAction    *action,
 
869
                             GtkWidget    *proxy,
 
870
                             ThunarWindow *window)
 
871
{
 
872
  /* we want to get informed when the user hovers a menu item */
 
873
  if (GTK_IS_MENU_ITEM (proxy))
 
874
    {
 
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);
 
877
    }
 
878
}
 
879
 
 
880
 
 
881
 
 
882
static void
 
883
thunar_window_disconnect_proxy (GtkUIManager *manager,
 
884
                                GtkAction    *action,
 
885
                                GtkWidget    *proxy,
 
886
                                ThunarWindow *window)
 
887
{
 
888
  /* undo what we did in connect_proxy() */
 
889
  if (GTK_IS_MENU_ITEM (proxy))
 
890
    {
 
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);
 
893
    }
 
894
}
 
895
 
 
896
 
 
897
 
 
898
static void
 
899
thunar_window_menu_item_selected (GtkWidget    *menu_item,
 
900
                                  ThunarWindow *window)
 
901
{
 
902
  GtkAction *action;
 
903
  gchar     *tooltip;
 
904
 
 
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))
 
908
    return;
 
909
 
 
910
  /* determine the tooltip from the action */
 
911
  g_object_get (G_OBJECT (action), "tooltip", &tooltip, NULL);
 
912
  if (G_LIKELY (tooltip != NULL))
 
913
    {
 
914
      gtk_statusbar_push (GTK_STATUSBAR (window->statusbar), window->menu_item_tooltip_id, tooltip);
 
915
      g_free (tooltip);
 
916
    }
 
917
}
 
918
 
 
919
 
 
920
 
 
921
static void
 
922
thunar_window_menu_item_deselected (GtkWidget    *menu_item,
 
923
                                    ThunarWindow *window)
 
924
{
 
925
  /* drop the last tooltip from the statusbar */
 
926
  gtk_statusbar_pop (GTK_STATUSBAR (window->statusbar), window->menu_item_tooltip_id);
 
927
}
 
928
 
 
929
 
 
930
 
 
931
static void
 
932
thunar_window_notify_loading (ThunarView   *view,
 
933
                              GParamSpec   *pspec,
 
934
                              ThunarWindow *window)
 
935
{
 
936
  GdkCursor *cursor;
 
937
 
 
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);
 
941
 
 
942
  if (GTK_WIDGET_REALIZED (window))
 
943
    {
 
944
      /* setup the proper cursor */
 
945
      if (thunar_view_get_loading (view))
 
946
        {
 
947
          cursor = gdk_cursor_new (GDK_WATCH);
 
948
          gdk_window_set_cursor (GTK_WIDGET (window)->window, cursor);
 
949
          gdk_cursor_unref (cursor);
 
950
        }
 
951
      else
 
952
        {
 
953
          gdk_window_set_cursor (GTK_WIDGET (window)->window, NULL);
 
954
        }
 
955
    }
 
956
}
 
957
  
 
958
 
 
959
 
 
960
/**
 
961
 * thunar_window_new:
 
962
 *
 
963
 * Allocates a new #ThunarWindow instance, which isn't
 
964
 * associated with any directory.
 
965
 *
 
966
 * Return value: the newly allocated #ThunarWindow instance.
 
967
 **/
 
968
GtkWidget*
 
969
thunar_window_new (void)
 
970
{
 
971
  return g_object_new (THUNAR_TYPE_WINDOW, NULL);
 
972
}
 
973
 
 
974
 
 
975
 
 
976
/**
 
977
 * thunar_window_get_current_directory:
 
978
 * @window : a #ThunarWindow instance.
 
979
 * 
 
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.
 
983
 *
 
984
 * Return value: the directory currently displayed within @window or %NULL.
 
985
 **/
 
986
ThunarFile*
 
987
thunar_window_get_current_directory (ThunarWindow *window)
 
988
{
 
989
  g_return_val_if_fail (THUNAR_IS_WINDOW (window), NULL);
 
990
  return window->current_directory;
 
991
}
 
992
 
 
993
 
 
994
 
 
995
/**
 
996
 * thunar_window_set_current_directory:
 
997
 * @window            : a #ThunarWindow instance.
 
998
 * @current_directory : the new directory or %NULL.
 
999
 **/
 
1000
void
 
1001
thunar_window_set_current_directory (ThunarWindow *window,
 
1002
                                     ThunarFile   *current_directory)
 
1003
{
 
1004
  g_return_if_fail (THUNAR_IS_WINDOW (window));
 
1005
  g_return_if_fail (current_directory == NULL || THUNAR_IS_FILE (current_directory));
 
1006
 
 
1007
  /* check if we already display the requested directory */
 
1008
  if (G_UNLIKELY (window->current_directory == current_directory))
 
1009
    return;
 
1010
 
 
1011
  /* disconnect from the previously active directory */
 
1012
  if (G_LIKELY (window->current_directory != NULL))
 
1013
    {
 
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));
 
1016
    }
 
1017
 
 
1018
  window->current_directory = current_directory;
 
1019
 
 
1020
  /* connect to the new directory */
 
1021
  if (G_LIKELY (current_directory != NULL))
 
1022
    {
 
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));
 
1026
    
 
1027
      /* update window icon and title */
 
1028
      thunar_window_current_directory_changed (current_directory, window);
 
1029
    }
 
1030
 
 
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));
 
1033
 
 
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)));
 
1037
 
 
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.
 
1041
   */
 
1042
  g_object_notify (G_OBJECT (window), "current-directory");
 
1043
}
 
1044
 
 
1045
 
 
1046