summaryrefslogtreecommitdiff
path: root/src/nautilus-window.c
blob: 36d8970d4afb74dbe4224884026571c28aa4205b (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

/*
 *  Nautilus
 *
 *  Copyright (C) 1999, 2000 Red Hat, Inc.
 *  Copyright (C) 1999, 2000 Eazel, Inc.
 *
 *  This library 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.
 *
 *  This library 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 library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Authors: Elliot Lee <sopwith@redhat.com>
 *  	     John Sullivan <sullivan@eazel.com>
 *
 */
/* ntl-window.c: Implementation of the main window object */

#include "config.h"
#include <gnome.h>
#include <math.h>
#include "nautilus.h"
#include "nautilus-bookmarks-menu.h"
#include "nautilus-signaller.h"
#include "explorer-location-bar.h"
#include "ntl-index-panel.h"
#include "ntl-window-private.h"
#include "ntl-miniicon.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libnautilus/nautilus-gtk-extensions.h>
#include <libnautilus/nautilus-icon-factory.h>
#include <libnautilus/nautilus-string.h>
#include "nautilus-zoom-control.h"
#include <ctype.h>

enum
{
	LAST_SIGNAL
};

static void nautilus_window_realize (GtkWidget *widget);
static void nautilus_window_real_set_content_view (NautilusWindow *window, NautilusView *new_view);

/* Object framework static variables */
static GnomeAppClass *parent_class = NULL;
static guint window_signals[LAST_SIGNAL];

/* Other static variables */
static GSList *history_list = NULL;


/* Stuff for handling the CORBA interface */
typedef struct {
  POA_Nautilus_ViewWindow servant;
  gpointer bonobo_object;

  NautilusWindow *window;
} impl_POA_Nautilus_ViewWindow;

static const CORBA_char *impl_Nautilus_ViewWindow__get_current_uri (impl_POA_Nautilus_ViewWindow *servant,
                                                                    CORBA_Environment            *ev);

static Nautilus_Application impl_Nautilus_ViewWindow__get_application (impl_POA_Nautilus_ViewWindow *servant,
                                                                       CORBA_Environment            *ev);

static void impl_Nautilus_ViewWindow_open_uri                         (impl_POA_Nautilus_ViewWindow *servant,
                                                                       CORBA_char                   *uri,
                                                                       CORBA_Environment            *ev);

static void impl_Nautilus_ViewWindow_close                            (impl_POA_Nautilus_ViewWindow *servant,
                                                                       CORBA_Environment            *ev);


static POA_Nautilus_ViewWindow__epv impl_Nautilus_ViewWindow_epv =
{
  NULL,
  (gpointer) &impl_Nautilus_ViewWindow__get_current_uri,
  (gpointer) &impl_Nautilus_ViewWindow__get_application,
  (gpointer) &impl_Nautilus_ViewWindow_open_uri,
  (gpointer) &impl_Nautilus_ViewWindow_close
};

static PortableServer_ServantBase__epv base_epv = { NULL, NULL, NULL };

static POA_Nautilus_ViewWindow__vepv impl_Nautilus_ViewWindow_vepv =
{
   &base_epv,
   NULL,
   &impl_Nautilus_ViewWindow_epv
};

static const CORBA_char *
impl_Nautilus_ViewWindow__get_current_uri (impl_POA_Nautilus_ViewWindow *servant,
                                           CORBA_Environment            *ev)
{
  return nautilus_window_get_requested_uri (servant->window);
}


static Nautilus_Application
impl_Nautilus_ViewWindow__get_application (impl_POA_Nautilus_ViewWindow *servant,
                                           CORBA_Environment            *ev)
{
  return CORBA_OBJECT_NIL;
}

static void
impl_Nautilus_ViewWindow_open_uri (impl_POA_Nautilus_ViewWindow *servant,
                                   CORBA_char                   *uri,
                                   CORBA_Environment            *ev)
{
  nautilus_window_goto_uri (servant->window, uri);
}

static void
impl_Nautilus_ViewWindow_close (impl_POA_Nautilus_ViewWindow *servant,
                                CORBA_Environment            *ev)
{
  nautilus_window_close (servant->window);
}


static void
impl_Nautilus_ViewWindow__destroy(BonoboObject *obj, impl_POA_Nautilus_ViewWindow *servant)
{
   PortableServer_ObjectId *objid;
   CORBA_Environment ev;

   CORBA_exception_init(&ev);

   objid = PortableServer_POA_servant_to_id(bonobo_poa(), servant, &ev);
   PortableServer_POA_deactivate_object(bonobo_poa(), objid, &ev);
   CORBA_free(objid);
   obj->servant = NULL;

   POA_Nautilus_ViewWindow__fini((PortableServer_Servant) servant, &ev);
   g_free(servant);

   CORBA_exception_free(&ev);
}

static BonoboObject *
impl_Nautilus_ViewWindow__create(NautilusWindow *window)
{
   BonoboObject *retval;
   impl_POA_Nautilus_ViewWindow *newservant;
   CORBA_Environment ev;

   CORBA_exception_init(&ev);

   newservant = g_new0(impl_POA_Nautilus_ViewWindow, 1);
   newservant->servant.vepv = &impl_Nautilus_ViewWindow_vepv;
   newservant->window = window;
   POA_Nautilus_ViewWindow__init((PortableServer_Servant) newservant, &ev);

   retval = bonobo_object_new_from_servant(newservant);

   gtk_signal_connect(GTK_OBJECT(retval), "destroy", GTK_SIGNAL_FUNC(impl_Nautilus_ViewWindow__destroy), newservant);
   CORBA_exception_free(&ev);

   return retval;
}

static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
static void nautilus_window_destroy (NautilusWindow *window);
static void nautilus_window_back (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_up (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_reload (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_home (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_color_confirm (GtkWidget *widget);
static void nautilus_window_show_color_picker (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_stop (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_set_arg (GtkObject      *object,
                                     GtkArg         *arg,
                                     guint	      arg_id);
static void nautilus_window_get_arg (GtkObject      *object,
                                     GtkArg         *arg,
                                     guint	      arg_id);
static void nautilus_window_goto_uri_cb (GtkWidget *widget,
                                         const char *uri,
                                         GtkWidget *window);
static void nautilus_window_about_cb (GtkWidget *widget,
                                      NautilusWindow *window);

/* #define CONTENTS_AS_HBOX 1 */

/* milliseconds */
#define STATUSBAR_CLEAR_TIMEOUT 5000

/* menu definitions */

static void
file_menu_close_cb (GtkWidget *widget,
                    gpointer data)
{
        g_assert (NAUTILUS_IS_WINDOW (data));
	nautilus_window_close (NAUTILUS_WINDOW (data));
}

static void
file_menu_new_window_cb (GtkWidget *widget,
                         gpointer data)
{
  NautilusWindow *current_mainwin;
  NautilusWindow *new_mainwin;

  g_return_if_fail(NAUTILUS_IS_WINDOW(data));
  
  current_mainwin = NAUTILUS_WINDOW(data);

  new_mainwin = nautilus_app_create_window();

  nautilus_window_goto_uri(new_mainwin, 
                           nautilus_window_get_requested_uri(current_mainwin));

  gtk_widget_show(GTK_WIDGET(new_mainwin));
}

static void
file_menu_exit_cb (GtkWidget *widget,
                   gpointer data)
{
  gtk_main_quit();
}

static void
edit_menu_prefs_cb(GtkWidget *widget,
                   GtkWindow *mainwin)
{
  nautilus_prefs_ui_show(mainwin);
}

static GnomeUIInfo file_menu_info[] = {
  {
    GNOME_APP_UI_ITEM,
    N_("New Window"), N_("Create a new window"),
    file_menu_new_window_cb, NULL, NULL,
    GNOME_APP_PIXMAP_NONE, NULL,
    'N', GDK_CONTROL_MASK, NULL
  },
  GNOMEUIINFO_MENU_CLOSE_ITEM(file_menu_close_cb, NULL),
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_MENU_EXIT_ITEM(file_menu_exit_cb, NULL),
  GNOMEUIINFO_END
};

/* FIXME: These all need implementation, though we might end up doing that
 * separately for each content view (and merging with the insensitive items here)
 */
static GnomeUIInfo edit_menu_info[] = {
  GNOMEUIINFO_MENU_UNDO_ITEM(NULL, NULL),
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_MENU_CUT_ITEM(NULL, NULL),
  GNOMEUIINFO_MENU_COPY_ITEM(NULL, NULL),
  GNOMEUIINFO_MENU_PASTE_ITEM(NULL, NULL),
  GNOMEUIINFO_MENU_CLEAR_ITEM(NULL, NULL),
  GNOMEUIINFO_SEPARATOR,
  /* Didn't use standard SELECT_ALL_ITEM 'cuz it didn't have accelerator */
  {
    GNOME_APP_UI_ITEM,
    N_("Select All"), NULL,
    NULL, NULL, NULL,
    GNOME_APP_PIXMAP_NONE, NULL,
    'A', GDK_CONTROL_MASK, NULL
  },
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_MENU_PREFERENCES_ITEM(edit_menu_prefs_cb, NULL),
  GNOMEUIINFO_END
};

#define GO_MENU_BACK_ITEM_INDEX		0
#define GO_MENU_FORWARD_ITEM_INDEX	1
#define GO_MENU_UP_ITEM_INDEX		2
#define GO_MENU_HOME_ITEM_INDEX		3
#define GO_MENU_SEPARATOR_ITEM_INDEX	4
static GnomeUIInfo go_menu_info[] = {
  {
    GNOME_APP_UI_ITEM,
    N_("Back"), N_("Go to the previous visited location"),
    nautilus_window_back, NULL, NULL,
    GNOME_APP_PIXMAP_NONE, NULL,
    'B', GDK_CONTROL_MASK, NULL
  },
  {
    GNOME_APP_UI_ITEM,
    N_("Forward"), N_("Go to the next visited location"),
    nautilus_window_fwd, NULL, NULL,
    GNOME_APP_PIXMAP_NONE, NULL,
    'F', GDK_CONTROL_MASK, NULL
  },
  {
    GNOME_APP_UI_ITEM,
    N_("Up"), N_("Go to the location that contains this one"),
    nautilus_window_up, NULL, NULL,
    GNOME_APP_PIXMAP_NONE, NULL,
    'U', GDK_CONTROL_MASK, NULL
  },
  {
    GNOME_APP_UI_ITEM,
    N_("Home"), N_("Go to the home location"),
    nautilus_window_home, NULL, NULL,
    GNOME_APP_PIXMAP_NONE, NULL,
    'H', GDK_CONTROL_MASK, NULL
  },
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_END
};

static GnomeUIInfo bookmarks_menu_info[] = {
  GNOMEUIINFO_END
};

static GnomeUIInfo help_menu_info[] = {
  {
    GNOME_APP_UI_ITEM,
    N_("About Nautilus..."), N_("Info about the Nautilus program"),
    nautilus_window_about_cb, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT,
    0, 0, NULL
  },
  GNOMEUIINFO_END
};

static GnomeUIInfo debug_menu_info [] = {
	GNOMEUIINFO_ITEM_NONE (N_("Show Color selector..."), N_("Show the color picker window"), nautilus_window_show_color_picker),
	GNOMEUIINFO_END
};


#define GO_MENU_INDEX		2
#define BOOKMARKS_MENU_INDEX	3
static GnomeUIInfo main_menu[] = {
  GNOMEUIINFO_MENU_FILE_TREE (file_menu_info),
  GNOMEUIINFO_MENU_EDIT_TREE (edit_menu_info),
  GNOMEUIINFO_SUBTREE(N_("_Go"), go_menu_info),
  GNOMEUIINFO_SUBTREE(N_("_Bookmarks"), bookmarks_menu_info),
  GNOMEUIINFO_MENU_HELP_TREE (help_menu_info),
  GNOMEUIINFO_SUBTREE(N_("_Debug"), debug_menu_info),
  GNOMEUIINFO_END
};

/* toolbar definitions */

#define TOOLBAR_BACK_BUTTON_INDEX	0
#define TOOLBAR_FORWARD_BUTTON_INDEX	1
#define TOOLBAR_UP_BUTTON_INDEX		2
#define TOOLBAR_RELOAD_BUTTON_INDEX	3
/* separator */
#define TOOLBAR_HOME_BUTTON_INDEX	5
/* separator */
#define TOOLBAR_STOP_BUTTON_INDEX	7
static GnomeUIInfo toolbar_info[] = {
  GNOMEUIINFO_ITEM_STOCK
  (N_("Back"), N_("Go to the previously visited directory"),
   nautilus_window_back, GNOME_STOCK_PIXMAP_BACK),
  GNOMEUIINFO_ITEM_STOCK
  (N_("Forward"), N_("Go to the next directory"),
   nautilus_window_fwd, GNOME_STOCK_PIXMAP_FORWARD),
  GNOMEUIINFO_ITEM_STOCK
  (N_("Up"), N_("Go up a level in the directory heirarchy"),
   nautilus_window_up, GNOME_STOCK_PIXMAP_UP),
  GNOMEUIINFO_ITEM_STOCK
  (N_("Reload"), N_("Reload this view"),
   nautilus_window_reload, GNOME_STOCK_PIXMAP_REFRESH),
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_ITEM_STOCK
  (N_("Home"), N_("Go to your home directory"),
   nautilus_window_home, GNOME_STOCK_PIXMAP_HOME),
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_ITEM_STOCK
  (N_("Stop"), N_("Interrupt loading"),
   nautilus_window_stop, GNOME_STOCK_PIXMAP_STOP),
  GNOMEUIINFO_END
};

static void
clear_go_menu_history (NautilusWindow *window)
{
	GList *children;
	GList *iterator;
	GtkMenu *go_menu;
	gboolean found_dynamic_items;

	g_assert (NAUTILUS_IS_WINDOW (window));

	go_menu = GTK_MENU (window->go_menu);

	/* Remove all the old history items */
	children = gtk_container_children (GTK_CONTAINER (go_menu));
	iterator = children;
	found_dynamic_items = FALSE;

	while (iterator != NULL)
	{
		if (found_dynamic_items)
		{
			gtk_container_remove (GTK_CONTAINER (go_menu), iterator->data);
		}
		else if (iterator->data == window->go_menu_separator_item)
		{
			found_dynamic_items = TRUE;
		}
		iterator = g_list_next (iterator);
	}

	g_assert (found_dynamic_items);
	g_list_free (children);
}

static void
activate_bookmark_in_menu_item (GtkMenuItem *menu_item, NautilusWindow *window)
{
	g_assert (GTK_IS_MENU_ITEM (menu_item));
	g_assert (NAUTILUS_IS_WINDOW (window));
	g_assert (NAUTILUS_IS_BOOKMARK (gtk_object_get_user_data (GTK_OBJECT (menu_item))));

	nautilus_window_goto_uri (window, nautilus_bookmark_get_uri (
		NAUTILUS_BOOKMARK (gtk_object_get_user_data (GTK_OBJECT (menu_item)))));
}

static void
refresh_history_list_in_go_menu (NautilusWindow *window)
{
	GSList *iterator;
	GtkMenu *go_menu;

	g_assert (NAUTILUS_IS_WINDOW (window));

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

	go_menu = GTK_MENU (window->go_menu);

	/* Add in a new set of history items. */
	for (iterator = history_list; iterator != NULL; iterator = g_slist_next (iterator))
	{
		NautilusBookmark *bookmark;
		GtkWidget *menu_item;

		bookmark = NAUTILUS_BOOKMARK (iterator->data);
		menu_item = nautilus_bookmark_menu_item_new (bookmark);
		/* Store the history list's bookmark in the menu item's data.
		 * The menu item holds no ref, but that's OK because the
		 * history list owns the bookmark and the menu item will be
		 * destroyed when the history list changes.
		 */
		gtk_object_set_user_data (GTK_OBJECT (menu_item), bookmark);
		gtk_widget_show (GTK_WIDGET (menu_item));
  		gtk_signal_connect(GTK_OBJECT(menu_item), 
  			"activate",
                     	activate_bookmark_in_menu_item, 
                     	window);
		
		gtk_menu_append (go_menu, menu_item);
	}	
}

	
GtkType
nautilus_window_get_type(void)
{
  static guint window_type = 0;

  if (!window_type)
    {
      GtkTypeInfo window_info =
      {
	"NautilusWindow",
	sizeof(NautilusWindow),
	sizeof(NautilusWindowClass),
	(GtkClassInitFunc) nautilus_window_class_init,
	(GtkObjectInitFunc) nautilus_window_init,
        NULL,
        NULL,
        NULL
      };

      window_type = gtk_type_unique (gnome_app_get_type(), &window_info);
    }

  return window_type;
}

#if 0
typedef void (*GtkSignal_NONE__BOXED_OBJECT) (GtkObject * object,
                                              gpointer arg1,
                                              GtkObject *arg2,
					       gpointer user_data);
static void 
gtk_marshal_NONE__BOXED_OBJECT (GtkObject * object,
			       GtkSignalFunc func,
			       gpointer func_data,
			       GtkArg * args)
{
  GtkSignal_NONE__BOXED_OBJECT rfunc;
  rfunc = (GtkSignal_NONE__BOXED_OBJECT) func;
  (*rfunc) (object,
	    GTK_VALUE_BOXED (args[0]),
	    GTK_VALUE_OBJECT (args[1]),
	    func_data);
}
#endif

enum {
  ARG_0,
  ARG_APP_ID,
  ARG_CONTENT_VIEW
};

static void
nautilus_window_class_init (NautilusWindowClass *klass)
{
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;

  parent_class = gtk_type_class(gnome_app_get_type());
  
  object_class = (GtkObjectClass*) klass;
  object_class->destroy = (void (*)(GtkObject *))nautilus_window_destroy;
  object_class->get_arg = nautilus_window_get_arg;
  object_class->set_arg = nautilus_window_set_arg;

  widget_class = (GtkWidgetClass*) klass;
  klass->parent_class = gtk_type_class (gtk_type_parent (object_class->type));

  gtk_object_class_add_signals (object_class, window_signals, LAST_SIGNAL);

  gtk_object_add_arg_type ("NautilusWindow::app_id",
			   GTK_TYPE_STRING,
			   GTK_ARG_READWRITE|GTK_ARG_CONSTRUCT,
			   ARG_APP_ID);
  gtk_object_add_arg_type ("NautilusWindow::content_view",
			   GTK_TYPE_OBJECT,
			   GTK_ARG_READWRITE,
			   ARG_CONTENT_VIEW);
  impl_Nautilus_ViewWindow_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv();

  widget_class->realize = nautilus_window_realize;
}

static void
nautilus_window_init (NautilusWindow *window)
{
  gtk_quit_add_destroy (1, GTK_OBJECT (window));

  gtk_signal_connect_object_while_alive (GTK_OBJECT (nautilus_signaller_get_current ()),
  				         "history_list_changed",
  				         refresh_history_list_in_go_menu,
  				         GTK_OBJECT (window));

  gtk_signal_connect_object_while_alive (nautilus_icon_factory_get (),
				         "theme_changed",
				         refresh_history_list_in_go_menu,
				         GTK_OBJECT (window));
				         
}

static gboolean
nautilus_window_clear_status(NautilusWindow *window)
{
  gtk_statusbar_pop(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx);
  window->statusbar_clear_id = 0;
  return FALSE;
}

void
nautilus_window_set_status(NautilusWindow *window, const char *txt)
{
  if(window->statusbar_clear_id)
    g_source_remove(window->statusbar_clear_id);

  gtk_statusbar_pop(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx);
  if(txt && *txt)
    {
      window->statusbar_clear_id = g_timeout_add(STATUSBAR_CLEAR_TIMEOUT, (GSourceFunc)nautilus_window_clear_status, window);
      gtk_statusbar_push(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx, txt);
    }
  else
    window->statusbar_clear_id = 0;
}

void
nautilus_window_goto_uri (NautilusWindow *window, const char *uri)
{
  Nautilus_NavigationRequestInfo navinfo;

  memset(&navinfo, 0, sizeof(navinfo));
  navinfo.requested_uri = (char *)uri;
  navinfo.new_window_default = navinfo.new_window_suggested = Nautilus_V_FALSE;
  navinfo.new_window_enforced = Nautilus_V_UNKNOWN;

  nautilus_window_request_location_change (window, &navinfo, NULL);
}

static void
nautilus_window_goto_uri_cb (GtkWidget *widget,
                             const char *uri,
                             GtkWidget *window)
{
  nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
}

static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item, 
				    NautilusWindow *window,
				    gboolean back)
{
	int index;
	NautilusBookmark *bookmark;
	
	g_assert (GTK_IS_MENU_ITEM (menu_item));
	g_assert (NAUTILUS_IS_WINDOW (window));

	index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (menu_item)));
	bookmark = NAUTILUS_BOOKMARK (g_slist_nth_data (back ? window->back_list 
							     : window->forward_list, 
							index));

	/* FIXME: This should do the equivalent of going back or forward n times,
	 * rather than just going to the right uri. This is needed to
	 * keep the back/forward chain intact.
	 */
	nautilus_window_goto_uri (window, nautilus_bookmark_get_uri (bookmark));
}

static void
activate_back_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
	activate_back_or_forward_menu_item (menu_item, window, TRUE);
}

static void
activate_forward_menu_item_cb (GtkMenuItem *menu_item, NautilusWindow *window)
{
	activate_back_or_forward_menu_item (menu_item, window, FALSE);
}

static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
	GtkMenu *menu;
	GtkWidget *menu_item;
	GSList *list_link;
	int index;

	g_assert (NAUTILUS_IS_WINDOW (window));
	
	menu = GTK_MENU (gtk_menu_new ());

	list_link = back ? window->back_list : window->forward_list;
	index = 0;
	while (list_link != NULL)
	{
		menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list_link->data));		
		gtk_object_set_user_data (GTK_OBJECT (menu_item), GINT_TO_POINTER (index));
		gtk_widget_show (GTK_WIDGET (menu_item));
  		gtk_signal_connect(GTK_OBJECT(menu_item), 
  			"activate",
                     	back ? activate_back_menu_item_cb : activate_forward_menu_item_cb, 
                     	window);
		
		gtk_menu_append (menu, menu_item);
		list_link = g_slist_next (list_link);
		++index;
	}

	return menu;
}

static int
back_or_forward_button_clicked_cb (GtkWidget *widget, 
				   GdkEventButton *event, 
				   gpointer *user_data)
{
	gboolean back;

	g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
	g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
	g_return_val_if_fail (event != NULL, FALSE);

	back = NAUTILUS_WINDOW (user_data)->back_button == widget;
	g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);

	if (event->button == 3)
	{
		nautilus_pop_up_context_menu (
			create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
						     back),
                        NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
                        NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT);

		return TRUE;
	}

	return FALSE;
	
}

static void
nautilus_window_constructed(NautilusWindow *window)
{
  GnomeApp *app;
  GtkWidget *location_bar_box, *statusbar;
  GtkWidget *temp_frame, *zoom_control;
  GtkWidget *toolbar;
  
  app = GNOME_APP(window);

  /* set up toolbar */
  toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
  gnome_app_fill_toolbar_with_data(GTK_TOOLBAR(toolbar), toolbar_info, app->accel_group, app);
  gnome_app_set_toolbar(app, GTK_TOOLBAR(toolbar));

  /* set up location bar */

  location_bar_box = gtk_hbox_new(FALSE, GNOME_PAD);
  gtk_container_set_border_width(GTK_CONTAINER(location_bar_box), GNOME_PAD_SMALL);

  window->ent_uri = explorer_location_bar_new();
  gtk_signal_connect(GTK_OBJECT(window->ent_uri), "location_changed",
                     nautilus_window_goto_uri_cb, window);
  gtk_box_pack_start(GTK_BOX(location_bar_box), window->ent_uri, TRUE, TRUE, GNOME_PAD_SMALL);
  gnome_app_add_docked(app, location_bar_box, "uri-entry",
  					   GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
                       GNOME_DOCK_TOP, 2, 0, 0);

  /* Option menu for content view types; it's empty here, filled in when a uri is set. */
  window->option_cvtype = gtk_option_menu_new();
  gtk_box_pack_end(GTK_BOX(location_bar_box), window->option_cvtype, FALSE, FALSE, GNOME_PAD_SMALL);
  gtk_widget_show(window->option_cvtype);

  /* allocate the zoom control and place on the right next to the menu */
  
  zoom_control = nautilus_zoom_control_new();
  gtk_widget_show(zoom_control);
  gtk_box_pack_end(GTK_BOX(location_bar_box), zoom_control, FALSE, FALSE, 0);
  
  gtk_widget_show_all(location_bar_box);

  /* set up status bar */

  gnome_app_set_statusbar(app, (statusbar = gtk_statusbar_new()));
  /* insert a little padding so text isn't jammed against frame */
  gtk_misc_set_padding(GTK_MISC ((GTK_STATUSBAR (statusbar))->label), GNOME_PAD, 0);
  window->statusbar_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "IhateGtkStatusbar");

  /* set up window contents and policy */

  gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
  gtk_window_set_default_size(GTK_WINDOW(window), 650, 400);

#ifdef CONTENTS_AS_HBOX
  window->content_hbox = gtk_hbox_new(FALSE, 0);
#else
  window->content_hbox = gtk_hpaned_new();
  {
/* special case the width of the index panel for sopwith */
	char *user_name = getenv("USER");
	gint pos = 136;

	if (!strcmp(user_name, "sopwith"))
		pos = 275;
	gtk_paned_set_position(GTK_PANED(window->content_hbox), pos);
  }
#endif
  gnome_app_set_contents(app, window->content_hbox);

  /* set up the index panel in a frame */

  temp_frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type(GTK_FRAME(temp_frame), GTK_SHADOW_OUT);
  gtk_widget_show(temp_frame);
  
  window->index_panel = nautilus_index_panel_new();
  gtk_widget_show (GTK_WIDGET (window->index_panel));
  gtk_container_add(GTK_CONTAINER(temp_frame), GTK_WIDGET (window->index_panel));

#ifdef CONTENTS_AS_HBOX
  gtk_box_pack_start(GTK_BOX(window->content_hbox), temp_frame, FALSE, FALSE, 0);
#else
  gtk_paned_pack1(GTK_PANED(window->content_hbox), temp_frame, TRUE, TRUE);
#endif

  gtk_widget_show_all(window->content_hbox);

  /* CORBA stuff */
  window->ntl_viewwindow = impl_Nautilus_ViewWindow__create(window);
  window->uih = bonobo_ui_handler_new();

  /* set up menu bar */
  gnome_app_create_menus_with_data(app, main_menu, window);

  /* desensitize the items that haven't yet been implemented
   * FIXME: these all need to be implemented. I'm using hardwired numbers
   * rather than enum symbols here just 'cuz the enums aren't needed (I think)
   * once we've implemented things. If it turns out they are, we'll define 'em.
   */

  gtk_widget_set_sensitive(edit_menu_info[0].widget, FALSE); /* Undo */
  gtk_widget_set_sensitive(edit_menu_info[2].widget, FALSE); /* Cut */
  gtk_widget_set_sensitive(edit_menu_info[3].widget, FALSE); /* Copy */
  gtk_widget_set_sensitive(edit_menu_info[4].widget, FALSE); /* Paste */
  gtk_widget_set_sensitive(edit_menu_info[5].widget, FALSE); /* Clear */
  gtk_widget_set_sensitive(edit_menu_info[7].widget, FALSE); /* Select All */

  /* insert bookmarks menu */
  gtk_menu_item_set_submenu(GTK_MENU_ITEM (main_menu[BOOKMARKS_MENU_INDEX].widget), 
  			    nautilus_bookmarks_menu_new(window));
  gnome_app_install_menu_hints(app, main_menu); /* This has to go here
                                                   after the statusbar
                                                   creation */

  /* Remember some widgets now so their state can be changed later */
  window->back_button = toolbar_info[TOOLBAR_BACK_BUTTON_INDEX].widget;
  window->forward_button = toolbar_info[TOOLBAR_FORWARD_BUTTON_INDEX].widget;
  window->up_button = toolbar_info[TOOLBAR_UP_BUTTON_INDEX].widget;
  window->reload_button = toolbar_info[TOOLBAR_RELOAD_BUTTON_INDEX].widget;
  window->stop_button = toolbar_info[TOOLBAR_STOP_BUTTON_INDEX].widget;

  window->go_menu = GTK_MENU_ITEM (main_menu[GO_MENU_INDEX].widget)->submenu;

  window->back_menu_item = go_menu_info[GO_MENU_BACK_ITEM_INDEX].widget;
  window->forward_menu_item = go_menu_info[GO_MENU_FORWARD_ITEM_INDEX].widget;
  window->up_menu_item = go_menu_info[GO_MENU_UP_ITEM_INDEX].widget;
  window->go_menu_separator_item = go_menu_info[GO_MENU_SEPARATOR_ITEM_INDEX].widget;

  gtk_signal_connect (GTK_OBJECT (window->back_button),
		      "button_press_event",
		      GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb), 
		      window);

  gtk_signal_connect (GTK_OBJECT (window->forward_button),
		      "button_press_event",
		      GTK_SIGNAL_FUNC (back_or_forward_button_clicked_cb), 
		      window);

  /* Set initial sensitivity of some buttons & menu items 
   * now that they're all created.
   */
  nautilus_window_allow_back(window, FALSE);
  nautilus_window_allow_forward(window, FALSE);
  nautilus_window_allow_stop(window, FALSE);

  bonobo_ui_handler_set_menubar(window->uih, app->menubar);
  bonobo_ui_handler_set_app(window->uih, app);
  bonobo_ui_handler_set_statusbar(window->uih, statusbar);
  bonobo_ui_handler_set_toolbar(window->uih, "Main", toolbar);
}

static void
nautilus_window_set_arg (GtkObject      *object,
			  GtkArg         *arg,
			  guint	      arg_id)
{
  GnomeApp *app = (GnomeApp *) object;
  char *old_app_name;
  NautilusWindow *window = (NautilusWindow *) object;

  switch(arg_id) {
  case ARG_APP_ID:
    if(!GTK_VALUE_STRING(*arg))
      return;

    old_app_name = app->name;
    g_free(app->name);
    app->name = g_strdup(GTK_VALUE_STRING(*arg));
    g_assert(app->name);
    g_free(app->prefix);
    app->prefix = g_strconcat("/", app->name, "/", NULL);
    if(!old_app_name)
      nautilus_window_constructed(NAUTILUS_WINDOW(object));
    break;
  case ARG_CONTENT_VIEW:
    nautilus_window_real_set_content_view (window, (NautilusView *)GTK_VALUE_OBJECT(*arg));
    break;
  }
}

static void
nautilus_window_get_arg (GtkObject      *object,
			  GtkArg         *arg,
			  guint	      arg_id)
{
  GnomeApp *app = (GnomeApp *) object;

  switch(arg_id) {
  case ARG_APP_ID:
    GTK_VALUE_STRING(*arg) = app->name;
    break;
  case ARG_CONTENT_VIEW:
    GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(((NautilusWindow *)object)->content_view);
    break;
  }
}

static void nautilus_window_destroy (NautilusWindow *window)
{
  NautilusWindowClass *klass = NAUTILUS_WINDOW_CLASS(GTK_OBJECT(window)->klass);

  g_slist_free(window->meta_views);
  CORBA_free(window->ni);
  CORBA_free(window->si);
  g_slist_foreach(window->back_list, (GFunc)gtk_object_unref, NULL);
  g_slist_foreach(window->forward_list, (GFunc)gtk_object_unref, NULL);
  g_slist_free(window->back_list);
  g_slist_free(window->forward_list);

  if(window->statusbar_clear_id)
    g_source_remove(window->statusbar_clear_id);

  if(GTK_OBJECT_CLASS(klass->parent_class)->destroy)
    GTK_OBJECT_CLASS(klass->parent_class)->destroy(GTK_OBJECT(window));
}

GtkWidget *
nautilus_window_new(const char *app_id)
{
  return GTK_WIDGET (gtk_object_new (nautilus_window_get_type(), "app_id", app_id, NULL));
}

void
nautilus_window_close (NautilusWindow *window)
{
        g_return_if_fail (NAUTILUS_IS_WINDOW (window));
	gtk_widget_destroy (GTK_WIDGET (window));
}


/* The reason for this function is that
   `gdk_pixbuf_render_pixmap_and_mask', as currently implemented, will
   fail on a pixbuf with no alpha channel. This function will instead
   return with NULL in *mask_retval in such a case. If that ever gets
   fixed, this function should be removed.
*/

static void
would_be_in_gdk_pixbuf_if_federico_wasnt_stubborn_pixbuf_render(GdkPixbuf  *pixbuf,
                                                                GdkPixmap **pixmap,
                                                                GdkBitmap **mask_retval,
                                                                gint        alpha_threshold)
{
        GdkBitmap *mask = NULL;

        g_return_if_fail(pixbuf != NULL);

        /* generate mask */
        if (gdk_pixbuf_get_has_alpha(pixbuf)) {
                mask = gdk_pixmap_new(NULL,
                                      gdk_pixbuf_get_width(pixbuf),
                                      gdk_pixbuf_get_height(pixbuf),
                                      1);

                gdk_pixbuf_render_threshold_alpha(pixbuf, mask,
                                                  0, 0, 0, 0,
                                                  gdk_pixbuf_get_width(pixbuf),
                                                  gdk_pixbuf_get_height(pixbuf),
                                                  alpha_threshold);
        }

        /* Draw to pixmap */

        if (pixmap != NULL) {
                GdkGC* gc;

                *pixmap = gdk_pixmap_new(NULL,
                                         gdk_pixbuf_get_width(pixbuf),
                                         gdk_pixbuf_get_height(pixbuf),
                                         gdk_rgb_get_visual()->depth);

                gc = gdk_gc_new(*pixmap);

                gdk_gc_set_clip_mask(gc, mask);

                gdk_pixbuf_render_to_drawable(pixbuf, *pixmap,
                                              gc,
                                              0, 0, 0, 0,
                                              gdk_pixbuf_get_width(pixbuf),
                                              gdk_pixbuf_get_height(pixbuf),
                                              GDK_RGB_DITHER_NORMAL,
                                              0, 0);

                gdk_gc_unref(gc);
        }

        if (mask_retval)
                *mask_retval = mask;
        else
                gdk_bitmap_unref(mask);
}

static void
nautilus_window_realize (GtkWidget *widget)
{
        GdkPixmap *pixmap = NULL;
        GdkBitmap *mask = NULL;
        gchar *filename;
        
        /* Create our GdkWindow */
        if (GTK_WIDGET_CLASS(parent_class)->realize)
                (* GTK_WIDGET_CLASS(parent_class)->realize) (widget);
        
        /* Set the mini icon */
        /* FIXME draw a real icon */
        /* FIXME The icon should be 16x16, we get garbage on the edges
           since it's 12x12 */
        filename = gnome_pixmap_file("panel-arrow-down.png");
        
        if (filename != NULL) {
                GdkPixbuf *pixbuf;

                pixbuf = gdk_pixbuf_new_from_file(filename);

                if (pixbuf != NULL) {
                        would_be_in_gdk_pixbuf_if_federico_wasnt_stubborn_pixbuf_render(pixbuf,
                                                                                        &pixmap,
                                                                                        &mask,
                                                                                        128);
                }
        }
                
                
        if (pixmap != NULL)
                nautilus_set_mini_icon(widget->window,
                                       pixmap,
                                       mask);

        /* FIXME I think we are leaking the pixmap/mask here */
}

/*
 * Main API
 */

#if 0
static gboolean
nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event, NautilusView *meta_view)
{
  if(event->button != 3)
    return FALSE;

  gtk_signal_emit_stop_by_name(GTK_OBJECT(dockitem), "button_press_event");

  nautilus_view_show_properties(meta_view);

  return TRUE;
}
#endif

void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
  nautilus_window_real_set_content_view (window, content_view);
}

void
nautilus_window_add_meta_view(NautilusWindow *window, NautilusView *meta_view)
{
  g_return_if_fail (!g_slist_find (window->meta_views, meta_view));
  g_return_if_fail (NAUTILUS_IS_META_VIEW (meta_view));

  nautilus_index_panel_add_meta_view (window->index_panel, meta_view);
  window->meta_views = g_slist_prepend (window->meta_views, meta_view);
}

void
nautilus_window_remove_meta_view_real(NautilusWindow *window, NautilusView *meta_view)
{
  nautilus_index_panel_remove_meta_view(window->index_panel, meta_view);
}

void
nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view)
{
  if(!g_slist_find(window->meta_views, meta_view))
    return;

  window->meta_views = g_slist_remove(window->meta_views, meta_view);
  nautilus_window_remove_meta_view_real(window, meta_view);
}

/* FIXME: Factor toolbar stuff out into ntl-window-toolbar.c */

static void
nautilus_window_back_or_forward (NautilusWindow *window, gboolean back)
{
  Nautilus_NavigationRequestInfo nri;

  g_assert(back ? window->back_list : window->forward_list);

  memset(&nri, 0, sizeof(nri));
  /* FIXME: Have to cast away the const for nri.requested_uri. This field should be
   * declared const. */
  nri.requested_uri = (char *)nautilus_bookmark_get_uri (back ?
  						         window->back_list->data :
  						         window->forward_list->data);
  nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;

  nautilus_window_change_location(window, &nri, NULL, back, FALSE);
}

static void
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
{
  nautilus_window_back_or_forward (window, TRUE);
}

static void
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
{
  nautilus_window_back_or_forward (window, FALSE);
}

const char *
nautilus_window_get_requested_uri (NautilusWindow *window)
{
  return window->ni == NULL ? NULL : window->ni->requested_uri;
}

BonoboUIHandler *
nautilus_window_get_uih(NautilusWindow *window)
{
  return window->uih;
}

static void
nautilus_window_up (GtkWidget *btn, NautilusWindow *window)
{
  const char *requested_uri;
  GnomeVFSURI *current_uri;
  GnomeVFSURI *parent_uri;
  char *parent_uri_string;

  requested_uri = nautilus_window_get_requested_uri(window);
  if (requested_uri == NULL)
    return;

  current_uri = gnome_vfs_uri_new (requested_uri);
  parent_uri = gnome_vfs_uri_get_parent (current_uri);
  gnome_vfs_uri_unref (current_uri);
  parent_uri_string = gnome_vfs_uri_to_string (parent_uri, GNOME_VFS_URI_HIDE_NONE);
  gnome_vfs_uri_unref (parent_uri);  
  
  nautilus_window_goto_uri (window, parent_uri_string);
  
  g_free (parent_uri_string);
}

static void
nautilus_window_reload (GtkWidget *btn, NautilusWindow *window)
{
  Nautilus_NavigationRequestInfo nri;

  memset(&nri, 0, sizeof(nri));
  nri.requested_uri = (char *)nautilus_window_get_requested_uri(window);
  nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
  nautilus_window_change_location(window, &nri, NULL, FALSE, TRUE);
}

static void
nautilus_window_home (GtkWidget *btn, NautilusWindow *window)
{
  nautilus_window_set_initial_state(window, NULL);
}

/* handle the OK button being pushed on the color selector */
/* for now, just vanquish it, since it's only for testing */
static void
nautilus_window_color_confirm (GtkWidget *widget)
{
	gtk_widget_destroy (gtk_widget_get_toplevel (widget));
}

static void nautilus_window_show_color_picker (GtkWidget *btn, NautilusWindow *window)
{
	GtkWidget *c;

	c = gtk_color_selection_dialog_new (_("Color selector"));
	gtk_signal_connect (GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (c)->ok_button),
			    "clicked", GTK_SIGNAL_FUNC (nautilus_window_color_confirm), c);
	gtk_widget_hide (GTK_COLOR_SELECTION_DIALOG (c)->cancel_button);
	gtk_widget_hide (GTK_COLOR_SELECTION_DIALOG (c)->help_button);
	gtk_widget_show (c);
}


static void
nautilus_window_stop (GtkWidget *btn, NautilusWindow *window)
{
  nautilus_window_set_state_info(window, RESET_TO_IDLE, 0);
}


/**
 * nautilus_window_about_cb:
 * 
 * Display about box, creating it first if necessary. Callback used when 
 * user selects "About Nautilus".
 * @widget: ignored
 * @window: ignored
 **/
static void
nautilus_window_about_cb (GtkWidget *widget,
                          NautilusWindow *window)
{
  static GtkWidget *aboot = NULL;

  if (aboot == NULL)
  {
    const char *authors[] = {
      "Darin Adler",
      "Andy Hertzfeld",
      "Elliot Lee",
      "Ettore Perazzoli",
      "Maciej Stachowiak",
      "John Sullivan",
      NULL
    };

    aboot = gnome_about_new(_("Nautilus"),
                            VERSION,
                            "Copyright (C) 1999, 2000",
                            authors,
                            _("The Cool Shell Program"),
                            "nautilus/nautilus3.jpg");

    gnome_dialog_close_hides (GNOME_DIALOG (aboot), TRUE);
  }

  nautilus_gtk_window_present (GTK_WINDOW (aboot));
}

void
nautilus_window_allow_back (NautilusWindow *window, gboolean allow)
{
   gtk_widget_set_sensitive(window->back_button, allow); 
   gtk_widget_set_sensitive(window->back_menu_item, allow); 
}

void
nautilus_window_allow_forward (NautilusWindow *window, gboolean allow)
{
   gtk_widget_set_sensitive(window->forward_button, allow); 
   gtk_widget_set_sensitive(window->forward_menu_item, allow); 
}

void
nautilus_window_allow_up (NautilusWindow *window, gboolean allow)
{
   gtk_widget_set_sensitive(window->up_button, allow); 
   gtk_widget_set_sensitive(window->up_menu_item, allow); 
}

void
nautilus_window_allow_reload (NautilusWindow *window, gboolean allow)
{
   gtk_widget_set_sensitive(window->reload_button, allow); 
}

void
nautilus_window_allow_stop (NautilusWindow *window, gboolean allow)
{
  gtk_widget_set_sensitive(window->stop_button, allow); 
}

void
nautilus_add_to_history_list (const char *uri)
{
	/* Note that the history is shared amongst all windows so
	 * this is not a NautilusWindow function. Perhaps it belongs
	 * in its own file.
	 */
	NautilusBookmark *bookmark;
	GSList *found_link;

	g_return_if_fail (nautilus_strlen(uri) > 0);

	bookmark = nautilus_bookmark_new (uri);

	found_link = g_slist_find_custom (history_list, 
					  bookmark,
					  nautilus_bookmark_compare_with);
	
	/* Remove any older entry for this same item. There can be at most 1. */
	if (found_link != NULL)
	{
		gtk_object_unref (found_link->data);
		history_list = g_slist_remove_link (history_list, found_link);
	}

	/* New item goes first. */
	history_list = g_slist_prepend(history_list, bookmark);

	/* Tell world that history list has changed. At least all the
	 * NautilusWindows (not just this one) are listening.
	 */
	gtk_signal_emit_by_name (GTK_OBJECT (nautilus_signaller_get_current ()),
			 	 "history_list_changed");
}




static void
nautilus_window_request_location_change_cb (NautilusView *view, 
                                            Nautilus_NavigationRequestInfo *info, 
                                            NautilusWindow *window)
{
  nautilus_window_request_location_change(window, info, view);
}


static void
nautilus_window_request_selection_change_cb (NautilusView *view, 
                                             Nautilus_SelectionRequestInfo *info, 
                                             NautilusWindow *window)
{
  nautilus_window_request_selection_change(window, info, view);  
}

static void
nautilus_window_request_status_change_cb (NautilusView *view,
                                          Nautilus_StatusRequestInfo *info,
                                          NautilusWindow *window)
{
  nautilus_window_request_status_change(window, info, view);  
}

static void
nautilus_window_request_progress_change_cb (NautilusView *view,
                                            Nautilus_ProgressRequestInfo *info,
                                            NautilusWindow *window)
{
  nautilus_window_request_progress_change(window, info, view);  
}

void
nautilus_window_connect_view(NautilusWindow *window, NautilusView *view)
{
  GtkObject *viewo;

  viewo = GTK_OBJECT(view);
  gtk_signal_connect(viewo,
                     "request_location_change", 
                     nautilus_window_request_location_change_cb, 
                     window);
  gtk_signal_connect(viewo, 
                     "request_selection_change", 
                     nautilus_window_request_selection_change_cb, 
                     window);
  gtk_signal_connect(viewo, 
                     "request_status_change", 
                     nautilus_window_request_status_change_cb, 
                     window);
  gtk_signal_connect(viewo, 
                     "request_progress_change", 
                     nautilus_window_request_progress_change_cb, 
                     window);
  gtk_signal_connect(viewo,
                     "destroy",
                     nautilus_window_view_destroyed,
                     window);
}

void
nautilus_window_display_error(NautilusWindow *window, const char *error_msg)
{
  GtkWidget *dialog;

  dialog = gnome_message_box_new(error_msg, GNOME_MESSAGE_BOX_ERROR, _("Close"), NULL);
  gnome_dialog_set_close(GNOME_DIALOG(dialog), TRUE);

  gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);

  gtk_widget_show(dialog);
}

static void
nautilus_window_real_set_content_view (NautilusWindow *window, NautilusView *new_view)
{
  g_return_if_fail (NAUTILUS_IS_WINDOW (window));
  g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW (new_view));

  if (new_view == window->content_view)
    {
      return;
    }

  if (window->content_view != NULL)
    {
      gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));      
    }

  if (new_view != NULL)
    {
      gtk_widget_show (GTK_WIDGET (new_view));
#ifdef CONTENTS_AS_HBOX
      gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET (new_view), TRUE, TRUE, 0);
#else
      gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET (new_view), TRUE, FALSE);
#endif      
    }
      
  gtk_widget_queue_resize(window->content_hbox);
  window->content_view = new_view;
}