summaryrefslogtreecommitdiff
path: root/src/nautilus-window-menus.c
blob: 72b18df8aa02f3680487e6aa7a08ca740613c5e9 (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
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/*
 * Nautilus
 *
 * Copyright (C) 2000 Eazel, Inc.
 *
 * Nautilus 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.
 *
 * Nautilus 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Author: John Sullivan <sullivan@eazel.com>
 */

/* nautilus-window-menus.h - implementation of nautilus window menu operations,
 *                           split into separate file just for convenience.
 */
#include <config.h>

#include "nautilus-about.h"
#include "nautilus-application.h"
#include "nautilus-bookmark-list.h"
#include "nautilus-bookmark-parsing.h"
#include "nautilus-bookmarks-window.h"
#include "nautilus-property-browser.h"
#include "nautilus-signaller.h"
#include "nautilus-theme-selector.h"
#include "nautilus-window-private.h"
#include <gtk/gtkmain.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libnautilus-extensions/nautilus-bonobo-extensions.h>
#include <libnautilus-extensions/nautilus-debug.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-gnome-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-stock-dialogs.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-undo-manager.h>
#include <libnautilus-extensions/nautilus-user-level-manager.h>
#include <libnautilus-extensions/nautilus-xml-extensions.h>
#include <libnautilus/nautilus-bonobo-ui.h>
#include <parser.h>
#include <xmlmemory.h>

#define STATIC_BOOKMARKS_FILE_NAME	"static_bookmarks.xml"

/* Private menu paths that components don't know about */
#define NAUTILUS_MENU_PATH_NEW_WINDOW_ITEM		"/File/New Window"
#define NAUTILUS_MENU_PATH_CLOSE_ITEM			"/File/Close"
#define NAUTILUS_MENU_PATH_CLOSE_ALL_WINDOWS_ITEM	"/File/Close All Windows"
#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_FIND	"/File/Separator before Find"
#define NAUTILUS_MENU_PATH_TOGGLE_FIND_MODE		"/File/Toggle Find Mode"
#define NAUTILUS_MENU_PATH_GO_TO_WEB_SEARCH		"/File/Go to Web Search"

#define NAUTILUS_MENU_PATH_UNDO_ITEM			"/Edit/Undo"
#define NAUTILUS_MENU_PATH_SEPARATOR_AFTER_UNDO		"/Edit/Separator after Undo"
#define NAUTILUS_MENU_PATH_SEPARATOR_AFTER_CLEAR	"/Edit/Separator after Clear"
#define NAUTILUS_MENU_PATH_SEPARATOR_AFTER_SELECT_ALL	"/Edit/Separator after Select All"

#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_SHOW_HIDE	"/View/Separator before Show Hide"
#define NAUTILUS_MENU_PATH_SHOW_HIDE_SIDEBAR		"/View/Show Hide Sidebar"
#define NAUTILUS_MENU_PATH_SHOW_HIDE_TOOL_BAR		"/View/Show Hide Tool Bar"
#define NAUTILUS_MENU_PATH_SHOW_HIDE_LOCATION_BAR	"/View/Show Hide Location Bar"
#define NAUTILUS_MENU_PATH_SHOW_HIDE_STATUS_BAR		"/View/Show Hide Status Bar"

#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_ZOOM	"/View/Separator before Zoom"

#define NAUTILUS_MENU_PATH_HOME_ITEM			"/Go/Home"
#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_FORGET	"/Go/Separator before Forget"
#define NAUTILUS_MENU_PATH_FORGET_HISTORY_ITEM		"/Go/Forget History"

#define NAUTILUS_MENU_PATH_HISTORY_ITEMS_PLACEHOLDER	"/Go/History Placeholder"
#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_HISTORY	"/Go/Separator before History"

#define NAUTILUS_MENU_PATH_ADD_BOOKMARK_ITEM		"/Bookmarks/Add Bookmark"
#define NAUTILUS_MENU_PATH_EDIT_BOOKMARKS_ITEM		"/Bookmarks/Edit Bookmarks"
#define NAUTILUS_MENU_PATH_BOOKMARK_ITEMS_PLACEHOLDER	"/Bookmarks/Bookmarks Placeholder"
#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_BOOKMARKS	"/Bookmarks/Separator before Bookmarks"

#define NAUTILUS_MENU_PATH_ABOUT_ITEM			"/Help/About Nautilus"
#define NAUTILUS_MENU_PATH_NAUTILUS_FEEDBACK		"/Help/Nautilus Feedback"


#define SWITCH_TO_BEGINNER_VERB				"Switch to Beginner Level"
#define SWITCH_TO_INTERMEDIATE_VERB			"Switch to Intermediate Level"
#define SWITCH_TO_ADVANCED_VERB				"Switch to Advanced Level"

static GtkWindow *bookmarks_window = NULL;

#ifdef UIH
static void                  activate_bookmark_in_menu_item                 (BonoboUIHandler        *uih,
									     gpointer                user_data,
									     const char             *path);
#endif
static void                  append_bookmark_to_menu                        (NautilusWindow         *window,
									     NautilusBookmark *bookmark,
									     const char             *menu_item_path,
									     gboolean		     is_in_bookmarks_menu);
static void		     append_dynamic_bookmarks 			    (NautilusWindow *window);
static void                  remove_bookmarks_after	                    (NautilusWindow         *window,
									     const char             *menu_path,
									     const char             *last_static_item_path);
static NautilusBookmarkList *get_bookmark_list                              (void);
static void                  refresh_go_menu                   		    (NautilusWindow         *window);
static void                  refresh_bookmarks_menu            	    	    (NautilusWindow         *window);
static void		     schedule_refresh_go_menu 		    	    (NautilusWindow 	    *window);
static void		     schedule_refresh_bookmarks_menu 	    	    (NautilusWindow 	    *window);
static void                  edit_bookmarks                                 (NautilusWindow         *window);




/* User level things */
static guint                 convert_verb_to_user_level               	    (const char             *verb);
static const char *          convert_user_level_to_verb	    		    (guint                   user_level);
static char *                get_customize_user_level_settings_menu_string  (void);
static void                  update_user_level_menu_items                   (NautilusWindow         *window);
static char *                get_customize_user_level_string                (void);
static void		     switch_to_user_level 			    (NautilusWindow 	    *window, 
									     int 		     new_user_level);
static void		     update_preferences_dialog_title		    (void);

static const char * normal_menu_titles[] = {
	NAUTILUS_MENU_PATH_FILE_MENU,
	NAUTILUS_MENU_PATH_EDIT_MENU,
	NAUTILUS_MENU_PATH_VIEW_MENU,
	NAUTILUS_MENU_PATH_GO_MENU,
	NAUTILUS_MENU_PATH_BOOKMARKS_MENU,
	NAUTILUS_MENU_PATH_HELP_MENU
};

/* Struct that stores all the info necessary to activate a bookmark. */
typedef struct {
        NautilusBookmark *bookmark;
        NautilusWindow *window;
        gboolean prompt_for_removal;
} BookmarkHolder;

static BookmarkHolder *
bookmark_holder_new (NautilusBookmark *bookmark, 
		     NautilusWindow *window,
		     gboolean prompt_for_removal)
{
	BookmarkHolder *new_bookmark_holder;

	new_bookmark_holder = g_new (BookmarkHolder, 1);
	new_bookmark_holder->window = window;
	new_bookmark_holder->bookmark = bookmark;
	/* Ref the bookmark because it might be unreffed away while 
	 * we're holding onto it (not an issue for window).
	 */
	gtk_object_ref (GTK_OBJECT (bookmark));
	new_bookmark_holder->prompt_for_removal = prompt_for_removal;

	return new_bookmark_holder;
}

static void
bookmark_holder_free (BookmarkHolder *bookmark_holder)
{
	gtk_object_unref (GTK_OBJECT (bookmark_holder->bookmark));
	g_free (bookmark_holder);
}

/* Private menu definitions; others are in <libnautilus/nautilus-bonobo-ui.h>.
 * These are not part of the published set, either because they are
 * development-only or because we expect to change them and
 * don't want other code relying on their existence.
 */

#define NAUTILUS_MENU_PATH_CUSTOMIZE_ITEM			"/Edit/Customization"
#define NAUTILUS_MENU_PATH_CHANGE_APPEARANCE_ITEM		"/Edit/Change_Appearance"

#define NAUTILUS_MENU_PATH_USER_LEVEL				"/UserLevel"
#define NAUTILUS_MENU_PATH_NOVICE_ITEM				"/UserLevel/Novice"
#define NAUTILUS_MENU_PATH_INTERMEDIATE_ITEM			"/UserLevel/Intermediate"
#define NAUTILUS_MENU_PATH_EXPERT_ITEM				"/UserLevel/Expert"
#define NAUTILUS_MENU_PATH_AFTER_USER_LEVEL_SEPARATOR		"/UserLevel/After User Level Separator"
#define NAUTILUS_MENU_PATH_USER_LEVEL_CUSTOMIZE			"/UserLevel/User Level Customization"

#define NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_CANNED_BOOKMARKS	"/Bookmarks/Before Canned Separator"

static void
file_menu_new_window_callback (BonoboUIComponent *component, 
			       gpointer user_data, 
			       const char *verb)
{
	NautilusWindow *current_window;
	NautilusWindow *new_window;

	current_window = NAUTILUS_WINDOW (user_data);
	new_window = nautilus_application_create_window (current_window->application);
	nautilus_window_goto_uri (new_window, current_window->location);
}

static void
file_menu_close_window_callback (BonoboUIComponent *component, 
			         gpointer user_data, 
			         const char *verb)
{
	nautilus_window_close (NAUTILUS_WINDOW (user_data));
}

static void
file_menu_close_all_windows_callback (BonoboUIComponent *component, 
			              gpointer user_data, 
			              const char *verb)
{
	nautilus_application_close_all_windows ();
}

static void
file_menu_toggle_find_mode_callback (BonoboUIComponent *component, 
			             gpointer user_data, 
			             const char *verb)
{
	NautilusWindow *window;

	window = NAUTILUS_WINDOW (user_data);

	nautilus_window_set_search_mode 
		(window, !nautilus_window_get_search_mode (window));
}

static void
file_menu_web_search_callback (BonoboUIComponent *component, 
			       gpointer user_data, 
			       const char *verb)
{
	nautilus_window_go_web_search (NAUTILUS_WINDOW (user_data));
}

static void
edit_menu_undo_callback (BonoboUIComponent *component, 
			 gpointer user_data, 
			 const char *verb) 
{
	nautilus_undo_manager_undo
		(NAUTILUS_WINDOW (user_data)->application->undo_manager);
}

static void
edit_menu_cut_callback (BonoboUIComponent *component, 
			gpointer user_data, 
			const char *verb) 
{
	GtkWindow *window;

	window = GTK_WINDOW (user_data);
	if (GTK_IS_EDITABLE (window->focus_widget)) {
		gtk_editable_cut_clipboard (GTK_EDITABLE (window->focus_widget));
	}
}

static void
edit_menu_copy_callback (BonoboUIComponent *component, 
			 gpointer user_data, 
			 const char *verb) 
{
	GtkWindow *window;

	window = GTK_WINDOW (user_data);
	if (GTK_IS_EDITABLE (window->focus_widget)) {
		gtk_editable_copy_clipboard (GTK_EDITABLE (window->focus_widget));
	}
}


static void
edit_menu_paste_callback (BonoboUIComponent *component, 
			  gpointer user_data, 
			  const char *verb) 
{
	GtkWindow *window;

	window = GTK_WINDOW (user_data);
	if (GTK_IS_EDITABLE (window->focus_widget)) {
		gtk_editable_paste_clipboard (GTK_EDITABLE (window->focus_widget));
	}

}

static void
edit_menu_clear_callback (BonoboUIComponent *component, 
			  gpointer user_data, 
			  const char *verb) 
{
	GtkWindow *window;

	window = GTK_WINDOW (user_data);
	if (GTK_IS_EDITABLE (window->focus_widget)) {
		/* A negative index deletes until the end of the string */
		gtk_editable_delete_text (GTK_EDITABLE (window->focus_widget),0, -1);
	}

}

static void
go_menu_back_callback (BonoboUIComponent *component, 
		       gpointer user_data, 
		       const char *verb) 
{
	nautilus_window_go_back (NAUTILUS_WINDOW (user_data));
}

static void
go_menu_forward_callback (BonoboUIComponent *component, 
			  gpointer user_data, 
			  const char *verb) 
{
	nautilus_window_go_forward (NAUTILUS_WINDOW (user_data));
}

static void
go_menu_up_callback (BonoboUIComponent *component, 
		     gpointer user_data, 
		     const char *verb) 
{
	nautilus_window_go_up (NAUTILUS_WINDOW (user_data));
}

static void
go_menu_home_callback (BonoboUIComponent *component, 
		       gpointer user_data, 
		       const char *verb) 
{
	nautilus_window_go_home (NAUTILUS_WINDOW (user_data));
}

static void
forget_history_if_confirmed (NautilusWindow *window)
{
	GnomeDialog *dialog;
	char *prompt;

	/* Confirm before forgetting history because it's a rare operation that
	 * is hard to recover from. We don't want people doing it accidentally
	 * when they intended to choose another Go menu item.
	 */
	if ((rand() % 10) == 0) {
		/* This is a little joke, shows up occasionally. I only
		 * implemented this feature so I could use this joke. 
		 */
		prompt = g_strdup (_("Are you sure you want to forget history? "
				     "If you do, you will be doomed to repeat it."));
	} else {
		prompt = g_strdup (_("Are you sure you want Nautilus to forget "
				     "which locations you have visited?"));
	}
					   
	dialog = nautilus_yes_no_dialog (prompt,
					 _("Forget History?"),
					 _("Forget"),
					 GNOME_STOCK_BUTTON_CANCEL,
					 GTK_WINDOW (window));
	g_free (prompt);					 

	gtk_signal_connect
		(GTK_OBJECT (nautilus_gnome_dialog_get_button_by_index
			     (dialog, GNOME_OK)),
		 "clicked",
		 nautilus_forget_history,
		 NULL);

	gnome_dialog_set_default (dialog, GNOME_CANCEL);
}

static void
go_menu_forget_history_callback (BonoboUIComponent *component, 
			         gpointer user_data, 
			         const char *verb) 
{
	forget_history_if_confirmed (NAUTILUS_WINDOW (user_data));
}

static void
view_menu_reload_callback (BonoboUIComponent *component, 
			   gpointer user_data, 
			   const char *verb) 
{
	nautilus_window_reload (NAUTILUS_WINDOW (user_data));
}

static void
view_menu_show_hide_sidebar_callback (BonoboUIComponent *component, 
			              gpointer user_data, 
			              const char *verb) 
{
	NautilusWindow *window;

	window = NAUTILUS_WINDOW (user_data);
	if (nautilus_window_sidebar_showing (window)) {
		nautilus_window_hide_sidebar (window);
	} else {
		nautilus_window_show_sidebar (window);
	}
}

static void
view_menu_show_hide_tool_bar_callback (BonoboUIComponent *component, 
			               gpointer user_data, 
			               const char *verb) 
{
	NautilusWindow *window;

	window = NAUTILUS_WINDOW (user_data);
	if (nautilus_window_tool_bar_showing (window)) {
		nautilus_window_hide_tool_bar (window);
	} else {
		nautilus_window_show_tool_bar (window);
	}
}

static void
view_menu_show_hide_location_bar_callback (BonoboUIComponent *component, 
			                   gpointer user_data, 
			                   const char *verb) 
{
	NautilusWindow *window;

	window = NAUTILUS_WINDOW (user_data);
	if (nautilus_window_location_bar_showing (window)) {
		nautilus_window_hide_location_bar (window);
	} else {
		nautilus_window_show_location_bar (window);
	}
}

static void
view_menu_show_hide_status_bar_callback (BonoboUIComponent *component, 
			                 gpointer user_data, 
			                 const char *verb) 
{
	NautilusWindow *window;

	window = NAUTILUS_WINDOW (user_data);
	if (nautilus_window_status_bar_showing (window)) {
		nautilus_window_hide_status_bar (window);
	} else {
		nautilus_window_show_status_bar (window);
	}
}

void
nautilus_window_update_show_hide_menu_items (NautilusWindow *window) 
{
	g_assert (NAUTILUS_IS_WINDOW (window));
	
#ifdef UIH
	bonobo_ui_handler_menu_set_label 
		(window->ui_handler, 
		 NAUTILUS_MENU_PATH_SHOW_HIDE_STATUS_BAR, 
		 nautilus_window_status_bar_showing (window)
		 	? _("Hide Status Bar")
		 	: _("Show Status Bar"));

	bonobo_ui_handler_menu_set_label 
		(window->ui_handler, 
		 NAUTILUS_MENU_PATH_SHOW_HIDE_SIDEBAR, 
		 nautilus_window_sidebar_showing (window)
		 	? _("Hide Sidebar")
		 	: _("Show Sidebar"));

	bonobo_ui_handler_menu_set_label 
		(window->ui_handler, 
		 NAUTILUS_MENU_PATH_SHOW_HIDE_TOOL_BAR, 
		 nautilus_window_tool_bar_showing (window)
		 	? _("Hide Tool Bar")
		 	: _("Show Tool Bar"));

	bonobo_ui_handler_menu_set_label 
		(window->ui_handler, 
		 NAUTILUS_MENU_PATH_SHOW_HIDE_LOCATION_BAR, 
		 nautilus_window_location_bar_showing (window)
		 	? _("Hide Location Bar")
		 	: _("Show Location Bar"));

#endif
}

static void
view_menu_zoom_in_callback (BonoboUIComponent *component, 
			    gpointer user_data, 
			    const char *verb) 
{
	nautilus_window_zoom_in (NAUTILUS_WINDOW (user_data));
}

static void
view_menu_zoom_out_callback (BonoboUIComponent *component, 
			     gpointer user_data, 
			     const char *verb) 
{
	nautilus_window_zoom_out (NAUTILUS_WINDOW (user_data));
}

static void
view_menu_zoom_normal_callback (BonoboUIComponent *component, 
			        gpointer user_data, 
			        const char *verb) 
{
	nautilus_window_zoom_to_fit (NAUTILUS_WINDOW (user_data));
}

static void
bookmarks_menu_add_bookmark_callback (BonoboUIComponent *component, 
			              gpointer user_data, 
			              const char *verb)
{
        nautilus_window_add_bookmark_for_current_location (NAUTILUS_WINDOW (user_data));
}

static void
bookmarks_menu_edit_bookmarks_callback (BonoboUIComponent *component, 
			                gpointer user_data, 
			                const char *verb)
{
        edit_bookmarks (NAUTILUS_WINDOW (user_data));
}

static void
switch_and_show_intermediate_settings_callback (GtkWidget *button, gpointer user_data)
{
	g_assert (NAUTILUS_IS_WINDOW (user_data));

	switch_to_user_level (NAUTILUS_WINDOW (user_data), NAUTILUS_USER_LEVEL_INTERMEDIATE);
	nautilus_global_preferences_show_dialog ();
}

static void
user_level_customize_callback (BonoboUIComponent *component, 
			       gpointer user_data, 
			       const char *verb)
{
	GnomeDialog *dialog;
	NautilusWindow *window;
	char *novice_level_name;
	char *intermediate_level_name;
	char *expert_level_name;
	char *prompt;
	char *dialog_title;

	window = NAUTILUS_WINDOW (user_data);

	if (nautilus_user_level_manager_get_user_level () == NAUTILUS_USER_LEVEL_NOVICE) {
		novice_level_name = 
			nautilus_user_level_manager_get_user_level_name_for_display 
				(NAUTILUS_USER_LEVEL_NOVICE);
		intermediate_level_name = 
			nautilus_user_level_manager_get_user_level_name_for_display 
				(NAUTILUS_USER_LEVEL_INTERMEDIATE);
		expert_level_name = 
			nautilus_user_level_manager_get_user_level_name_for_display 
				(NAUTILUS_USER_LEVEL_HACKER);
		/* Localizers: This is the message in the dialog that appears if the user chooses "Edit Beginner Settings".
		 * The first %s is the name of the lowest user level ("Beginner"). The 2nd and 4th %s are the
		 * names of the middle user level ("Intermediate"). The 3rd %s is the name of the highest user
		 * level ("Advanced").
		 */
		prompt = g_strdup_printf (_("None of the settings for the %s level can be edited. "
					    "If you want to edit the settings you must choose the %s or %s "
					    "level. Do you want to switch to the %s level now "
					    "and edit its settings?"),
					    novice_level_name,
					    intermediate_level_name,
					    expert_level_name,
					    intermediate_level_name);

		/* Localizers: This is the title of the dialog that appears if the user chooses "Edit Beginner Settings".
		 * The %s is the name of the middle user level ("Intermediate").
		 */
		dialog_title = g_strdup_printf (_("Switch to %s Level?"), intermediate_level_name);
		dialog = nautilus_yes_no_dialog (prompt,
						 dialog_title,
						 _("Switch"),
						 GNOME_STOCK_BUTTON_CANCEL,
						 GTK_WINDOW (window));
		gnome_dialog_button_connect 
			(dialog, GNOME_OK, switch_and_show_intermediate_settings_callback, window);
		gnome_dialog_set_default (dialog, GNOME_CANCEL);

		g_free (prompt);
		g_free (dialog_title);
		g_free (novice_level_name);
		g_free (intermediate_level_name);
		g_free (expert_level_name);
	} else {
		nautilus_global_preferences_show_dialog ();
	}
}

static void
customize_callback (BonoboUIComponent *component, 
		    gpointer user_data, 
		    const char *verb)
{
	nautilus_property_browser_show ();
}

static void
change_appearance_callback (BonoboUIComponent *component, 
			    gpointer user_data, 
			    const char *verb)
{
	nautilus_theme_selector_show ();
}

static void
help_menu_about_nautilus_callback (BonoboUIComponent *component, 
			           gpointer user_data, 
			           const char *verb)
{
	static GtkWidget *about = NULL;

	if (about == NULL) {

		const char *authors[] = {
			"Ali Abdin",
			"Darin Adler",
			"Josh Barrow",
			"Pavel Císler",
			"J Shane Culpepper",
			"Mike Engber",
			"Ramiro Estrugo",
			"Mike Fleming",
			"Andy Hertzfeld",
			"Susan Kare",
			"Mathieu Lacage",
			"George Lebl",
			"Elliot Lee",
			"Raph Levien",
			"Ian McKellar",
			"Seth Nickell",
			"Eskil Heyn Olsen",
			"Ettore Perazzoli",
			"Robey Pointer",
			"Gene Z. Ragan",
			"Arlo Rose",
			"Rebecca Schulman",
			"Robin * Slomkowski",
			"Maciej Stachowiak",
			"John Sullivan",
			"Bud Tribble",
			NULL
		};

		about = nautilus_about_new(_("Nautilus"),
					VERSION,
					"(C) 1999-2000 Eazel, Inc.",
					authors,
					_("Nautilus is a graphical shell \nfor GNOME that makes it \neasy to manage your files \nand the rest of your system."),
					NAUTILUS_TIMESTAMP);
	} else {
		nautilus_about_update_authors (NAUTILUS_ABOUT (about));
	}
	
	nautilus_gtk_window_present (GTK_WINDOW (about));
}

static void
help_menu_nautilus_feedback_callback (BonoboUIComponent *component, 
			              gpointer user_data, 
			              const char *verb)
{
	nautilus_window_goto_uri (NAUTILUS_WINDOW (user_data), "http://www.eazel.com/feedback.html");
}

/* utility routine to return an image corresponding to the passed-in user level */

static GdkPixbuf *
get_user_level_image (int user_level, gboolean is_selected)
{
	const char *image_name;
	char *temp_str, *full_image_name;
	GdkPixbuf *pixbuf;
	
	switch (user_level) {
	case NAUTILUS_USER_LEVEL_NOVICE:
		image_name = "novice";
		break;
	case NAUTILUS_USER_LEVEL_HACKER:
		image_name = "expert";
		break;
	case NAUTILUS_USER_LEVEL_INTERMEDIATE:
	default:
		image_name = "intermediate";
		break;
	}
	
	if (is_selected) {
		full_image_name = g_strdup_printf ("%s-selected.png", image_name);
	} else {
		full_image_name = g_strdup_printf ("%s.png", image_name);	
	}
	
	temp_str = nautilus_pixmap_file (full_image_name);
	g_free (full_image_name);
	if (temp_str) {
		pixbuf = gdk_pixbuf_new_from_file (temp_str);
		g_free (temp_str);
	} else {
		pixbuf = NULL;
	}
	
	return pixbuf;
}

/* handle user level changes */
static void
switch_to_user_level (NautilusWindow *window, int new_user_level)
{
	GdkPixbuf *pixbuf;
	int old_user_level;

	old_user_level = nautilus_user_level_manager_get_user_level ();
	if (new_user_level == old_user_level) {
		return;
	}

	nautilus_user_level_manager_set_user_level (new_user_level);
	
	/* change the item pixbufs to reflect the new user level */
	pixbuf = get_user_level_image (old_user_level, FALSE);
#ifdef UIH
	bonobo_ui_handler_menu_set_pixmap 
		(window->ui_handler, 
		 convert_user_level_to_verb (old_user_level), 
		 BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA, 
		 pixbuf);
#endif
	gdk_pixbuf_unref (pixbuf);
	
	pixbuf = get_user_level_image (new_user_level, TRUE);
#ifdef UIH
	bonobo_ui_handler_menu_set_pixmap 
		(window->ui_handler, 
		 convert_user_level_to_verb (new_user_level), 
		 BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA, 
		 pixbuf);
#endif
	gdk_pixbuf_unref (pixbuf);
	
	/* set up the menu title image to reflect the new user level */
	pixbuf = get_user_level_image (new_user_level, FALSE);
#ifdef UIH
	bonobo_ui_handler_menu_set_pixmap 
		(window->ui_handler, 
		 NAUTILUS_MENU_PATH_USER_LEVEL, 
		 BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA, 
		 pixbuf);
#endif
	gdk_pixbuf_unref (pixbuf);
} 
 
static void
user_level_menu_item_callback (BonoboUIComponent *component, 
			       gpointer user_data, 
			       const char *verb)
{
	NautilusWindow *window;

	window = NAUTILUS_WINDOW (user_data);
		
	switch_to_user_level (window, convert_verb_to_user_level (verb));
}

static void
remove_bookmarks_for_uri (GtkWidget *button, gpointer callback_data)
{
	const char *uri;

	g_assert (GTK_IS_WIDGET (button));
	g_assert (callback_data != NULL);

	uri = (const char *)callback_data;

	nautilus_bookmark_list_delete_items_with_uri (get_bookmark_list (), uri);
}

static void
show_bogus_bookmark_window (BookmarkHolder *holder)
{
	GnomeDialog *dialog;
	char *uri;
	char *uri_for_display;
	char *prompt;

	uri = nautilus_bookmark_get_uri (holder->bookmark);
	uri_for_display = nautilus_format_uri_for_display (uri);

	if (holder->prompt_for_removal) {
		prompt = g_strdup_printf (_("The location \"%s\" does not exist. Do you "
					    "want to remove any bookmarks with this "
					    "location from your list?"), uri_for_display);
		dialog = nautilus_yes_no_dialog (prompt,
						 _("Bookmark for Nonexistent Location"),
						 _("Remove"),
						 GNOME_STOCK_BUTTON_CANCEL,
						 GTK_WINDOW (holder->window));

		nautilus_gtk_signal_connect_free_data
			(GTK_OBJECT (nautilus_gnome_dialog_get_button_by_index
				     (dialog, GNOME_OK)),
			 "clicked",
			 remove_bookmarks_for_uri,
			 g_strdup (uri));

		gnome_dialog_set_default (dialog, GNOME_CANCEL);
	} else {
		prompt = g_strdup_printf (_("The location \"%s\" no longer exists."), uri_for_display);
		dialog = nautilus_info_dialog (prompt, _("Go to Nonexistent Location"), GTK_WINDOW (holder->window));
	}

	g_free (uri);
	g_free (uri_for_display);
	g_free (prompt);
}

#ifdef UIH

static void
activate_bookmark_in_menu_item (BonoboUIHandler *uih, gpointer user_data, const char *path)
{
        BookmarkHolder *holder;
        char *uri;

        holder = (BookmarkHolder *)user_data;

	if (nautilus_bookmark_uri_known_not_to_exist (holder->bookmark)) {
		show_bogus_bookmark_window (holder);
	} else {
	        uri = nautilus_bookmark_get_uri (holder->bookmark);
	        nautilus_window_goto_uri (holder->window, uri);
	        g_free (uri);
        }
}

#endif

static void
append_placeholder (NautilusWindow *window, const char *placeholder_path)
{
#ifdef UIH
        bonobo_ui_handler_menu_new_placeholder (window->ui_handler,
                                                placeholder_path);
#endif
}

static void
append_separator (NautilusWindow *window, const char *separator_path)
{
#ifdef UIH
        bonobo_ui_handler_menu_new_separator (window->ui_handler,
                                              separator_path,
                                              -1);
#endif
}

static void
append_bookmark_to_menu (NautilusWindow *window, 
                         NautilusBookmark *bookmark, 
                         const char *menu_item_path,
                         gboolean is_bookmarks_menu)
{
	BookmarkHolder *bookmark_holder;	
	GdkPixbuf *pixbuf;
#ifdef UIH
	BonoboUIHandlerPixmapType pixmap_type;
#endif
	char *raw_name, *display_name, *truncated_name;

	pixbuf = nautilus_bookmark_get_pixbuf (bookmark, NAUTILUS_ICON_SIZE_FOR_MENUS);

	/* Set up pixmap type based on result of function.  If we fail, set pixmap type to none */
#ifdef UIH
	if (pixbuf != NULL) {
		pixmap_type = BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA;
	} else {
		pixmap_type = BONOBO_UI_HANDLER_PIXMAP_NONE;
	}
#endif

	bookmark_holder = bookmark_holder_new (bookmark, window, is_bookmarks_menu);

	/* We double the underscores here to escape them so Bonobo will know they are
	 * not keyboard accelerator character prefixes. If we ever find we need to
	 * escape more than just the underscores, we'll add a menu helper function
	 * instead of a string utility. (Like maybe escaping control characters.)
	 */
	raw_name = nautilus_bookmark_get_name (bookmark);
	truncated_name = nautilus_truncate_text_for_menu_item (raw_name);
	display_name = nautilus_str_double_underscores (truncated_name);
	g_free (raw_name);
	g_free (truncated_name);
#ifdef UIH
 	bonobo_ui_handler_menu_new_item (window->ui_handler,
					 menu_item_path,
					 display_name,
					 _("Go to the specified location"),
					 -1,
					 pixmap_type,
					 pixbuf,
					 0,
					 0,
					 NULL,
					 NULL);
#endif
	g_free (display_name);

	/* We must use "set_callback" since we have a destroy-notify function. */
#ifdef UIH
	bonobo_ui_handler_menu_set_callback
		(window->ui_handler, menu_item_path,
		 activate_bookmark_in_menu_item,
		 bookmark_holder, (GDestroyNotify) bookmark_holder_free);
#endif

	/* Let's get notified whenever a bookmark changes. */
	gtk_signal_connect_object (GTK_OBJECT (bookmark), "changed",
				   is_bookmarks_menu
				   ? schedule_refresh_bookmarks_menu
				   : schedule_refresh_go_menu,
				   GTK_OBJECT (window));
}

static char *
get_static_bookmarks_file_path (void)
{
	char *xml_file_path, *user_directory_path;
	
	/* first, try to fetch it from the service update directory. Use the one from there
	 * if there is one, otherwise, get the built-in one from shared data
	 */
	
	user_directory_path = nautilus_get_user_directory ();
	xml_file_path = g_strdup_printf ("%s/updates/%s", user_directory_path, STATIC_BOOKMARKS_FILE_NAME);
	g_free (user_directory_path);
	if (g_file_exists (xml_file_path)) {
		return xml_file_path;
	}
	
	g_free (xml_file_path);
	
	xml_file_path = nautilus_make_path (NAUTILUS_DATADIR, STATIC_BOOKMARKS_FILE_NAME);
	if (g_file_exists (xml_file_path)) {
		return xml_file_path;
	}
	g_free (xml_file_path);

	return NULL;
}

static char *
create_menu_item_from_node (NautilusWindow *window,
			     xmlNodePtr node, 
			     const char *menu_path,
			     int index)
{
	NautilusBookmark *bookmark;
	xmlChar *xml_folder_name;
	int sub_index;
	char *index_as_string;
	char *item_path;
	char *sub_item_path;
	
	index_as_string = g_strdup_printf ("item_%d", index);
#ifdef UIH
	item_path = bonobo_ui_handler_build_path (menu_path, index_as_string, NULL);
#else
	item_path = NULL;
#endif
	g_free (index_as_string);

	if (strcmp (node->name, "bookmark") == 0) {
		bookmark = nautilus_bookmark_new_from_node (node);
		append_bookmark_to_menu (window, bookmark, item_path, TRUE);
		gtk_object_unref (GTK_OBJECT (bookmark));
	} else if (strcmp (node->name, "separator") == 0) {
		append_separator (window, item_path);
	} else if (strcmp (node->name, "folder") == 0) {
		xml_folder_name = xmlGetProp (node, "name");
#ifdef UIH
	 	bonobo_ui_handler_menu_new_subtree (window->ui_handler,
						    item_path,
						    xml_folder_name,
						    NULL,
						    -1,
						    BONOBO_UI_HANDLER_PIXMAP_NONE,
						    NULL,
						    0,
						    0);
#endif
		for (node = nautilus_xml_get_children (node), sub_index = 0;
		     node != NULL;
		     node = node->next, ++sub_index) {
			sub_item_path = create_menu_item_from_node (window, node, item_path, sub_index);
			g_free (sub_item_path);
		}
		xmlFree (xml_folder_name);
	} else {
		g_message ("found unknown node '%s', ignoring", node->name);
	}

	return item_path;
}

static void
append_static_bookmarks (NautilusWindow *window, const char *menu_path)
{
	xmlDocPtr doc;
	xmlNodePtr node;
	char *file_path;
	char *item_path;
	int index;

	/* Walk through XML tree creating bookmarks, folders, and separators. */
	file_path = get_static_bookmarks_file_path ();

	if (file_path == NULL) {
		return;
	}
	
	doc = xmlParseFile (file_path);
	g_free (file_path);

	node = nautilus_xml_get_root_children (doc);
	index = 0;
	
	if (node != NULL) {
		append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_CANNED_BOOKMARKS);
	}

	for (index = 0; node != NULL; node = node->next, ++index) {
		item_path = create_menu_item_from_node 
			(window, node, menu_path, index);
		g_free (item_path);
	}
	
	xmlFreeDoc(doc);
}

/**
 * remove_bookmarks_after
 * 
 * Remove bookmark menu items from the end of this window's menu. Each removed
 * item should have callback data that's either NULL or is a BookmarkHolder *.
 * @window: The NautilusWindow whose menu should be cleaned.
 * @menu_path: The BonoboUIHandler-style path for the menu to be cleaned (e.g. "/Go").
 * @last_retained_item_path: The BonoboUIHandler-style path for the last menu item to
 * leave in place (e.g. "/Go/Home"). All menu items after this one will be removed.
 */
static void
remove_bookmarks_after (NautilusWindow *window, 
                        const char *menu_path, 
                        const char *last_retained_item_path)
{
#ifdef UIH
	GList *children, *p;
	gboolean found_items_to_remove;
	gpointer callback_data;
	BookmarkHolder *bookmark_holder;

	g_assert (NAUTILUS_IS_WINDOW (window));

	children = bonobo_ui_handler_menu_get_child_paths (window->ui_handler, menu_path);
	found_items_to_remove = FALSE;

	for (p = children; p != NULL; p = p->next) {
                if (found_items_to_remove) {
                	bonobo_ui_handler_menu_get_callback (window->ui_handler, p->data, 
                					     NULL, &callback_data, NULL);
                	bookmark_holder = (BookmarkHolder *)callback_data;
			/* bookmark_holder is NULL for separator in Bookmarks menu */
                	if (bookmark_holder != NULL) {
	                	gtk_signal_disconnect_by_data (GTK_OBJECT (bookmark_holder->bookmark), window);
                	}
                        bonobo_ui_handler_menu_remove (window->ui_handler, p->data);
		} else if (strcmp ((const char *) p->data, last_retained_item_path) == 0) {
			found_items_to_remove = TRUE;
		}
	}

	g_assert (found_items_to_remove);
        nautilus_g_list_free_deep (children);
#endif
}

static NautilusBookmarkList *bookmarks = NULL;

static void
free_bookmark_list (void)
{
	gtk_object_unref (GTK_OBJECT (bookmarks));
}

static NautilusBookmarkList *
get_bookmark_list (void)
{
        if (bookmarks == NULL) {
                bookmarks = nautilus_bookmark_list_new ();
		g_atexit (free_bookmark_list);
        }

        return bookmarks;
}

static GtkWindow *
get_or_create_bookmarks_window (GtkObject *undo_manager_source)
{
	if (bookmarks_window == NULL) {
		bookmarks_window = create_bookmarks_window (get_bookmark_list(), undo_manager_source);
	}
	return bookmarks_window;
}

/**
 * nautilus_bookmarks_exiting:
 * 
 * Last chance to save state before app exits.
 * Called when application exits; don't call from anywhere else.
 **/
void
nautilus_bookmarks_exiting (void)
{
	if (bookmarks_window != NULL) {
		nautilus_bookmarks_window_save_geometry (bookmarks_window);
	}
}

/**
 * nautilus_window_add_bookmark_for_current_location
 * 
 * Add a bookmark for the displayed location to the bookmarks menu.
 * Does nothing if there's already a bookmark for the displayed location.
 */
void
nautilus_window_add_bookmark_for_current_location (NautilusWindow *window)
{
	g_return_if_fail (NAUTILUS_IS_WINDOW (window));

	nautilus_bookmark_list_append (get_bookmark_list (), window->current_location_bookmark);
}

static void
edit_bookmarks (NautilusWindow *window)
{
        nautilus_gtk_window_present
		(get_or_create_bookmarks_window (GTK_OBJECT (window)));
}

static void
refresh_bookmarks_menu (NautilusWindow *window)
{
	/* Unregister any pending call to this function. */
	nautilus_window_remove_bookmarks_menu_callback (window);

	nautilus_window_remove_bookmarks_menu_items (window);				

	if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS, 
					       FALSE)) {
		append_static_bookmarks (window, NAUTILUS_MENU_PATH_BOOKMARKS_MENU);
	}

	append_dynamic_bookmarks (window);
}

static char *
get_menu_title (const char *path)
{
	if (strcmp (path, NAUTILUS_MENU_PATH_FILE_MENU) == 0) {
		return g_strdup (_("_File"));
	}

	if (strcmp (path, NAUTILUS_MENU_PATH_EDIT_MENU) == 0) {
		return g_strdup (_("_Edit"));
	}

	if (strcmp (path, NAUTILUS_MENU_PATH_VIEW_MENU) == 0) {
		return g_strdup (_("_View"));
	}

	if (strcmp (path, NAUTILUS_MENU_PATH_GO_MENU) == 0) {
		return g_strdup (_("_Go"));
	}

	if (strcmp (path, NAUTILUS_MENU_PATH_BOOKMARKS_MENU) == 0) {
		return g_strdup (_("_Bookmarks"));
	}

	if (strcmp (path, NAUTILUS_MENU_PATH_HELP_MENU) == 0) {
		return g_strdup (_("_Help"));
	}

	g_assert_not_reached ();

	return NULL;
}


static void
remove_underline_accelerator_from_menu_title (NautilusWindow *window, 
					      const char *menu_path)
{
#ifdef UIH
	char *old_label;
	char *new_label;

	old_label = bonobo_ui_handler_menu_get_label (window->ui_handler, menu_path);
	new_label = nautilus_str_strip_chr (old_label, '_');
	bonobo_ui_handler_menu_set_label (window->ui_handler, menu_path, new_label);

	g_free (old_label);
	g_free (new_label);
#endif
}					      

/**
 * nautilus_window_disable_keyboard_navigation_for_menus
 * 
 * Prevents alt-key shortcuts from pulling down menus.
 */
void
nautilus_window_disable_keyboard_navigation_for_menus (NautilusWindow *window)
{
	int index;

	for (index = 0; index < NAUTILUS_N_ELEMENTS (normal_menu_titles); ++index) {
		remove_underline_accelerator_from_menu_title (window, normal_menu_titles[index]);
	}
}

/**
 * nautilus_window_initialize_bookmarks_menu
 * 
 * Fill in bookmarks menu with stored bookmarks, and wire up signals
 * so we'll be notified when bookmark list changes.
 */
static void 
nautilus_window_initialize_bookmarks_menu (NautilusWindow *window)
{
	/* Construct the initial set of bookmarks. */
	refresh_bookmarks_menu (window);

	/* Recreate static & dynamic part of menu if preference about
	 * showing static bookmarks changes.
	 */
	nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS,
					   (NautilusPreferencesCallback)refresh_bookmarks_menu,
					   window);
		
	/* Recreate dynamic part of menu if bookmark list changes */
	gtk_signal_connect_object_while_alive (GTK_OBJECT (get_bookmark_list ()),
			                       "contents_changed",
			                       schedule_refresh_bookmarks_menu,
			   	               GTK_OBJECT (window));

	/* Recreate static & dynamic parts of menu if icon theme changes */
	gtk_signal_connect_object_while_alive (nautilus_icon_factory_get (),
					       "icons_changed",
					       schedule_refresh_bookmarks_menu,
					       GTK_OBJECT (window));
}

/**
 * nautilus_window_initialize_go_menu
 * 
 * Wire up signals so we'll be notified when history list changes.
 */
static void 
nautilus_window_initialize_go_menu (NautilusWindow *window)
{
	/* Recreate bookmarks part of menu if history list changes
	 * or if icon theme changes.
	 */
	gtk_signal_connect_object_while_alive (GTK_OBJECT (nautilus_signaller_get_current ()),
			                       "history_list_changed",
			                       schedule_refresh_go_menu,
			   	               GTK_OBJECT (window));
	 
	gtk_signal_connect_object_while_alive (nautilus_icon_factory_get (),
					       "icons_changed",
					       schedule_refresh_go_menu,
					       GTK_OBJECT (window));

}

static void
new_top_level_menu (NautilusWindow *window, 
		    const char *menu_path)
{
	char *title;

	title = get_menu_title (menu_path);

	/* Note that we don't bother with hints for menu titles.
	 * We can revisit this anytime if someone thinks they're useful.
	 */
#ifdef UIH
	bonobo_ui_handler_menu_new_subtree (window->ui_handler,
					    menu_path,
					    title,
					    NULL,
					    -1,
					    BONOBO_UI_HANDLER_PIXMAP_NONE,
					    NULL,
					    0,
					    0);
#endif

	g_free (title);
}				    

/*( handler to receive the user_level_changed signal, so we can update the menu and dialog
    when the user level changes */
static void
user_level_changed_callback (GtkObject	*user_level_manager,
			     gpointer	user_data)
{
	g_return_if_fail (user_data != NULL);
	g_return_if_fail (NAUTILUS_IS_WINDOW (user_data));

	update_user_level_menu_items (NAUTILUS_WINDOW (user_data));

	/* Hide the customize dialog for novice user level */
	if (nautilus_user_level_manager_get_user_level () == NAUTILUS_USER_LEVEL_NOVICE) {
		nautilus_global_preferences_hide_dialog ();
	}
	/* Otherwise update its title to reflect the user level */
	else {
		update_preferences_dialog_title ();
	}
}

static void
nautilus_window_create_top_level_menus (NautilusWindow *window)
{
	int index;

	for (index = 0; index < NAUTILUS_N_ELEMENTS (normal_menu_titles); ++index) {
		new_top_level_menu (window, normal_menu_titles[index]);
	}
}

static void
add_user_level_menu_item (NautilusWindow *window, 
			  const char *menu_path, 
			  guint user_level)
{
#ifdef UIH
	BonoboUIHandler *ui_handler;
#endif
        GdkPixbuf *pixbuf;
        guint current_user_level;
        char *user_level_name;
        char *menu_label;
        char *menu_hint;

#ifdef UIH
	ui_handler = window->ui_handler;
#endif
        user_level_name = nautilus_user_level_manager_get_user_level_name_for_display (user_level);
	current_user_level = nautilus_user_level_manager_get_user_level ();


	/* Hackily hardwire leading space so text doesn't butt up against pixmap. */
        menu_label = g_strdup_printf (" %s", user_level_name);
        /* Localizers: This is the menu hint for the user-level setting (%s is name of user
         * level, "Beginner", "Intermediate", or "Advanced")
         */
	menu_hint = g_strdup_printf (_("Use %s settings"), user_level_name);

	pixbuf = get_user_level_image (user_level, current_user_level == user_level);
#ifdef UIH
	bonobo_ui_handler_menu_new_item (ui_handler,
        				 menu_path,
        				 menu_label,
 					 menu_hint,
       				 	 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA,
        				 pixbuf,
        				 0,
        				 0,
        				 user_level_menu_item_callback,
        				 window);
#endif
	g_free (user_level_name);
	g_free (menu_label);
	g_free (menu_hint);
	gdk_pixbuf_unref (pixbuf);
}

/**
 * nautilus_window_initialize_menus
 * 
 * Create and install the set of menus for this window.
 * @window: A recently-created NautilusWindow.
 */
void 
nautilus_window_initialize_menus (NautilusWindow *window)
{
#ifdef UIH
        GdkPixbuf *pixbuf;
	BonoboUIHandler *ui_handler;
#endif

	BonoboUIVerb verbs [] = {
		BONOBO_UI_VERB ("New Window", file_menu_new_window_callback),
		BONOBO_UI_VERB ("Close", file_menu_close_window_callback),
		BONOBO_UI_VERB ("Close All", file_menu_close_all_windows_callback),
		BONOBO_UI_VERB ("Toggle Find Mode", file_menu_toggle_find_mode_callback),
		BONOBO_UI_VERB ("Go to Web Search", file_menu_web_search_callback),
		BONOBO_UI_VERB ("Undo", edit_menu_undo_callback),
		BONOBO_UI_VERB ("Cut", edit_menu_cut_callback),
		BONOBO_UI_VERB ("Copy", edit_menu_copy_callback),
		BONOBO_UI_VERB ("Paste", edit_menu_paste_callback),
		BONOBO_UI_VERB ("Clear", edit_menu_clear_callback),
		BONOBO_UI_VERB ("Customize", customize_callback),
		BONOBO_UI_VERB ("Change Appearance", change_appearance_callback),
		BONOBO_UI_VERB ("Back", go_menu_back_callback),
		BONOBO_UI_VERB ("Forward", go_menu_forward_callback),
		BONOBO_UI_VERB ("Up", go_menu_up_callback),
		BONOBO_UI_VERB ("Home", go_menu_home_callback),
		BONOBO_UI_VERB ("Forget History", go_menu_forget_history_callback),
		BONOBO_UI_VERB ("Reload", view_menu_reload_callback),
		BONOBO_UI_VERB ("Show Hide Sidebar", view_menu_show_hide_sidebar_callback),
		BONOBO_UI_VERB ("Show Hide Tool Bar", view_menu_show_hide_tool_bar_callback),
		BONOBO_UI_VERB ("Show Hide Location Bar", view_menu_show_hide_location_bar_callback),
		BONOBO_UI_VERB ("Show Hide Status Bar", view_menu_show_hide_status_bar_callback),
		BONOBO_UI_VERB ("Zoom In", view_menu_zoom_in_callback),
		BONOBO_UI_VERB ("Zoom Out", view_menu_zoom_out_callback),
		BONOBO_UI_VERB ("Zoom Normal", view_menu_zoom_normal_callback),
		BONOBO_UI_VERB ("Add Bookmark", bookmarks_menu_add_bookmark_callback),
		BONOBO_UI_VERB ("Edit Bookmarks", bookmarks_menu_edit_bookmarks_callback),
		BONOBO_UI_VERB ("About Nautilus", help_menu_about_nautilus_callback),
		BONOBO_UI_VERB ("Nautilus Feedback", help_menu_nautilus_feedback_callback),
#ifdef UIH	
	/* The next set of verbs doesn't work. Need some different mechanism for radio items apparently */
#endif
		BONOBO_UI_VERB (SWITCH_TO_BEGINNER_VERB, user_level_menu_item_callback),
		BONOBO_UI_VERB (SWITCH_TO_INTERMEDIATE_VERB, user_level_menu_item_callback),
		BONOBO_UI_VERB (SWITCH_TO_ADVANCED_VERB, user_level_menu_item_callback),
		BONOBO_UI_VERB ("User Level Customization", user_level_customize_callback),
		BONOBO_UI_VERB_END
	};

	bonobo_ui_component_add_verb_list_with_data (window->details->shell_ui, verbs, window);

#ifdef UIH
        ui_handler = window->ui_handler;
        g_assert (ui_handler != NULL);
        
        bonobo_ui_handler_create_menubar (ui_handler);
#endif
	nautilus_window_create_top_level_menus (window);

#ifdef UIH
	/* File menu */

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_NEW_WINDOW_ITEM,
        				 _("_New Window"),
        				 _("Create a new window"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_NEW,
        				 0,
        				 0,
        				 file_menu_new_window_callback,
        				 window);

        append_placeholder (window, NAUTILUS_MENU_PATH_NEW_ITEMS_PLACEHOLDER);
        append_placeholder (window, NAUTILUS_MENU_PATH_OPEN_PLACEHOLDER);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_CLOSE_ITEM,
        				 _("_Close Window"),
        				 _("Close this window"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_CLOSE,
        				 'W',
        				 GDK_CONTROL_MASK,
        				 file_menu_close_window_callback,
        				 window);
        				 
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_CLOSE_ALL_WINDOWS_ITEM,
        				 _("Close _All Windows"),
        				 _("Close all Nautilus windows"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'W',
        				 GDK_CONTROL_MASK | GDK_SHIFT_MASK,
        				 file_menu_close_all_windows_callback,
        				 NULL);

        append_placeholder (window, NAUTILUS_MENU_PATH_FILE_ITEMS_PLACEHOLDER);

	append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_FIND);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_TOGGLE_FIND_MODE,
        				 "", /* No initial text; set in update_find_menu_item */
        				 _(NAUTILUS_HINT_FIND),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'F',
        				 GDK_CONTROL_MASK,
        				 file_menu_toggle_find_mode_callback,
        				 window);
        nautilus_window_update_find_menu_item (window);
        				 
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_GO_TO_WEB_SEARCH,
        				 _("_Web Search"),
        				 _(NAUTILUS_HINT_WEB_SEARCH),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'F',
        				 GDK_CONTROL_MASK | GDK_SHIFT_MASK,
        				 file_menu_web_search_callback,
        				 window);
        append_placeholder (window, NAUTILUS_MENU_PATH_GLOBAL_FILE_ITEMS_PLACEHOLDER);

	/* Edit menu */

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_UNDO_ITEM,
        				 _("_Undo"),
        				 _("Undo the last text change"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_UNDO,
        				 GNOME_KEY_NAME_UNDO,
        				 GNOME_KEY_MOD_UNDO,
        				 edit_menu_undo_callback,
        				 window);

        append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_AFTER_UNDO);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_CUT_ITEM,
        				 _("_Cut Text"),
        				 _("Cuts the selected text to the clipboard"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_CUT,
        				 GNOME_KEY_NAME_CUT,
        				 GNOME_KEY_MOD_CUT,
        				 edit_menu_cut_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_COPY_ITEM,
        				 _("_Copy Text"),
        				 _("Copies the selected text to the clipboard"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_COPY,
        				 GNOME_KEY_NAME_COPY,
        				 GNOME_KEY_MOD_COPY,
        				 edit_menu_copy_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_PASTE_ITEM,
        				 _("_Paste Text"),
        				 _("Pastes the text stored on the clipboard"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_PASTE,
        				 GNOME_KEY_NAME_PASTE,
        				 GNOME_KEY_MOD_PASTE,
        				 edit_menu_paste_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_CLEAR_ITEM,
        				 _("C_lear Text"),
        				 _("Removes the selected text without putting it on the clipboard"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 GNOME_KEY_NAME_CLEAR,
        				 GNOME_KEY_MOD_CLEAR,
        				 edit_menu_clear_callback,
        				 window);

	/* Desensitize these menu items until something gets selected */
	bonobo_ui_handler_menu_set_sensitivity (ui_handler,
						NAUTILUS_MENU_PATH_CUT_ITEM,
						TRUE);
	bonobo_ui_handler_menu_set_sensitivity (ui_handler,
						NAUTILUS_MENU_PATH_COPY_ITEM,
						TRUE);
	bonobo_ui_handler_menu_set_sensitivity (ui_handler,
						NAUTILUS_MENU_PATH_PASTE_ITEM,
						TRUE);
	bonobo_ui_handler_menu_set_sensitivity (ui_handler,
						NAUTILUS_MENU_PATH_CLEAR_ITEM,
						TRUE);
        append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_AFTER_CLEAR);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_SELECT_ALL_ITEM,
        				 _("_Select All"),
        				 NULL,	/* No hint since it's insensitive here */
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'A',	/* Keyboard shortcut applies to overriders too */
        				 GDK_CONTROL_MASK,
        				 NULL,
        				 NULL);

	append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_AFTER_SELECT_ALL);
	
	bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_CUSTOMIZE_ITEM,
        				 _("_Customization..."),
        				 _("Displays the Property Browser, to add properties to objects and customize appearance"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 customize_callback,
        				 NULL);
	
	bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_CHANGE_APPEARANCE_ITEM,
        				 _("_Change Appearance..."),
        				 _("Displays a list of alternative appearances, to allow you to change the appearance"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 change_appearance_callback,
        				 NULL);

        append_placeholder (window, NAUTILUS_MENU_PATH_GLOBAL_EDIT_ITEMS_PLACEHOLDER);
        append_placeholder (window, NAUTILUS_MENU_PATH_EDIT_ITEMS_PLACEHOLDER);

        /* View menu */

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_RELOAD_ITEM,
        				 _("_Refresh"),
        				 _(NAUTILUS_HINT_REFRESH),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'R',
        				 GDK_CONTROL_MASK,
        				 view_menu_reload_callback,
        				 window);

        append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_SHOW_HIDE);
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_SHOW_HIDE_SIDEBAR,
        				 "", /* Title computed dynamically */
        				 _("Change the visibility of this window's sidebar"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 view_menu_show_hide_sidebar_callback,
        				 window);
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_SHOW_HIDE_TOOL_BAR,
        				 "", /* Title computed dynamically */
        				 _("Change the visibility of this window's tool bar"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 view_menu_show_hide_tool_bar_callback,
        				 window);
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_SHOW_HIDE_LOCATION_BAR,
        				 "", /* Title computed dynamically */
        				 _("Change the visibility of this window's location bar"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 view_menu_show_hide_location_bar_callback,
        				 window);
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_SHOW_HIDE_STATUS_BAR,
        				 "", /* Title computed dynamically */
        				 _("Change the visibility of this window's status bar"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 view_menu_show_hide_status_bar_callback,
        				 window);
        nautilus_window_update_show_hide_menu_items (window);

        append_placeholder (window, NAUTILUS_MENU_PATH_SHOW_HIDE_PLACEHOLDER);
        append_placeholder (window, NAUTILUS_MENU_PATH_VIEW_ITEMS_PLACEHOLDER);

        append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_ZOOM);
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_ZOOM_IN_ITEM,
        				 _("Zoom _In"),
        				 _("Show the contents in more detail"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 '=',
        				 GDK_CONTROL_MASK,
        				 view_menu_zoom_in_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_ZOOM_OUT_ITEM,
        				 _("Zoom _Out"),
        				 _("Show the contents in less detail"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 '-',
        				 GDK_CONTROL_MASK,
        				 view_menu_zoom_out_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_ZOOM_NORMAL_ITEM,
        				 _("_Normal Size"),
        				 _("Show the contents at the normal size"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 view_menu_zoom_normal_callback,
        				 window);

        

	/* Go menu */

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_BACK_ITEM,
        				 _("_Back"),
        				 _(NAUTILUS_HINT_BACK),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 '[',
        				 GDK_CONTROL_MASK,
        				 go_menu_back_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_FORWARD_ITEM,
        				 _("_Forward"),
        				 _(NAUTILUS_HINT_FORWARD),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 ']',
        				 GDK_CONTROL_MASK,
        				 go_menu_forward_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_UP_ITEM,
        				 _("_Up a Level"),
        				 _(NAUTILUS_HINT_UP),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'U',
        				 GDK_CONTROL_MASK,
        				 go_menu_up_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_HOME_ITEM,
        				 _("_Home"),
        				 _(NAUTILUS_HINT_HOME),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'H',
        				 GDK_CONTROL_MASK,
        				 go_menu_home_callback,
        				 window);
        				 
	append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_FORGET);
        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_FORGET_HISTORY_ITEM,
        				 _("For_get History"),
        				 _("Clear contents of Go menu and Back/Forward lists"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0, 0,
        				 go_menu_forget_history_callback,
        				 window);

        append_placeholder (window, NAUTILUS_MENU_PATH_HISTORY_ITEMS_PLACEHOLDER);

        
	/* Bookmarks */

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_ADD_BOOKMARK_ITEM,
        				 _("_Add Bookmark"),
        				 _("Add a bookmark for the current location to this menu"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 'B',
        				 GDK_CONTROL_MASK,
        				 bookmarks_menu_add_bookmark_callback,
        				 window);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_EDIT_BOOKMARKS_ITEM,
        				 _("_Edit Bookmarks..."),
        				 _("Display a window that allows editing the bookmarks in this menu"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 bookmarks_menu_edit_bookmarks_callback,
        				 window);

	append_placeholder (window, NAUTILUS_MENU_PATH_BOOKMARK_ITEMS_PLACEHOLDER);			 

	/* Help */

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_ABOUT_ITEM,
        				 _("_About Nautilus..."),
        				 _("Displays information about the Nautilus program"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_STOCK,
        				 GNOME_STOCK_MENU_ABOUT,
        				 '/',
        				 GDK_CONTROL_MASK,
        				 help_menu_about_nautilus_callback,
        				 NULL);

        bonobo_ui_handler_menu_new_item (ui_handler,
        				 NAUTILUS_MENU_PATH_NAUTILUS_FEEDBACK,
        				 _("_Nautilus Feedback"),
        				 _("Shows a page from which you can send feedback about Nautilus to its creators"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 help_menu_nautilus_feedback_callback,
        				 window);

        /* Desensitize the items that aren't implemented at this level.
         * Some (hopefully all) will be overridden by implementations by the
         * different content views.
         */
	bonobo_ui_handler_menu_set_sensitivity (ui_handler, 
        				        NAUTILUS_MENU_PATH_SELECT_ALL_ITEM, 
						FALSE);

	/* connect to the user level changed signal, so we can update the menu when the
	   user level changes */
	gtk_signal_connect_while_alive (GTK_OBJECT (nautilus_user_level_manager_get ()),
					"user_level_changed",
					user_level_changed_callback,
					window,
					GTK_OBJECT (window));

	/* create the user level menu.  First, the menu item itself */

	pixbuf = get_user_level_image (nautilus_user_level_manager_get_user_level (), FALSE);	
	bonobo_ui_handler_menu_new_subtree (ui_handler,
					    NAUTILUS_MENU_PATH_USER_LEVEL,
					    "",
					    NULL,
					    -1,
					    BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA,
					    pixbuf,
					    0,
					    0);
	gdk_pixbuf_unref (pixbuf);
	
	/* now add items for each of the three user levels */
	add_user_level_menu_item (window, NAUTILUS_MENU_PATH_NOVICE_ITEM, 
				  NAUTILUS_USER_LEVEL_NOVICE);
	add_user_level_menu_item (window, NAUTILUS_MENU_PATH_INTERMEDIATE_ITEM, 
				  NAUTILUS_USER_LEVEL_INTERMEDIATE);
	add_user_level_menu_item (window, NAUTILUS_MENU_PATH_EXPERT_ITEM, 
				  NAUTILUS_USER_LEVEL_HACKER);

	bonobo_ui_handler_menu_new_separator (ui_handler,
					      NAUTILUS_MENU_PATH_AFTER_USER_LEVEL_SEPARATOR,
					      -1);

	bonobo_ui_handler_menu_new_item (ui_handler,
					 NAUTILUS_MENU_PATH_USER_LEVEL_CUSTOMIZE,
					 _("Edit Settings..."),
					 _("Edit Settings for the Current User Level"),
        				 -1,
        				 BONOBO_UI_HANDLER_PIXMAP_NONE,
        				 NULL,
        				 0,
        				 0,
        				 user_level_customize_callback,
        				 window);

        update_user_level_menu_items (window);
	
	/* Connect to undo manager so it will handle the menu item. */
	nautilus_undo_manager_set_up_bonobo_ui_handler_undo_item
		(window->application->undo_manager,
		 ui_handler, NAUTILUS_MENU_PATH_UNDO_ITEM,
		 _("_Undo"), _("Undo the last text change"));
#endif /* UIH */
	
        nautilus_window_initialize_bookmarks_menu (window);
        nautilus_window_initialize_go_menu (window);
}

void
nautilus_window_remove_bookmarks_menu_callback (NautilusWindow *window)
{
        if (window->details->refresh_bookmarks_menu_idle_id != 0) {
                gtk_idle_remove (window->details->refresh_bookmarks_menu_idle_id);
		window->details->refresh_bookmarks_menu_idle_id = 0;
        }
}

void
nautilus_window_remove_go_menu_callback (NautilusWindow *window)
{
        if (window->details->refresh_go_menu_idle_id != 0) {
                gtk_idle_remove (window->details->refresh_go_menu_idle_id);
		window->details->refresh_go_menu_idle_id = 0;
        }
}

void
nautilus_window_remove_bookmarks_menu_items (NautilusWindow *window)
{
	remove_bookmarks_after (window, 
				NAUTILUS_MENU_PATH_BOOKMARKS_MENU, 
				NAUTILUS_MENU_PATH_BOOKMARK_ITEMS_PLACEHOLDER);
}

void
nautilus_window_remove_go_menu_items (NautilusWindow *window)
{
	remove_bookmarks_after (window, 
				NAUTILUS_MENU_PATH_GO_MENU, 
				NAUTILUS_MENU_PATH_HISTORY_ITEMS_PLACEHOLDER);
}

void
nautilus_window_update_find_menu_item (NautilusWindow *window)
{
	char *label_string;

	g_return_if_fail (NAUTILUS_IS_WINDOW (window));

	label_string = g_strdup 
		(nautilus_window_get_search_mode (window) 
			? _("_Browse") 
			: _("_Find"));
#ifdef UIH
	bonobo_ui_handler_menu_set_label (window->ui_handler, 
					  NAUTILUS_MENU_PATH_TOGGLE_FIND_MODE, 
					  label_string);
#endif
	g_free (label_string);

#ifndef UIH
	/* avoid "unused function" warnings */
	return;

	add_user_level_menu_item (0, 0, 0);
	append_placeholder (0, 0);
	bookmark_holder_free (0);
	edit_bookmarks (0);
	convert_user_level_to_verb (0);
	forget_history_if_confirmed (0);
	show_bogus_bookmark_window (0);
	switch_and_show_intermediate_settings_callback (0, 0);
	user_level_changed_callback (0, 0);
#endif
}

static void
append_dynamic_bookmarks (NautilusWindow *window)
{
        NautilusBookmarkList *bookmarks;
	guint 	bookmark_count;
	guint	index;
	
	g_assert (NAUTILUS_IS_WINDOW (window));

	bookmarks = get_bookmark_list ();

	bookmark_count = nautilus_bookmark_list_length (bookmarks);

        /* Add separator before bookmarks, unless there are no bookmarks. */
        if (bookmark_count > 0) {
	        append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_BOOKMARKS);
        }

	/* append new set of bookmarks */
	for (index = 0; index < bookmark_count; ++index)
	{
		char *path;

		path = g_strdup_printf ("/Bookmarks/Bookmark%d", index);
		append_bookmark_to_menu (window, 
		                         nautilus_bookmark_list_item_at (bookmarks, index), 
		                         path,
		                         TRUE); 
                g_free (path);
	}	
}

static gboolean
refresh_bookmarks_menu_idle_callback (gpointer data)
{
	g_assert (NAUTILUS_IS_WINDOW (data));

	refresh_bookmarks_menu (NAUTILUS_WINDOW (data));

        /* Don't call this again (unless rescheduled) */
        return FALSE;
}

static void
schedule_refresh_bookmarks_menu (NautilusWindow *window)
{
	g_assert (NAUTILUS_IS_WINDOW (window));

	if (window->details->refresh_bookmarks_menu_idle_id == 0) {
                window->details->refresh_bookmarks_menu_idle_id
                        = gtk_idle_add (refresh_bookmarks_menu_idle_callback,
                                        window);
	}	
}

/**
 * refresh_go_menu:
 * 
 * Refresh list of bookmarks at end of Go menu to match centralized history list.
 * @window: The NautilusWindow whose Go menu will be refreshed.
 **/
static void
refresh_go_menu (NautilusWindow *window)
{
	GList *p;
	int index;
	char *path;
	
	g_assert (NAUTILUS_IS_WINDOW (window));

	/* Unregister any pending call to this function. */
	nautilus_window_remove_go_menu_callback (window);

	/* Remove old set of history items. */
	nautilus_window_remove_go_menu_items (window);

	/* Add in a new set of history items. */
	index = 0;
	p = nautilus_get_history_list ();
	if (p != NULL) {
		/* Append the separator when there's any history items */
		append_separator (window, NAUTILUS_MENU_PATH_SEPARATOR_BEFORE_HISTORY);

		while (p != NULL) {
			path = g_strdup_printf ("/Go/History%d", index); 
	                append_bookmark_to_menu (window,
	                                         NAUTILUS_BOOKMARK (p->data),
	                                         path,
	                                         FALSE);
	                g_free (path);

	                ++index;
			p = p->next;
		}
	}
}

static gboolean
refresh_go_menu_idle_callback (gpointer data)
{
	g_assert (NAUTILUS_IS_WINDOW (data));

	refresh_go_menu (NAUTILUS_WINDOW (data));

        /* Don't call this again (unless rescheduled) */
        return FALSE;
}

static void
schedule_refresh_go_menu (NautilusWindow *window)
{
	g_assert (NAUTILUS_IS_WINDOW (window));

	if (window->details->refresh_go_menu_idle_id == 0) {
                window->details->refresh_go_menu_idle_id
                        = gtk_idle_add (refresh_go_menu_idle_callback,
                                        window);
	}	
}


static void
update_user_level_menu_items (NautilusWindow *window)
{
	char *customize_string;
	int user_level;
	
        g_assert (window != NULL);
        g_assert (NAUTILUS_IS_WINDOW (window));

	user_level = nautilus_user_level_manager_get_user_level ();

	customize_string = get_customize_user_level_settings_menu_string ();
	g_assert (customize_string != NULL);

 	/* Update the user radio group to reflect reality */
#ifdef UIH
	bonobo_ui_handler_menu_set_radio_state (window->ui_handler, 
						convert_user_level_to_menu_path (user_level),
						TRUE);

 	/* Update the "Edit Settings..." item to reflect the user level to customize */
	bonobo_ui_handler_menu_set_label (window->ui_handler,
					  NAUTILUS_MENU_PATH_USER_LEVEL_CUSTOMIZE,
					  customize_string);
#endif

	g_free (customize_string);
}

static guint
convert_verb_to_user_level (const char *verb)
{
        g_assert (verb != NULL);
	
	if (strcmp (verb, SWITCH_TO_BEGINNER_VERB) == 0) {
		return NAUTILUS_USER_LEVEL_NOVICE;
	}
	else if (strcmp (verb, SWITCH_TO_INTERMEDIATE_VERB) == 0) {
		return NAUTILUS_USER_LEVEL_INTERMEDIATE;
	}
	else if (strcmp (verb, SWITCH_TO_ADVANCED_VERB) == 0) {
		return NAUTILUS_USER_LEVEL_HACKER;
	}

	g_assert_not_reached ();

	return NAUTILUS_USER_LEVEL_NOVICE;
}

static const char *
convert_user_level_to_verb (guint user_level)
{
	switch (user_level) {
	case NAUTILUS_USER_LEVEL_NOVICE:
		return SWITCH_TO_BEGINNER_VERB;
		break;

	case NAUTILUS_USER_LEVEL_INTERMEDIATE:
		return SWITCH_TO_INTERMEDIATE_VERB;
		break;

	case NAUTILUS_USER_LEVEL_HACKER:
		return SWITCH_TO_ADVANCED_VERB;
		break;
	}

	g_assert_not_reached ();

	return NAUTILUS_MENU_PATH_NOVICE_ITEM;
}

static char *
get_customize_user_level_string (void)
{
	char *user_level_string_for_display;
	char *title;
	
	user_level_string_for_display = 
		nautilus_user_level_manager_get_user_level_name_for_display 
			(nautilus_user_level_manager_get_user_level ());

	/* Localizers: This is the label for the menu item that brings up the
	 * user-level settings dialog. %s will be replaced with the name of a
	 * user level ("Beginner", "Intermediate", or "Advanced").
	 */
	title = g_strdup_printf ("Edit %s Settings", user_level_string_for_display);

	g_free (user_level_string_for_display);

	return title;
}

static char *
get_customize_user_level_settings_menu_string (void)
{
	char *title;
	char *ellipse_suffixed_title;

	title = get_customize_user_level_string ();
	g_assert (title != NULL);

	ellipse_suffixed_title = g_strdup_printf ("%s...", title);

	g_free (title);

	return ellipse_suffixed_title;
}

static void
update_preferences_dialog_title (void)
{
	char *dialog_title;
	
	dialog_title = get_customize_user_level_string ();
	g_assert (dialog_title != NULL);
	
	nautilus_global_preferences_set_dialog_title (dialog_title);

	g_free (dialog_title);
}