summaryrefslogtreecommitdiff
path: root/src/caja-window.c
blob: 4a22548534232a1dbe3dd2497d73139273b6f9b9 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
/*
 *  Caja
 *
 *  Copyright (C) 1999, 2000, 2004 Red Hat, Inc.
 *  Copyright (C) 1999, 2000, 2001 Eazel, Inc.
 *
 *  Caja 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.
 *
 *  Caja 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *  Authors: Elliot Lee <sopwith@redhat.com>
 *  	     John Sullivan <sullivan@eazel.com>
 *           Alexander Larsson <alexl@redhat.com>
 */

/* caja-window.c: Implementation of the main window object */

#include <config.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 "../eel/eel-debug.h"
#include "../eel/eel-gtk-macros.h"
#include "../eel/eel-string.h"

#include "../libcaja-private/caja-file-utilities.h"
#include "../libcaja-private/caja-file-attributes.h"
#include "../libcaja-private/caja-global-preferences.h"
#include "../libcaja-private/caja-metadata.h"
#include "../libcaja-private/caja-mime-actions.h"
#include "../libcaja-private/caja-program-choosing.h"
#include "../libcaja-private/caja-view-factory.h"
#include "../libcaja-private/caja-clipboard.h"
#include "../libcaja-private/caja-search-directory.h"
#include "../libcaja-private/caja-signaller.h"

#include "caja-window-private.h"
#include "caja-actions.h"
#include "caja-application.h"
#include "caja-bookmarks-window.h"
#include "caja-information-panel.h"
#include "caja-window-manage-views.h"
#include "caja-window-bookmarks.h"
#include "caja-window-slot.h"
#include "caja-navigation-window-slot.h"
#include "caja-search-bar.h"
#include "caja-navigation-window-pane.h"
#include "caja-src-marshal.h"

#define MAX_HISTORY_ITEMS 50

#define EXTRA_VIEW_WIDGETS_BACKGROUND "#a7c6e1"

/* dock items */

#define CAJA_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER	"/MenuBar/View/View Choices/Extra Viewer"
#define CAJA_MENU_PATH_SHORT_LIST_PLACEHOLDER  	"/MenuBar/View/View Choices/Short List"

enum {
	ARG_0,
	ARG_APP
};

enum {
	GO_UP,
	RELOAD,
	PROMPT_FOR_LOCATION,
	ZOOM_CHANGED,
	VIEW_AS_CHANGED,
	LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

typedef struct
{
    CajaWindow *window;
    char *id;
} ActivateViewData;

static void cancel_view_as_callback         (CajaWindowSlot      *slot);
static void caja_window_info_iface_init (CajaWindowInfoIface *iface);
static void action_view_as_callback         (GtkAction               *action,
        ActivateViewData        *data);

static GList *history_list;

G_DEFINE_TYPE_WITH_CODE (CajaWindow, caja_window, GTK_TYPE_WINDOW,
                         G_ADD_PRIVATE (CajaWindow)
                         G_IMPLEMENT_INTERFACE (CAJA_TYPE_WINDOW_INFO,
                                 caja_window_info_iface_init));

static const struct
{
    unsigned int keyval;
    const char *action;
} extra_window_keybindings [] =
{
#ifdef HAVE_X11_XF86KEYSYM_H
    { XF86XK_AddFavorite,	CAJA_ACTION_ADD_BOOKMARK },
    { XF86XK_Favorites,	CAJA_ACTION_EDIT_BOOKMARKS },
    { XF86XK_Go,		CAJA_ACTION_GO_TO_LOCATION },
    /* TODO?{ XF86XK_History,	CAJA_ACTION_HISTORY }, */
    { XF86XK_HomePage,      CAJA_ACTION_GO_HOME },
    { XF86XK_OpenURL,	CAJA_ACTION_GO_TO_LOCATION },
    { XF86XK_Refresh,	CAJA_ACTION_RELOAD },
    { XF86XK_Reload,	CAJA_ACTION_RELOAD },
    { XF86XK_Search,	CAJA_ACTION_SEARCH },
    { XF86XK_Start,		CAJA_ACTION_GO_HOME },
    { XF86XK_Stop,		CAJA_ACTION_STOP },
    { XF86XK_ZoomIn,	CAJA_ACTION_ZOOM_IN },
    { XF86XK_ZoomOut,	CAJA_ACTION_ZOOM_OUT }
#endif
};

static void
caja_window_init (CajaWindow *window)
{
    GtkWidget *grid;
    GtkWidget *menu;
    GtkWidget *statusbar;

    static const gchar css_custom[] =
      "#caja-extra-view-widget {"
      "  background-color: " EXTRA_VIEW_WIDGETS_BACKGROUND ";"
      "}";

    GError *error = NULL;
    GtkCssProvider *provider = gtk_css_provider_new ();
    gtk_css_provider_load_from_data (provider, css_custom, -1, &error);

    if (error != NULL) {
            g_warning ("Can't parse CajaWindow's CSS custom description: %s\n", error->message);
            g_error_free (error);
    } else {
            gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (window)),
                                            GTK_STYLE_PROVIDER (provider),
                                            GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    }

    g_object_unref (provider);
    window->details = caja_window_get_instance_private (window);

    window->details->panes = NULL;
    window->details->active_pane = NULL;

    window->details->show_hidden_files_mode = CAJA_WINDOW_SHOW_HIDDEN_FILES_DEFAULT;

    /* Set initial window title */
    gtk_window_set_title (GTK_WINDOW (window), _("Caja"));

    grid = gtk_grid_new ();
    gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
    window->details->grid = grid;
    gtk_widget_show (grid);
    gtk_container_add (GTK_CONTAINER (window), grid);

    statusbar = gtk_statusbar_new ();
    gtk_widget_set_name (statusbar, "statusbar-noborder");

/* set margin to zero to reduce size of statusbar */
	gtk_widget_set_margin_top (GTK_WIDGET (statusbar), 0);
	gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0);

    window->details->statusbar = statusbar;
    window->details->help_message_cid = gtk_statusbar_get_context_id
                                        (GTK_STATUSBAR (statusbar), "help_message");
    /* Statusbar is packed in the subclasses */

    caja_window_initialize_menus (window);

    menu = gtk_ui_manager_get_widget (window->details->ui_manager, "/MenuBar");
    window->details->menubar = menu;
    gtk_widget_set_hexpand (menu, TRUE);
    gtk_widget_show (menu);
    gtk_grid_attach (GTK_GRID (grid), menu, 0, 0, 1, 1);

    /* Register to menu provider extension signal managing menu updates */
    g_signal_connect_object (caja_signaller_get_current (), "popup_menu_changed",
                             G_CALLBACK (caja_window_load_extension_menus), window, G_CONNECT_SWAPPED);
}

/* Unconditionally synchronize the GtkUIManager of WINDOW. */
static void
caja_window_ui_update (CajaWindow *window)
{
    g_assert (CAJA_IS_WINDOW (window));

    gtk_ui_manager_ensure_update (window->details->ui_manager);
}

static void
caja_window_push_status (CajaWindow *window,
                         const char *text)
{
    g_return_if_fail (CAJA_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
caja_window_sync_status (CajaWindow *window)
{
    CajaWindowSlot *slot;

    slot = window->details->active_pane->active_slot;
    caja_window_push_status (window, slot->status_text);
}

void
caja_window_go_to (CajaWindow *window, GFile *location)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    caja_window_slot_go_to (window->details->active_pane->active_slot, location, FALSE);
}

void
caja_window_go_to_tab (CajaWindow *window, GFile *location)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    caja_window_slot_go_to (window->details->active_pane->active_slot, location, TRUE);
}

void
caja_window_go_to_full (CajaWindow *window,
                        GFile                 *location,
                        CajaWindowGoToCallback callback,
                        gpointer               user_data)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    caja_window_slot_go_to_full (window->details->active_pane->active_slot, location, FALSE, callback, user_data);
}

void
caja_window_go_to_with_selection (CajaWindow *window, GFile *location, GList *new_selection)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    caja_window_slot_go_to_with_selection (window->details->active_pane->active_slot, location, new_selection);
}

static gboolean
caja_window_go_up_signal (CajaWindow *window, gboolean close_behind)
{
    caja_window_go_up (window, close_behind, FALSE);
    return TRUE;
}

void
caja_window_new_tab (CajaWindow *window)
{
    CajaWindowSlot *current_slot;
    CajaWindowOpenFlags flags;
    GFile *location = NULL;

    current_slot = window->details->active_pane->active_slot;
    location = caja_window_slot_get_location (current_slot);

    if (location != NULL) {
        CajaWindowSlot *new_slot;
        int new_slot_position;
        char *scheme;

    	flags = 0;

    	new_slot_position = g_settings_get_enum (caja_preferences, CAJA_PREFERENCES_NEW_TAB_POSITION);
    	if (new_slot_position == CAJA_NEW_TAB_POSITION_END) {
    		flags = CAJA_WINDOW_OPEN_SLOT_APPEND;
    	}

    	scheme = g_file_get_uri_scheme (location);
    	if (!strcmp (scheme, "x-caja-search")) {
    		g_object_unref (location);
    		location = g_file_new_for_path (g_get_home_dir ());
    	}
    	g_free (scheme);

    	new_slot = caja_window_open_slot (current_slot->pane, flags);
    	caja_window_set_active_slot (window, new_slot);
    	caja_window_slot_go_to (new_slot, location, FALSE);
    	g_object_unref (location);
    }
}

void
caja_window_go_up (CajaWindow *window, gboolean close_behind, gboolean new_tab)
{
    CajaWindowSlot *slot;
    GFile *parent;
    GList *selection;
    CajaWindowOpenFlags flags;

    g_assert (CAJA_IS_WINDOW (window));

    slot = window->details->active_pane->active_slot;

    if (slot->location == NULL)
    {
        return;
    }

    parent = g_file_get_parent (slot->location);

    if (parent == NULL)
    {
        return;
    }

    selection = g_list_prepend (NULL, g_object_ref (slot->location));

    flags = 0;
    if (close_behind)
    {
        flags |= CAJA_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
    }
    if (new_tab)
    {
        flags |= CAJA_WINDOW_OPEN_FLAG_NEW_TAB;
    }

    caja_window_slot_open_location_full (slot, parent,
                                         CAJA_WINDOW_OPEN_ACCORDING_TO_MODE,
                                         flags,
                                         selection,
                                         NULL, NULL);

    g_object_unref (parent);

    g_list_free_full (selection, g_object_unref);
}

static void
real_set_allow_up (CajaWindow *window,
                   gboolean        allow)
{
    GtkAction *action;

    g_assert (CAJA_IS_WINDOW (window));

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_UP);
    gtk_action_set_sensitive (action, allow);
    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_UP_ACCEL);
    gtk_action_set_sensitive (action, allow);
    G_GNUC_END_IGNORE_DEPRECATIONS;
}

void
caja_window_allow_up (CajaWindow *window, gboolean allow)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    EEL_CALL_METHOD (CAJA_WINDOW_CLASS, window,
                     set_allow_up, (window, allow));
}

static void
update_cursor (CajaWindow *window)
{
    CajaWindowSlot *slot;

    slot = window->details->active_pane->active_slot;

    if (slot->allow_stop)
    {
        GdkDisplay *display;
        GdkCursor * cursor;

        display = gtk_widget_get_display (GTK_WIDGET (window));
        cursor = gdk_cursor_new_for_display (display, 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
caja_window_sync_allow_stop (CajaWindow *window,
                             CajaWindowSlot *slot)
{
    GtkAction *action;
    gboolean allow_stop;

    g_assert (CAJA_IS_WINDOW (window));

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_STOP);
    allow_stop = gtk_action_get_sensitive (action);
    G_GNUC_END_IGNORE_DEPRECATIONS;

    if (slot != window->details->active_pane->active_slot ||
            allow_stop != slot->allow_stop)
    {
        if (slot == window->details->active_pane->active_slot)
        {
            G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
            gtk_action_set_sensitive (action, slot->allow_stop);
            G_GNUC_END_IGNORE_DEPRECATIONS;
        }

        if (gtk_widget_get_realized (GTK_WIDGET (window)))
        {
            update_cursor (window);
        }

        EEL_CALL_METHOD (CAJA_WINDOW_CLASS, window,
                         sync_allow_stop, (window, slot));
    }
}

void
caja_window_allow_reload (CajaWindow *window, gboolean allow)
{
    GtkAction *action;

    g_return_if_fail (CAJA_IS_WINDOW (window));

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_RELOAD);
    gtk_action_set_sensitive (action, allow);
    G_GNUC_END_IGNORE_DEPRECATIONS;
}

void
caja_window_go_home (CajaWindow *window)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    caja_window_slot_go_home (window->details->active_pane->active_slot, FALSE);
}

void
caja_window_prompt_for_location (CajaWindow *window,
                                 const char     *initial)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    EEL_CALL_METHOD (CAJA_WINDOW_CLASS, window,
                     prompt_for_location, (window, initial));
}

static char *
caja_window_get_location_uri (CajaWindow *window)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW (window));

    slot = window->details->active_pane->active_slot;

    if (slot->location)
    {
        return g_file_get_uri (slot->location);
    }
    return NULL;
}

void
caja_window_zoom_in (CajaWindow *window)
{
    g_assert (window != NULL);

    caja_window_pane_zoom_in (window->details->active_pane);
}

void
caja_window_zoom_to_level (CajaWindow *window,
                           CajaZoomLevel level)
{
    g_assert (window != NULL);

    caja_window_pane_zoom_to_level (window->details->active_pane, level);
}

void
caja_window_zoom_out (CajaWindow *window)
{
    g_assert (window != NULL);

    caja_window_pane_zoom_out (window->details->active_pane);
}

void
caja_window_zoom_to_default (CajaWindow *window)
{
    g_assert (window != NULL);

    caja_window_pane_zoom_to_default (window->details->active_pane);
}

/* 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)
{
    gint scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
    return (HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale * 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)
{
    gint scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
    return (WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale * 90) / 100;
}

/* This must be called when construction of CajaWindow is finished,
 * since it depends on the type of the argument, which isn't decided at
 * construction time.
 */
static void
caja_window_set_initial_window_geometry (CajaWindow *window)
{
    GdkScreen *screen;
    guint max_width_for_screen, max_height_for_screen;

    guint default_width = 0;
    guint default_height = 0;

    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);

    EEL_CALL_METHOD (CAJA_WINDOW_CLASS, window,
                     get_default_size, (window, &default_width, &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 void
caja_window_constructed (GObject *self)
{
    CajaWindow *window;

    window = CAJA_WINDOW (self);

    caja_window_initialize_bookmarks_menu (window);
    caja_window_set_initial_window_geometry (window);
}

static void
caja_window_set_property (GObject *object,
                          guint arg_id,
                          const GValue *value,
                          GParamSpec *pspec)
{
    CajaWindow *window;

    window = CAJA_WINDOW (object);

    switch (arg_id)
    {
    case ARG_APP:
        window->application = CAJA_APPLICATION (g_value_get_object (value));
        break;
    }
}

static void
caja_window_get_property (GObject *object,
                          guint arg_id,
                          GValue *value,
                          GParamSpec *pspec)
{
    switch (arg_id)
    {
    case ARG_APP:
        g_value_set_object (value, CAJA_WINDOW (object)->application);
        break;
    }
}

static void
free_stored_viewers (CajaWindow *window)
{
    g_list_free_full (window->details->short_list_viewers, g_free);
    window->details->short_list_viewers = NULL;
    g_free (window->details->extra_viewer);
    window->details->extra_viewer = NULL;
}

static void
caja_window_destroy (GtkWidget *object)
{
    CajaWindow *window;
    GList *panes_copy;

    window = CAJA_WINDOW (object);

    /* close all panes safely */
    panes_copy = g_list_copy (window->details->panes);
    g_list_free_full (panes_copy, (GDestroyNotify) caja_window_close_pane);

    /* the panes list should now be empty */
    g_assert (window->details->panes == NULL);
    g_assert (window->details->active_pane == NULL);

    GTK_WIDGET_CLASS (caja_window_parent_class)->destroy (object);
}

static void
caja_window_finalize (GObject *object)
{
    CajaWindow *window;

    window = CAJA_WINDOW (object);

    caja_window_finalize_menus (window);
    free_stored_viewers (window);

    if (window->details->bookmark_list != NULL)
    {
        g_object_unref (window->details->bookmark_list);
    }

    /* caja_window_close() should have run */
    g_assert (window->details->panes == NULL);

    g_object_unref (window->details->ui_manager);

    G_OBJECT_CLASS (caja_window_parent_class)->finalize (object);
}

static GObject *
caja_window_constructor (GType type,
                         guint n_construct_properties,
                         GObjectConstructParam *construct_params)
{
    GObject *object;
    CajaWindow *window;
    CajaWindowSlot *slot;

    object = (* G_OBJECT_CLASS (caja_window_parent_class)->constructor) (type,
             n_construct_properties,
             construct_params);

    window = CAJA_WINDOW (object);

    slot = caja_window_open_slot (window->details->active_pane, 0);
    caja_window_set_active_slot (window, slot);

    return object;
}

void
caja_window_show_window (CajaWindow    *window)
{
    CajaWindowSlot *slot;
    CajaWindowPane *pane;
    GList *l, *walk;

    for (walk = window->details->panes; walk; walk = walk->next)
    {
        pane = walk->data;
        for (l = pane->slots; l != NULL; l = l->next)
        {
            slot = l->data;

            caja_window_slot_update_title (slot);
            caja_window_slot_update_icon (slot);
        }
    }

    gtk_widget_show (GTK_WIDGET (window));

    slot = window->details->active_pane->active_slot;

    if (slot->viewed_file)
    {
        if (CAJA_IS_SPATIAL_WINDOW (window))
        {
            caja_file_set_has_open_window (slot->viewed_file, TRUE);
        }
    }
}

static void
caja_window_view_visible (CajaWindow *window,
                          CajaView *view)
{
    CajaWindowSlot *slot;
    CajaWindowPane *pane;
    GList *l, *walk;

    g_return_if_fail (CAJA_IS_WINDOW (window));

    slot = caja_window_get_slot_for_view (window, view);

    /* Ensure we got the right active state for newly added panes */
    caja_window_slot_is_in_active_pane (slot, slot->pane->is_active);

    if (slot->visible)
    {
        return;
    }

    slot->visible = TRUE;

    pane = slot->pane;

    if (pane->visible)
    {
        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 */
    caja_window_pane_show (pane);

    /* Look for other non-visible panes */
    for (walk = window->details->panes; walk; walk = walk->next)
    {
        pane = walk->data;

        if (!pane->visible)
        {
            return;
        }
    }

    caja_window_pane_grab_focus (window->details->active_pane);

    /* All slots and panes visible, show window */
    caja_window_show_window (window);
}

void
caja_window_close (CajaWindow *window)
{
    g_return_if_fail (CAJA_IS_WINDOW (window));

    EEL_CALL_METHOD (CAJA_WINDOW_CLASS, window,
                     close, (window));

    gtk_widget_destroy (GTK_WIDGET (window));
}

CajaWindowSlot *
caja_window_open_slot (CajaWindowPane *pane,
                       CajaWindowOpenSlotFlags flags)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW_PANE (pane));
    g_assert (CAJA_IS_WINDOW (pane->window));

    slot = EEL_CALL_METHOD_WITH_RETURN_VALUE (CAJA_WINDOW_CLASS, pane->window,
            open_slot, (pane, flags));

    g_assert (CAJA_IS_WINDOW_SLOT (slot));
    g_assert (pane->window == slot->pane->window);

    pane->slots = g_list_append (pane->slots, slot);

    return slot;
}

void
caja_window_close_pane (CajaWindowPane *pane)
{
    CajaWindow *window;

    g_assert (CAJA_IS_WINDOW_PANE (pane));
    g_assert (CAJA_IS_WINDOW (pane->window));
    g_assert (g_list_find (pane->window->details->panes, pane) != NULL);

    while (pane->slots != NULL)
    {
        CajaWindowSlot *slot = pane->slots->data;

        caja_window_close_slot (slot);
    }

    window = pane->window;

    /* If the pane was active, set it to NULL. The caller is responsible
     * for setting a new active pane with caja_window_pane_switch_to()
     * if it wants to continue using the window. */
    if (window->details->active_pane == pane)
    {
        window->details->active_pane = NULL;
    }

    window->details->panes = g_list_remove (window->details->panes, pane);

    g_object_unref (pane);
}

static void
real_close_slot (CajaWindowPane *pane,
                 CajaWindowSlot *slot)
{
    caja_window_manage_views_close_slot (pane, slot);
    cancel_view_as_callback (slot);
}

void
caja_window_close_slot (CajaWindowSlot *slot)
{
    CajaWindowPane *pane;

    g_assert (CAJA_IS_WINDOW_SLOT (slot));
    g_assert (CAJA_IS_WINDOW_PANE(slot->pane));
    g_assert (g_list_find (slot->pane->slots, slot) != NULL);

    /* save pane because slot is not valid anymore after this call */
    pane = slot->pane;

    EEL_CALL_METHOD (CAJA_WINDOW_CLASS, slot->pane->window,
                     close_slot, (slot->pane, slot));

    g_object_run_dispose (G_OBJECT (slot));
    slot->pane = NULL;
    g_object_unref (slot);
    pane->slots = g_list_remove (pane->slots, slot);
    pane->active_slots = g_list_remove (pane->active_slots, slot);

}

CajaWindowPane*
caja_window_get_active_pane (CajaWindow *window)
{
    g_assert (CAJA_IS_WINDOW (window));
    return window->details->active_pane;
}

static void
real_set_active_pane (CajaWindow *window, CajaWindowPane *new_pane)
{
    /* make old pane inactive, and new one active.
     * Currently active pane may be NULL (after init). */
    if (window->details->active_pane &&
            window->details->active_pane != new_pane)
    {
        caja_window_pane_set_active (new_pane->window->details->active_pane, FALSE);
    }
    caja_window_pane_set_active (new_pane, TRUE);

    window->details->active_pane = new_pane;
}

/* Make the given pane the active pane of its associated window. This
 * always implies making the containing active slot the active slot of
 * the window. */
void
caja_window_set_active_pane (CajaWindow *window,
                             CajaWindowPane *new_pane)
{
    g_assert (CAJA_IS_WINDOW_PANE (new_pane));
    if (new_pane->active_slot)
    {
        caja_window_set_active_slot (window, new_pane->active_slot);
    }
    else if (new_pane != window->details->active_pane)
    {
        real_set_active_pane (window, new_pane);
    }
}

/* Make both, the given slot the active slot and its corresponding
 * pane the active pane of the associated window.
 * new_slot may be NULL. */
void
caja_window_set_active_slot (CajaWindow *window, CajaWindowSlot *new_slot)
{
    CajaWindowSlot *old_slot;

    g_assert (CAJA_IS_WINDOW (window));

    if (new_slot)
    {
        g_assert (CAJA_IS_WINDOW_SLOT (new_slot));
        g_assert (CAJA_IS_WINDOW_PANE (new_slot->pane));
        g_assert (window == new_slot->pane->window);
        g_assert (g_list_find (new_slot->pane->slots, new_slot) != NULL);
    }

    if (window->details->active_pane != NULL)
    {
        old_slot = window->details->active_pane->active_slot;
    }
    else
    {
        old_slot = NULL;
    }

    if (old_slot == new_slot)
    {
        return;
    }

    /* make old slot inactive if it exists (may be NULL after init, for example) */
    if (old_slot != NULL)
    {
        /* inform window */
        if (old_slot->content_view != NULL)
        {
            caja_window_slot_disconnect_content_view (old_slot, old_slot->content_view);
        }

        /* inform slot & view */
        g_signal_emit_by_name (old_slot, "inactive");
    }

    /* deal with panes */
    if (new_slot &&
            new_slot->pane != window->details->active_pane)
    {
        real_set_active_pane (window, new_slot->pane);
    }

    window->details->active_pane->active_slot = new_slot;

    /* make new slot active, if it exists */
    if (new_slot)
    {
        window->details->active_pane->active_slots =
            g_list_remove (window->details->active_pane->active_slots, new_slot);
        window->details->active_pane->active_slots =
            g_list_prepend (window->details->active_pane->active_slots, new_slot);

        /* inform sidebar panels */
        caja_window_report_location_change (window);
        /* TODO decide whether "selection-changed" should be emitted */

        if (new_slot->content_view != NULL)
        {
            /* inform window */
            caja_window_slot_connect_content_view (new_slot, new_slot->content_view);
        }

        /* inform slot & view */
        g_signal_emit_by_name (new_slot, "active");
    }
}

void
caja_window_slot_close (CajaWindowSlot *slot)
{
    caja_window_pane_slot_close (slot->pane, slot);
}

static void
caja_window_realize (GtkWidget *widget)
{
    GTK_WIDGET_CLASS (caja_window_parent_class)->realize (widget);
    update_cursor (CAJA_WINDOW (widget));
}

static gboolean
caja_window_key_press_event (GtkWidget *widget,
                             GdkEventKey *event)
{
    /* Fix for https://github.com/mate-desktop/caja/issues/1024 */
    if ((event->state & GDK_CONTROL_MASK) &&
        ((event->keyval == '.') || (event->keyval == ';')))
        return TRUE;

    CajaWindow *window;
    int i;

    window = CAJA_WINDOW (widget);

    for (i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++)
    {
        if (extra_window_keybindings[i].keyval == event->keyval)
        {
            const GList *action_groups;
            GtkAction *action;

            action = NULL;

            action_groups = gtk_ui_manager_get_action_groups (window->details->ui_manager);
            G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
            while (action_groups != NULL && action == NULL)
            {
                action = gtk_action_group_get_action (action_groups->data, extra_window_keybindings[i].action);
                action_groups = action_groups->next;
            }

            g_assert (action != NULL);
            if (gtk_action_is_sensitive (action))
            {
                gtk_action_activate (action);
                return TRUE;
            }
            G_GNUC_END_IGNORE_DEPRECATIONS;

            break;
        }
    }

    return GTK_WIDGET_CLASS (caja_window_parent_class)->key_press_event (widget, event);
}

/*
 * Main API
 */

static void
free_activate_view_data (gpointer data)
{
    ActivateViewData *activate_data;

    activate_data = data;

    g_free (activate_data->id);

    g_slice_free (ActivateViewData, activate_data);
}

static void
action_view_as_callback (GtkAction *action,
                         ActivateViewData *data)
{
    CajaWindow *window;

    window = data->window;

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
    {
        CajaWindowSlot *slot;

        slot = window->details->active_pane->active_slot;
        caja_window_slot_set_content_view (slot,
                                           data->id);
    }
    G_GNUC_END_IGNORE_DEPRECATIONS;
}

static GtkRadioAction *
add_view_as_menu_item (CajaWindow *window,
                       const char *placeholder_path,
                       const char *identifier,
                       int index, /* extra_viewer is always index 0 */
                       guint merge_id)
{
    const CajaViewInfo *info;
    GtkRadioAction *action;
    char action_name[32];
    ActivateViewData *data;

    info = caja_view_factory_lookup (identifier);

    g_snprintf (action_name, sizeof (action_name), "view_as_%d", index);
    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    action = gtk_radio_action_new (action_name,
                                   _(info->view_menu_label_with_mnemonic),
                                   _(info->display_location_label),
                                   NULL,
                                   0);
    G_GNUC_END_IGNORE_DEPRECATIONS;

    if (index >= 1 && index <= 9)
    {
        char accel[32];
        char accel_path[48];
        unsigned int accel_keyval;

        g_snprintf (accel, sizeof (accel), "%d", index);
        g_snprintf (accel_path, sizeof (accel_path), "<Caja-Window>/%s", action_name);

        accel_keyval = gdk_keyval_from_name (accel);
		g_assert (accel_keyval != GDK_KEY_VoidSymbol);

        gtk_accel_map_add_entry (accel_path, accel_keyval, GDK_CONTROL_MASK);
        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
        gtk_action_set_accel_path (GTK_ACTION (action), accel_path);
        G_GNUC_END_IGNORE_DEPRECATIONS;
    }

    if (window->details->view_as_radio_action != NULL)
    {
        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
        gtk_radio_action_set_group (action,
                                    gtk_radio_action_get_group (window->details->view_as_radio_action));
        G_GNUC_END_IGNORE_DEPRECATIONS;
    }
    else if (index != 0)
    {
        /* Index 0 is the extra view, and we don't want to use that here,
           as it can get deleted/changed later */
        window->details->view_as_radio_action = action;
    }

    data = g_slice_new (ActivateViewData);
    data->window = window;
    data->id = g_strdup (identifier);
    g_signal_connect_data (action, "activate",
                           G_CALLBACK (action_view_as_callback),
                           data, (GClosureNotify) free_activate_view_data, 0);

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    gtk_action_group_add_action (window->details->view_as_action_group,
                                 GTK_ACTION (action));
    g_object_unref (action);
    G_GNUC_END_IGNORE_DEPRECATIONS;

    gtk_ui_manager_add_ui (window->details->ui_manager,
                           merge_id,
                           placeholder_path,
                           action_name,
                           action_name,
                           GTK_UI_MANAGER_MENUITEM,
                           FALSE);

    return action; /* return value owned by group */
}

/* Make a special first item in the "View as" option menu that represents
 * the current content view. This should only be called if the current
 * content view isn't already in the "View as" option menu.
 */
static void
update_extra_viewer_in_view_as_menus (CajaWindow *window,
                                      const char *id)
{
    gboolean had_extra_viewer;

    had_extra_viewer = window->details->extra_viewer != NULL;

    if (id == NULL)
    {
        if (!had_extra_viewer)
        {
            return;
        }
    }
    else
    {
        if (had_extra_viewer
                && strcmp (window->details->extra_viewer, id) == 0)
        {
            return;
        }
    }
    g_free (window->details->extra_viewer);
    window->details->extra_viewer = g_strdup (id);

    if (window->details->extra_viewer_merge_id != 0)
    {
        gtk_ui_manager_remove_ui (window->details->ui_manager,
                                  window->details->extra_viewer_merge_id);
        window->details->extra_viewer_merge_id = 0;
    }

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    if (window->details->extra_viewer_radio_action != NULL)
    {
        gtk_action_group_remove_action (window->details->view_as_action_group,
                                        GTK_ACTION (window->details->extra_viewer_radio_action));
        window->details->extra_viewer_radio_action = NULL;
    }
    G_GNUC_END_IGNORE_DEPRECATIONS;

    if (id != NULL)
    {
        window->details->extra_viewer_merge_id = gtk_ui_manager_new_merge_id (window->details->ui_manager);
        window->details->extra_viewer_radio_action =
            add_view_as_menu_item (window,
                                   CAJA_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
                                   window->details->extra_viewer,
                                   0,
                                   window->details->extra_viewer_merge_id);
    }
}

static void
remove_extra_viewer_in_view_as_menus (CajaWindow *window)
{
    update_extra_viewer_in_view_as_menus (window, NULL);
}

static void
replace_extra_viewer_in_view_as_menus (CajaWindow *window)
{
    CajaWindowSlot *slot;
    const char *id;

    slot = window->details->active_pane->active_slot;

    id = caja_window_slot_get_content_view_id (slot);
    update_extra_viewer_in_view_as_menus (window, id);
}

/**
 * caja_window_synch_view_as_menus:
 *
 * Set the visible item of the "View as" option menu and
 * the marked "View as" item in the View menu to
 * match the current content view.
 *
 * @window: The CajaWindow whose "View as" option menu should be synched.
 */
static void
caja_window_synch_view_as_menus (CajaWindow *window)
{
    CajaWindowSlot *slot;
    int index;
    char action_name[32];
    GList *node;
    GtkAction *action;

    g_assert (CAJA_IS_WINDOW (window));

    slot = window->details->active_pane->active_slot;

    if (slot->content_view == NULL)
    {
        return;
    }
    for (node = window->details->short_list_viewers, index = 1;
            node != NULL;
            node = node->next, ++index)
    {
        if (caja_window_slot_content_view_matches_iid (slot, (char *)node->data))
        {
            break;
        }
    }
    if (node == NULL)
    {
        replace_extra_viewer_in_view_as_menus (window);
        index = 0;
    }
    else
    {
        remove_extra_viewer_in_view_as_menus (window);
    }

    g_snprintf (action_name, sizeof (action_name), "view_as_%d", index);
    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    action = gtk_action_group_get_action (window->details->view_as_action_group,
                                          action_name);
    G_GNUC_END_IGNORE_DEPRECATIONS;

    /* Don't trigger the action callback when we're synchronizing */
    g_signal_handlers_block_matched (action,
                                     G_SIGNAL_MATCH_FUNC,
                                     0, 0,
                                     NULL,
                                     action_view_as_callback,
                                     NULL);
    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
    G_GNUC_END_IGNORE_DEPRECATIONS;
    g_signal_handlers_unblock_matched (action,
                                       G_SIGNAL_MATCH_FUNC,
                                       0, 0,
                                       NULL,
                                       action_view_as_callback,
                                       NULL);
}

static void
refresh_stored_viewers (CajaWindow *window)
{
    CajaWindowSlot *slot;
    GList *viewers;
    char *uri, *mimetype;

    slot = window->details->active_pane->active_slot;

    uri = caja_file_get_uri (slot->viewed_file);
    mimetype = caja_file_get_mime_type (slot->viewed_file);
    viewers = caja_view_factory_get_views_for_uri (uri,
              caja_file_get_file_type (slot->viewed_file),
              mimetype);
    g_free (uri);
    g_free (mimetype);

    free_stored_viewers (window);
    window->details->short_list_viewers = viewers;
}

static void
load_view_as_menu (CajaWindow *window)
{
    GList *node;
    int index;
    guint merge_id;

    if (window->details->short_list_merge_id != 0)
    {
        gtk_ui_manager_remove_ui (window->details->ui_manager,
                                  window->details->short_list_merge_id);
        window->details->short_list_merge_id = 0;
    }
    if (window->details->extra_viewer_merge_id != 0)
    {
        gtk_ui_manager_remove_ui (window->details->ui_manager,
                                  window->details->extra_viewer_merge_id);
        window->details->extra_viewer_merge_id = 0;
        window->details->extra_viewer_radio_action = NULL;
    }
    if (window->details->view_as_action_group != NULL)
    {
        gtk_ui_manager_remove_action_group (window->details->ui_manager,
                                            window->details->view_as_action_group);
        window->details->view_as_action_group = NULL;
    }


    refresh_stored_viewers (window);

    merge_id = gtk_ui_manager_new_merge_id (window->details->ui_manager);
    window->details->short_list_merge_id = merge_id;
    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    window->details->view_as_action_group = gtk_action_group_new ("ViewAsGroup");
    gtk_action_group_set_translation_domain (window->details->view_as_action_group, GETTEXT_PACKAGE);
    G_GNUC_END_IGNORE_DEPRECATIONS;
    window->details->view_as_radio_action = NULL;

    /* Add a menu item for each view in the preferred list for this location. */
    /* Start on 1, because extra_viewer gets index 0 */
    for (node = window->details->short_list_viewers, index = 1;
            node != NULL;
            node = node->next, ++index)
    {
        /* Menu item in View menu. */
        add_view_as_menu_item (window,
                               CAJA_MENU_PATH_SHORT_LIST_PLACEHOLDER,
                               node->data,
                               index,
                               merge_id);
    }
    gtk_ui_manager_insert_action_group (window->details->ui_manager,
                                        window->details->view_as_action_group,
                                        -1);
    g_object_unref (window->details->view_as_action_group); /* owned by ui_manager */

    caja_window_synch_view_as_menus (window);

    g_signal_emit (window, signals[VIEW_AS_CHANGED], 0);

}

static void
load_view_as_menus_callback (CajaFile *file,
                             gpointer callback_data)
{
    CajaWindow *window;
    CajaWindowSlot *slot;

    slot = callback_data;
    window = CAJA_WINDOW (slot->pane->window);

    if (slot == window->details->active_pane->active_slot)
    {
        load_view_as_menu (window);
    }
}

static void
cancel_view_as_callback (CajaWindowSlot *slot)
{
    caja_file_cancel_call_when_ready (slot->viewed_file,
                                      load_view_as_menus_callback,
                                      slot);
}

void
caja_window_load_view_as_menus (CajaWindow *window)
{
    CajaWindowSlot *slot;
    CajaFileAttributes attributes;

    g_return_if_fail (CAJA_IS_WINDOW (window));

    attributes = caja_mime_actions_get_required_file_attributes ();

    slot = window->details->active_pane->active_slot;

    cancel_view_as_callback (slot);
    caja_file_call_when_ready (slot->viewed_file,
                               attributes,
                               load_view_as_menus_callback,
                               slot);
}

void
caja_window_display_error (CajaWindow *window, const char *error_msg)
{
    GtkWidget *dialog;

    g_return_if_fail (CAJA_IS_WINDOW (window));

    dialog = gtk_message_dialog_new (GTK_WINDOW (window), 0, GTK_MESSAGE_ERROR,
                                     GTK_BUTTONS_OK, error_msg, NULL);
    gtk_widget_show (dialog);
}

static char *
real_get_title (CajaWindow *window)
{
    g_assert (CAJA_IS_WINDOW (window));

    return caja_window_slot_get_title (window->details->active_pane->active_slot);
}

static void
real_sync_title (CajaWindow *window,
                 CajaWindowSlot *slot)
{
    if (slot == window->details->active_pane->active_slot)
    {
        char *copy;

        copy = g_strdup (slot->title);
        g_signal_emit_by_name (window, "title_changed",
                               slot->title);
        g_free (copy);
    }
}

void
caja_window_sync_title (CajaWindow *window,
                        CajaWindowSlot *slot)
{
    EEL_CALL_METHOD (CAJA_WINDOW_CLASS, window,
                     sync_title, (window, slot));
}

void
caja_window_sync_zoom_widgets (CajaWindow *window)
{
    CajaWindowSlot *slot;
    CajaView *view;
    GtkAction *action;
    gboolean supports_zooming;
    gboolean can_zoom, can_zoom_in, can_zoom_out;
    CajaZoomLevel zoom_level;

    slot = window->details->active_pane->active_slot;
    view = slot->content_view;

    if (view != NULL)
    {
        supports_zooming = caja_view_supports_zooming (view);
        zoom_level = caja_view_get_zoom_level (view);
        can_zoom = supports_zooming &&
                   zoom_level >= CAJA_ZOOM_LEVEL_SMALLEST &&
                   zoom_level <= CAJA_ZOOM_LEVEL_LARGEST;
        can_zoom_in = can_zoom && caja_view_can_zoom_in (view);
        can_zoom_out = can_zoom && caja_view_can_zoom_out (view);
    }
    else
    {
        zoom_level = CAJA_ZOOM_LEVEL_STANDARD;
        supports_zooming = FALSE;
        can_zoom = FALSE;
        can_zoom_in = FALSE;
        can_zoom_out = FALSE;
    }

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_ZOOM_IN);
    gtk_action_set_visible (action, supports_zooming);
    gtk_action_set_sensitive (action, can_zoom_in);

    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_ZOOM_OUT);
    gtk_action_set_visible (action, supports_zooming);
    gtk_action_set_sensitive (action, can_zoom_out);

    action = gtk_action_group_get_action (window->details->main_action_group,
                                          CAJA_ACTION_ZOOM_NORMAL);
    gtk_action_set_visible (action, supports_zooming);
    gtk_action_set_sensitive (action, can_zoom);
    G_GNUC_END_IGNORE_DEPRECATIONS;

    g_signal_emit (window, signals[ZOOM_CHANGED], 0,
                   zoom_level, supports_zooming, can_zoom,
                   can_zoom_in, can_zoom_out);
}

static void
zoom_level_changed_callback (CajaView *view,
                             CajaWindow *window)
{
    g_assert (CAJA_IS_WINDOW (window));

    /* This is called each time the component in
     * the active slot successfully completed
     * a zooming operation.
     */
    caja_window_sync_zoom_widgets (window);
}


/* These are called
 *   A) when switching the view within the active slot
 *   B) when switching the active slot
 *   C) when closing the active slot (disconnect)
*/
void
caja_window_connect_content_view (CajaWindow *window,
                                  CajaView *view)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW (window));
    g_assert (CAJA_IS_VIEW (view));

    slot = caja_window_get_slot_for_view (window, view);
    g_assert (slot == caja_window_get_active_slot (window));

    g_signal_connect (view, "zoom-level-changed",
                      G_CALLBACK (zoom_level_changed_callback),
                      window);

    /* Update displayed view in menu. Only do this if we're not switching
     * locations though, because if we are switching locations we'll
     * install a whole new set of views in the menu later (the current
     * views in the menu are for the old location).
     */
    if (slot->pending_location == NULL)
    {
        caja_window_load_view_as_menus (window);
    }

    caja_view_grab_focus (view);
}

void
caja_window_disconnect_content_view (CajaWindow *window,
                                     CajaView *view)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW (window));
    g_assert (CAJA_IS_VIEW (view));

    slot = caja_window_get_slot_for_view (window, view);
    g_assert (slot == caja_window_get_active_slot (window));

    g_signal_handlers_disconnect_by_func (view, G_CALLBACK (zoom_level_changed_callback), window);
}

/**
 * caja_window_show:
 * @widget:	GtkWidget
 *
 * Call parent and then show/hide window items
 * base on user prefs.
 */
static void
caja_window_show (GtkWidget *widget)
{
    CajaWindow *window;

    window = CAJA_WINDOW (widget);

    GTK_WIDGET_CLASS (caja_window_parent_class)->show (widget);

    caja_window_ui_update (window);
}

GtkUIManager *
caja_window_get_ui_manager (CajaWindow *window)
{
    g_return_val_if_fail (CAJA_IS_WINDOW (window), NULL);

    return window->details->ui_manager;
}

CajaWindowPane *
caja_window_get_next_pane (CajaWindow *window)
{
    CajaWindowPane *next_pane;
    GList *node;

    /* return NULL if there is only one pane */
    if (!window->details->panes || !window->details->panes->next)
    {
        return NULL;
    }

    /* get next pane in the (wrapped around) list */
    node = g_list_find (window->details->panes, window->details->active_pane);
    g_return_val_if_fail (node, NULL);
    if (node->next)
    {
        next_pane = node->next->data;
    }
    else
    {
        next_pane =  window->details->panes->data;
    }

    return next_pane;
}


void
caja_window_slot_set_viewed_file (CajaWindowSlot *slot,
                                  CajaFile *file)
{
    CajaFileAttributes attributes;

    if (slot->viewed_file == file)
    {
        return;
    }

    caja_file_ref (file);

    cancel_view_as_callback (slot);

    if (slot->viewed_file != NULL)
    {
        CajaWindow *window;

        window = slot->pane->window;

        if (CAJA_IS_SPATIAL_WINDOW (window))
        {
            caja_file_set_has_open_window (slot->viewed_file,
                                           FALSE);
        }
        caja_file_monitor_remove (slot->viewed_file,
                                  slot);
    }

    if (file != NULL)
    {
        attributes =
            CAJA_FILE_ATTRIBUTE_INFO |
            CAJA_FILE_ATTRIBUTE_LINK_INFO;
        caja_file_monitor_add (file, slot, attributes);
    }

    caja_file_unref (slot->viewed_file);
    slot->viewed_file = file;
}

void
caja_send_history_list_changed (void)
{
    g_signal_emit_by_name (caja_signaller_get_current (),
                           "history_list_changed");
}

static void
free_history_list (void)
{
    g_list_free_full (history_list, g_object_unref);
    history_list = NULL;
}

/* Remove the this URI from the history list.
 * Do not sent out a change notice.
 * We pass in a bookmark for convenience.
 */
static void
remove_from_history_list (CajaBookmark *bookmark)
{
    GList *node;

    /* Compare only the uris here. Comparing the names also is not
     * necessary and can cause problems due to the asynchronous
     * nature of when the title of the window is set.
     */
    node = g_list_find_custom (history_list,
                               bookmark,
                               caja_bookmark_compare_uris);

    /* Remove any older entry for this same item. There can be at most 1. */
    if (node != NULL)
    {
        history_list = g_list_remove_link (history_list, node);
        g_object_unref (node->data);
        g_list_free_1 (node);
    }
}

gboolean
caja_add_bookmark_to_history_list (CajaBookmark *bookmark)
{
    /* Note that the history is shared amongst all windows so
     * this is not a CajaNavigationWindow function. Perhaps it belongs
     * in its own file.
     */
    GList *l, *next;
    static gboolean free_history_list_is_set_up;

    g_assert (CAJA_IS_BOOKMARK (bookmark));

    if (!free_history_list_is_set_up)
    {
        eel_debug_call_at_shutdown (free_history_list);
        free_history_list_is_set_up = TRUE;
    }

    /*	g_warning ("Add to history list '%s' '%s'",
    		   caja_bookmark_get_name (bookmark),
    		   caja_bookmark_get_uri (bookmark)); */

    if (!history_list ||
            caja_bookmark_compare_uris (history_list->data, bookmark))
    {
        int i;

        g_object_ref (bookmark);
        remove_from_history_list (bookmark);
        history_list = g_list_prepend (history_list, bookmark);

        for (i = 0, l = history_list; l; l = next)
        {
            next = l->next;

            if (i++ >= MAX_HISTORY_ITEMS)
            {
                g_object_unref (l->data);
                history_list = g_list_delete_link (history_list, l);
            }
        }

        return TRUE;
    }

    return FALSE;
}

void
caja_remove_from_history_list_no_notify (GFile *location)
{
    CajaBookmark *bookmark;

    bookmark = caja_bookmark_new (location, "", FALSE, NULL);
    remove_from_history_list (bookmark);
    g_object_unref (bookmark);
}

gboolean
caja_add_to_history_list_no_notify (GFile *location,
                                    const char *name,
                                    gboolean has_custom_name,
                                    GIcon *icon)
{
    CajaBookmark *bookmark;
    gboolean ret;

    bookmark = caja_bookmark_new (location, name, has_custom_name, icon);
    ret = caja_add_bookmark_to_history_list (bookmark);
    g_object_unref (bookmark);

    return ret;
}

CajaWindowSlot *
caja_window_get_slot_for_view (CajaWindow *window,
                               CajaView *view)
{
    CajaWindowSlot *slot;
    GList *l, *walk;

    for (walk = window->details->panes; walk; walk = walk->next)
    {
        CajaWindowPane *pane = walk->data;

        for (l = pane->slots; l != NULL; l = l->next)
        {
            slot = l->data;
            if (slot->content_view == view ||
                    slot->new_content_view == view)
            {
                return slot;
            }
        }
    }

    return NULL;
}

void
caja_forget_history (void)
{
    CajaWindowSlot *slot;
    CajaNavigationWindowSlot *navigation_slot;
    GList *window_node, *l, *walk;
    CajaApplication *app;

    app = CAJA_APPLICATION (g_application_get_default ());
    /* Clear out each window's back & forward lists. Also, remove
     * each window's current location bookmark from history list
     * so it doesn't get clobbered.
     */
    for (window_node = gtk_application_get_windows (GTK_APPLICATION (app));
            window_node != NULL;
            window_node = window_node->next)
    {

        if (CAJA_IS_NAVIGATION_WINDOW (window_node->data))
        {
            CajaNavigationWindow *window;

            window = CAJA_NAVIGATION_WINDOW (window_node->data);

            for (walk = CAJA_WINDOW (window_node->data)->details->panes; walk; walk = walk->next)
            {
                CajaWindowPane *pane = walk->data;
                for (l = pane->slots; l != NULL; l = l->next)
                {
                    navigation_slot = l->data;

                    caja_navigation_window_slot_clear_back_list (navigation_slot);
                    caja_navigation_window_slot_clear_forward_list (navigation_slot);
                }
            }

            caja_navigation_window_allow_back (window, FALSE);
            caja_navigation_window_allow_forward (window, FALSE);
        }

        for (walk = CAJA_WINDOW (window_node->data)->details->panes; walk; walk = walk->next)
        {
            CajaWindowPane *pane = walk->data;
            for (l = pane->slots; l != NULL; l = l->next)
            {
                slot = l->data;
                history_list = g_list_remove (history_list,
                                              slot->current_location_bookmark);
            }
        }
    }

    /* Clobber history list. */
    free_history_list ();

    /* Re-add each window's current location to history list. */
    for (window_node = gtk_application_get_windows (GTK_APPLICATION (app));
            window_node != NULL;
            window_node = window_node->next)
    {
        CajaWindow *window;
        CajaWindowSlot *slot;
        GList *l;

        window = CAJA_WINDOW (window_node->data);
        for (walk = window->details->panes; walk; walk = walk->next)
        {
            CajaWindowPane *pane = walk->data;
            for (l = pane->slots; l != NULL; l = l->next)
            {
                slot = CAJA_WINDOW_SLOT (l->data);
                caja_window_slot_add_current_location_to_history_list (slot);
            }
        }
    }
}

GList *
caja_get_history_list (void)
{
    return history_list;
}

static GList *
caja_window_get_history (CajaWindow *window)
{
    return g_list_copy_deep (history_list, (GCopyFunc) g_object_ref, NULL);
}


static CajaWindowType
caja_window_get_window_type (CajaWindow *window)
{
    g_assert (CAJA_IS_WINDOW (window));

    return CAJA_WINDOW_GET_CLASS (window)->window_type;
}

static int
caja_window_get_selection_count (CajaWindow *window)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW (window));

    slot = window->details->active_pane->active_slot;

    if (slot->content_view != NULL)
    {
        return caja_view_get_selection_count (slot->content_view);
    }

    return 0;
}

static GList *
caja_window_get_selection (CajaWindow *window)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW (window));

    slot = window->details->active_pane->active_slot;

    if (slot->content_view != NULL)
    {
        return caja_view_get_selection (slot->content_view);
    }
    return NULL;
}

static CajaWindowShowHiddenFilesMode
caja_window_get_hidden_files_mode (CajaWindowInfo *window)
{
    return window->details->show_hidden_files_mode;
}

static void
caja_window_set_hidden_files_mode (CajaWindowInfo *window,
                                   CajaWindowShowHiddenFilesMode  mode)
{
    window->details->show_hidden_files_mode = mode;

    g_signal_emit_by_name (window, "hidden_files_mode_changed");
}

static CajaWindowShowBackupFilesMode
caja_window_get_backup_files_mode (CajaWindowInfo *window)
{
    return window->details->show_backup_files_mode;
}

static void
caja_window_set_backup_files_mode (CajaWindowInfo *window,
                                   CajaWindowShowBackupFilesMode  mode)
{
    window->details->show_backup_files_mode = mode;

    g_signal_emit_by_name (window, "backup_files_mode_changed");
}

static gboolean
caja_window_get_initiated_unmount (CajaWindowInfo *window)
{
    return window->details->initiated_unmount;
}

static void
caja_window_set_initiated_unmount (CajaWindowInfo *window,
                                   gboolean initiated_unmount)
{
    window->details->initiated_unmount = initiated_unmount;
}

static char *
caja_window_get_cached_title (CajaWindow *window)
{
    CajaWindowSlot *slot;

    g_assert (CAJA_IS_WINDOW (window));

    slot = window->details->active_pane->active_slot;

    return g_strdup (slot->title);
}

CajaWindowSlot *
caja_window_get_active_slot (CajaWindow *window)
{
    g_assert (CAJA_IS_WINDOW (window));

    return window->details->active_pane->active_slot;
}

CajaWindowSlot *
caja_window_get_extra_slot (CajaWindow *window)
{
    CajaWindowPane *extra_pane;
    GList *node;

    g_assert (CAJA_IS_WINDOW (window));


    /* return NULL if there is only one pane */
    if (window->details->panes == NULL ||
            window->details->panes->next == NULL)
    {
        return NULL;
    }

    /* get next pane in the (wrapped around) list */
    node = g_list_find (window->details->panes,
                        window->details->active_pane);
    g_return_val_if_fail (node, FALSE);

    if (node->next)
    {
        extra_pane = node->next->data;
    }
    else
    {
        extra_pane =  window->details->panes->data;
    }

    return extra_pane->active_slot;
}

GList *
caja_window_get_slots (CajaWindow *window)
{
    GList *walk,*list;

    g_assert (CAJA_IS_WINDOW (window));

    list = NULL;
    for (walk = window->details->panes; walk; walk = walk->next)
    {
        CajaWindowPane *pane = walk->data;
        list  = g_list_concat (list, g_list_copy(pane->slots));
    }
    return list;
}

static void
caja_window_info_iface_init (CajaWindowInfoIface *iface)
{
    iface->report_load_underway = caja_window_report_load_underway;
    iface->report_load_complete = caja_window_report_load_complete;
    iface->report_selection_changed = caja_window_report_selection_changed;
    iface->report_view_failed = caja_window_report_view_failed;
    iface->view_visible = caja_window_view_visible;
    iface->close_window = caja_window_close;
    iface->push_status = caja_window_push_status;
    iface->get_window_type = caja_window_get_window_type;
    iface->get_title = caja_window_get_cached_title;
    iface->get_history = caja_window_get_history;
    iface->get_current_location = caja_window_get_location_uri;
    iface->get_ui_manager = caja_window_get_ui_manager;
    iface->get_selection_count = caja_window_get_selection_count;
    iface->get_selection = caja_window_get_selection;
    iface->get_hidden_files_mode = caja_window_get_hidden_files_mode;
    iface->set_hidden_files_mode = caja_window_set_hidden_files_mode;

    iface->get_backup_files_mode = caja_window_get_backup_files_mode;
    iface->set_backup_files_mode = caja_window_set_backup_files_mode;

    iface->get_active_slot = caja_window_get_active_slot;
    iface->get_extra_slot = caja_window_get_extra_slot;
    iface->get_initiated_unmount = caja_window_get_initiated_unmount;
    iface->set_initiated_unmount = caja_window_set_initiated_unmount;
}

static void
caja_window_class_init (CajaWindowClass *class)
{
    GtkBindingSet *binding_set;

    G_OBJECT_CLASS (class)->constructor = caja_window_constructor;
    G_OBJECT_CLASS (class)->constructed = caja_window_constructed;
    G_OBJECT_CLASS (class)->get_property = caja_window_get_property;
    G_OBJECT_CLASS (class)->set_property = caja_window_set_property;
    G_OBJECT_CLASS (class)->finalize = caja_window_finalize;

    GTK_WIDGET_CLASS (class)->destroy = caja_window_destroy;

    GTK_WIDGET_CLASS (class)->show = caja_window_show;

    GTK_WIDGET_CLASS (class)->realize = caja_window_realize;
    GTK_WIDGET_CLASS (class)->key_press_event = caja_window_key_press_event;
    class->get_title = real_get_title;
    class->sync_title = real_sync_title;
    class->set_allow_up = real_set_allow_up;
    class->close_slot = real_close_slot;

    g_object_class_install_property (G_OBJECT_CLASS (class),
                                     ARG_APP,
                                     g_param_spec_object ("app",
                                             "Application",
                                             "The CajaApplication associated with this window.",
                                             CAJA_TYPE_APPLICATION,
                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));

    signals[GO_UP] =
        g_signal_new ("go_up",
                      G_TYPE_FROM_CLASS (class),
                      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                      G_STRUCT_OFFSET (CajaWindowClass, go_up),
                      g_signal_accumulator_true_handled, NULL,
                      caja_src_marshal_BOOLEAN__BOOLEAN,
                      G_TYPE_BOOLEAN, 1, G_TYPE_BOOLEAN);
    signals[RELOAD] =
        g_signal_new ("reload",
                      G_TYPE_FROM_CLASS (class),
                      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                      G_STRUCT_OFFSET (CajaWindowClass, reload),
                      NULL, NULL,
                      g_cclosure_marshal_VOID__VOID,
                      G_TYPE_NONE, 0);
    signals[PROMPT_FOR_LOCATION] =
        g_signal_new ("prompt-for-location",
                      G_TYPE_FROM_CLASS (class),
                      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                      G_STRUCT_OFFSET (CajaWindowClass, prompt_for_location),
                      NULL, NULL,
                      g_cclosure_marshal_VOID__STRING,
                      G_TYPE_NONE, 1, G_TYPE_STRING);
    signals[ZOOM_CHANGED] =
        g_signal_new ("zoom-changed",
                      G_TYPE_FROM_CLASS (class),
                      G_SIGNAL_RUN_LAST,
                      0,
                      NULL, NULL,
                      caja_src_marshal_VOID__INT_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN,
                      G_TYPE_NONE, 5,
                      G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
                      G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
    signals[VIEW_AS_CHANGED] =
        g_signal_new ("view-as-changed",
                      G_TYPE_FROM_CLASS (class),
                      G_SIGNAL_RUN_LAST,
                      0,
                      NULL, NULL,
                      g_cclosure_marshal_VOID__VOID,
                      G_TYPE_NONE, 0);

    binding_set = gtk_binding_set_by_class (class);
	gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
                                  "go_up", 1,
                                  G_TYPE_BOOLEAN, FALSE);
	gtk_binding_entry_add_signal (binding_set, GDK_KEY_F5, 0,
                                  "reload", 0);
	gtk_binding_entry_add_signal (binding_set, GDK_KEY_slash, 0,
                                  "prompt-for-location", 1,
                                  G_TYPE_STRING, "/");

    class->reload = caja_window_reload;
    class->go_up = caja_window_go_up_signal;
}