r13: Changed scanning system so that it doesn't crash if you close a directory
[rox-filer.git] / ROX-Filer / src / menu.c
blob235112caf6673a56f953ad38341e2aed066f43a1
1 /* vi: set cindent:
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
6 */
8 /* menu.c - code for handling the popup menu */
10 #include <gtk/gtk.h>
12 #include "filer.h"
13 #include "support.h"
15 #define C_ "<control>"
17 GtkAccelGroup *filer_keys;
20 /* Static prototypes */
21 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data);
22 static void open_parent(gpointer data, guint action, GtkWidget *widget);
24 static GtkWidget *filer_menu; /* The popup filer menu */
25 static FilerWindow *menu_owner;
27 static GtkItemFactoryEntry filer_menu_def[] = {
28 {"/_Display", NULL, NULL, 0, "<Branch>"},
29 {"/Display/_Large Icons", NULL, NULL, 0, "<RadioItem>"},
30 {"/Display/_Small Icons", NULL, NULL, 0, "/Display/Large Icons"},
31 {"/Display/_Full Info", NULL, NULL, 0, "/Display/Large Icons"},
32 {"/Display/Separator", NULL, NULL, 0, "<Separator>"},
33 {"/Display/Sort by _Name", NULL, NULL, 0, "<RadioItem>"},
34 {"/Display/Sort by _Type", NULL, NULL, 0, "/Display/Sort by Name"},
35 {"/Display/Sort by _Date", NULL, NULL, 0, "/Display/Sort by Name"},
36 {"/Display/Sort by Si_ze", NULL, NULL, 0, "/Display/Sort by Name"},
37 {"/Display/Separator", NULL, NULL, 0, "<Separator>"},
38 {"/Display/Show _Hidden", C_"H", NULL, 0, "<ToggleItem>"},
39 {"/Display/Refresh", C_"L", NULL, 0, NULL},
40 {"/File", NULL, NULL, 0, "<Branch>"},
41 {"/File/_Copy", NULL, NULL, 0, NULL},
42 {"/File/_Rename", NULL, NULL, 0, NULL},
43 {"/File/_Help", "F1", NULL, 0, NULL},
44 {"/File/_Info", NULL, NULL, 0, NULL},
45 {"/File/Separator", NULL, NULL, 0, "<Separator>"},
46 {"/File/_Delete", C_"X", NULL, 0, NULL},
47 {"/File/Disk _Usage", C_"U", NULL, 0, NULL},
48 {"/File/_Permissions", NULL, NULL, 0, NULL},
49 {"/File/_Stamp", NULL, NULL, 0, NULL},
50 {"/File/_Find", NULL, NULL, 0, NULL},
51 {"/_Select All", C_"A", NULL, 0, NULL},
52 {"/_Clear Selection", C_"Z", NULL, 0, NULL},
53 {"/_Options", NULL, NULL, 0, "<Branch>"},
54 {"/Options/_Confirm", NULL, NULL, 0, "<ToggleItem>"},
55 {"/Options/_Verbose", NULL, NULL, 0, "<ToggleItem>"},
56 {"/Options/_Force", NULL, NULL, 0, "<ToggleItem>"},
57 {"/Options/_Newer", NULL, NULL, 0, "<ToggleItem>"},
58 {"/_New directory", NULL, NULL, 0, NULL},
59 {"/_Open parent", NULL, open_parent, 0, NULL},
63 void menu_init()
65 GtkItemFactory *item_factory;
67 filer_keys = gtk_accel_group_new();
68 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<popup>", filer_keys);
70 gtk_item_factory_create_items(item_factory,
71 sizeof(filer_menu_def) / sizeof(*filer_menu_def),
72 filer_menu_def,
73 NULL);
75 filer_menu = gtk_item_factory_get_widget(item_factory, "<popup>");
78 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data)
80 GtkRequisition requisition;
82 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
84 *x -= requisition.width >> 2;
85 *y -= requisition.height >> 2;
88 void show_filer_menu(FilerWindow *filer_window, GdkEventButton *event)
90 menu_owner = filer_window;
92 gtk_menu_popup(GTK_MENU(filer_menu), NULL, NULL, position_menu,
93 NULL, event->button, event->time);
96 static void open_parent(gpointer data, guint action, GtkWidget *widget)
98 filer_opendir(make_path(menu_owner->path, "/..")->str);