r1322: Converted MaskedPixmap to GObject.
[rox-filer.git] / ROX-Filer / src / menu.c
blobaca28c287d41a377bab1c12cd5780ae12d868143
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* menu.c - code for handling the popup menu */
24 #include "config.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <sys/wait.h>
29 #include <sys/param.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #include <string.h>
33 #include <dirent.h>
35 #include <gtk/gtk.h>
37 #include "global.h"
39 #include "menu.h"
40 #include "run.h"
41 #include "action.h"
42 #include "filer.h"
43 #include "pixmaps.h"
44 #include "type.h"
45 #include "support.h"
46 #include "gui_support.h"
47 #include "options.h"
48 #include "choices.h"
49 #include "gtksavebox.h"
50 #include "mount.h"
51 #include "minibuffer.h"
52 #include "i18n.h"
53 #include "main.h"
54 #include "pinboard.h"
55 #include "dir.h"
56 #include "diritem.h"
57 #include "appmenu.h"
58 #include "usericons.h"
59 #include "infobox.h"
60 #include "collection.h"
61 #include "display.h"
63 #define C_ "<control>"
65 typedef enum {
66 FILE_COPY_ITEM,
67 FILE_RENAME_ITEM,
68 FILE_LINK_ITEM,
69 FILE_OPEN_FILE,
70 FILE_HELP,
71 FILE_SHOW_FILE_INFO,
72 FILE_RUN_ACTION,
73 FILE_SET_ICON,
74 FILE_SEND_TO,
75 FILE_DELETE,
76 FILE_USAGE,
77 FILE_CHMOD_ITEMS,
78 FILE_FIND,
79 FILE_OPEN_VFS_AVFS,
80 } FileOp;
82 typedef enum menu_icon_style {
83 MIS_NONE, MIS_SMALL, MIS_LARGE, MIS_HUGE,
84 MIS_CURRENT, /* As per current filer window */
85 MIS_DEFAULT
86 } MenuIconStyle;
88 typedef void (*ActionFn)(GList *paths,
89 const char *dest_dir, const char *leaf, int quiet);
90 typedef void MenuCallback(GtkWidget *widget, gpointer data);
92 typedef gboolean (*SaveCb)(GObject *savebox,
93 const gchar *current, const gchar *new);
95 GtkAccelGroup *filer_keys;
96 GtkAccelGroup *pinboard_keys;
98 GtkWidget *popup_menu = NULL; /* Currently open menu */
100 static gint updating_menu = 0; /* Non-zero => ignore activations */
101 static GList *send_to_paths = NULL;
103 static Option o_menu_iconsize, o_menu_xterm;
105 /* Static prototypes */
107 static void save_menus(void);
108 static void menu_closed(GtkWidget *widget);
109 static void items_sensitive(gboolean state);
110 static void savebox_show(const gchar *action, const gchar *path,
111 MaskedPixmap *image, SaveCb callback);
112 static gint save_to_file(GObject *savebox,
113 const gchar *pathname, gpointer data);
114 static gboolean action_with_leaf(ActionFn action,
115 const gchar *current, const gchar *new);
116 static gboolean link_cb(GObject *savebox,
117 const gchar *initial, const gchar *path);
118 static void select_nth_item(GtkMenuShell *shell, int n);
119 static void new_file_type(gchar *templ);
120 static void do_send_to(gchar *templ);
121 static void show_send_to_menu(GList *paths, GdkEvent *event);
122 static GList *set_keys_button(Option *option, xmlNode *node, guchar *label);
124 /* Note that for most of these callbacks none of the arguments are used. */
126 /* (action used in these three - DetailsType) */
127 static void huge_with(gpointer data, guint action, GtkWidget *widget);
128 static void large_with(gpointer data, guint action, GtkWidget *widget);
129 static void small_with(gpointer data, guint action, GtkWidget *widget);
131 static void sort_name(gpointer data, guint action, GtkWidget *widget);
132 static void sort_type(gpointer data, guint action, GtkWidget *widget);
133 static void sort_size(gpointer data, guint action, GtkWidget *widget);
134 static void sort_date(gpointer data, guint action, GtkWidget *widget);
136 static void hidden(gpointer data, guint action, GtkWidget *widget);
137 static void show_thumbs(gpointer data, guint action, GtkWidget *widget);
138 static void refresh(gpointer data, guint action, GtkWidget *widget);
140 static void file_op(gpointer data, FileOp action, GtkWidget *widget);
142 static void select_all(gpointer data, guint action, GtkWidget *widget);
143 static void clear_selection(gpointer data, guint action, GtkWidget *widget);
144 static void invert_selection(gpointer data, guint action, GtkWidget *widget);
145 static void new_directory(gpointer data, guint action, GtkWidget *widget);
146 static void new_file(gpointer data, guint action, GtkWidget *widget);
147 static void xterm_here(gpointer data, guint action, GtkWidget *widget);
149 static void open_parent_same(gpointer data, guint action, GtkWidget *widget);
150 static void open_parent(gpointer data, guint action, GtkWidget *widget);
151 static void home_directory(gpointer data, guint action, GtkWidget *widget);
152 static void new_window(gpointer data, guint action, GtkWidget *widget);
153 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
154 static void close_window(gpointer data, guint action, GtkWidget *widget);
156 /* (action used in this - MiniType) */
157 static void mini_buffer(gpointer data, guint action, GtkWidget *widget);
158 static void resize(gpointer data, guint action, GtkWidget *widget);
160 #define MENUS_NAME "menus2"
161 static void keys_changed(gpointer data);
163 static GtkWidget *filer_menu; /* The popup filer menu */
164 static GtkWidget *filer_file_item; /* The File '' label */
165 static GtkWidget *filer_file_menu; /* The File '' menu */
166 static GtkWidget *file_shift_item; /* Shift Open label */
167 GtkWidget *display_large_menu; /* Display->Large With... */
168 GtkWidget *display_small_menu; /* Display->Small With... */
169 static GtkWidget *filer_hidden_menu; /* The Show Hidden item */
170 static GtkWidget *filer_thumb_menu; /* The Show Thumbs item */
171 static GtkWidget *filer_new_window; /* The New Window item */
172 static GtkWidget *filer_new_menu; /* The New submenu */
174 #undef N_
175 #define N_(x) x
177 static GtkItemFactoryEntry filer_menu_def[] = {
178 {N_("Display"), NULL, NULL, 0, "<Branch>"},
179 {">" N_("Huge Icons"), NULL, huge_with, DETAILS_NONE, NULL},
180 {">" N_("Large Icons"), NULL, large_with, DETAILS_NONE, NULL},
181 {">" N_("Small Icons"), NULL, small_with, DETAILS_NONE, NULL},
182 {">" N_("Huge, With..."), NULL, NULL, 0, "<Branch>"},
183 {">>" N_("Summary"), NULL, huge_with, DETAILS_SUMMARY, NULL},
184 {">>" N_("Sizes"), NULL, huge_with, DETAILS_SIZE, NULL},
185 {">>" N_("Permissions"), NULL, huge_with, DETAILS_PERMISSIONS, NULL},
186 {">>" N_("Type"), NULL, huge_with, DETAILS_TYPE, NULL},
187 {">>" N_("Times"), NULL, huge_with, DETAILS_TIMES, NULL},
188 {">" N_("Large, With..."), NULL, NULL, 0, "<Branch>"},
189 {">>" N_("Summary"), NULL, large_with, DETAILS_SUMMARY, NULL},
190 {">>" N_("Sizes"), NULL, large_with, DETAILS_SIZE, NULL},
191 {">>" N_("Permissions"), NULL, large_with, DETAILS_PERMISSIONS, NULL},
192 {">>" N_("Type"), NULL, large_with, DETAILS_TYPE, NULL},
193 {">>" N_("Times"), NULL, large_with, DETAILS_TIMES, NULL},
194 {">" N_("Small, With..."), NULL, NULL, 0, "<Branch>"},
195 {">>" N_("Summary"), NULL, small_with, DETAILS_SUMMARY, NULL},
196 {">>" N_("Sizes"), NULL, small_with, DETAILS_SIZE, NULL},
197 {">>" N_("Permissions"), NULL, small_with, DETAILS_PERMISSIONS, NULL},
198 {">>" N_("Type"), NULL, small_with, DETAILS_TYPE, NULL},
199 {">>" N_("Times"), NULL, small_with, DETAILS_TIMES, NULL},
200 {">", NULL, NULL, 0, "<Separator>"},
201 {">" N_("Sort by Name"), NULL, sort_name, 0, NULL},
202 {">" N_("Sort by Type"), NULL, sort_type, 0, NULL},
203 {">" N_("Sort by Date"), NULL, sort_date, 0, NULL},
204 {">" N_("Sort by Size"), NULL, sort_size, 0, NULL},
205 {">", NULL, NULL, 0, "<Separator>"},
206 {">" N_("Show Hidden"), NULL, hidden, 0, "<ToggleItem>"},
207 {">" N_("Show Thumbnails"), NULL, show_thumbs, 0, "<ToggleItem>"},
208 {">" N_("Refresh"), NULL, refresh, 0, NULL},
209 {N_("File"), NULL, NULL, 0, "<Branch>"},
210 {">" N_("Copy..."), NULL, file_op, FILE_COPY_ITEM, NULL},
211 {">" N_("Rename..."), NULL, file_op, FILE_RENAME_ITEM, NULL},
212 {">" N_("Link..."), NULL, file_op, FILE_LINK_ITEM, NULL},
213 {">" N_("Shift Open"), NULL, file_op, FILE_OPEN_FILE, NULL},
214 {">" N_("Help"), NULL, file_op, FILE_HELP, NULL},
215 {">" N_("Info"), NULL, file_op, FILE_SHOW_FILE_INFO, NULL},
216 {">" N_("Set Run Action..."), NULL, file_op, FILE_RUN_ACTION, NULL},
217 {">" N_("Set Icon..."), NULL, file_op, FILE_SET_ICON, NULL},
218 {">" N_("Open AVFS"), NULL, file_op, FILE_OPEN_VFS_AVFS, NULL},
219 {">", NULL, NULL, 0, "<Separator>"},
220 {">" N_("Send To..."), NULL, file_op, FILE_SEND_TO, NULL},
221 {">" N_("Delete"), NULL, file_op, FILE_DELETE, NULL},
222 {">" N_("Disk Usage"), NULL, file_op, FILE_USAGE, NULL},
223 {">" N_("Permissions"), NULL, file_op, FILE_CHMOD_ITEMS, NULL},
224 {">" N_("Find"), NULL, file_op, FILE_FIND, NULL},
225 {N_("Select"), NULL, NULL, 0, "<Branch>"},
226 {">" N_("Select All"), NULL, select_all, 0, NULL},
227 {">" N_("Clear Selection"), NULL, clear_selection, 0, NULL},
228 {">" N_("Invert Selection"), NULL, invert_selection, 0, NULL},
229 {">" N_("Select If..."), NULL, mini_buffer, MINI_SELECT_IF, NULL},
230 {N_("Options..."), NULL, menu_show_options, 0, NULL},
231 {N_("New"), NULL, NULL, 0, "<Branch>"},
232 {">" N_("Directory"), NULL, new_directory, 0, NULL},
233 {">" N_("Blank file"), NULL, new_file, 0, NULL},
234 {N_("Xterm Here"), NULL, xterm_here, 0, NULL},
235 {N_("Window"), NULL, NULL, 0, "<Branch>"},
236 {">" N_("Parent, New Window"), NULL, open_parent, 0, NULL},
237 {">" N_("Parent, Same Window"), NULL, open_parent_same, 0, NULL},
238 {">" N_("New Window"), NULL, new_window, 0, NULL},
239 {">" N_("Home Directory"), NULL, home_directory, 0, NULL},
240 {">" N_("Resize Window"), NULL, resize, 0, NULL},
241 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
243 {">" N_("Close Window"), NULL, close_window, 0, NULL},
244 {">", NULL, NULL, 0, "<Separator>"},
245 {">" N_("Enter Path..."), "slash", mini_buffer, MINI_PATH, NULL},
246 {">" N_("Shell Command..."), NULL, mini_buffer, MINI_SHELL, NULL},
247 {">", NULL, NULL, 0, "<Separator>"},
248 {">" N_("Show ROX-Filer Help"), "F1", menu_rox_help, 0, NULL},
252 #define GET_MENU_ITEM(var, menu) \
253 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
255 #define GET_SMENU_ITEM(var, menu, sub) \
256 do { \
257 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
258 var = gtk_item_factory_get_widget(item_factory, tmp); \
259 g_free(tmp); \
260 } while (0)
262 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
263 do { \
264 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
265 var = gtk_item_factory_get_widget(item_factory, tmp); \
266 g_free(tmp); \
267 } while (0)
269 void menu_init(void)
271 char *menurc;
272 GList *items;
273 guchar *tmp;
274 GtkWidget *item;
275 GtkItemFactory *item_factory;
277 filer_keys = gtk_accel_group_new();
278 item_factory = menu_create(filer_menu_def,
279 sizeof(filer_menu_def) / sizeof(*filer_menu_def),
280 "<filer>", filer_keys);
282 GET_MENU_ITEM(filer_menu, "filer");
283 GET_SMENU_ITEM(filer_file_menu, "filer", "File");
284 GET_SSMENU_ITEM(filer_hidden_menu, "filer", "Display", "Show Hidden");
285 GET_SSMENU_ITEM(filer_thumb_menu, "filer", "Display",
286 "Show Thumbnails");
288 GET_SSMENU_ITEM(display_large_menu, "filer",
289 "Display", "Large, With...");
290 GET_SSMENU_ITEM(display_small_menu, "filer",
291 "Display", "Small, With...");
293 GET_SMENU_ITEM(filer_new_menu, "filer", "New");
295 /* File '' label... */
296 items = gtk_container_get_children(GTK_CONTAINER(filer_menu));
297 filer_file_item = GTK_BIN(g_list_nth(items, 1)->data)->child;
298 g_list_free(items);
300 /* Shift Open... label */
301 items = gtk_container_get_children(GTK_CONTAINER(filer_file_menu));
302 file_shift_item = GTK_BIN(g_list_nth(items, 3)->data)->child;
303 g_list_free(items);
305 GET_SSMENU_ITEM(item, "filer", "Window", "New Window");
306 filer_new_window = GTK_BIN(item)->child;
308 menurc = choices_find_path_load(MENUS_NAME, PROJECT);
309 if (menurc)
311 gtk_accel_map_load(menurc);
312 g_free(menurc);
315 g_signal_connect(filer_menu, "unmap_event",
316 G_CALLBACK(menu_closed), NULL);
317 g_signal_connect(filer_file_menu, "unmap_event",
318 G_CALLBACK(menu_closed), NULL);
320 option_add_string(&o_menu_xterm, "menu_xterm", "xterm");
321 option_add_int(&o_menu_iconsize, "menu_iconsize", MIS_SMALL);
322 option_add_saver(save_menus);
324 g_signal_connect_object(G_OBJECT(filer_keys), "accel_changed",
325 (GCallback) keys_changed, NULL, 0);
327 option_register_widget("menu-set-keys", set_keys_button);
330 /* Name is in the form "<panel>" */
331 GtkItemFactory *menu_create(GtkItemFactoryEntry *def, int n_entries,
332 const gchar *name, GtkAccelGroup *keys)
334 GtkItemFactory *item_factory;
335 GtkItemFactoryEntry *translated;
337 if (!keys)
339 keys = gtk_accel_group_new();
340 gtk_accel_group_lock(keys);
343 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, name, keys);
345 translated = translate_entries(def, n_entries);
346 gtk_item_factory_create_items(item_factory, n_entries,
347 translated, NULL);
348 free_translated_entries(translated, n_entries);
350 return item_factory;
353 /* Prevent the user from setting a short-cut on this item */
354 void menuitem_no_shortcuts(GtkWidget *item)
356 /* XXX */
357 #if 0
358 GtkMenuItem *menuitem = GTK_MENU_ITEM(item);
360 _gtk_widget_set_accel_path(item, NULL, NULL);
361 g_free(menuitem->accel_path);
362 menuitem->accel_path = NULL;
363 #endif
366 static void items_sensitive(gboolean state)
368 int n = 9;
369 GList *items, *item;
371 items = gtk_container_get_children(GTK_CONTAINER(filer_file_menu));
372 item = items;
374 while (item && n--)
376 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
377 item = item->next;
379 g_list_free(items);
382 /* 'data' is an array of three ints:
383 * [ pointer_x, pointer_y, item_under_pointer ]
385 void position_menu(GtkMenu *menu, gint *x, gint *y,
386 gboolean *push_in, gpointer data)
388 int *pos = (int *) data;
389 GtkRequisition requisition;
390 GList *items, *next;
391 int y_shift = 0;
392 int item = pos[2];
394 next = items = gtk_container_get_children(GTK_CONTAINER(menu));
396 while (item >= 0 && next)
398 int h = ((GtkWidget *) next->data)->requisition.height;
400 if (item > 0)
401 y_shift += h;
402 else
403 y_shift += h / 2;
405 next = next->next;
406 item--;
409 g_list_free(items);
411 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
413 *x = pos[0] - (requisition.width * 7 / 8);
414 *y = pos[1] - y_shift;
416 *x = CLAMP(*x, 0, screen_width - requisition.width);
417 *y = CLAMP(*y, 0, screen_height - requisition.height);
419 *push_in = FALSE;
422 #if 0
423 /* Used when you menu-click on the Large or Small toolbar tools */
424 void show_style_menu(FilerWindow *filer_window,
425 GdkEventButton *event,
426 GtkWidget *menu)
428 int pos[3];
430 pos[0] = event->x_root;
431 pos[1] = event->y_root;
432 pos[2] = 0;
434 window_with_focus = filer_window;
436 popup_menu = menu;
438 gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, position_menu,
439 (gpointer) pos, event->button, event->time);
441 #endif
443 static GList *menu_from_dir(GtkWidget *menu, const gchar *dname,
444 MenuIconStyle style, CallbackFn func,
445 gboolean separator, gboolean strip_ext)
447 GList *widgets = NULL;
448 DirItem *ditem;
449 DIR *dir;
450 struct dirent *ent;
451 GtkWidget *item;
453 dir = opendir(dname);
454 if (!dir)
455 goto out;
457 if (separator)
459 item = gtk_menu_item_new();
460 widgets = g_list_append(widgets, item);
461 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
464 while ((ent = readdir(dir)))
466 char *dot, *leaf;
467 GtkWidget *hbox;
468 GtkWidget *img;
469 GtkWidget *label;
470 gchar *fname;
471 GdkPixmap *icon;
472 GdkBitmap *mask;
474 /* Ignore hidden files */
475 if (ent->d_name[0] == '.')
476 continue;
478 /* Strip off extension, if any */
479 dot = strchr(ent->d_name, '.');
480 if (strip_ext && dot)
481 leaf = g_strndup(ent->d_name, dot - ent->d_name);
482 else
483 leaf = g_strdup(ent->d_name);
485 fname = g_strconcat(dname, "/", ent->d_name, NULL);
486 ditem = diritem_new(NULL);
487 diritem_restat(fname, ditem);
489 if (ditem->image && style != MIS_NONE)
491 switch (style) {
492 case MIS_HUGE:
493 if (!ditem->image->huge_pixmap)
494 pixmap_make_huge(ditem->image);
495 icon = ditem->image->huge_pixmap;
496 mask = ditem->image->huge_mask;
497 break;
498 case MIS_LARGE:
499 icon = ditem->image->pixmap;
500 mask = ditem->image->mask;
501 break;
503 case MIS_SMALL:
504 default:
505 if (!ditem->image->sm_pixmap)
506 pixmap_make_small(ditem->image);
507 icon = ditem->image->sm_pixmap;
508 mask = ditem->image->sm_mask;
509 break;
512 item = gtk_menu_item_new();
513 /* TODO: Find a way to allow short-cuts */
514 menuitem_no_shortcuts(item);
516 hbox = gtk_hbox_new(FALSE, 2);
517 gtk_container_add(GTK_CONTAINER(item), hbox);
519 img = gtk_image_new_from_pixmap(icon, mask);
520 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 2);
522 label = gtk_label_new(leaf);
523 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
524 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 2);
526 diritem_free(ditem);
528 else
529 item = gtk_menu_item_new_with_label(leaf);
531 g_free(leaf);
533 g_signal_connect_swapped(item, "activate",
534 G_CALLBACK(func), fname);
535 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
536 g_signal_connect_swapped(item, "destroy",
537 G_CALLBACK(g_free), fname);
539 widgets = g_list_append(widgets, item);
542 closedir(dir);
543 out:
545 return widgets;
548 /* Scan the templates dir and create entries for the New menu */
549 static void update_new_files_menu(MenuIconStyle style)
551 static GList *widgets = NULL;
553 gchar *templ_dname = NULL;
555 if (widgets)
557 GList *next;
559 for (next = widgets; next; next = next->next)
560 gtk_widget_destroy((GtkWidget *) next->data);
562 g_list_free(widgets);
563 widgets = NULL;
566 templ_dname = choices_find_path_load("Templates", "");
567 if (templ_dname)
569 widgets = menu_from_dir(filer_new_menu, templ_dname, style,
570 (CallbackFn) new_file_type, TRUE, TRUE);
571 g_free(templ_dname);
573 gtk_widget_show_all(filer_new_menu);
576 /* 'item' is the number of the item to appear under the pointer. */
577 void show_popup_menu(GtkWidget *menu, GdkEvent *event, int item)
579 int pos[3];
580 int button = 0;
581 guint32 time = 0;
583 if (event && (event->type == GDK_BUTTON_PRESS ||
584 event->type == GDK_BUTTON_RELEASE))
586 GdkEventButton *bev = (GdkEventButton *) event;
588 pos[0] = bev->x_root;
589 pos[1] = bev->y_root;
590 button = bev->button;
591 time = bev->time;
593 else if (event && event->type == GDK_KEY_PRESS)
595 GdkEventKey *kev = (GdkEventKey *) event;
597 get_pointer_xy(pos, pos + 1);
598 time = kev->time;
600 else
601 get_pointer_xy(pos, pos + 1);
603 pos[2] = item;
605 gtk_widget_show_all(menu);
606 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
607 position_menu, (gpointer) pos, button, time);
608 select_nth_item(GTK_MENU_SHELL(menu), item);
611 static MenuIconStyle get_menu_icon_style(void)
613 MenuIconStyle mis;
614 int display;
616 mis = o_menu_iconsize.int_value;
618 switch (mis)
620 case MIS_NONE: case MIS_SMALL: case MIS_LARGE: case MIS_HUGE:
621 return mis;
622 default:
623 break;
626 if (mis == MIS_CURRENT && window_with_focus)
628 switch (window_with_focus->display_style)
630 case HUGE_ICONS:
631 return MIS_HUGE;
632 case LARGE_ICONS:
633 return MIS_LARGE;
634 case SMALL_ICONS:
635 return MIS_SMALL;
636 default:
637 break;
641 display = o_display_size.int_value;
642 switch (display)
644 case HUGE_ICONS:
645 return MIS_HUGE;
646 case LARGE_ICONS:
647 return MIS_LARGE;
648 case SMALL_ICONS:
649 return MIS_SMALL;
650 default:
651 break;
654 return MIS_SMALL;
657 void show_filer_menu(FilerWindow *filer_window, GdkEvent *event, int item)
659 DirItem *file_item = NULL;
660 GdkModifierType state = 0;
662 updating_menu++;
664 /* Remove previous AppMenu, if any */
665 appmenu_remove();
667 window_with_focus = filer_window;
669 if (event->type == GDK_BUTTON_PRESS)
670 state = ((GdkEventButton *) event)->state;
671 else if (event->type == GDK_KEY_PRESS)
672 state = ((GdkEventKey *) event)->state;
674 if (filer_window->collection->number_selected == 0 && item >= 0)
676 filer_window->temp_item_selected = TRUE;
677 collection_select_item(filer_window->collection, item);
679 else
681 filer_window->temp_item_selected = FALSE;
684 /* Short-cut to the Send To menu */
685 if (state & GDK_SHIFT_MASK)
687 GList *paths;
689 updating_menu--;
691 if (filer_window->collection->number_selected == 0)
693 report_error(
694 _("You should Shift+Menu click over a file to "
695 "send it somewhere"));
696 return;
699 paths = filer_selected_items(filer_window);
701 show_send_to_menu(paths, event); /* (paths eaten) */
703 return;
707 GtkWidget *file_label, *file_menu;
708 Collection *collection = filer_window->collection;
709 GString *buffer;
710 DirItem *item;
712 file_label = filer_file_item;
713 file_menu = filer_file_menu;
714 gtk_check_menu_item_set_active(
715 GTK_CHECK_MENU_ITEM(filer_thumb_menu),
716 filer_window->show_thumbs);
717 gtk_check_menu_item_set_active(
718 GTK_CHECK_MENU_ITEM(filer_hidden_menu),
719 filer_window->show_hidden);
720 buffer = g_string_new(NULL);
722 switch (collection->number_selected)
724 case 0:
725 g_string_assign(buffer, _("Next Click"));
726 items_sensitive(TRUE);
727 break;
728 case 1:
729 item = selected_item(filer_window->collection);
730 if (!item->image)
731 dir_update_item(filer_window->directory,
732 item->leafname);
733 items_sensitive(TRUE);
734 file_item = selected_item(
735 filer_window->collection);
736 g_string_sprintf(buffer, "%s '%s'",
737 basetype_name(file_item),
738 file_item->leafname);
739 if (!can_set_run_action(file_item))
740 menu_set_items_shaded(filer_file_menu,
741 TRUE, 6, 1);
742 break;
743 default:
744 items_sensitive(FALSE);
745 g_string_sprintf(buffer, _("%d items"),
746 collection->number_selected);
747 break;
749 gtk_label_set_text(GTK_LABEL(file_label), buffer->str);
750 g_string_free(buffer, TRUE);
752 menu_show_shift_action(file_shift_item, file_item,
753 collection->number_selected == 0);
754 if (file_item)
755 appmenu_add(make_path(filer_window->path,
756 file_item->leafname)->str,
757 file_item, filer_file_menu);
760 update_new_files_menu(get_menu_icon_style());
762 gtk_widget_set_sensitive(filer_new_window,
763 !o_unique_filer_windows.int_value);
765 popup_menu = (state & GDK_CONTROL_MASK)
766 ? filer_file_menu
767 : filer_menu;
769 updating_menu--;
771 show_popup_menu(popup_menu, event,
772 popup_menu == filer_file_menu ? 5 : 1);
775 static void menu_closed(GtkWidget *widget)
777 if (window_with_focus == NULL || widget != popup_menu)
778 return; /* Close panel item chosen? */
780 popup_menu = NULL;
782 if (window_with_focus->temp_item_selected)
784 collection_clear_selection(window_with_focus->collection);
785 window_with_focus->temp_item_selected = FALSE;
789 void target_callback(FilerWindow *filer_window,
790 gint item,
791 gpointer action)
793 Collection *collection = filer_window->collection;
795 g_return_if_fail(window_with_focus != NULL);
796 g_return_if_fail(window_with_focus == filer_window);
798 /* Don't grab the primary selection */
799 filer_window->temp_item_selected = TRUE;
801 collection_wink_item(collection, item);
802 collection_clear_except(collection, item);
803 file_op(NULL, GPOINTER_TO_INT(action), GTK_WIDGET(collection));
805 if (item < collection->number_of_items)
806 collection_unselect_item(collection, item);
807 filer_window->temp_item_selected = FALSE;
810 /* Set the text of the 'Shift Open...' menu item.
811 * If icon is NULL, reset the text and also shade it, unless 'next'.
813 void menu_show_shift_action(GtkWidget *menu_item, DirItem *item, gboolean next)
815 guchar *shift_action = NULL;
817 if (item)
819 if (item->flags & ITEM_FLAG_MOUNT_POINT)
821 if (item->flags & ITEM_FLAG_MOUNTED)
822 shift_action = N_("Unmount");
823 else
824 shift_action = N_("Mount");
826 else if (item->flags & ITEM_FLAG_SYMLINK)
827 shift_action = N_("Show Target");
828 else if (item->base_type == TYPE_DIRECTORY)
829 shift_action = N_("Look Inside");
830 else if (item->base_type == TYPE_FILE)
831 shift_action = N_("Open As Text");
833 gtk_label_set_text(GTK_LABEL(menu_item),
834 shift_action ? _(shift_action)
835 : _("Shift Open"));
836 gtk_widget_set_sensitive(menu_item, shift_action != NULL || next);
839 /* Actions */
841 static void huge_with(gpointer data, guint action, GtkWidget *widget)
843 display_set_layout(window_with_focus, HUGE_ICONS, action);
846 static void large_with(gpointer data, guint action, GtkWidget *widget)
848 display_set_layout(window_with_focus, LARGE_ICONS, action);
851 static void small_with(gpointer data, guint action, GtkWidget *widget)
853 display_set_layout(window_with_focus, SMALL_ICONS, action);
856 static void sort_name(gpointer data, guint action, GtkWidget *widget)
858 g_return_if_fail(window_with_focus != NULL);
860 display_set_sort_fn(window_with_focus, sort_by_name);
863 static void sort_type(gpointer data, guint action, GtkWidget *widget)
865 g_return_if_fail(window_with_focus != NULL);
867 display_set_sort_fn(window_with_focus, sort_by_type);
870 static void sort_date(gpointer data, guint action, GtkWidget *widget)
872 g_return_if_fail(window_with_focus != NULL);
874 display_set_sort_fn(window_with_focus, sort_by_date);
877 static void sort_size(gpointer data, guint action, GtkWidget *widget)
879 g_return_if_fail(window_with_focus != NULL);
881 display_set_sort_fn(window_with_focus, sort_by_size);
884 static void hidden(gpointer data, guint action, GtkWidget *widget)
886 if (updating_menu)
887 return;
889 g_return_if_fail(window_with_focus != NULL);
891 display_set_hidden(window_with_focus, !window_with_focus->show_hidden);
894 static void show_thumbs(gpointer data, guint action, GtkWidget *widget)
896 if (updating_menu)
897 return;
899 g_return_if_fail(window_with_focus != NULL);
901 display_set_thumbs(window_with_focus, !window_with_focus->show_thumbs);
904 static void refresh(gpointer data, guint action, GtkWidget *widget)
906 g_return_if_fail(window_with_focus != NULL);
908 full_refresh();
909 filer_update_dir(window_with_focus, TRUE);
912 static void delete(FilerWindow *filer_window)
914 GList *paths;
915 paths = filer_selected_items(filer_window);
916 action_delete(paths);
917 g_list_foreach(paths, (GFunc) g_free, NULL);
918 g_list_free(paths);
921 static void usage(FilerWindow *filer_window)
923 GList *paths;
924 paths = filer_selected_items(filer_window);
925 action_usage(paths);
926 g_list_foreach(paths, (GFunc) g_free, NULL);
927 g_list_free(paths);
930 static void chmod_items(FilerWindow *filer_window)
932 GList *paths;
933 paths = filer_selected_items(filer_window);
934 action_chmod(paths);
935 g_list_foreach(paths, (GFunc) g_free, NULL);
936 g_list_free(paths);
939 static void find(FilerWindow *filer_window)
941 GList *paths;
942 paths = filer_selected_items(filer_window);
943 action_find(paths);
944 g_list_foreach(paths, (GFunc) g_free, NULL);
945 g_list_free(paths);
948 /* This creates a new savebox widget, and allows the user to pick a new path
949 * for the file.
950 * Once the new path has been picked, the callback will be called with
951 * both the current and new paths.
952 * NOTE: This function unrefs 'image'!
954 static void savebox_show(const gchar *action, const gchar *path,
955 MaskedPixmap *image, SaveCb callback)
957 GtkWidget *savebox = NULL;
958 GtkWidget *check_relative = NULL;
960 g_return_if_fail(image != NULL);
962 savebox = gtk_savebox_new(action);
964 if (callback == link_cb)
966 check_relative = gtk_check_button_new_with_mnemonic(
967 _("_Relative link"));
968 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative),
969 TRUE);
971 GTK_WIDGET_UNSET_FLAGS(check_relative, GTK_CAN_FOCUS);
972 gtk_tooltips_set_tip(tooltips, check_relative,
973 _("If on, the symlink will store the path from the "
974 "symlink to the target file. Use this if the symlink "
975 "and the target will be moved together.\n"
976 "If off, the path from the root directory is stored - "
977 "use this if the symlink may move but the target will "
978 "stay put."), NULL);
979 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox)->vbox),
980 check_relative, FALSE, TRUE, 0);
981 gtk_widget_show(check_relative);
984 g_signal_connect(savebox, "save_to_file",
985 G_CALLBACK(save_to_file), NULL);
987 g_object_set_data_full(G_OBJECT(savebox), "current_path",
988 g_strdup(path), g_free);
989 g_object_set_data(G_OBJECT(savebox), "action_callback", callback);
990 g_object_set_data(G_OBJECT(savebox), "check_relative", check_relative);
992 gtk_window_set_title(GTK_WINDOW(savebox), action);
993 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox), path);
994 gtk_savebox_set_icon(GTK_SAVEBOX(savebox), image->pixmap, image->mask);
995 g_object_unref(image);
997 gtk_widget_show(savebox);
1000 static gint save_to_file(GObject *savebox,
1001 const gchar *pathname, gpointer data)
1003 SaveCb callback;
1004 const gchar *current_path;
1006 callback = g_object_get_data(savebox, "action_callback");
1007 current_path = g_object_get_data(savebox, "current_path");
1009 g_return_val_if_fail(callback != NULL, GTK_XDS_SAVE_ERROR);
1010 g_return_val_if_fail(current_path != NULL, GTK_XDS_SAVE_ERROR);
1012 return callback(savebox, current_path, pathname)
1013 ? GTK_XDS_SAVED : GTK_XDS_SAVE_ERROR;
1016 static gboolean copy_cb(GObject *savebox,
1017 const gchar *current, const gchar *new)
1019 return action_with_leaf(action_copy, current, new);
1022 static gboolean action_with_leaf(ActionFn action,
1023 const gchar *current, const gchar *new)
1025 const char *leaf;
1026 char *new_dir;
1027 GList *local_paths;
1029 if (new[0] != '/')
1031 report_error(_("New pathname is not absolute"));
1032 return FALSE;
1035 if (new[strlen(new) - 1] == '/')
1037 new_dir = g_strdup(new);
1038 leaf = NULL;
1040 else
1042 const gchar *slash;
1044 slash = strrchr(new, '/');
1045 new_dir = g_strndup(new, slash - new);
1046 leaf = slash + 1;
1049 local_paths = g_list_append(NULL, (gchar *) current);
1050 action(local_paths, new_dir, leaf, -1);
1051 g_list_free(local_paths);
1053 g_free(new_dir);
1055 return TRUE;
1058 /* Open a savebox to act on the selected file.
1059 * Call 'callback' later to perform the operation.
1061 static void src_dest_action_item(const gchar *path, MaskedPixmap *image,
1062 const gchar *action, SaveCb callback)
1064 g_object_ref(image);
1065 savebox_show(action, path, image, callback);
1068 static gboolean rename_cb(GObject *savebox,
1069 const gchar *current, const gchar *new)
1071 return action_with_leaf(action_move, current, new);
1074 static gboolean link_cb(GObject *savebox,
1075 const gchar *initial, const gchar *path)
1077 GtkToggleButton *check_relative;
1078 int err;
1080 check_relative = g_object_get_data(savebox, "check_relative");
1082 if (gtk_toggle_button_get_active(check_relative))
1084 guchar *rpath;
1086 rpath = get_relative_path(path, initial);
1087 err = symlink(rpath, path);
1089 g_free(rpath);
1091 else
1092 err = symlink(initial, path);
1094 if (err)
1096 report_error("symlink: %s", g_strerror(errno));
1097 return FALSE;
1100 dir_check_this(path);
1102 return TRUE;
1105 static void run_action(DirItem *item)
1107 if (can_set_run_action(item))
1108 type_set_handler_dialog(item->mime_type);
1109 else
1110 report_error(
1111 _("You can only set the run action for a "
1112 "regular file"));
1115 void open_home(gpointer data, guint action, GtkWidget *widget)
1117 filer_opendir(home_dir, NULL);
1120 static void open_vfs_avfs(FilerWindow *filer_window, DirItem *item)
1122 gchar *path;
1124 path = g_strconcat(filer_window->path,
1125 "/", item->leafname, "#", NULL);
1127 filer_change_to(filer_window, path, NULL);
1128 g_free(path);
1131 static void select_all(gpointer data, guint action, GtkWidget *widget)
1133 g_return_if_fail(window_with_focus != NULL);
1135 window_with_focus->temp_item_selected = FALSE;
1136 collection_select_all(window_with_focus->collection);
1139 static void clear_selection(gpointer data, guint action, GtkWidget *widget)
1141 g_return_if_fail(window_with_focus != NULL);
1143 window_with_focus->temp_item_selected = FALSE;
1144 collection_clear_selection(window_with_focus->collection);
1147 static void invert_selection(gpointer data, guint action, GtkWidget *widget)
1149 g_return_if_fail(window_with_focus != NULL);
1151 window_with_focus->temp_item_selected = FALSE;
1152 collection_invert_selection(window_with_focus->collection);
1155 void menu_show_options(gpointer data, guint action, GtkWidget *widget)
1157 options_show();
1160 static gboolean new_directory_cb(GObject *savebox,
1161 const gchar *initial, const gchar *path)
1163 if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO))
1165 report_error("mkdir: %s", g_strerror(errno));
1166 return FALSE;
1169 dir_check_this(path);
1171 if (filer_exists(window_with_focus))
1173 guchar *leaf;
1174 leaf = strrchr(path, '/');
1175 if (leaf)
1176 display_set_autoselect(window_with_focus, leaf + 1);
1179 return TRUE;
1182 static void new_directory(gpointer data, guint action, GtkWidget *widget)
1184 g_return_if_fail(window_with_focus != NULL);
1186 savebox_show(_("Create"),
1187 make_path(window_with_focus->path, _("NewDir"))->str,
1188 type_to_icon(special_directory),
1189 new_directory_cb);
1192 static gboolean new_file_cb(GObject *savebox,
1193 const gchar *initial, const gchar *path)
1195 int fd;
1197 fd = open(path, O_CREAT | O_EXCL, 0666);
1199 if (fd == -1)
1201 report_error(_("Error creating '%s': %s"),
1202 path, g_strerror(errno));
1203 return FALSE;
1206 if (close(fd))
1207 report_error(_("Error creating '%s': %s"),
1208 path, g_strerror(errno));
1210 dir_check_this(path);
1212 if (filer_exists(window_with_focus))
1214 guchar *leaf;
1215 leaf = strrchr(path, '/');
1216 if (leaf)
1217 display_set_autoselect(window_with_focus, leaf + 1);
1220 return TRUE;
1223 static void new_file(gpointer data, guint action, GtkWidget *widget)
1225 g_return_if_fail(window_with_focus != NULL);
1227 savebox_show(_("Create"),
1228 make_path(window_with_focus->path, _("NewFile"))->str,
1229 type_to_icon(text_plain),
1230 new_file_cb);
1233 static gboolean new_file_type_cb(GObject *savebox,
1234 const gchar *initial, const gchar *path)
1236 const gchar *oleaf, *leaf;
1237 gchar *templ, *templ_dname, *dest;
1238 GList *paths;
1240 /* We can work out the template path from the initial name */
1241 oleaf = g_basename(initial);
1242 templ_dname = choices_find_path_load("Templates", "");
1243 if (!templ_dname)
1245 report_error(
1246 _("Error creating file: could not find the template for %s"),
1247 oleaf);
1248 return FALSE;
1251 templ = g_strconcat(templ_dname, "/", oleaf, NULL);
1252 g_free(templ_dname);
1254 dest = g_dirname(path);
1255 leaf = g_basename(path);
1256 paths = g_list_append(NULL, templ);
1258 action_copy(paths, dest, leaf, -1);
1260 g_list_free(paths);
1261 g_free(dest);
1262 g_free(templ);
1264 if (filer_exists(window_with_focus))
1265 display_set_autoselect(window_with_focus, leaf);
1267 return TRUE;
1270 static void do_send_to(gchar *templ)
1272 g_return_if_fail(send_to_paths != NULL);
1274 run_with_files(templ, send_to_paths);
1277 static void new_file_type(gchar *templ)
1279 const gchar *leaf;
1280 MIME_type *type;
1282 g_return_if_fail(window_with_focus != NULL);
1284 leaf = g_basename(templ);
1285 type = type_get_type(templ);
1287 savebox_show(_("Create"),
1288 make_path(window_with_focus->path, leaf)->str,
1289 type_to_icon(type),
1290 new_file_type_cb);
1293 static void customise_send_to(gpointer data)
1295 GPtrArray *path;
1296 guchar *save;
1297 GString *dirs;
1298 int i;
1300 dirs = g_string_new(NULL);
1302 path = choices_list_dirs("");
1303 for (i = 0; i < path->len; i++)
1305 guchar *old = (guchar *) path->pdata[i];
1307 g_string_append(dirs, old);
1308 g_string_append(dirs, "SendTo\n");
1310 choices_free_list(path);
1312 save = choices_find_path_save("", "SendTo", TRUE);
1313 if (save)
1314 mkdir(save, 0777);
1316 report_error(
1317 _("The `Send To' menu provides a quick way to send some files "
1318 "to an application. The applications listed are those in "
1319 "the following directories:\n\n%s\n%s\n"
1320 "The `Send To' menu may be opened by Shift+Menu clicking "
1321 "over a file."),
1322 dirs->str,
1323 save ? _("I'll show you your SendTo directory now; you should "
1324 "symlink (Ctrl+Shift drag) any applications you want "
1325 "into it.")
1326 : _("Your CHOICESPATH variable setting prevents "
1327 "customisations - sorry."));
1329 g_string_free(dirs, TRUE);
1331 if (save)
1332 filer_opendir(save, NULL);
1335 /* Scan the SendTo dir and create and show the Send To menu.
1336 * The 'paths' list and every path in it is claimed, and will be
1337 * freed later -- don't free it yourself!
1339 static void show_send_to_menu(GList *paths, GdkEvent *event)
1341 GtkWidget *menu, *item;
1342 GPtrArray *path;
1343 int i;
1345 menu = gtk_menu_new();
1347 path = choices_list_dirs("SendTo");
1349 for (i = 0; i < path->len; i++)
1351 GList *widgets = NULL;
1352 guchar *dir = (guchar *) path->pdata[i];
1354 widgets = menu_from_dir(menu, dir, get_menu_icon_style(),
1355 (CallbackFn) do_send_to,
1356 FALSE, FALSE);
1358 if (widgets)
1359 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
1360 gtk_menu_item_new());
1362 g_list_free(widgets); /* TODO: Get rid of this */
1365 choices_free_list(path);
1367 item = gtk_menu_item_new_with_label(_("Customise"));
1368 g_signal_connect_swapped(item, "activate",
1369 G_CALLBACK(customise_send_to), NULL);
1370 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1372 if (send_to_paths)
1374 g_list_foreach(send_to_paths, (GFunc) g_free, NULL);
1375 g_list_free(send_to_paths);
1377 send_to_paths = paths;
1379 g_signal_connect(menu, "unmap_event", G_CALLBACK(menu_closed), NULL);
1381 popup_menu = menu;
1382 show_popup_menu(menu, event, 0);
1385 static void send_to(FilerWindow *filer_window)
1387 GList *paths;
1388 GdkEvent *event;
1390 paths = filer_selected_items(filer_window);
1391 event = gtk_get_current_event();
1393 /* Eats paths */
1394 show_send_to_menu(paths, event);
1396 gdk_event_free(event);
1399 static void xterm_here(gpointer data, guint action, GtkWidget *widget)
1401 const char *argv[] = {"sh", "-c", NULL, NULL};
1403 argv[2] = o_menu_xterm.value;
1405 g_return_if_fail(window_with_focus != NULL);
1407 rox_spawn(window_with_focus->path, argv);
1410 static void home_directory(gpointer data, guint action, GtkWidget *widget)
1412 g_return_if_fail(window_with_focus != NULL);
1414 filer_change_to(window_with_focus, home_dir, NULL);
1417 static void open_parent(gpointer data, guint action, GtkWidget *widget)
1419 g_return_if_fail(window_with_focus != NULL);
1421 filer_open_parent(window_with_focus);
1424 static void open_parent_same(gpointer data, guint action, GtkWidget *widget)
1426 g_return_if_fail(window_with_focus != NULL);
1428 change_to_parent(window_with_focus);
1431 static void resize(gpointer data, guint action, GtkWidget *widget)
1433 g_return_if_fail(window_with_focus != NULL);
1435 filer_window_autosize(window_with_focus, TRUE);
1438 static void new_window(gpointer data, guint action, GtkWidget *widget)
1440 g_return_if_fail(window_with_focus != NULL);
1442 if (o_unique_filer_windows.int_value)
1444 report_error(_("You can't open a second view onto "
1445 "this directory because the `Unique Windows' option "
1446 "is turned on in the Options window."));
1448 else
1449 filer_opendir(window_with_focus->path, window_with_focus);
1452 #if 0
1453 static void su_to_user(GtkWidget *dialog)
1455 char *argv[] = {
1456 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL};
1457 GtkEntry *user;
1458 guchar *path;
1460 g_return_if_fail(dialog != NULL);
1462 path = gtk_object_get_data(GTK_OBJECT(dialog), "dir_path");
1463 user = gtk_object_get_data(GTK_OBJECT(dialog), "user_name");
1465 g_return_if_fail(user != NULL && path != NULL);
1467 argv[2] = g_strconcat(app_dir, "/su_rox", NULL);
1468 argv[3] = gtk_entry_get_text(user);
1469 argv[4] = g_strconcat(app_dir, "/AppRun", NULL);
1470 argv[5] = path;
1472 if (!spawn(argv))
1473 report_error(_("fork: %s"), g_strerror(errno));
1475 g_free(argv[2]);
1476 g_free(argv[4]);
1478 gtk_widget_destroy(dialog);
1481 static void new_user(gpointer data, guint action, GtkWidget *widget)
1483 GtkWidget *dialog, *vbox, *hbox, *entry, *button;
1485 g_return_if_fail(window_with_focus != NULL);
1487 dialog = gtk_window_new(GTK_WINDOW_DIALOG);
1488 gtk_window_set_title(GTK_WINDOW(dialog), _("New window, as user..."));
1489 gtk_container_set_border_width(GTK_CONTAINER(dialog), 4);
1490 gtk_object_set_data_full(GTK_OBJECT(dialog), "dir_path",
1491 g_strdup(window_with_focus->path), g_free);
1493 vbox = gtk_vbox_new(FALSE, 4);
1494 gtk_container_add(GTK_CONTAINER(dialog), vbox);
1495 gtk_box_pack_start(GTK_BOX(vbox),
1496 gtk_label_new(_("Browse as which user?")),
1497 TRUE, TRUE, 2);
1499 hbox = gtk_hbox_new(FALSE, 4);
1500 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
1502 gtk_box_pack_start(GTK_BOX(hbox),
1503 gtk_label_new(_("User:")), FALSE, TRUE, 2);
1505 entry = gtk_entry_new();
1506 gtk_entry_set_text(GTK_ENTRY(entry), "root");
1507 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
1508 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 2);
1509 gtk_widget_grab_focus(entry);
1510 gtk_object_set_data(GTK_OBJECT(dialog), "user_name", entry);
1511 gtk_signal_connect_object(GTK_OBJECT(entry), "activate",
1512 GTK_SIGNAL_FUNC(su_to_user), GTK_OBJECT(dialog));
1514 hbox = gtk_hbox_new(TRUE, 0);
1515 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
1517 button = gtk_button_new_with_label(_("OK"));
1518 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
1519 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1520 gtk_window_set_default(GTK_WINDOW(dialog), button);
1521 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
1522 GTK_SIGNAL_FUNC(su_to_user), GTK_OBJECT(dialog));
1524 button = gtk_button_new_with_label(_("Cancel"));
1525 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1526 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
1527 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
1528 GTK_SIGNAL_FUNC(gtk_widget_destroy),
1529 GTK_OBJECT(dialog));
1531 gtk_widget_show_all(dialog);
1533 #endif
1535 static void close_window(gpointer data, guint action, GtkWidget *widget)
1537 g_return_if_fail(window_with_focus != NULL);
1539 gtk_widget_destroy(window_with_focus->window);
1542 static void mini_buffer(gpointer data, guint action, GtkWidget *widget)
1544 MiniType type = (MiniType) action;
1546 g_return_if_fail(window_with_focus != NULL);
1548 /* Item needs to remain selected... */
1549 if (type == MINI_SHELL)
1550 window_with_focus->temp_item_selected = FALSE;
1552 minibuffer_show(window_with_focus, type);
1555 void menu_rox_help(gpointer data, guint action, GtkWidget *widget)
1557 filer_opendir(make_path(app_dir, "Help")->str, NULL);
1560 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1561 void menu_set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n)
1563 GList *items, *item;
1565 items = gtk_container_get_children(GTK_CONTAINER(menu));
1567 item = g_list_nth(items, from);
1568 while (item && n--)
1570 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, !shaded);
1571 item = item->next;
1573 g_list_free(items);
1576 static void save_menus(void)
1578 char *menurc;
1580 menurc = choices_find_path_save(MENUS_NAME, PROJECT, TRUE);
1581 if (menurc)
1583 gtk_accel_map_save(menurc);
1584 g_free(menurc);
1588 static void keys_changed(gpointer data)
1590 save_menus();
1593 static void select_nth_item(GtkMenuShell *shell, int n)
1595 GList *items, *nth;
1596 GtkWidget *item = NULL;
1598 items = gtk_container_get_children(GTK_CONTAINER(shell));
1599 nth = g_list_nth(items, n);
1601 g_return_if_fail(nth != NULL);
1603 item = (GtkWidget *) (nth->data);
1604 g_list_free(items);
1606 gtk_menu_shell_select_item(shell, item);
1609 static void file_op(gpointer data, FileOp action, GtkWidget *widget)
1611 Collection *collection;
1612 DirItem *item;
1613 gchar *path;
1615 g_return_if_fail(window_with_focus != NULL);
1617 collection = window_with_focus->collection;
1619 if (collection->number_selected < 1)
1621 const char *prompt;
1623 switch (action)
1625 case FILE_COPY_ITEM:
1626 prompt = _("Copy ... ?");
1627 break;
1628 case FILE_RENAME_ITEM:
1629 prompt = _("Rename ... ?");
1630 break;
1631 case FILE_LINK_ITEM:
1632 prompt = _("Symlink ... ?");
1633 break;
1634 case FILE_OPEN_FILE:
1635 prompt = _("Shift Open ... ?");
1636 break;
1637 case FILE_HELP:
1638 prompt = _("Help about ... ?");
1639 break;
1640 case FILE_SHOW_FILE_INFO:
1641 prompt = _("Examine ... ?");
1642 break;
1643 case FILE_RUN_ACTION:
1644 prompt = _("Set run action for ... ?");
1645 break;
1646 case FILE_SET_ICON:
1647 prompt = _("Set icon for ... ?");
1648 break;
1649 case FILE_SEND_TO:
1650 prompt = _("Send ... to ... ?");
1651 break;
1652 case FILE_DELETE:
1653 prompt = _("DELETE ... ?");
1654 break;
1655 case FILE_USAGE:
1656 prompt = _("Count the size of ... ?");
1657 break;
1658 case FILE_CHMOD_ITEMS:
1659 prompt = _("Set permissions on ... ?");
1660 break;
1661 case FILE_FIND:
1662 prompt = _("Search inside ... ?");
1663 break;
1664 case FILE_OPEN_VFS_AVFS:
1665 prompt = _("Look inside ... ?");
1666 break;
1667 default:
1668 g_warning("Unknown action!");
1669 return;
1671 filer_target_mode(window_with_focus, target_callback,
1672 GINT_TO_POINTER(action), prompt);
1673 return;
1676 switch (action)
1678 case FILE_SEND_TO:
1679 send_to(window_with_focus);
1680 return;
1681 case FILE_DELETE:
1682 delete(window_with_focus);
1683 return;
1684 case FILE_USAGE:
1685 usage(window_with_focus);
1686 return;
1687 case FILE_CHMOD_ITEMS:
1688 chmod_items(window_with_focus);
1689 return;
1690 case FILE_FIND:
1691 find(window_with_focus);
1692 return;
1693 default:
1694 break;
1697 /* All the following actions require exactly one file selected */
1699 if (collection->number_selected > 1)
1701 report_error(_("You cannot do this to more than "
1702 "one item at a time"));
1703 return;
1706 item = selected_item(collection);
1707 g_return_if_fail(item != NULL);
1708 if (!item->image)
1709 item = dir_update_item(window_with_focus->directory,
1710 item->leafname);
1712 if (!item)
1714 report_error(_("Item no longer exists!"));
1715 return;
1718 path = make_path(window_with_focus->path, item->leafname)->str;
1720 switch (action)
1722 case FILE_COPY_ITEM:
1723 src_dest_action_item(path, item->image,
1724 _("Copy"), copy_cb);
1725 break;
1726 case FILE_RENAME_ITEM:
1727 src_dest_action_item(path, item->image,
1728 _("Rename"), rename_cb);
1729 break;
1730 case FILE_LINK_ITEM:
1731 src_dest_action_item(path, item->image,
1732 _("Symlink"), link_cb);
1733 break;
1734 case FILE_OPEN_FILE:
1735 filer_openitem(window_with_focus,
1736 selected_item_number(collection),
1737 OPEN_SAME_WINDOW | OPEN_SHIFT);
1738 break;
1739 case FILE_HELP:
1740 show_item_help(path, item);
1741 break;
1742 case FILE_SHOW_FILE_INFO:
1743 infobox_new(path);
1744 break;
1745 case FILE_RUN_ACTION:
1746 run_action(item);
1747 break;
1748 case FILE_SET_ICON:
1749 icon_set_handler_dialog(item, path);
1750 break;
1751 case FILE_OPEN_VFS_AVFS:
1752 open_vfs_avfs(window_with_focus, item);
1753 break;
1754 default:
1755 g_warning("Unknown action!");
1756 return;
1760 static void show_key_help(GtkWidget *button, gpointer data)
1762 report_error(_("To set a keyboard short-cut for a menu item:\n\n"
1763 "- Open the menu over a filer window,\n"
1764 "- Move the pointer over the item you want to use,\n"
1765 "- Press the key you want attached to it.\n\n"
1766 "The key will appear next to the menu item and you can just press "
1767 "that key without opening the menu in future."));
1770 static GList *set_keys_button(Option *option, xmlNode *node, guchar *label)
1772 GtkWidget *button, *align;
1774 g_return_val_if_fail(option == NULL, NULL);
1776 align = gtk_alignment_new(0.5, 0.5, 0, 0);
1777 button = gtk_button_new_with_label(_("Set keyboard shortcuts"));
1778 gtk_container_add(GTK_CONTAINER(align), button);
1779 g_signal_connect(button, "clicked", G_CALLBACK(show_key_help), NULL);
1781 return g_list_append(NULL, align);