r328: Changed the install script so that the CVS directories don't get installed.
[rox-filer.git] / ROX-Filer / src / menu.c
blob88fda8a316cc275da2584a552f6789dd2115fae9
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2000, Thomas Leonard, <tal197@ecs.soton.ac.uk>.
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>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <sys/wait.h>
30 #include <sys/param.h>
31 #include <fcntl.h>
32 #include <unistd.h>
33 #include <errno.h>
34 #include <string.h>
36 #include <gtk/gtk.h>
38 #include "menu.h"
39 #include "run.h"
40 #include "action.h"
41 #include "filer.h"
42 #include "type.h"
43 #include "support.h"
44 #include "gui_support.h"
45 #include "options.h"
46 #include "choices.h"
47 #include "gtksavebox.h"
48 #include "mount.h"
49 #include "minibuffer.h"
50 #include "i18n.h"
52 #define C_ "<control>"
54 #define MENU_MARGIN 32
56 GtkAccelGroup *filer_keys;
57 GtkAccelGroup *panel_keys;
58 GtkAccelGroup *pinboard_keys;
60 static GtkWidget *popup_menu = NULL; /* Currently open menu */
62 static gint updating_menu = 0; /* Non-zero => ignore activations */
64 /* Options */
65 static GtkWidget *xterm_here_entry;
66 static char *xterm_here_value;
68 /* TRUE if we selected an icon automatically when the menu was opened */
69 static gboolean pin_temp_item_selected;
71 /* Static prototypes */
73 static void save_menus(void);
74 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data);
75 static void pin_menu_closed(GtkWidget *widget);
76 static void menu_closed(GtkWidget *widget);
77 static void items_sensitive(gboolean state);
78 static char *load_xterm_here(char *data);
79 static void savebox_show(guchar *title, guchar *path, MaskedPixmap *image,
80 gboolean (*callback)(guchar *current, guchar *new));
81 static gint save_to_file(GtkSavebox *savebox, guchar *pathname);
82 static GList *list_paths(FilerWindow *filer_window);
83 static void free_paths(GList *paths);
85 /* Note that for most of these callbacks none of the arguments are used. */
86 static void large(gpointer data, guint action, GtkWidget *widget);
87 static void small(gpointer data, guint action, GtkWidget *widget);
89 /* (action used in these two - (DetailsType) */
90 static void large_with(gpointer data, guint action, GtkWidget *widget);
91 static void small_with(gpointer data, guint action, GtkWidget *widget);
93 static void sort_name(gpointer data, guint action, GtkWidget *widget);
94 static void sort_type(gpointer data, guint action, GtkWidget *widget);
95 static void sort_size(gpointer data, guint action, GtkWidget *widget);
96 static void sort_date(gpointer data, guint action, GtkWidget *widget);
98 static void hidden(gpointer data, guint action, GtkWidget *widget);
99 static void refresh(gpointer data, guint action, GtkWidget *widget);
101 static void copy_item(gpointer data, guint action, GtkWidget *widget);
102 static void rename_item(gpointer data, guint action, GtkWidget *widget);
103 static void link_item(gpointer data, guint action, GtkWidget *widget);
104 static void open_file(gpointer data, guint action, GtkWidget *widget);
105 static void help(gpointer data, guint action, GtkWidget *widget);
106 static void show_file_info(gpointer data, guint action, GtkWidget *widget);
107 static void mount(gpointer data, guint action, GtkWidget *widget);
108 static void delete(gpointer data, guint action, GtkWidget *widget);
109 static void remove_link(gpointer data, guint action, GtkWidget *widget);
110 static void usage(gpointer data, guint action, GtkWidget *widget);
111 static void chmod_items(gpointer data, guint action, GtkWidget *widget);
112 static void find(gpointer data, guint action, GtkWidget *widget);
114 static void open_vfs_rpm(gpointer data, guint action, GtkWidget *widget);
115 static void open_vfs_utar(gpointer data, guint action, GtkWidget *widget);
116 static void open_vfs_uzip(gpointer data, guint action, GtkWidget *widget);
118 static void select_all(gpointer data, guint action, GtkWidget *widget);
119 static void clear_selection(gpointer data, guint action, GtkWidget *widget);
120 static void show_options(gpointer data, guint action, GtkWidget *widget);
121 static void new_directory(gpointer data, guint action, GtkWidget *widget);
122 static void xterm_here(gpointer data, guint action, GtkWidget *widget);
124 static void open_parent_same(gpointer data, guint action, GtkWidget *widget);
125 static void open_parent(gpointer data, guint action, GtkWidget *widget);
126 static void new_window(gpointer data, guint action, GtkWidget *widget);
127 static void close_window(gpointer data, guint action, GtkWidget *widget);
128 static void enter_path(gpointer data, guint action, GtkWidget *widget);
129 static void shell_command(gpointer data, guint action, GtkWidget *widget);
130 static void run_action(gpointer data, guint action, GtkWidget *widget);
131 static void select_if(gpointer data, guint action, GtkWidget *widget);
132 static void rox_help(gpointer data, guint action, GtkWidget *widget);
134 static void open_as_dir(gpointer data, guint action, GtkWidget *widget);
135 static void close_panel(gpointer data, guint action, GtkWidget *widget);
137 static void pin_help(gpointer data, guint action, GtkWidget *widget);
138 static void pin_remove(gpointer data, guint action, GtkWidget *widget);
140 static void set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n);
142 static GtkWidget *create_options();
143 static void update_options();
144 static void set_options();
145 static void save_options();
147 static OptionsSection options =
149 N_("Menu options"),
150 create_options,
151 update_options,
152 set_options,
153 save_options
157 static GtkWidget *filer_menu; /* The popup filer menu */
158 static GtkWidget *filer_file_item; /* The File '' label */
159 static GtkWidget *filer_file_menu; /* The File '' menu */
160 static GtkWidget *filer_vfs_menu; /* The Open VFS menu */
161 static GtkWidget *filer_hidden_menu; /* The Show Hidden item */
162 static GtkWidget *filer_new_window; /* The New Window item */
163 static GtkWidget *panel_menu; /* The popup panel menu */
164 static GtkWidget *panel_hidden_menu; /* The Show Hidden item */
165 static GtkWidget *pinboard_menu; /* The popup pinboard menu */
167 /* Used for Copy, etc */
168 static GtkWidget *savebox = NULL;
169 static guchar *current_path = NULL;
170 static gboolean (*current_savebox_callback)(guchar *current, guchar *new);
172 #undef N_
173 #define N_(x) x
175 static GtkItemFactoryEntry filer_menu_def[] = {
176 {N_("Display"), NULL, NULL, 0, "<Branch>"},
177 {">" N_("Large Icons"), NULL, large, 0, NULL},
178 {">" N_("Small Icons"), NULL, small, 0, NULL},
179 {">" N_("Large, With..."), NULL, NULL, 0, "<Branch>"},
180 {">>" N_("Summary"), NULL, large_with, DETAILS_SUMMARY, NULL},
181 {">>" N_("Sizes"), NULL, large_with, DETAILS_SIZE, NULL},
182 {">>" N_("Size Bars"), NULL, large_with, DETAILS_SIZE_BARS, NULL},
183 {">" N_("Small, With..."), NULL, NULL, 0, "<Branch>"},
184 {">>" N_("Summary"), NULL, small_with, DETAILS_SUMMARY, NULL},
185 {">>" N_("Sizes"), NULL, small_with, DETAILS_SIZE, NULL},
186 {">>" N_("Size Bars"), NULL, small_with, DETAILS_SIZE_BARS, NULL},
187 {">", NULL, NULL, 0, "<Separator>"},
188 {">" N_("Sort by Name"), NULL, sort_name, 0, NULL},
189 {">" N_("Sort by Type"), NULL, sort_type, 0, NULL},
190 {">" N_("Sort by Date"), NULL, sort_date, 0, NULL},
191 {">" N_("Sort by Size"), NULL, sort_size, 0, NULL},
192 {">", NULL, NULL, 0, "<Separator>"},
193 {">" N_("Show Hidden"), NULL, hidden, 0, "<ToggleItem>"},
194 {">" N_("Refresh"), NULL, refresh, 0, NULL},
195 {N_("File"), NULL, NULL, 0, "<Branch>"},
196 {">" N_("Copy..."), NULL, copy_item, 0, NULL},
197 {">" N_("Rename..."), NULL, rename_item, 0, NULL},
198 {">" N_("Link..."), NULL, link_item, 0, NULL},
199 {">" N_("Shift Open"), NULL, open_file, 0, NULL},
200 {">" N_("Help"), NULL, help, 0, NULL},
201 {">" N_("Info"), NULL, show_file_info, 0, NULL},
202 {">" N_("Open VFS"), NULL, NULL, 0, "<Branch>"},
203 {">>" N_("Unzip"), NULL, open_vfs_uzip, 0, NULL},
204 {">>" N_("Untar"), NULL, open_vfs_utar, 0, NULL},
205 {">>" N_("RPM"), NULL, open_vfs_rpm, 0, NULL},
206 {">", NULL, NULL, 0, "<Separator>"},
207 {">" N_("Mount"), NULL, mount, 0, NULL},
208 {">" N_("Delete"), NULL, delete, 0, NULL},
209 {">" N_("Disk Usage"), NULL, usage, 0, NULL},
210 {">" N_("Permissions"), NULL, chmod_items, 0, NULL},
211 {">" N_("Find"), NULL, find, 0, NULL},
212 {N_("Select All"), NULL, select_all, 0, NULL},
213 {N_("Clear Selection"), NULL, clear_selection, 0, NULL},
214 {N_("Options..."), NULL, show_options, 0, NULL},
215 {N_("New Directory..."), NULL, new_directory, 0, NULL},
216 {N_("Xterm Here"), NULL, xterm_here, 0, NULL},
217 {N_("Window"), NULL, NULL, 0, "<Branch>"},
218 {">" N_("Parent, New Window"), NULL, open_parent, 0, NULL},
219 {">" N_("Parent, Same Window"), NULL, open_parent_same, 0, NULL},
220 {">" N_("New Window"), NULL, new_window, 0, NULL},
221 {">" N_("Close Window"), NULL, close_window, 0, NULL},
222 {">", NULL, NULL, 0, "<Separator>"},
223 {">" N_("Enter Path..."), NULL, enter_path, 0, NULL},
224 {">" N_("Shell Command..."), NULL, shell_command, 0, NULL},
225 {">" N_("Set Run Action..."), NULL, run_action, 0, NULL},
226 {">" N_("Select If..."), NULL, select_if, 0, NULL},
227 {">", NULL, NULL, 0, "<Separator>"},
228 {">" N_("Show ROX-Filer Help"), NULL, rox_help, 0, NULL},
231 static GtkItemFactoryEntry panel_menu_def[] = {
232 {N_("Display"), NULL, NULL, 0, "<Branch>"},
233 {">" N_("Sort by Name"), NULL, sort_name, 0, NULL},
234 {">" N_("Sort by Type"), NULL, sort_type, 0, NULL},
235 {">" N_("Sort by Date"), NULL, sort_date, 0, NULL},
236 {">" N_("Sort by Size"), NULL, sort_size, 0, NULL},
237 {">", NULL, NULL, 0, "<Separator>"},
238 {">" N_("Show Hidden"), NULL, hidden, 0, "<ToggleItem>"},
239 {">" N_("Refresh"), NULL, refresh, 0, NULL},
240 {N_("Open Panel as Directory"), NULL, open_as_dir, 0, NULL},
241 {N_("Close Panel"), NULL, close_panel, 0, NULL},
242 {"", NULL, NULL, 0, "<Separator>"},
243 {N_("ROX-Filer Help"), NULL, rox_help, 0, NULL},
244 {N_("ROX-Filer Options..."), NULL, show_options, 0, NULL},
245 {"", NULL, NULL, 0, "<Separator>"},
246 {N_("Show Help"), NULL, help, 0, NULL},
247 {N_("Remove Item"), NULL, remove_link, 0, NULL},
250 static GtkItemFactoryEntry pinboard_menu_def[] = {
251 {N_("Show Help"), NULL, pin_help, 0, NULL},
252 {N_("Remove Item(s)"), NULL, pin_remove, 0, NULL},
253 {"", NULL, NULL, 0, "<Separator>"},
254 {N_("ROX-Filer Help"), NULL, rox_help, 0, NULL},
255 {N_("ROX-Filer Options..."), NULL, show_options, 0, NULL},
259 typedef struct _FileStatus FileStatus;
261 /* This is for the 'file(1) says...' thing */
262 struct _FileStatus
264 int fd; /* FD to read from, -1 if closed */
265 int input; /* Input watcher tag if fd valid */
266 GtkLabel *label; /* Widget to output to */
267 gboolean start; /* No output yet */
270 #define GET_MENU_ITEM(var, menu) \
271 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
273 #define GET_SMENU_ITEM(var, menu, sub) \
274 do { \
275 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
276 var = gtk_item_factory_get_widget(item_factory, tmp); \
277 g_free(tmp); \
278 } while (0)
280 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
281 do { \
282 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
283 var = gtk_item_factory_get_widget(item_factory, tmp); \
284 g_free(tmp); \
285 } while (0)
287 /* Creates menu <name> from the <name>_menu_def array.
288 * The accel group <name>_keys must also have been created.
289 * All menu items are translated. Sets 'item_factory'.
291 #define MAKE_MENU(name) \
292 do { \
293 GtkItemFactoryEntry *translated; \
294 int n_entries; \
296 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, \
297 "<" #name ">", name ## _keys); \
299 n_entries = sizeof(name ## _menu_def) / sizeof(*name ## _menu_def); \
300 translated = translate_entries(name ## _menu_def, n_entries); \
301 gtk_item_factory_create_items (item_factory, n_entries, \
302 translated, NULL); \
303 free_translated_entries(translated, n_entries); \
304 } while (0)
306 void menu_init()
308 char *menurc;
309 GList *items;
310 guchar *tmp;
311 GtkWidget *item;
312 GtkItemFactory *item_factory; \
314 filer_keys = gtk_accel_group_new();
315 MAKE_MENU(filer);
317 GET_MENU_ITEM(filer_menu, "filer");
318 GET_SMENU_ITEM(filer_file_menu, "filer", "File");
319 GET_SSMENU_ITEM(filer_vfs_menu, "filer", "File", "Open VFS");
320 GET_SSMENU_ITEM(filer_hidden_menu, "filer", "Display", "Show Hidden");
322 items = gtk_container_children(GTK_CONTAINER(filer_menu));
323 filer_file_item = GTK_BIN(g_list_nth(items, 1)->data)->child;
324 g_list_free(items);
326 GET_SSMENU_ITEM(item, "filer", "Window", "New Window");
327 filer_new_window = GTK_BIN(item)->child;
329 panel_keys = gtk_accel_group_new();
330 MAKE_MENU(panel);
332 GET_MENU_ITEM(panel_menu, "panel");
333 GET_SSMENU_ITEM(panel_hidden_menu, "panel", "Display", "Show Hidden");
335 menurc = choices_find_path_load("menus", PROJECT);
336 if (menurc)
337 gtk_item_factory_parse_rc(menurc);
339 gtk_accel_group_lock(panel_keys);
341 pinboard_keys = gtk_accel_group_new();
342 MAKE_MENU(pinboard);
343 gtk_accel_group_lock(pinboard_keys);
344 GET_MENU_ITEM(pinboard_menu, "pinboard");
346 gtk_signal_connect(GTK_OBJECT(pinboard_menu), "unmap_event",
347 GTK_SIGNAL_FUNC(pin_menu_closed), NULL);
348 gtk_signal_connect(GTK_OBJECT(filer_menu), "unmap_event",
349 GTK_SIGNAL_FUNC(menu_closed), NULL);
350 gtk_signal_connect(GTK_OBJECT(panel_menu), "unmap_event",
351 GTK_SIGNAL_FUNC(menu_closed), NULL);
352 gtk_signal_connect(GTK_OBJECT(filer_file_menu), "unmap_event",
353 GTK_SIGNAL_FUNC(menu_closed), NULL);
355 options_sections = g_slist_prepend(options_sections, &options);
356 xterm_here_value = g_strdup("xterm");
357 option_register("xterm_here", load_xterm_here);
359 savebox = gtk_savebox_new();
360 gtk_signal_connect_object(GTK_OBJECT(savebox), "save_to_file",
361 GTK_SIGNAL_FUNC(save_to_file), NULL);
362 gtk_signal_connect_object(GTK_OBJECT(savebox), "save_done",
363 GTK_SIGNAL_FUNC(gtk_widget_hide),
364 GTK_OBJECT(savebox));
366 atexit(save_menus);
369 /* Build up some option widgets to go in the options dialog, but don't
370 * fill them in yet.
372 static GtkWidget *create_options()
374 GtkWidget *table, *label;
376 table = gtk_table_new(2, 2, FALSE);
377 gtk_container_set_border_width(GTK_CONTAINER(table), 4);
379 label = gtk_label_new(
380 _("To set the keyboard short-cuts, simply open "
381 "the menu over a filer window, move the pointer over "
382 "the item you want to use and press a key. The key "
383 "will appear next to the menu item and you can just "
384 "press that key without opening the menu in future."));
385 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
386 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1);
388 label = gtk_label_new(_("'Xterm here' program:"));
389 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
390 xterm_here_entry = gtk_entry_new();
391 gtk_table_attach_defaults(GTK_TABLE(table), xterm_here_entry,
392 1, 2, 1, 2);
394 return table;
397 static char *load_xterm_here(char *data)
399 g_free(xterm_here_value);
400 xterm_here_value = g_strdup(data);
401 return NULL;
404 static void update_options()
406 gtk_entry_set_text(GTK_ENTRY(xterm_here_entry), xterm_here_value);
409 static void set_options()
411 g_free(xterm_here_value);
412 xterm_here_value = g_strdup(gtk_entry_get_text(
413 GTK_ENTRY(xterm_here_entry)));
416 static void save_options()
418 save_menus();
419 option_write("xterm_here", xterm_here_value);
423 static void items_sensitive(gboolean state)
425 int n = 7;
426 GList *items, *item;
428 items = item = gtk_container_children(GTK_CONTAINER(filer_file_menu));
429 while (item && n--)
431 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
432 item = item->next;
434 g_list_free(items);
436 items = item = gtk_container_children(GTK_CONTAINER(filer_vfs_menu));
437 while (item)
439 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
440 item = item->next;
442 g_list_free(items);
445 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data)
447 int *pos = (int *) data;
448 GtkRequisition requisition;
450 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
452 if (pos[0] == -1)
453 *x = screen_width - MENU_MARGIN - requisition.width;
454 else if (pos[0] == -2)
455 *x = MENU_MARGIN;
456 else
457 *x = pos[0] - (requisition.width >> 2);
459 if (pos[1] == -1)
460 *y = screen_height - MENU_MARGIN - requisition.height;
461 else if (pos[1] == -2)
462 *y = MENU_MARGIN;
463 else
464 *y = pos[1] - (requisition.height >> 2);
466 *x = CLAMP(*x, 0, screen_width - requisition.width);
467 *y = CLAMP(*y, 0, screen_height - requisition.height);
470 /* Display the pinboard menu. Set icon to NULL if no particular icon
471 * was clicked.
473 void show_pinboard_menu(GdkEventButton *event, PinIcon *icon)
475 int pos[2];
476 GList *icons;
478 if (icon)
480 if (pinboard_is_selected(icon))
481 pin_temp_item_selected = FALSE;
482 else
484 pinboard_select_only(icon);
485 pin_temp_item_selected = TRUE;
489 icons = pinboard_get_selected();
491 pos[0] = event->x_root;
492 pos[1] = event->y_root;
494 if (icons)
496 set_items_shaded(pinboard_menu,
497 icons->next ? TRUE : FALSE , 0, 1);
499 set_items_shaded(pinboard_menu, FALSE, 1, 1);
501 else
502 set_items_shaded(pinboard_menu, TRUE, 0, 2);
504 gtk_menu_popup(GTK_MENU(pinboard_menu), NULL, NULL, position_menu,
505 (gpointer) pos, event->button, event->time);
508 void show_filer_menu(FilerWindow *filer_window, GdkEventButton *event,
509 int item)
511 DirItem *file_item;
512 int pos[2];
514 updating_menu++;
516 pos[0] = event->x_root;
517 pos[1] = event->y_root;
519 window_with_focus = filer_window;
521 switch (filer_window->panel_type)
523 case PANEL_TOP:
524 pos[1] = -2;
525 break;
526 case PANEL_BOTTOM:
527 pos[1] = -1;
528 break;
529 default:
530 break;
533 if (filer_window->panel_type)
534 collection_clear_selection(filer_window->collection); /* ??? */
536 if (filer_window->collection->number_selected == 0 && item >= 0)
538 collection_select_item(filer_window->collection, item);
539 filer_window->temp_item_selected = TRUE;
541 else
542 filer_window->temp_item_selected = FALSE;
544 if (filer_window->panel_type)
546 gtk_check_menu_item_set_active(
547 GTK_CHECK_MENU_ITEM(panel_hidden_menu),
548 filer_window->show_hidden);
550 else
552 GtkWidget *file_label, *file_menu;
553 Collection *collection = filer_window->collection;
554 GString *buffer;
556 file_label = filer_file_item;
557 file_menu = filer_file_menu;
558 gtk_check_menu_item_set_active(
559 GTK_CHECK_MENU_ITEM(filer_hidden_menu),
560 filer_window->show_hidden);
561 buffer = g_string_new(NULL);
562 switch (collection->number_selected)
564 case 0:
565 g_string_assign(buffer, _("Next Click"));
566 items_sensitive(TRUE);
567 break;
568 case 1:
569 items_sensitive(TRUE);
570 file_item = selected_item(
571 filer_window->collection);
572 g_string_sprintf(buffer, "%s '%s'",
573 basetype_name(file_item),
574 file_item->leafname);
575 break;
576 default:
577 items_sensitive(FALSE);
578 g_string_sprintf(buffer, _("%d items"),
579 collection->number_selected);
580 break;
582 gtk_label_set_text(GTK_LABEL(file_label), buffer->str);
583 g_string_free(buffer, TRUE);
587 gtk_widget_set_sensitive(filer_new_window, !o_unique_filer_windows);
589 if (filer_window->panel_type)
590 popup_menu = panel_menu;
591 else
592 popup_menu = (event->state & GDK_CONTROL_MASK)
593 ? filer_file_menu
594 : filer_menu;
596 updating_menu--;
598 gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, position_menu,
599 (gpointer) pos, event->button, event->time);
602 static void pin_menu_closed(GtkWidget *widget)
604 if (pin_temp_item_selected)
605 pinboard_clear_selection();
608 static void menu_closed(GtkWidget *widget)
610 if (window_with_focus == NULL || widget != popup_menu)
611 return; /* Close panel item chosen? */
613 if (window_with_focus->temp_item_selected)
615 collection_clear_selection(window_with_focus->collection);
616 window_with_focus->temp_item_selected = FALSE;
620 void target_callback(Collection *collection, gint item, gpointer real_fn)
622 g_return_if_fail(window_with_focus != NULL);
623 g_return_if_fail(window_with_focus->collection == collection);
624 g_return_if_fail(real_fn != NULL);
626 collection_wink_item(collection, item);
627 collection_clear_selection(collection);
628 collection_select_item(collection, item);
629 ((CollectionTargetFunc)real_fn)(NULL, 0, collection);
630 if (item < collection->number_of_items)
631 collection_unselect_item(collection, item);
634 /* Actions */
636 static void large(gpointer data, guint action, GtkWidget *widget)
638 g_return_if_fail(window_with_focus != NULL);
640 display_style_set(window_with_focus, LARGE_ICONS);
643 static void small(gpointer data, guint action, GtkWidget *widget)
645 g_return_if_fail(window_with_focus != NULL);
647 display_style_set(window_with_focus, SMALL_ICONS);
650 static void large_with(gpointer data, guint action, GtkWidget *widget)
652 g_return_if_fail(window_with_focus != NULL);
654 display_style_set(window_with_focus, LARGE_FULL_INFO);
655 display_details_set(window_with_focus, (DetailsType) action);
658 static void small_with(gpointer data, guint action, GtkWidget *widget)
660 g_return_if_fail(window_with_focus != NULL);
662 display_style_set(window_with_focus, SMALL_FULL_INFO);
663 display_details_set(window_with_focus, (DetailsType) action);
666 static void sort_name(gpointer data, guint action, GtkWidget *widget)
668 g_return_if_fail(window_with_focus != NULL);
670 display_set_sort_fn(window_with_focus, sort_by_name);
673 static void sort_type(gpointer data, guint action, GtkWidget *widget)
675 g_return_if_fail(window_with_focus != NULL);
677 display_set_sort_fn(window_with_focus, sort_by_type);
680 static void sort_date(gpointer data, guint action, GtkWidget *widget)
682 g_return_if_fail(window_with_focus != NULL);
684 display_set_sort_fn(window_with_focus, sort_by_date);
687 static void sort_size(gpointer data, guint action, GtkWidget *widget)
689 g_return_if_fail(window_with_focus != NULL);
691 display_set_sort_fn(window_with_focus, sort_by_size);
694 static void hidden(gpointer data, guint action, GtkWidget *widget)
696 if (updating_menu)
697 return;
699 g_return_if_fail(window_with_focus != NULL);
701 display_set_hidden(window_with_focus, !window_with_focus->show_hidden);
704 static void refresh(gpointer data, guint action, GtkWidget *widget)
706 g_return_if_fail(window_with_focus != NULL);
708 full_refresh();
709 filer_update_dir(window_with_focus, TRUE);
712 static void mount(gpointer data, guint action, GtkWidget *widget)
714 g_return_if_fail(window_with_focus != NULL);
716 if (window_with_focus->collection->number_selected == 0)
717 collection_target(window_with_focus->collection,
718 target_callback, mount);
719 else
721 GList *paths;
723 paths = list_paths(window_with_focus);
724 action_mount(paths);
725 free_paths(paths);
729 static void delete(gpointer data, guint action, GtkWidget *widget)
731 g_return_if_fail(window_with_focus != NULL);
733 if (window_with_focus->collection->number_selected == 0)
734 collection_target(window_with_focus->collection,
735 target_callback, delete);
736 else
737 action_delete(window_with_focus);
740 static void remove_link(gpointer data, guint action, GtkWidget *widget)
742 g_return_if_fail(window_with_focus != NULL);
744 if (window_with_focus->collection->number_selected > 1)
746 report_error(PROJECT,
747 _("You can only remove one link at a time"));
748 return;
750 else if (window_with_focus->collection->number_selected == 0)
751 collection_target(window_with_focus->collection,
752 target_callback, remove_link);
753 else
755 struct stat info;
756 DirItem *item;
757 guchar *path;
759 item = selected_item(window_with_focus->collection);
761 path = make_path(window_with_focus->path, item->leafname)->str;
762 if (lstat(path, &info))
763 report_error(PROJECT, g_strerror(errno));
764 else if (!S_ISLNK(info.st_mode))
765 report_error(PROJECT,
766 _("You can only remove symbolic links this way - "
767 "try the 'Open Panel as Directory' item."));
768 else if (unlink(path))
769 report_error(PROJECT, g_strerror(errno));
770 else
771 filer_update_dir(window_with_focus, TRUE);
775 static void usage(gpointer data, guint action, GtkWidget *widget)
777 g_return_if_fail(window_with_focus != NULL);
779 if (window_with_focus->collection->number_selected == 0)
780 collection_target(window_with_focus->collection,
781 target_callback, usage);
782 else
783 action_usage(window_with_focus);
786 static void chmod_items(gpointer data, guint action, GtkWidget *widget)
788 g_return_if_fail(window_with_focus != NULL);
790 if (window_with_focus->collection->number_selected == 0)
791 collection_target(window_with_focus->collection,
792 target_callback, chmod_items);
793 else
794 action_chmod(window_with_focus);
797 static void find(gpointer data, guint action, GtkWidget *widget)
799 g_return_if_fail(window_with_focus != NULL);
801 if (window_with_focus->collection->number_selected == 0)
802 collection_target(window_with_focus->collection,
803 target_callback, find);
804 else
805 action_find(window_with_focus);
808 /* This pops up our savebox widget, cancelling any currently open one,
809 * and allows the user to pick a new path for it.
810 * Once the new path has been picked, the callback will be called with
811 * both the current and new paths.
813 static void savebox_show(guchar *title, guchar *path, MaskedPixmap *image,
814 gboolean (*callback)(guchar *current, guchar *new))
816 if (GTK_WIDGET_VISIBLE(savebox))
817 gtk_widget_hide(savebox);
819 if (current_path)
820 g_free(current_path);
821 current_path = g_strdup(path);
822 current_savebox_callback = callback;
824 gtk_window_set_title(GTK_WINDOW(savebox), title);
825 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox), current_path);
826 gtk_savebox_set_icon(GTK_SAVEBOX(savebox), image->pixmap, image->mask);
828 gtk_widget_grab_focus(GTK_SAVEBOX(savebox)->entry);
829 gtk_widget_show(savebox);
832 static gint save_to_file(GtkSavebox *savebox, guchar *pathname)
834 g_return_val_if_fail(current_savebox_callback != NULL,
835 GTK_XDS_SAVE_ERROR);
837 return current_savebox_callback(current_path, pathname)
838 ? GTK_XDS_SAVED : GTK_XDS_SAVE_ERROR;
841 static gboolean copy_cb(guchar *current, guchar *new)
843 char *new_dir, *leaf;
844 GSList *local_paths;
846 if (new[0] != '/')
848 report_error(PROJECT, _("New pathname is not absolute"));
849 return FALSE;
852 if (new[strlen(new) - 1] == '/')
854 new_dir = g_strdup(new);
855 leaf = NULL;
857 else
859 guchar *slash;
861 slash = strrchr(new, '/');
862 new_dir = g_strndup(new, slash - new);
863 leaf = slash + 1;
866 local_paths = g_slist_append(NULL, current);
867 action_copy(local_paths, new_dir, leaf);
868 g_slist_free(local_paths);
870 g_free(new_dir);
872 return TRUE;
875 #define SHOW_SAVEBOX(title, callback) \
877 DirItem *item; \
878 guchar *path; \
879 item = selected_item(collection); \
880 path = make_path(window_with_focus->path, item->leafname)->str; \
881 savebox_show(title, path, item->image, callback); \
884 static void copy_item(gpointer data, guint action, GtkWidget *widget)
886 Collection *collection;
888 g_return_if_fail(window_with_focus != NULL);
890 collection = window_with_focus->collection;
891 if (collection->number_selected > 1)
893 report_error(PROJECT, _("You cannot do this to more than "
894 "one item at a time"));
895 return;
897 else if (collection->number_selected != 1)
898 collection_target(collection, target_callback, copy_item);
899 else
900 SHOW_SAVEBOX(_("Copy"), copy_cb);
903 static gboolean rename_cb(guchar *current, guchar *new)
905 if (rename(current, new))
907 report_error("ROX-Filer: rename()", g_strerror(errno));
908 return FALSE;
910 return TRUE;
913 static void rename_item(gpointer data, guint action, GtkWidget *widget)
915 Collection *collection;
917 g_return_if_fail(window_with_focus != NULL);
919 collection = window_with_focus->collection;
920 if (collection->number_selected > 1)
922 report_error(PROJECT, _("You cannot do this to more than "
923 "one item at a time"));
924 return;
926 else if (collection->number_selected != 1)
927 collection_target(collection, target_callback, rename_item);
928 else
929 SHOW_SAVEBOX(_("Rename"), rename_cb);
932 static gboolean link_cb(guchar *initial, guchar *path)
934 if (symlink(initial, path))
936 report_error("ROX-Filer: symlink()", g_strerror(errno));
937 return FALSE;
939 return TRUE;
942 static void link_item(gpointer data, guint action, GtkWidget *widget)
944 Collection *collection;
946 g_return_if_fail(window_with_focus != NULL);
948 collection = window_with_focus->collection;
949 if (collection->number_selected > 1)
951 report_error(PROJECT, _("You cannot do this to more than "
952 "one item at a time"));
953 return;
955 else if (collection->number_selected != 1)
956 collection_target(collection, target_callback, link_item);
957 else
958 SHOW_SAVEBOX(_("Symlink"), link_cb);
961 static void open_file(gpointer data, guint action, GtkWidget *widget)
963 Collection *collection;
965 g_return_if_fail(window_with_focus != NULL);
967 collection = window_with_focus->collection;
968 if (collection->number_selected > 1)
970 report_error(PROJECT, _("You cannot do this to more than "
971 "one item at a time"));
972 return;
974 else if (collection->number_selected != 1)
975 collection_target(collection, target_callback, open_file);
976 else
977 filer_openitem(window_with_focus,
978 selected_item_number(collection),
979 OPEN_SAME_WINDOW | OPEN_SHIFT);
982 /* Got some data from file(1) - stick it in the window. */
983 static void add_file_output(FileStatus *fs,
984 gint source, GdkInputCondition condition)
986 char buffer[20];
987 char *str;
988 int got;
990 got = read(source, buffer, sizeof(buffer) - 1);
991 if (got <= 0)
993 int err = errno;
994 gtk_input_remove(fs->input);
995 close(source);
996 fs->fd = -1;
997 if (got < 0)
998 delayed_error(_("ROX-Filer: file(1) says..."),
999 g_strerror(err));
1000 return;
1002 buffer[got] = '\0';
1004 if (fs->start)
1006 str = "";
1007 fs->start = FALSE;
1009 else
1010 gtk_label_get(fs->label, &str);
1012 str = g_strconcat(str, buffer, NULL);
1013 gtk_label_set_text(fs->label, str);
1014 g_free(str);
1017 static void file_info_destroyed(GtkWidget *widget, FileStatus *fs)
1019 if (fs->fd != -1)
1021 gtk_input_remove(fs->input);
1022 close(fs->fd);
1025 g_free(fs);
1028 /* g_free() the result */
1029 guchar *pretty_type(DirItem *file, guchar *path)
1031 if (file->flags & ITEM_FLAG_SYMLINK)
1033 char p[MAXPATHLEN + 1];
1034 int got;
1035 got = readlink(path, p, MAXPATHLEN);
1036 if (got > 0 && got <= MAXPATHLEN)
1038 p[got] = '\0';
1039 return g_strconcat(_("Symbolic link to "), p, NULL);
1042 return g_strdup(_("Symbolic link"));
1045 if (file->flags & ITEM_FLAG_EXEC_FILE)
1046 return g_strdup(_("Executable file"));
1048 if (file->flags & ITEM_FLAG_APPDIR)
1049 return g_strdup(_("ROX application"));
1051 if (file->flags & ITEM_FLAG_MOUNT_POINT)
1053 MountPoint *mp;
1054 if ((file->flags & ITEM_FLAG_MOUNTED) &&
1055 (mp = g_hash_table_lookup(mtab_mounts, path)))
1056 return g_strconcat(_("Mount point for "),
1057 mp->name, NULL);
1059 return g_strdup(_("Mount point"));
1062 if (file->mime_type)
1063 return g_strconcat(file->mime_type->media_type, "/",
1064 file->mime_type->subtype, NULL);
1066 return g_strdup("-");
1069 #define LABEL(text, row) \
1070 label = gtk_label_new(text); \
1071 gtk_misc_set_alignment(GTK_MISC(label), 1, .5); \
1072 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); \
1073 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, row, row + 1);
1075 #define VALUE(label, row) \
1076 gtk_misc_set_alignment(GTK_MISC(label), 0, .5); \
1077 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, row, row + 1);
1079 static void show_file_info(gpointer data, guint action, GtkWidget *widget)
1081 GtkWidget *window, *table, *label, *button, *frame, *value;
1082 GtkWidget *file_label;
1083 GString *gstring;
1084 int file_data[2];
1085 guchar *path, *tmp;
1086 char *argv[] = {"file", "-b", NULL, NULL};
1087 Collection *collection;
1088 DirItem *file;
1089 struct stat info;
1090 FileStatus *fs = NULL;
1091 guint perm;
1093 g_return_if_fail(window_with_focus != NULL);
1095 collection = window_with_focus->collection;
1096 if (collection->number_selected > 1)
1098 report_error(PROJECT, _("You cannot do this to more than "
1099 "one item at a time"));
1100 return;
1102 else if (collection->number_selected != 1)
1104 collection_target(collection, target_callback, show_file_info);
1105 return;
1107 file = selected_item(collection);
1108 path = make_path(window_with_focus->path,
1109 file->leafname)->str;
1110 if (lstat(path, &info))
1112 delayed_error(PROJECT, g_strerror(errno));
1113 return;
1116 gstring = g_string_new(NULL);
1118 window = gtk_window_new(GTK_WINDOW_DIALOG);
1119 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
1120 gtk_container_set_border_width(GTK_CONTAINER(window), 4);
1121 gtk_window_set_title(GTK_WINDOW(window), path);
1123 table = gtk_table_new(10, 2, FALSE);
1124 gtk_container_add(GTK_CONTAINER(window), table);
1125 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
1126 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
1128 value = gtk_label_new(file->leafname);
1129 LABEL(_("Name:"), 0);
1130 VALUE(value, 0);
1132 g_string_sprintf(gstring, "%s, %s", user_name(info.st_uid),
1133 group_name(info.st_gid));
1134 value = gtk_label_new(gstring->str);
1135 LABEL(_("Owner, Group:"), 1);
1136 VALUE(value, 1);
1138 if (info.st_size >= PRETTY_SIZE_LIMIT)
1140 g_string_sprintf(gstring, "%s (%ld %s)",
1141 format_size((unsigned long) info.st_size),
1142 (unsigned long) info.st_size, _("bytes"));
1144 else
1146 g_string_assign(gstring,
1147 format_size((unsigned long) info.st_size));
1149 value = gtk_label_new(gstring->str);
1150 LABEL(_("Size:"), 2);
1151 VALUE(value, 2);
1153 value = gtk_label_new(pretty_time(&info.st_ctime));
1154 LABEL(_("Change time:"), 3);
1155 VALUE(value, 3);
1157 value = gtk_label_new(pretty_time(&info.st_mtime));
1158 LABEL(_("Modify time:"), 4);
1159 VALUE(value, 4);
1161 value = gtk_label_new(pretty_time(&info.st_atime));
1162 LABEL(_("Access time:"), 5);
1163 VALUE(value, 5);
1165 value = gtk_label_new(pretty_permissions(info.st_mode));
1166 perm = applicable(info.st_uid, info.st_gid);
1167 gtk_label_set_pattern(GTK_LABEL(value),
1168 perm == 0 ? "___ " :
1169 perm == 1 ? " ___ " :
1170 " ___");
1171 gtk_widget_set_style(value, fixed_style);
1172 LABEL(_("Permissions:"), 6);
1173 VALUE(value, 6);
1175 tmp = pretty_type(file, path);
1176 value = gtk_label_new(tmp);
1177 g_free(tmp);
1178 LABEL(_("Type:"), 7);
1179 VALUE(value, 7);
1181 frame = gtk_frame_new(_("file(1) says..."));
1182 gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 2, 8, 9);
1183 file_label = gtk_label_new(_("<nothing yet>"));
1184 gtk_misc_set_padding(GTK_MISC(file_label), 4, 4);
1185 gtk_label_set_line_wrap(GTK_LABEL(file_label), TRUE);
1186 gtk_container_add(GTK_CONTAINER(frame), file_label);
1188 button = gtk_button_new_with_label(_("OK"));
1189 gtk_window_set_focus(GTK_WINDOW(window), button);
1190 gtk_table_attach(GTK_TABLE(table), button, 0, 2, 10, 11,
1191 GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 40, 4);
1192 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
1193 gtk_widget_destroy, GTK_OBJECT(window));
1195 gtk_widget_show_all(window);
1196 gdk_flush();
1198 if (pipe(file_data))
1200 g_string_sprintf(gstring, "pipe(): %s", g_strerror(errno));
1201 g_string_free(gstring, TRUE);
1202 return;
1204 switch (fork())
1206 case -1:
1207 g_string_sprintf(gstring, "fork(): %s",
1208 g_strerror(errno));
1209 gtk_label_set_text(GTK_LABEL(file_label), gstring->str);
1210 g_string_free(gstring, TRUE);
1211 close(file_data[0]);
1212 close(file_data[1]);
1213 break;
1214 case 0:
1215 /* We are the child */
1216 close(file_data[0]);
1217 dup2(file_data[1], STDOUT_FILENO);
1218 dup2(file_data[1], STDERR_FILENO);
1219 #ifdef FILE_B_FLAG
1220 argv[2] = path;
1221 #else
1222 argv[1] = file->leafname;
1223 chdir(window_with_focus->path);
1224 #endif
1225 if (execvp(argv[0], argv))
1226 fprintf(stderr, "execvp() error: %s\n",
1227 g_strerror(errno));
1228 _exit(0);
1229 default:
1230 /* We are the parent */
1231 close(file_data[1]);
1232 fs = g_new(FileStatus, 1);
1233 fs->label = GTK_LABEL(file_label);
1234 fs->fd = file_data[0];
1235 fs->start = TRUE;
1236 fs->input = gdk_input_add(fs->fd, GDK_INPUT_READ,
1237 (GdkInputFunction) add_file_output, fs);
1238 gtk_signal_connect(GTK_OBJECT(window), "destroy",
1239 GTK_SIGNAL_FUNC(file_info_destroyed), fs);
1240 g_string_free(gstring, TRUE);
1241 break;
1245 static void help(gpointer data, guint action, GtkWidget *widget)
1247 Collection *collection;
1248 DirItem *item;
1250 g_return_if_fail(window_with_focus != NULL);
1252 collection = window_with_focus->collection;
1253 if (collection->number_selected > 1)
1255 report_error(PROJECT, _("You cannot do this to more than "
1256 "one item at a time"));
1257 return;
1259 else if (collection->number_selected != 1)
1261 collection_target(collection, target_callback, help);
1262 return;
1264 item = selected_item(collection);
1266 show_item_help(make_path(window_with_focus->path, item->leafname)->str,
1267 item);
1270 #define OPEN_VFS(fs) \
1271 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1273 Collection *collection; \
1275 g_return_if_fail(window_with_focus != NULL); \
1277 collection = window_with_focus->collection; \
1278 if (collection->number_selected < 1) \
1279 collection_target(collection, target_callback, \
1280 open_vfs_ ## fs); \
1281 else \
1282 real_vfs_open(#fs); \
1285 static void real_vfs_open(char *fs)
1287 gchar *path;
1288 DirItem *item;
1290 if (window_with_focus->collection->number_selected != 1)
1292 report_error(PROJECT, _("You must select a single file "
1293 "to open as a Virtual File System"));
1294 return;
1297 item = selected_item(window_with_focus->collection);
1299 path = g_strconcat(window_with_focus->path,
1300 "/",
1301 item->leafname,
1302 "#", fs, NULL);
1304 filer_change_to(window_with_focus, path, NULL);
1305 g_free(path);
1308 OPEN_VFS(rpm)
1309 OPEN_VFS(utar)
1310 OPEN_VFS(uzip)
1312 static void select_all(gpointer data, guint action, GtkWidget *widget)
1314 g_return_if_fail(window_with_focus != NULL);
1316 collection_select_all(window_with_focus->collection);
1317 window_with_focus->temp_item_selected = FALSE;
1320 static void clear_selection(gpointer data, guint action, GtkWidget *widget)
1322 g_return_if_fail(window_with_focus != NULL);
1324 collection_clear_selection(window_with_focus->collection);
1325 window_with_focus->temp_item_selected = FALSE;
1328 static void show_options(gpointer data, guint action, GtkWidget *widget)
1330 options_show();
1333 static gboolean new_directory_cb(guchar *initial, guchar *path)
1335 if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO))
1337 report_error("mkdir", g_strerror(errno));
1338 return FALSE;
1340 return TRUE;
1343 static void new_directory(gpointer data, guint action, GtkWidget *widget)
1345 g_return_if_fail(window_with_focus != NULL);
1347 savebox_show(_("New Directory"),
1348 make_path(window_with_focus->path, _("NewDir"))->str,
1349 type_to_icon(&special_directory),
1350 new_directory_cb);
1353 static void xterm_here(gpointer data, guint action, GtkWidget *widget)
1355 char *argv[] = {NULL, NULL};
1357 argv[0] = xterm_here_value;
1359 g_return_if_fail(window_with_focus != NULL);
1361 if (!spawn_full(argv, window_with_focus->path))
1362 report_error(PROJECT, "Failed to fork() child "
1363 "process");
1366 static void open_parent(gpointer data, guint action, GtkWidget *widget)
1368 g_return_if_fail(window_with_focus != NULL);
1370 filer_open_parent(window_with_focus);
1373 static void open_parent_same(gpointer data, guint action, GtkWidget *widget)
1375 g_return_if_fail(window_with_focus != NULL);
1377 change_to_parent(window_with_focus);
1380 static void new_window(gpointer data, guint action, GtkWidget *widget)
1382 g_return_if_fail(window_with_focus != NULL);
1384 if (o_unique_filer_windows)
1385 report_error(PROJECT, _("You can't open a second view onto "
1386 "this directory because the `Unique Windows' option "
1387 "is turned on in the Options window."));
1388 else
1389 filer_opendir(window_with_focus->path, PANEL_NO);
1392 static void close_window(gpointer data, guint action, GtkWidget *widget)
1394 g_return_if_fail(window_with_focus != NULL);
1396 gtk_widget_destroy(window_with_focus->window);
1399 static void enter_path(gpointer data, guint action, GtkWidget *widget)
1401 g_return_if_fail(window_with_focus != NULL);
1403 minibuffer_show(window_with_focus, MINI_PATH);
1406 static void shell_command(gpointer data, guint action, GtkWidget *widget)
1408 g_return_if_fail(window_with_focus != NULL);
1410 minibuffer_show(window_with_focus, MINI_SHELL);
1413 static void run_action(gpointer data, guint action, GtkWidget *widget)
1415 g_return_if_fail(window_with_focus != NULL);
1417 minibuffer_show(window_with_focus, MINI_RUN_ACTION);
1420 static void select_if(gpointer data, guint action, GtkWidget *widget)
1422 g_return_if_fail(window_with_focus != NULL);
1424 minibuffer_show(window_with_focus, MINI_SELECT_IF);
1427 void rox_help(gpointer data, guint action, GtkWidget *widget)
1429 filer_opendir(make_path(getenv("APP_DIR"), "Help")->str, PANEL_NO);
1432 static void open_as_dir(gpointer data, guint action, GtkWidget *widget)
1434 g_return_if_fail(window_with_focus != NULL);
1436 filer_opendir(window_with_focus->path, PANEL_NO);
1439 static void close_panel(gpointer data, guint action, GtkWidget *widget)
1441 g_return_if_fail(window_with_focus != NULL);
1443 gtk_widget_destroy(window_with_focus->window);
1446 /* Return a list of full paths of all the selected items */
1447 static GList *list_paths(FilerWindow *filer_window)
1449 Collection *collection = filer_window->collection;
1450 GList *paths = NULL;
1451 int i;
1453 for (i = 0; i < collection->number_of_items; i++)
1455 CollectionItem *colitem = &collection->items[i];
1457 if (colitem->selected)
1459 DirItem *item = (DirItem *) colitem->data;
1461 paths = g_list_prepend(paths,
1462 g_strdup(make_path(filer_window->path,
1463 item->leafname)->str));
1467 return paths;
1470 static void free_paths(GList *paths)
1472 GList *next;
1474 if (!paths)
1475 return;
1477 for (next = paths; next; next = next->next)
1478 g_free(next->data);
1480 g_list_free(paths);
1483 static void pin_help(gpointer data, guint action, GtkWidget *widget)
1485 PinIcon *icon;
1487 icon = pinboard_selected_icon();
1489 if (icon)
1490 pinboard_show_help(icon);
1491 else
1492 delayed_error(PROJECT,
1493 _("You must first select a single pinned icon to get "
1494 "help on."));
1497 static void pin_remove(gpointer data, guint action, GtkWidget *widget)
1499 pinboard_unpin_selection();
1502 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1503 static void set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n)
1505 GList *items, *item;
1507 items = gtk_container_children(GTK_CONTAINER(menu));
1509 item = g_list_nth(items, from);
1510 while (item && n--)
1512 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, !shaded);
1513 item = item->next;
1515 g_list_free(items);
1518 static void save_menus(void)
1520 char *menurc;
1522 menurc = choices_find_path_save("menus", PROJECT, TRUE);
1523 if (menurc)
1524 gtk_item_factory_dump_rc(menurc, NULL, TRUE);