-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathnemo-window.c
More file actions
2432 lines (1955 loc) · 67.6 KB
/
nemo-window.c
File metadata and controls
2432 lines (1955 loc) · 67.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Nemo
*
* Copyright (C) 1999, 2000, 2004 Red Hat, Inc.
* Copyright (C) 1999, 2000, 2001 Eazel, Inc.
*
* Nemo is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* Nemo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Suite 500, MA 02110-1335, USA.
*
* Authors: Elliot Lee <[email protected]>
* John Sullivan <[email protected]>
* Alexander Larsson <[email protected]>
*/
/* nemo-window.c: Implementation of the main window object */
#include <config.h>
#include "nemo-window-private.h"
#include "nemo-actions.h"
#include "nemo-application.h"
#include "nemo-bookmarks-window.h"
#include "nemo-desktop-window.h"
#include "nemo-location-bar.h"
#include "nemo-mime-actions.h"
#include "nemo-notebook.h"
#include "nemo-places-sidebar.h"
#include "nemo-tree-sidebar.h"
#include "nemo-view-factory.h"
#include "nemo-window-manage-views.h"
#include "nemo-window-bookmarks.h"
#include "nemo-window-slot.h"
#include "nemo-window-menus.h"
#include "nemo-icon-view.h"
#include "nemo-list-view.h"
#include "nemo-statusbar.h"
#include <eel/eel-debug.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-string.h>
#include <eel/eel-vfs-extensions.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#ifdef HAVE_X11_XF86KEYSYM_H
#include <X11/XF86keysym.h>
#endif
#include <libnemo-private/nemo-file-utilities.h>
#include <libnemo-private/nemo-file-attributes.h>
#include <libnemo-private/nemo-global-preferences.h>
#include <libnemo-private/nemo-metadata.h>
#include <libnemo-private/nemo-clipboard.h>
#include <libnemo-private/nemo-undo.h>
#include <libnemo-private/nemo-search-directory.h>
#include <libnemo-private/nemo-signaller.h>
#define DEBUG_FLAG NEMO_DEBUG_WINDOW
#include <libnemo-private/nemo-debug.h>
#include <math.h>
#include <sys/time.h>
#define MAX_TITLE_LENGTH 180
/* Forward and back buttons on the mouse */
static gboolean mouse_extra_buttons = TRUE;
static guint mouse_forward_button = 9;
static guint mouse_back_button = 8;
static void mouse_back_button_changed (gpointer callback_data);
static void mouse_forward_button_changed (gpointer callback_data);
static void use_extra_mouse_buttons_changed (gpointer callback_data);
static void side_pane_id_changed (NemoWindow *window);
static void toggle_menubar (NemoWindow *window,
gint action);
static void nemo_window_reload (NemoWindow *window);
/* Sanity check: highest mouse button value I could find was 14. 5 is our
* lower threshold (well-documented to be the one of the button events for the
* scrollwheel), so it's hardcoded in the functions below. However, if you have
* a button that registers higher and want to map it, file a bug and
* we'll move the bar. Makes you wonder why the X guys don't have
* defined values for these like the XKB stuff, huh?
*/
#define UPPER_MOUSE_LIMIT 14
enum {
PROP_DISABLE_CHROME = 1,
PROP_SIDEBAR_VIEW_TYPE,
PROP_SHOW_SIDEBAR,
NUM_PROPERTIES,
};
enum {
GO_UP,
RELOAD,
PROMPT_FOR_LOCATION,
LOADING_URI,
HIDDEN_FILES_MODE_CHANGED,
SLOT_ADDED,
SLOT_REMOVED,
LAST_SIGNAL
};
enum {
MENU_HIDE,
MENU_SHOW,
MENU_TOGGLE
};
static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
G_DEFINE_TYPE (NemoWindow, nemo_window, GTK_TYPE_APPLICATION_WINDOW);
static const struct {
unsigned int keyval;
const char *action;
} extra_window_keybindings [] = {
#ifdef HAVE_X11_XF86KEYSYM_H
{ XF86XK_AddFavorite, NEMO_ACTION_ADD_BOOKMARK },
{ XF86XK_Favorites, NEMO_ACTION_EDIT_BOOKMARKS },
{ XF86XK_Go, NEMO_ACTION_EDIT_LOCATION },
{ XF86XK_HomePage, NEMO_ACTION_GO_HOME },
{ XF86XK_OpenURL, NEMO_ACTION_EDIT_LOCATION },
{ XF86XK_Refresh, NEMO_ACTION_RELOAD },
{ XF86XK_Reload, NEMO_ACTION_RELOAD },
{ XF86XK_Search, NEMO_ACTION_SEARCH },
{ XF86XK_Start, NEMO_ACTION_GO_HOME },
{ XF86XK_Stop, NEMO_ACTION_STOP },
{ XF86XK_ZoomIn, NEMO_ACTION_ZOOM_IN },
{ XF86XK_ZoomOut, NEMO_ACTION_ZOOM_OUT },
{ XF86XK_Back, NEMO_ACTION_BACK },
{ XF86XK_Forward, NEMO_ACTION_FORWARD }
#endif
};
void
nemo_window_push_status (NemoWindow *window,
const char *text)
{
g_return_if_fail (NEMO_IS_WINDOW (window));
/* clear any previous message, underflow is allowed */
gtk_statusbar_pop (GTK_STATUSBAR (window->details->statusbar), 0);
if (text != NULL && text[0] != '\0') {
gtk_statusbar_push (GTK_STATUSBAR (window->details->statusbar), 0, text);
}
}
void
nemo_window_go_to (NemoWindow *window, GFile *location)
{
g_return_if_fail (NEMO_IS_WINDOW (window));
nemo_window_slot_open_location (nemo_window_get_active_slot (window),
location, 0);
}
void
nemo_window_go_to_tab (NemoWindow *window, GFile *location)
{
g_return_if_fail (NEMO_IS_WINDOW (window));
nemo_window_slot_open_location (nemo_window_get_active_slot (window),
location, NEMO_WINDOW_OPEN_FLAG_NEW_TAB);
}
void
nemo_window_go_to_full (NemoWindow *window,
GFile *location,
NemoWindowGoToCallback callback,
gpointer user_data)
{
g_return_if_fail (NEMO_IS_WINDOW (window));
nemo_window_slot_open_location_full (nemo_window_get_active_slot (window),
location, 0, NULL, callback, user_data);
}
static void
nemo_window_go_up_signal (NemoWindow *window)
{
nemo_window_slot_go_up (nemo_window_get_active_slot (window), 0);
}
void
nemo_window_slot_removed (NemoWindow *window, NemoWindowSlot *slot)
{
g_signal_emit (window, signals[SLOT_REMOVED], 0, slot);
}
void
nemo_window_slot_added (NemoWindow *window, NemoWindowSlot *slot)
{
g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
}
void
nemo_window_new_tab (NemoWindow *window)
{
NemoWindowSlot *current_slot;
NemoWindowSlot *new_slot;
NemoWindowOpenFlags flags;
GFile *location;
int new_slot_position;
char *scheme;
current_slot = nemo_window_get_active_slot (window);
location = nemo_window_slot_get_location (current_slot);
if (location != NULL) {
flags = 0;
new_slot_position = g_settings_get_enum (nemo_preferences, NEMO_PREFERENCES_NEW_TAB_POSITION);
if (new_slot_position == NEMO_NEW_TAB_POSITION_END) {
flags = NEMO_WINDOW_OPEN_SLOT_APPEND;
}
scheme = g_file_get_uri_scheme (location);
if (!strcmp (scheme, "x-nemo-search")) {
g_object_unref (location);
location = g_file_new_for_path (g_get_home_dir ());
}
g_free (scheme);
new_slot = nemo_window_pane_open_slot (current_slot->pane, flags);
nemo_window_set_active_slot (window, new_slot);
nemo_window_slot_open_location (new_slot, location, 0);
g_object_unref (location);
}
}
static void
update_cursor (NemoWindow *window)
{
NemoWindowSlot *slot;
GdkCursor *cursor;
slot = nemo_window_get_active_slot (window);
if (slot && slot->allow_stop) {
cursor = gdk_cursor_new (GDK_WATCH);
gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), cursor);
g_object_unref (cursor);
} else {
gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
}
}
void
nemo_window_sync_allow_stop (NemoWindow *window,
NemoWindowSlot *slot)
{
GtkAction *stop_action;
GtkAction *reload_action;
gboolean allow_stop, slot_is_active;
NemoNotebook *notebook;
stop_action = gtk_action_group_get_action (nemo_window_get_main_action_group (window),
NEMO_ACTION_STOP);
reload_action = gtk_action_group_get_action (nemo_window_get_main_action_group (window),
NEMO_ACTION_RELOAD);
allow_stop = gtk_action_get_sensitive (stop_action);
slot_is_active = (slot == nemo_window_get_active_slot (window));
if (!slot_is_active ||
allow_stop != slot->allow_stop) {
if (slot_is_active) {
gtk_action_set_visible (stop_action, slot->allow_stop);
gtk_action_set_visible (reload_action, !slot->allow_stop);
}
if (gtk_widget_get_realized (GTK_WIDGET (window))) {
update_cursor (window);
}
notebook = NEMO_NOTEBOOK (slot->pane->notebook);
nemo_notebook_sync_loading (notebook, slot);
}
}
static void
nemo_window_prompt_for_location (NemoWindow *window,
const char *initial)
{
NemoWindowPane *pane;
g_return_if_fail (NEMO_IS_WINDOW (window));
if (!NEMO_IS_DESKTOP_WINDOW (window)) {
if (initial) {
NemoEntry *entry;
nemo_window_show_location_entry(window);
pane = window->details->active_pane;
entry = nemo_location_bar_get_entry (NEMO_LOCATION_BAR (pane->location_bar));
nemo_entry_set_text (entry, initial);
gtk_editable_set_position (GTK_EDITABLE (entry), -1);
}
}
}
/* Code should never force the window taller than this size.
* (The user can still stretch the window taller if desired).
*/
static guint
get_max_forced_height (GdkScreen *screen)
{
return (gdk_screen_get_height (screen) * 90) / 100;
}
/* Code should never force the window wider than this size.
* (The user can still stretch the window wider if desired).
*/
static guint
get_max_forced_width (GdkScreen *screen)
{
return (gdk_screen_get_width (screen) * 90) / 100;
}
/* This must be called when construction of NemoWindow is finished,
* since it depends on the type of the argument, which isn't decided at
* construction time.
*/
static void
nemo_window_set_initial_window_geometry (NemoWindow *window)
{
GdkScreen *screen;
guint max_width_for_screen, max_height_for_screen;
guint default_width, default_height;
screen = gtk_window_get_screen (GTK_WINDOW (window));
max_width_for_screen = get_max_forced_width (screen);
max_height_for_screen = get_max_forced_height (screen);
default_width = NEMO_WINDOW_DEFAULT_WIDTH;
default_height = NEMO_WINDOW_DEFAULT_HEIGHT;
gtk_window_set_default_size (GTK_WINDOW (window),
MIN (default_width,
max_width_for_screen),
MIN (default_height,
max_height_for_screen));
}
static gboolean
save_sidebar_width_cb (gpointer user_data)
{
NemoWindow *window = user_data;
window->details->sidebar_width_handler_id = 0;
DEBUG ("Saving sidebar width: %d", window->details->side_pane_width);
g_settings_set_int (nemo_window_state,
NEMO_WINDOW_STATE_SIDEBAR_WIDTH,
window->details->side_pane_width);
return FALSE;
}
/* side pane helpers */
static void
side_pane_size_allocate_callback (GtkWidget *widget,
GtkAllocation *allocation,
gpointer user_data)
{
NemoWindow *window;
window = user_data;
if (window->details->sidebar_width_handler_id != 0) {
g_source_remove (window->details->sidebar_width_handler_id);
window->details->sidebar_width_handler_id = 0;
}
if (allocation->width != window->details->side_pane_width &&
allocation->width > 1) {
window->details->side_pane_width = allocation->width;
window->details->sidebar_width_handler_id =
g_timeout_add (100, save_sidebar_width_cb, window);
}
}
static void
setup_side_pane_width (NemoWindow *window)
{
g_return_if_fail (window->details->sidebar != NULL);
window->details->side_pane_width =
g_settings_get_int (nemo_window_state,
NEMO_WINDOW_STATE_SIDEBAR_WIDTH);
gtk_paned_set_position (GTK_PANED (window->details->content_paned),
window->details->side_pane_width);
}
static void
nemo_window_set_up_sidebar (NemoWindow *window)
{
GtkWidget *sidebar;
DEBUG ("Setting up sidebar id %s", window->details->sidebar_id);
window->details->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_style_context_add_class (gtk_widget_get_style_context (window->details->sidebar),
GTK_STYLE_CLASS_SIDEBAR);
gtk_paned_pack1 (GTK_PANED (window->details->content_paned),
GTK_WIDGET (window->details->sidebar),
FALSE, FALSE);
setup_side_pane_width (window);
g_signal_connect (window->details->sidebar,
"size_allocate",
G_CALLBACK (side_pane_size_allocate_callback),
window);
g_signal_connect_object (NEMO_WINDOW (window), "notify::sidebar-view-id",
G_CALLBACK (side_pane_id_changed), window, 0);
if (g_strcmp0 (window->details->sidebar_id, NEMO_WINDOW_SIDEBAR_PLACES) == 0) {
sidebar = nemo_places_sidebar_new (window);
} else if (g_strcmp0 (window->details->sidebar_id, NEMO_WINDOW_SIDEBAR_TREE) == 0) {
sidebar = nemo_tree_sidebar_new (window);
} else {
g_assert_not_reached ();
}
gtk_box_pack_start (GTK_BOX (window->details->sidebar), sidebar, TRUE, TRUE, 0);
gtk_widget_show (sidebar);
gtk_widget_show (GTK_WIDGET (window->details->sidebar));
}
static void
nemo_window_tear_down_sidebar (NemoWindow *window)
{
DEBUG ("Destroying sidebar");
g_signal_handlers_disconnect_by_func (NEMO_WINDOW (window), side_pane_id_changed, window);
if (window->details->sidebar != NULL) {
gtk_widget_destroy (GTK_WIDGET (window->details->sidebar));
window->details->sidebar = NULL;
}
}
void
nemo_window_hide_sidebar (NemoWindow *window)
{
DEBUG ("Called hide_sidebar()");
if (window->details->sidebar == NULL) {
return;
}
nemo_window_tear_down_sidebar (window);
nemo_window_update_show_hide_ui_elements (window);
nemo_window_set_show_sidebar (window, FALSE);
}
void
nemo_window_show_sidebar (NemoWindow *window)
{
DEBUG ("Called show_sidebar()");
if (window->details->sidebar != NULL) {
return;
}
if (window->details->disable_chrome) {
return;
}
nemo_window_set_up_sidebar (window);
nemo_window_update_show_hide_ui_elements (window);
nemo_window_set_show_sidebar (window, TRUE);
}
static gboolean
sidebar_id_is_valid (const gchar *sidebar_id)
{
return (g_strcmp0 (sidebar_id, NEMO_WINDOW_SIDEBAR_PLACES) == 0 ||
g_strcmp0 (sidebar_id, NEMO_WINDOW_SIDEBAR_TREE) == 0);
}
static void
side_pane_id_changed (NemoWindow *window)
{
if (!sidebar_id_is_valid (window->details->sidebar_id)) {
return;
}
/* refresh the sidebar setting */
nemo_window_tear_down_sidebar (window);
nemo_window_set_up_sidebar (window);
}
gboolean
nemo_window_disable_chrome_mapping (GValue *value,
GVariant *variant,
gpointer user_data)
{
NemoWindow *window = user_data;
g_value_set_boolean (value,
g_variant_get_boolean (variant) &&
!window->details->disable_chrome);
return TRUE;
}
static gboolean
on_button_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
NemoWindow *window = NEMO_WINDOW (user_data);
if (event->button == 3) {
toggle_menubar (window, MENU_TOGGLE);
}
return GDK_EVENT_STOP;
}
static void
clear_menu_hide_delay (NemoWindow *window)
{
if (window->details->menu_hide_delay_id > 0) {
g_source_remove (window->details->menu_hide_delay_id);
}
window->details->menu_hide_delay_id = 0;
}
static gboolean
hide_menu_on_delay (NemoWindow *window)
{
toggle_menubar (window, MENU_HIDE);
window->details->menu_hide_delay_id = 0;
return FALSE;
}
static gboolean
on_menu_focus_out (GtkMenuShell *widget,
GdkEvent *event,
gpointer user_data)
{
NemoWindow *window = NEMO_WINDOW (user_data);
/* The menu, when visible on demand, gets the keyboard grab.
* If the user clicks on some element in the window,, we want the menu
* to disappear, but if it's done immediately, everything shifts up the
* height of the menu, and the user will more than likely end up clicking
* in the wrong spot. Delay the hide momentarily, to allow the user to
* complete their click action. */
clear_menu_hide_delay (window);
/* When a submenu pops-up, the menu loses focus. The menu should disappear
* only when none of its elements is selected. */
if (!gtk_menu_shell_get_selected_item (widget)) {
window->details->menu_hide_delay_id = g_timeout_add (200, (GSourceFunc) hide_menu_on_delay, window);
}
return GDK_EVENT_PROPAGATE;
}
void
on_menu_selection_done (GtkMenuShell *menushell,
gpointer user_data)
{
NemoWindow *window = NEMO_WINDOW (user_data);
/* Remove the menu inmediately after selecting an item. */
clear_menu_hide_delay (window);
window->details->menu_hide_delay_id = g_timeout_add (0, (GSourceFunc) hide_menu_on_delay, window);
}
static void
nemo_window_constructed (GObject *self)
{
NemoWindow *window;
GtkWidget *grid;
GtkWidget *menu;
GtkWidget *hpaned;
GtkWidget *vbox;
GtkWidget *toolbar_holder;
GtkWidget *nemo_statusbar;
NemoWindowPane *pane;
NemoWindowSlot *slot;
NemoApplication *application;
window = NEMO_WINDOW (self);
application = nemo_application_get_singleton ();
G_OBJECT_CLASS (nemo_window_parent_class)->constructed (self);
gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (application));
/* disable automatic menubar handling, since we show our regular
* menubar together with the app menu.
*/
gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (self), FALSE);
grid = gtk_grid_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
gtk_widget_show (grid);
gtk_container_add (GTK_CONTAINER (window), grid);
/* Statusbar is packed in the subclasses */
nemo_window_initialize_menus (window);
nemo_window_initialize_actions (window);
menu = gtk_ui_manager_get_widget (window->details->ui_manager, "/MenuBar");
window->details->menubar = menu;
gtk_widget_set_can_focus (menu, TRUE);
gtk_widget_set_hexpand (menu, TRUE);
g_signal_connect_object (menu,
"focus-out-event",
G_CALLBACK (on_menu_focus_out),
window,
0);
g_signal_connect_object (menu,
"selection-done",
G_CALLBACK (on_menu_selection_done),
window,
0);
if (g_settings_get_boolean (nemo_window_state, NEMO_WINDOW_STATE_START_WITH_MENU_BAR)){
gtk_widget_show (menu);
} else {
gtk_widget_hide (menu);
}
g_settings_bind_with_mapping (nemo_window_state,
NEMO_WINDOW_STATE_START_WITH_MENU_BAR,
window->details->menubar,
"visible",
G_SETTINGS_BIND_GET,
nemo_window_disable_chrome_mapping, NULL,
window, NULL);
gtk_container_add (GTK_CONTAINER (grid), menu);
/* Set up the toolbar place holder */
toolbar_holder = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (grid), toolbar_holder);
gtk_widget_show (toolbar_holder);
g_signal_connect_object (toolbar_holder, "button-press-event",
G_CALLBACK (on_button_press_callback), window, 0);
window->details->toolbar_holder = toolbar_holder;
/* Register to menu provider extension signal managing menu updates */
g_signal_connect_object (nemo_signaller_get_current (), "popup_menu_changed",
G_CALLBACK (nemo_window_load_extension_menus), window, G_CONNECT_SWAPPED);
window->details->content_paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_hexpand (window->details->content_paned, TRUE);
gtk_widget_set_vexpand (window->details->content_paned, TRUE);
gtk_container_add (GTK_CONTAINER (grid), window->details->content_paned);
gtk_widget_show (window->details->content_paned);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_paned_pack2 (GTK_PANED (window->details->content_paned), vbox,
TRUE, FALSE);
gtk_widget_show (vbox);
hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
gtk_widget_show (hpaned);
window->details->split_view_hpane = hpaned;
pane = nemo_window_pane_new (window);
window->details->panes = g_list_prepend (window->details->panes, pane);
gtk_paned_pack1 (GTK_PANED (hpaned), GTK_WIDGET (pane), TRUE, FALSE);
nemo_statusbar = nemo_status_bar_new (window);
window->details->nemo_status_bar = nemo_statusbar;
GtkWidget *sep = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (grid), sep);
gtk_widget_show (sep);
GtkWidget *eb;
eb = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (eb), nemo_statusbar);
gtk_container_add (GTK_CONTAINER (grid), eb);
gtk_widget_show (eb);
window->details->statusbar = nemo_status_bar_get_real_statusbar (NEMO_STATUS_BAR (nemo_statusbar));
window->details->help_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->details->statusbar),
"help_message");
gtk_widget_add_events (GTK_WIDGET (eb), GDK_BUTTON_PRESS_MASK);
g_signal_connect_object (GTK_WIDGET (eb), "button-press-event",
G_CALLBACK (on_button_press_callback), window, 0);
g_settings_bind_with_mapping (nemo_window_state,
NEMO_WINDOW_STATE_START_WITH_STATUS_BAR,
window->details->nemo_status_bar,
"visible",
G_SETTINGS_BIND_DEFAULT,
nemo_window_disable_chrome_mapping, NULL,
window, NULL);
g_object_bind_property (window->details->nemo_status_bar, "visible",
sep, "visible",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
/* this has to be done after the location bar has been set up,
* but before menu stuff is being called */
nemo_window_set_active_pane (window, pane);
side_pane_id_changed (window);
nemo_window_initialize_bookmarks_menu (window);
nemo_window_set_initial_window_geometry (window);
slot = nemo_window_pane_open_slot (window->details->active_pane, 0);
nemo_window_set_active_slot (window, slot);
if (g_settings_get_boolean (nemo_preferences, NEMO_PREFERENCES_START_WITH_DUAL_PANE) &&
!window->details->disable_chrome)
nemo_window_split_view_on (window);
g_signal_connect_swapped (GTK_WINDOW (window),
"notify::scale-factor",
G_CALLBACK (nemo_window_reload),
window);
}
static void
nemo_window_set_property (GObject *object,
guint arg_id,
const GValue *value,
GParamSpec *pspec)
{
NemoWindow *window;
window = NEMO_WINDOW (object);
switch (arg_id) {
case PROP_DISABLE_CHROME:
window->details->disable_chrome = g_value_get_boolean (value);
break;
case PROP_SIDEBAR_VIEW_TYPE:
window->details->sidebar_id = g_strdup (g_value_get_string (value));
break;
case PROP_SHOW_SIDEBAR:
nemo_window_set_show_sidebar (window, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
break;
}
}
static void
nemo_window_get_property (GObject *object,
guint arg_id,
GValue *value,
GParamSpec *pspec)
{
NemoWindow *window;
window = NEMO_WINDOW (object);
switch (arg_id) {
case PROP_DISABLE_CHROME:
g_value_set_boolean (value, window->details->disable_chrome);
break;
case PROP_SIDEBAR_VIEW_TYPE:
g_value_set_string (value, window->details->sidebar_id);
break;
case PROP_SHOW_SIDEBAR:
g_value_set_boolean (value, window->details->show_sidebar);
break;
default:
g_assert_not_reached ();
break;
}
}
static void
destroy_panes_foreach (gpointer data,
gpointer user_data)
{
NemoWindowPane *pane = data;
NemoWindow *window = user_data;
nemo_window_close_pane (window, pane);
}
static void
nemo_window_destroy (GtkWidget *object)
{
NemoWindow *window;
GList *panes_copy;
window = NEMO_WINDOW (object);
DEBUG ("Destroying window");
/* close the sidebar first */
nemo_window_tear_down_sidebar (window);
/* close all panes safely */
panes_copy = g_list_copy (window->details->panes);
g_list_foreach (panes_copy, (GFunc) destroy_panes_foreach, window);
g_list_free (panes_copy);
/* the panes list should now be empty */
g_assert (window->details->panes == NULL);
g_assert (window->details->active_pane == NULL);
GTK_WIDGET_CLASS (nemo_window_parent_class)->destroy (object);
}
static void
nemo_window_finalize (GObject *object)
{
NemoWindow *window;
window = NEMO_WINDOW (object);
if (window->details->sidebar_width_handler_id != 0) {
g_source_remove (window->details->sidebar_width_handler_id);
window->details->sidebar_width_handler_id = 0;
}
g_signal_handlers_disconnect_by_func (nemo_preferences,
nemo_window_sync_thumbnail_action,
window);
clear_menu_hide_delay (window);
nemo_window_finalize_menus (window);
g_clear_object (&window->details->nav_state);
g_clear_object (&window->details->secondary_pane_last_location);
g_clear_object (&window->details->ui_manager);
g_free (window->details->sidebar_id);
/* nemo_window_close() should have run */
g_assert (window->details->panes == NULL);
G_OBJECT_CLASS (nemo_window_parent_class)->finalize (object);
}
void
nemo_window_view_visible (NemoWindow *window,
NemoView *view)
{
NemoWindowSlot *slot;
NemoWindowPane *pane;
GList *l, *walk;
g_return_if_fail (NEMO_IS_WINDOW (window));
slot = nemo_window_get_slot_for_view (window, view);
if (slot->visible) {
return;
}
slot->visible = TRUE;
pane = slot->pane;
if (gtk_widget_get_visible (GTK_WIDGET (pane))) {
return;
}
/* Look for other non-visible slots */
for (l = pane->slots; l != NULL; l = l->next) {
slot = l->data;
if (!slot->visible) {
return;
}
}
/* None, this pane is visible */
gtk_widget_show (GTK_WIDGET (pane));
/* Look for other non-visible panes */
for (walk = window->details->panes; walk; walk = walk->next) {
pane = walk->data;
if (!gtk_widget_get_visible (GTK_WIDGET (pane))) {
return;
}
for (l = pane->slots; l != NULL; l = l->next) {
slot = l->data;
nemo_window_slot_update_title (slot);
nemo_window_slot_update_icon (slot);
}
}
nemo_window_pane_grab_focus (window->details->active_pane);
/* All slots and panes visible, show window */
gtk_widget_show (GTK_WIDGET (window));
}
static gboolean
nemo_window_is_desktop (NemoWindow *window)
{
return window->details->disable_chrome;
}
static void
nemo_window_save_geometry (NemoWindow *window)
{
char *geometry_string;
gboolean is_maximized;
g_assert (NEMO_IS_WINDOW (window));
if (gtk_widget_get_window (GTK_WIDGET (window)) && !nemo_window_is_desktop (window)) {
GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
if (state & GDK_WINDOW_STATE_TILED) {
return;
}
geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
is_maximized = state & GDK_WINDOW_STATE_MAXIMIZED;
if (!is_maximized) {
g_settings_set_string
(nemo_window_state, NEMO_WINDOW_STATE_GEOMETRY,
geometry_string);
}
g_free (geometry_string);
g_settings_set_boolean
(nemo_window_state, NEMO_WINDOW_STATE_MAXIMIZED,
is_maximized);
}
}
void
nemo_window_close (NemoWindow *window)
{
NEMO_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->close (window);
}
void
nemo_window_close_pane (NemoWindow *window,
NemoWindowPane *pane)
{
g_assert (NEMO_IS_WINDOW_PANE (pane));
while (pane->slots != NULL) {
NemoWindowSlot *slot = pane->slots->data;
nemo_window_pane_remove_slot_unsafe (pane, slot);
}