r337: The new display styles can now be saved as the defaults (bug spotted by
[rox-filer/ma.git] / ROX-Filer / src / menu.c
blob36c12b6e18acabbd8384f605a6ea73c5a541060d
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"
51 #include "main.h"
53 #define C_ "<control>"
55 #define MENU_MARGIN 32
57 GtkAccelGroup *filer_keys;
58 GtkAccelGroup *panel_keys;
59 GtkAccelGroup *pinboard_keys;
61 GtkWidget *popup_menu = NULL; /* Currently open menu */
63 static gint updating_menu = 0; /* Non-zero => ignore activations */
65 /* Options */
66 static GtkWidget *xterm_here_entry;
67 static char *xterm_here_value;
69 /* TRUE if we selected an icon automatically when the menu was opened */
70 static gboolean pin_temp_item_selected;
72 /* Static prototypes */
74 static void save_menus(void);
75 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data);
76 static void pin_menu_closed(GtkWidget *widget);
77 static void menu_closed(GtkWidget *widget);
78 static void items_sensitive(gboolean state);
79 static char *load_xterm_here(char *data);
80 static void savebox_show(guchar *title, guchar *path, MaskedPixmap *image,
81 gboolean (*callback)(guchar *current, guchar *new));
82 static gint save_to_file(GtkSavebox *savebox, guchar *pathname);
83 static GList *list_paths(FilerWindow *filer_window);
84 static void free_paths(GList *paths);
86 /* Note that for most of these callbacks none of the arguments are used. */
87 static void large(gpointer data, guint action, GtkWidget *widget);
88 static void small(gpointer data, guint action, GtkWidget *widget);
90 /* (action used in these two - (DetailsType) */
91 static void large_with(gpointer data, guint action, GtkWidget *widget);
92 static void small_with(gpointer data, guint action, GtkWidget *widget);
94 static void sort_name(gpointer data, guint action, GtkWidget *widget);
95 static void sort_type(gpointer data, guint action, GtkWidget *widget);
96 static void sort_size(gpointer data, guint action, GtkWidget *widget);
97 static void sort_date(gpointer data, guint action, GtkWidget *widget);
99 static void hidden(gpointer data, guint action, GtkWidget *widget);
100 static void refresh(gpointer data, guint action, GtkWidget *widget);
102 static void copy_item(gpointer data, guint action, GtkWidget *widget);
103 static void rename_item(gpointer data, guint action, GtkWidget *widget);
104 static void link_item(gpointer data, guint action, GtkWidget *widget);
105 static void open_file(gpointer data, guint action, GtkWidget *widget);
106 static void help(gpointer data, guint action, GtkWidget *widget);
107 static void show_file_info(gpointer data, guint action, GtkWidget *widget);
108 static void mount(gpointer data, guint action, GtkWidget *widget);
109 static void delete(gpointer data, guint action, GtkWidget *widget);
110 static void remove_link(gpointer data, guint action, GtkWidget *widget);
111 static void usage(gpointer data, guint action, GtkWidget *widget);
112 static void chmod_items(gpointer data, guint action, GtkWidget *widget);
113 static void find(gpointer data, guint action, GtkWidget *widget);
115 static void open_vfs_rpm(gpointer data, guint action, GtkWidget *widget);
116 static void open_vfs_utar(gpointer data, guint action, GtkWidget *widget);
117 static void open_vfs_uzip(gpointer data, guint action, GtkWidget *widget);
119 static void select_all(gpointer data, guint action, GtkWidget *widget);
120 static void clear_selection(gpointer data, guint action, GtkWidget *widget);
121 static void show_options(gpointer data, guint action, GtkWidget *widget);
122 static void new_directory(gpointer data, guint action, GtkWidget *widget);
123 static void xterm_here(gpointer data, guint action, GtkWidget *widget);
125 static void open_parent_same(gpointer data, guint action, GtkWidget *widget);
126 static void open_parent(gpointer data, guint action, GtkWidget *widget);
127 static void new_window(gpointer data, guint action, GtkWidget *widget);
128 static void close_window(gpointer data, guint action, GtkWidget *widget);
129 static void enter_path(gpointer data, guint action, GtkWidget *widget);
130 static void shell_command(gpointer data, guint action, GtkWidget *widget);
131 static void run_action(gpointer data, guint action, GtkWidget *widget);
132 static void select_if(gpointer data, guint action, GtkWidget *widget);
133 static void rox_help(gpointer data, guint action, GtkWidget *widget);
135 static void open_as_dir(gpointer data, guint action, GtkWidget *widget);
136 static void close_panel(gpointer data, guint action, GtkWidget *widget);
138 static void pin_help(gpointer data, guint action, GtkWidget *widget);
139 static void pin_remove(gpointer data, guint action, GtkWidget *widget);
141 static void set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n);
143 static GtkWidget *create_options();
144 static void update_options();
145 static void set_options();
146 static void save_options();
148 static OptionsSection options =
150 N_("Menu options"),
151 create_options,
152 update_options,
153 set_options,
154 save_options
158 static GtkWidget *filer_menu; /* The popup filer menu */
159 static GtkWidget *filer_file_item; /* The File '' label */
160 static GtkWidget *filer_file_menu; /* The File '' menu */
161 static GtkWidget *filer_vfs_menu; /* The Open VFS menu */
162 static GtkWidget *filer_hidden_menu; /* The Show Hidden item */
163 static GtkWidget *filer_new_window; /* The New Window item */
164 static GtkWidget *panel_menu; /* The popup panel menu */
165 static GtkWidget *panel_hidden_menu; /* The Show Hidden item */
166 static GtkWidget *pinboard_menu; /* The popup pinboard menu */
168 /* Used for Copy, etc */
169 static GtkWidget *savebox = NULL;
170 static guchar *current_path = NULL;
171 static gboolean (*current_savebox_callback)(guchar *current, guchar *new);
173 #undef N_
174 #define N_(x) x
176 static GtkItemFactoryEntry filer_menu_def[] = {
177 {N_("Display"), NULL, NULL, 0, "<Branch>"},
178 {">" N_("Large Icons"), NULL, large, 0, NULL},
179 {">" N_("Small Icons"), NULL, small, 0, NULL},
180 {">" N_("Large, With..."), NULL, NULL, 0, "<Branch>"},
181 {">>" N_("Summary"), NULL, large_with, DETAILS_SUMMARY, NULL},
182 {">>" N_("Sizes"), NULL, large_with, DETAILS_SIZE, NULL},
183 {">>" N_("Size Bars"), NULL, large_with, DETAILS_SIZE_BARS, NULL},
184 {">" N_("Small, With..."), NULL, NULL, 0, "<Branch>"},
185 {">>" N_("Summary"), NULL, small_with, DETAILS_SUMMARY, NULL},
186 {">>" N_("Sizes"), NULL, small_with, DETAILS_SIZE, NULL},
187 {">>" N_("Size Bars"), NULL, small_with, DETAILS_SIZE_BARS, NULL},
188 {">", NULL, NULL, 0, "<Separator>"},
189 {">" N_("Sort by Name"), NULL, sort_name, 0, NULL},
190 {">" N_("Sort by Type"), NULL, sort_type, 0, NULL},
191 {">" N_("Sort by Date"), NULL, sort_date, 0, NULL},
192 {">" N_("Sort by Size"), NULL, sort_size, 0, NULL},
193 {">", NULL, NULL, 0, "<Separator>"},
194 {">" N_("Show Hidden"), NULL, hidden, 0, "<ToggleItem>"},
195 {">" N_("Refresh"), NULL, refresh, 0, NULL},
196 {N_("File"), NULL, NULL, 0, "<Branch>"},
197 {">" N_("Copy..."), NULL, copy_item, 0, NULL},
198 {">" N_("Rename..."), NULL, rename_item, 0, NULL},
199 {">" N_("Link..."), NULL, link_item, 0, NULL},
200 {">" N_("Shift Open"), NULL, open_file, 0, NULL},
201 {">" N_("Help"), NULL, help, 0, NULL},
202 {">" N_("Info"), NULL, show_file_info, 0, NULL},
203 {">" N_("Open VFS"), NULL, NULL, 0, "<Branch>"},
204 {">>" N_("Unzip"), NULL, open_vfs_uzip, 0, NULL},
205 {">>" N_("Untar"), NULL, open_vfs_utar, 0, NULL},
206 {">>" N_("RPM"), NULL, open_vfs_rpm, 0, NULL},
207 {">", NULL, NULL, 0, "<Separator>"},
208 {">" N_("Mount"), NULL, mount, 0, NULL},
209 {">" N_("Delete"), NULL, delete, 0, NULL},
210 {">" N_("Disk Usage"), NULL, usage, 0, NULL},
211 {">" N_("Permissions"), NULL, chmod_items, 0, NULL},
212 {">" N_("Find"), NULL, find, 0, NULL},
213 {N_("Select All"), NULL, select_all, 0, NULL},
214 {N_("Clear Selection"), NULL, clear_selection, 0, NULL},
215 {N_("Options..."), NULL, show_options, 0, NULL},
216 {N_("New Directory..."), NULL, new_directory, 0, NULL},
217 {N_("Xterm Here"), NULL, xterm_here, 0, NULL},
218 {N_("Window"), NULL, NULL, 0, "<Branch>"},
219 {">" N_("Parent, New Window"), NULL, open_parent, 0, NULL},
220 {">" N_("Parent, Same Window"), NULL, open_parent_same, 0, NULL},
221 {">" N_("New Window"), NULL, new_window, 0, NULL},
222 {">" N_("Close Window"), NULL, close_window, 0, NULL},
223 {">", NULL, NULL, 0, "<Separator>"},
224 {">" N_("Enter Path..."), NULL, enter_path, 0, NULL},
225 {">" N_("Shell Command..."), NULL, shell_command, 0, NULL},
226 {">" N_("Set Run Action..."), NULL, run_action, 0, NULL},
227 {">" N_("Select If..."), NULL, select_if, 0, NULL},
228 {">", NULL, NULL, 0, "<Separator>"},
229 {">" N_("Show ROX-Filer Help"), NULL, rox_help, 0, NULL},
232 static GtkItemFactoryEntry panel_menu_def[] = {
233 {N_("Display"), NULL, NULL, 0, "<Branch>"},
234 {">" N_("Sort by Name"), NULL, sort_name, 0, NULL},
235 {">" N_("Sort by Type"), NULL, sort_type, 0, NULL},
236 {">" N_("Sort by Date"), NULL, sort_date, 0, NULL},
237 {">" N_("Sort by Size"), NULL, sort_size, 0, NULL},
238 {">", NULL, NULL, 0, "<Separator>"},
239 {">" N_("Show Hidden"), NULL, hidden, 0, "<ToggleItem>"},
240 {">" N_("Refresh"), NULL, refresh, 0, NULL},
241 {N_("Open Panel as Directory"), NULL, open_as_dir, 0, NULL},
242 {N_("Close Panel"), NULL, close_panel, 0, NULL},
243 {"", NULL, NULL, 0, "<Separator>"},
244 {N_("ROX-Filer Help"), NULL, rox_help, 0, NULL},
245 {N_("ROX-Filer Options..."), NULL, show_options, 0, NULL},
246 {"", NULL, NULL, 0, "<Separator>"},
247 {N_("Show Help"), NULL, help, 0, NULL},
248 {N_("Remove Item"), NULL, remove_link, 0, NULL},
251 static GtkItemFactoryEntry pinboard_menu_def[] = {
252 {N_("Show Help"), NULL, pin_help, 0, NULL},
253 {N_("Remove Item(s)"), NULL, pin_remove, 0, NULL},
254 {"", NULL, NULL, 0, "<Separator>"},
255 {N_("ROX-Filer Help"), NULL, rox_help, 0, NULL},
256 {N_("ROX-Filer Options..."), NULL, show_options, 0, NULL},
260 typedef struct _FileStatus FileStatus;
262 /* This is for the 'file(1) says...' thing */
263 struct _FileStatus
265 int fd; /* FD to read from, -1 if closed */
266 int input; /* Input watcher tag if fd valid */
267 GtkLabel *label; /* Widget to output to */
268 gboolean start; /* No output yet */
271 #define GET_MENU_ITEM(var, menu) \
272 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
274 #define GET_SMENU_ITEM(var, menu, sub) \
275 do { \
276 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
277 var = gtk_item_factory_get_widget(item_factory, tmp); \
278 g_free(tmp); \
279 } while (0)
281 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
282 do { \
283 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
284 var = gtk_item_factory_get_widget(item_factory, tmp); \
285 g_free(tmp); \
286 } while (0)
288 /* Creates menu <name> from the <name>_menu_def array.
289 * The accel group <name>_keys must also have been created.
290 * All menu items are translated. Sets 'item_factory'.
292 #define MAKE_MENU(name) \
293 do { \
294 GtkItemFactoryEntry *translated; \
295 int n_entries; \
297 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, \
298 "<" #name ">", name ## _keys); \
300 n_entries = sizeof(name ## _menu_def) / sizeof(*name ## _menu_def); \
301 translated = translate_entries(name ## _menu_def, n_entries); \
302 gtk_item_factory_create_items (item_factory, n_entries, \
303 translated, NULL); \
304 free_translated_entries(translated, n_entries); \
305 } while (0)
307 void menu_init()
309 char *menurc;
310 GList *items;
311 guchar *tmp;
312 GtkWidget *item;
313 GtkItemFactory *item_factory; \
315 filer_keys = gtk_accel_group_new();
316 MAKE_MENU(filer);
318 GET_MENU_ITEM(filer_menu, "filer");
319 GET_SMENU_ITEM(filer_file_menu, "filer", "File");
320 GET_SSMENU_ITEM(filer_vfs_menu, "filer", "File", "Open VFS");
321 GET_SSMENU_ITEM(filer_hidden_menu, "filer", "Display", "Show Hidden");
323 items = gtk_container_children(GTK_CONTAINER(filer_menu));
324 filer_file_item = GTK_BIN(g_list_nth(items, 1)->data)->child;
325 g_list_free(items);
327 GET_SSMENU_ITEM(item, "filer", "Window", "New Window");
328 filer_new_window = GTK_BIN(item)->child;
330 panel_keys = gtk_accel_group_new();
331 MAKE_MENU(panel);
333 GET_MENU_ITEM(panel_menu, "panel");
334 GET_SSMENU_ITEM(panel_hidden_menu, "panel", "Display", "Show Hidden");
336 menurc = choices_find_path_load("menus", PROJECT);
337 if (menurc)
338 gtk_item_factory_parse_rc(menurc);
340 gtk_accel_group_lock(panel_keys);
342 pinboard_keys = gtk_accel_group_new();
343 MAKE_MENU(pinboard);
344 gtk_accel_group_lock(pinboard_keys);
345 GET_MENU_ITEM(pinboard_menu, "pinboard");
347 gtk_signal_connect(GTK_OBJECT(pinboard_menu), "unmap_event",
348 GTK_SIGNAL_FUNC(pin_menu_closed), NULL);
349 gtk_signal_connect(GTK_OBJECT(filer_menu), "unmap_event",
350 GTK_SIGNAL_FUNC(menu_closed), NULL);
351 gtk_signal_connect(GTK_OBJECT(panel_menu), "unmap_event",
352 GTK_SIGNAL_FUNC(menu_closed), NULL);
353 gtk_signal_connect(GTK_OBJECT(filer_file_menu), "unmap_event",
354 GTK_SIGNAL_FUNC(menu_closed), NULL);
356 options_sections = g_slist_prepend(options_sections, &options);
357 xterm_here_value = g_strdup("xterm");
358 option_register("xterm_here", load_xterm_here);
360 savebox = gtk_savebox_new();
361 gtk_signal_connect_object(GTK_OBJECT(savebox), "save_to_file",
362 GTK_SIGNAL_FUNC(save_to_file), NULL);
363 gtk_signal_connect_object(GTK_OBJECT(savebox), "save_done",
364 GTK_SIGNAL_FUNC(gtk_widget_hide),
365 GTK_OBJECT(savebox));
367 atexit(save_menus);
370 /* Build up some option widgets to go in the options dialog, but don't
371 * fill them in yet.
373 static GtkWidget *create_options()
375 GtkWidget *table, *label;
377 table = gtk_table_new(2, 2, FALSE);
378 gtk_container_set_border_width(GTK_CONTAINER(table), 4);
380 label = gtk_label_new(
381 _("To set the keyboard short-cuts, simply open "
382 "the menu over a filer window, move the pointer over "
383 "the item you want to use and press a key. The key "
384 "will appear next to the menu item and you can just "
385 "press that key without opening the menu in future."));
386 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
387 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1);
389 label = gtk_label_new(_("'Xterm here' program:"));
390 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
391 xterm_here_entry = gtk_entry_new();
392 gtk_table_attach_defaults(GTK_TABLE(table), xterm_here_entry,
393 1, 2, 1, 2);
395 return table;
398 static char *load_xterm_here(char *data)
400 g_free(xterm_here_value);
401 xterm_here_value = g_strdup(data);
402 return NULL;
405 static void update_options()
407 gtk_entry_set_text(GTK_ENTRY(xterm_here_entry), xterm_here_value);
410 static void set_options()
412 g_free(xterm_here_value);
413 xterm_here_value = g_strdup(gtk_entry_get_text(
414 GTK_ENTRY(xterm_here_entry)));
417 static void save_options()
419 save_menus();
420 option_write("xterm_here", xterm_here_value);
424 static void items_sensitive(gboolean state)
426 int n = 7;
427 GList *items, *item;
429 items = item = gtk_container_children(GTK_CONTAINER(filer_file_menu));
430 while (item && n--)
432 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
433 item = item->next;
435 g_list_free(items);
437 items = item = gtk_container_children(GTK_CONTAINER(filer_vfs_menu));
438 while (item)
440 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
441 item = item->next;
443 g_list_free(items);
446 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data)
448 int *pos = (int *) data;
449 GtkRequisition requisition;
451 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
453 if (pos[0] == -1)
454 *x = screen_width - MENU_MARGIN - requisition.width;
455 else if (pos[0] == -2)
456 *x = MENU_MARGIN;
457 else
458 *x = pos[0] - (requisition.width >> 2);
460 if (pos[1] == -1)
461 *y = screen_height - MENU_MARGIN - requisition.height;
462 else if (pos[1] == -2)
463 *y = MENU_MARGIN;
464 else
465 *y = pos[1] - (requisition.height >> 2);
467 *x = CLAMP(*x, 0, screen_width - requisition.width);
468 *y = CLAMP(*y, 0, screen_height - requisition.height);
471 /* Display the pinboard menu. Set icon to NULL if no particular icon
472 * was clicked.
474 void show_pinboard_menu(GdkEventButton *event, PinIcon *icon)
476 int pos[2];
477 GList *icons;
479 if (icon)
481 if (pinboard_is_selected(icon))
482 pin_temp_item_selected = FALSE;
483 else
485 pinboard_select_only(icon);
486 pin_temp_item_selected = TRUE;
490 icons = pinboard_get_selected();
492 pos[0] = event->x_root;
493 pos[1] = event->y_root;
495 if (icons)
497 set_items_shaded(pinboard_menu,
498 icons->next ? TRUE : FALSE , 0, 1);
500 set_items_shaded(pinboard_menu, FALSE, 1, 1);
502 else
503 set_items_shaded(pinboard_menu, TRUE, 0, 2);
505 gtk_menu_popup(GTK_MENU(pinboard_menu), NULL, NULL, position_menu,
506 (gpointer) pos, event->button, event->time);
509 void show_filer_menu(FilerWindow *filer_window, GdkEventButton *event,
510 int item)
512 DirItem *file_item;
513 int pos[2];
515 updating_menu++;
517 pos[0] = event->x_root;
518 pos[1] = event->y_root;
520 window_with_focus = filer_window;
522 switch (filer_window->panel_type)
524 case PANEL_TOP:
525 pos[1] = -2;
526 break;
527 case PANEL_BOTTOM:
528 pos[1] = -1;
529 break;
530 default:
531 break;
534 if (filer_window->panel_type)
535 collection_clear_selection(filer_window->collection); /* ??? */
537 if (filer_window->collection->number_selected == 0 && item >= 0)
539 collection_select_item(filer_window->collection, item);
540 filer_window->temp_item_selected = TRUE;
542 else
543 filer_window->temp_item_selected = FALSE;
545 if (filer_window->panel_type)
547 gtk_check_menu_item_set_active(
548 GTK_CHECK_MENU_ITEM(panel_hidden_menu),
549 filer_window->show_hidden);
551 else
553 GtkWidget *file_label, *file_menu;
554 Collection *collection = filer_window->collection;
555 GString *buffer;
557 file_label = filer_file_item;
558 file_menu = filer_file_menu;
559 gtk_check_menu_item_set_active(
560 GTK_CHECK_MENU_ITEM(filer_hidden_menu),
561 filer_window->show_hidden);
562 buffer = g_string_new(NULL);
563 switch (collection->number_selected)
565 case 0:
566 g_string_assign(buffer, _("Next Click"));
567 items_sensitive(TRUE);
568 break;
569 case 1:
570 items_sensitive(TRUE);
571 file_item = selected_item(
572 filer_window->collection);
573 g_string_sprintf(buffer, "%s '%s'",
574 basetype_name(file_item),
575 file_item->leafname);
576 break;
577 default:
578 items_sensitive(FALSE);
579 g_string_sprintf(buffer, _("%d items"),
580 collection->number_selected);
581 break;
583 gtk_label_set_text(GTK_LABEL(file_label), buffer->str);
584 g_string_free(buffer, TRUE);
588 gtk_widget_set_sensitive(filer_new_window, !o_unique_filer_windows);
590 if (filer_window->panel_type)
591 popup_menu = panel_menu;
592 else
593 popup_menu = (event->state & GDK_CONTROL_MASK)
594 ? filer_file_menu
595 : filer_menu;
597 updating_menu--;
599 gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, position_menu,
600 (gpointer) pos, event->button, event->time);
603 static void pin_menu_closed(GtkWidget *widget)
605 if (pin_temp_item_selected)
606 pinboard_clear_selection();
609 static void menu_closed(GtkWidget *widget)
611 if (window_with_focus == NULL || widget != popup_menu)
612 return; /* Close panel item chosen? */
614 popup_menu = NULL;
616 if (window_with_focus->temp_item_selected)
618 collection_clear_selection(window_with_focus->collection);
619 window_with_focus->temp_item_selected = FALSE;
623 void target_callback(Collection *collection, gint item, gpointer real_fn)
625 g_return_if_fail(window_with_focus != NULL);
626 g_return_if_fail(window_with_focus->collection == collection);
627 g_return_if_fail(real_fn != NULL);
629 collection_wink_item(collection, item);
630 collection_clear_selection(collection);
631 collection_select_item(collection, item);
632 ((CollectionTargetFunc)real_fn)(NULL, 0, collection);
633 if (item < collection->number_of_items)
634 collection_unselect_item(collection, item);
637 /* Actions */
639 static void large(gpointer data, guint action, GtkWidget *widget)
641 g_return_if_fail(window_with_focus != NULL);
643 display_set_layout(window_with_focus, "Large");
646 static void small(gpointer data, guint action, GtkWidget *widget)
648 g_return_if_fail(window_with_focus != NULL);
650 display_set_layout(window_with_focus, "Small");
653 static void set_layout(gboolean large, DetailsType details)
655 guchar *style;
657 g_return_if_fail(window_with_focus != NULL);
659 style = g_strdup_printf("%s+%s",
660 large ? "Large" : "Small",
661 details == DETAILS_SUMMARY ? "Summary" :
662 details == DETAILS_SIZE_BARS ? "SizeBars" :
663 "Sizes");
665 display_set_layout(window_with_focus, style);
666 g_free(style);
669 static void large_with(gpointer data, guint action, GtkWidget *widget)
671 set_layout(TRUE, (DetailsType) action);
674 static void small_with(gpointer data, guint action, GtkWidget *widget)
676 set_layout(FALSE, (DetailsType) action);
679 static void sort_name(gpointer data, guint action, GtkWidget *widget)
681 g_return_if_fail(window_with_focus != NULL);
683 display_set_sort_fn(window_with_focus, sort_by_name);
686 static void sort_type(gpointer data, guint action, GtkWidget *widget)
688 g_return_if_fail(window_with_focus != NULL);
690 display_set_sort_fn(window_with_focus, sort_by_type);
693 static void sort_date(gpointer data, guint action, GtkWidget *widget)
695 g_return_if_fail(window_with_focus != NULL);
697 display_set_sort_fn(window_with_focus, sort_by_date);
700 static void sort_size(gpointer data, guint action, GtkWidget *widget)
702 g_return_if_fail(window_with_focus != NULL);
704 display_set_sort_fn(window_with_focus, sort_by_size);
707 static void hidden(gpointer data, guint action, GtkWidget *widget)
709 if (updating_menu)
710 return;
712 g_return_if_fail(window_with_focus != NULL);
714 display_set_hidden(window_with_focus, !window_with_focus->show_hidden);
717 static void refresh(gpointer data, guint action, GtkWidget *widget)
719 g_return_if_fail(window_with_focus != NULL);
721 full_refresh();
722 filer_update_dir(window_with_focus, TRUE);
725 static void mount(gpointer data, guint action, GtkWidget *widget)
727 g_return_if_fail(window_with_focus != NULL);
729 if (window_with_focus->collection->number_selected == 0)
730 collection_target(window_with_focus->collection,
731 target_callback, mount);
732 else
734 GList *paths;
736 paths = list_paths(window_with_focus);
737 action_mount(paths);
738 free_paths(paths);
742 static void delete(gpointer data, guint action, GtkWidget *widget)
744 g_return_if_fail(window_with_focus != NULL);
746 if (window_with_focus->collection->number_selected == 0)
747 collection_target(window_with_focus->collection,
748 target_callback, delete);
749 else
750 action_delete(window_with_focus);
753 static void remove_link(gpointer data, guint action, GtkWidget *widget)
755 g_return_if_fail(window_with_focus != NULL);
757 if (window_with_focus->collection->number_selected > 1)
759 report_error(PROJECT,
760 _("You can only remove one link at a time"));
761 return;
763 else if (window_with_focus->collection->number_selected == 0)
764 collection_target(window_with_focus->collection,
765 target_callback, remove_link);
766 else
768 struct stat info;
769 DirItem *item;
770 guchar *path;
772 item = selected_item(window_with_focus->collection);
774 path = make_path(window_with_focus->path, item->leafname)->str;
775 if (lstat(path, &info))
776 report_error(PROJECT, g_strerror(errno));
777 else if (!S_ISLNK(info.st_mode))
778 report_error(PROJECT,
779 _("You can only remove symbolic links this way - "
780 "try the 'Open Panel as Directory' item."));
781 else if (unlink(path))
782 report_error(PROJECT, g_strerror(errno));
783 else
784 filer_update_dir(window_with_focus, TRUE);
788 static void usage(gpointer data, guint action, GtkWidget *widget)
790 g_return_if_fail(window_with_focus != NULL);
792 if (window_with_focus->collection->number_selected == 0)
793 collection_target(window_with_focus->collection,
794 target_callback, usage);
795 else
796 action_usage(window_with_focus);
799 static void chmod_items(gpointer data, guint action, GtkWidget *widget)
801 g_return_if_fail(window_with_focus != NULL);
803 if (window_with_focus->collection->number_selected == 0)
804 collection_target(window_with_focus->collection,
805 target_callback, chmod_items);
806 else
807 action_chmod(window_with_focus);
810 static void find(gpointer data, guint action, GtkWidget *widget)
812 g_return_if_fail(window_with_focus != NULL);
814 if (window_with_focus->collection->number_selected == 0)
815 collection_target(window_with_focus->collection,
816 target_callback, find);
817 else
818 action_find(window_with_focus);
821 /* This pops up our savebox widget, cancelling any currently open one,
822 * and allows the user to pick a new path for it.
823 * Once the new path has been picked, the callback will be called with
824 * both the current and new paths.
826 static void savebox_show(guchar *title, guchar *path, MaskedPixmap *image,
827 gboolean (*callback)(guchar *current, guchar *new))
829 if (GTK_WIDGET_VISIBLE(savebox))
830 gtk_widget_hide(savebox);
832 if (current_path)
833 g_free(current_path);
834 current_path = g_strdup(path);
835 current_savebox_callback = callback;
837 gtk_window_set_title(GTK_WINDOW(savebox), title);
838 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox), current_path);
839 gtk_savebox_set_icon(GTK_SAVEBOX(savebox), image->pixmap, image->mask);
841 gtk_widget_grab_focus(GTK_SAVEBOX(savebox)->entry);
842 gtk_widget_show(savebox);
845 static gint save_to_file(GtkSavebox *savebox, guchar *pathname)
847 g_return_val_if_fail(current_savebox_callback != NULL,
848 GTK_XDS_SAVE_ERROR);
850 return current_savebox_callback(current_path, pathname)
851 ? GTK_XDS_SAVED : GTK_XDS_SAVE_ERROR;
854 static gboolean copy_cb(guchar *current, guchar *new)
856 char *new_dir, *leaf;
857 GSList *local_paths;
859 if (new[0] != '/')
861 report_error(PROJECT, _("New pathname is not absolute"));
862 return FALSE;
865 if (new[strlen(new) - 1] == '/')
867 new_dir = g_strdup(new);
868 leaf = NULL;
870 else
872 guchar *slash;
874 slash = strrchr(new, '/');
875 new_dir = g_strndup(new, slash - new);
876 leaf = slash + 1;
879 local_paths = g_slist_append(NULL, current);
880 action_copy(local_paths, new_dir, leaf);
881 g_slist_free(local_paths);
883 g_free(new_dir);
885 return TRUE;
888 #define SHOW_SAVEBOX(title, callback) \
890 DirItem *item; \
891 guchar *path; \
892 item = selected_item(collection); \
893 path = make_path(window_with_focus->path, item->leafname)->str; \
894 savebox_show(title, path, item->image, callback); \
897 static void copy_item(gpointer data, guint action, GtkWidget *widget)
899 Collection *collection;
901 g_return_if_fail(window_with_focus != NULL);
903 collection = window_with_focus->collection;
904 if (collection->number_selected > 1)
906 report_error(PROJECT, _("You cannot do this to more than "
907 "one item at a time"));
908 return;
910 else if (collection->number_selected != 1)
911 collection_target(collection, target_callback, copy_item);
912 else
913 SHOW_SAVEBOX(_("Copy"), copy_cb);
916 static gboolean rename_cb(guchar *current, guchar *new)
918 if (rename(current, new))
920 report_error("ROX-Filer: rename()", g_strerror(errno));
921 return FALSE;
923 return TRUE;
926 static void rename_item(gpointer data, guint action, GtkWidget *widget)
928 Collection *collection;
930 g_return_if_fail(window_with_focus != NULL);
932 collection = window_with_focus->collection;
933 if (collection->number_selected > 1)
935 report_error(PROJECT, _("You cannot do this to more than "
936 "one item at a time"));
937 return;
939 else if (collection->number_selected != 1)
940 collection_target(collection, target_callback, rename_item);
941 else
942 SHOW_SAVEBOX(_("Rename"), rename_cb);
945 static gboolean link_cb(guchar *initial, guchar *path)
947 if (symlink(initial, path))
949 report_error("ROX-Filer: symlink()", g_strerror(errno));
950 return FALSE;
952 return TRUE;
955 static void link_item(gpointer data, guint action, GtkWidget *widget)
957 Collection *collection;
959 g_return_if_fail(window_with_focus != NULL);
961 collection = window_with_focus->collection;
962 if (collection->number_selected > 1)
964 report_error(PROJECT, _("You cannot do this to more than "
965 "one item at a time"));
966 return;
968 else if (collection->number_selected != 1)
969 collection_target(collection, target_callback, link_item);
970 else
971 SHOW_SAVEBOX(_("Symlink"), link_cb);
974 static void open_file(gpointer data, guint action, GtkWidget *widget)
976 Collection *collection;
978 g_return_if_fail(window_with_focus != NULL);
980 collection = window_with_focus->collection;
981 if (collection->number_selected > 1)
983 report_error(PROJECT, _("You cannot do this to more than "
984 "one item at a time"));
985 return;
987 else if (collection->number_selected != 1)
988 collection_target(collection, target_callback, open_file);
989 else
990 filer_openitem(window_with_focus,
991 selected_item_number(collection),
992 OPEN_SAME_WINDOW | OPEN_SHIFT);
995 /* Got some data from file(1) - stick it in the window. */
996 static void add_file_output(FileStatus *fs,
997 gint source, GdkInputCondition condition)
999 char buffer[20];
1000 char *str;
1001 int got;
1003 got = read(source, buffer, sizeof(buffer) - 1);
1004 if (got <= 0)
1006 int err = errno;
1007 gtk_input_remove(fs->input);
1008 close(source);
1009 fs->fd = -1;
1010 if (got < 0)
1011 delayed_error(_("ROX-Filer: file(1) says..."),
1012 g_strerror(err));
1013 return;
1015 buffer[got] = '\0';
1017 if (fs->start)
1019 str = "";
1020 fs->start = FALSE;
1022 else
1023 gtk_label_get(fs->label, &str);
1025 str = g_strconcat(str, buffer, NULL);
1026 gtk_label_set_text(fs->label, str);
1027 g_free(str);
1030 static void file_info_destroyed(GtkWidget *widget, FileStatus *fs)
1032 if (fs->fd != -1)
1034 gtk_input_remove(fs->input);
1035 close(fs->fd);
1038 g_free(fs);
1041 /* g_free() the result */
1042 guchar *pretty_type(DirItem *file, guchar *path)
1044 if (file->flags & ITEM_FLAG_SYMLINK)
1046 char p[MAXPATHLEN + 1];
1047 int got;
1048 got = readlink(path, p, MAXPATHLEN);
1049 if (got > 0 && got <= MAXPATHLEN)
1051 p[got] = '\0';
1052 return g_strconcat(_("Symbolic link to "), p, NULL);
1055 return g_strdup(_("Symbolic link"));
1058 if (file->flags & ITEM_FLAG_EXEC_FILE)
1059 return g_strdup(_("Executable file"));
1061 if (file->flags & ITEM_FLAG_APPDIR)
1062 return g_strdup(_("ROX application"));
1064 if (file->flags & ITEM_FLAG_MOUNT_POINT)
1066 MountPoint *mp;
1067 if ((file->flags & ITEM_FLAG_MOUNTED) &&
1068 (mp = g_hash_table_lookup(mtab_mounts, path)))
1069 return g_strconcat(_("Mount point for "),
1070 mp->name, NULL);
1072 return g_strdup(_("Mount point"));
1075 if (file->mime_type)
1076 return g_strconcat(file->mime_type->media_type, "/",
1077 file->mime_type->subtype, NULL);
1079 return g_strdup("-");
1082 #define LABEL(text, row) \
1083 label = gtk_label_new(text); \
1084 gtk_misc_set_alignment(GTK_MISC(label), 1, .5); \
1085 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); \
1086 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, row, row + 1);
1088 #define VALUE(label, row) \
1089 gtk_misc_set_alignment(GTK_MISC(label), 0, .5); \
1090 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, row, row + 1);
1092 static void show_file_info(gpointer data, guint action, GtkWidget *widget)
1094 GtkWidget *window, *table, *label, *button, *frame, *value;
1095 GtkWidget *file_label;
1096 GString *gstring;
1097 int file_data[2];
1098 guchar *path, *tmp;
1099 char *argv[] = {"file", "-b", NULL, NULL};
1100 Collection *collection;
1101 DirItem *file;
1102 struct stat info;
1103 FileStatus *fs = NULL;
1104 guint perm;
1106 g_return_if_fail(window_with_focus != NULL);
1108 collection = window_with_focus->collection;
1109 if (collection->number_selected > 1)
1111 report_error(PROJECT, _("You cannot do this to more than "
1112 "one item at a time"));
1113 return;
1115 else if (collection->number_selected != 1)
1117 collection_target(collection, target_callback, show_file_info);
1118 return;
1120 file = selected_item(collection);
1121 path = make_path(window_with_focus->path,
1122 file->leafname)->str;
1123 if (lstat(path, &info))
1125 delayed_error(PROJECT, g_strerror(errno));
1126 return;
1129 gstring = g_string_new(NULL);
1131 window = gtk_window_new(GTK_WINDOW_DIALOG);
1132 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
1133 gtk_container_set_border_width(GTK_CONTAINER(window), 4);
1134 gtk_window_set_title(GTK_WINDOW(window), path);
1136 table = gtk_table_new(10, 2, FALSE);
1137 gtk_container_add(GTK_CONTAINER(window), table);
1138 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
1139 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
1141 value = gtk_label_new(file->leafname);
1142 LABEL(_("Name:"), 0);
1143 VALUE(value, 0);
1145 g_string_sprintf(gstring, "%s, %s", user_name(info.st_uid),
1146 group_name(info.st_gid));
1147 value = gtk_label_new(gstring->str);
1148 LABEL(_("Owner, Group:"), 1);
1149 VALUE(value, 1);
1151 if (info.st_size >= PRETTY_SIZE_LIMIT)
1153 g_string_sprintf(gstring, "%s (%ld %s)",
1154 format_size((unsigned long) info.st_size),
1155 (unsigned long) info.st_size, _("bytes"));
1157 else
1159 g_string_assign(gstring,
1160 format_size((unsigned long) info.st_size));
1162 value = gtk_label_new(gstring->str);
1163 LABEL(_("Size:"), 2);
1164 VALUE(value, 2);
1166 value = gtk_label_new(pretty_time(&info.st_ctime));
1167 LABEL(_("Change time:"), 3);
1168 VALUE(value, 3);
1170 value = gtk_label_new(pretty_time(&info.st_mtime));
1171 LABEL(_("Modify time:"), 4);
1172 VALUE(value, 4);
1174 value = gtk_label_new(pretty_time(&info.st_atime));
1175 LABEL(_("Access time:"), 5);
1176 VALUE(value, 5);
1178 value = gtk_label_new(pretty_permissions(info.st_mode));
1179 perm = applicable(info.st_uid, info.st_gid);
1180 gtk_label_set_pattern(GTK_LABEL(value),
1181 perm == 0 ? "___ " :
1182 perm == 1 ? " ___ " :
1183 " ___");
1184 gtk_widget_set_style(value, fixed_style);
1185 LABEL(_("Permissions:"), 6);
1186 VALUE(value, 6);
1188 tmp = pretty_type(file, path);
1189 value = gtk_label_new(tmp);
1190 g_free(tmp);
1191 LABEL(_("Type:"), 7);
1192 VALUE(value, 7);
1194 frame = gtk_frame_new(_("file(1) says..."));
1195 gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 2, 8, 9);
1196 file_label = gtk_label_new(_("<nothing yet>"));
1197 gtk_misc_set_padding(GTK_MISC(file_label), 4, 4);
1198 gtk_label_set_line_wrap(GTK_LABEL(file_label), TRUE);
1199 gtk_container_add(GTK_CONTAINER(frame), file_label);
1201 button = gtk_button_new_with_label(_("OK"));
1202 gtk_window_set_focus(GTK_WINDOW(window), button);
1203 gtk_table_attach(GTK_TABLE(table), button, 0, 2, 10, 11,
1204 GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 40, 4);
1205 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
1206 gtk_widget_destroy, GTK_OBJECT(window));
1208 gtk_widget_show_all(window);
1209 gdk_flush();
1211 if (pipe(file_data))
1213 g_string_sprintf(gstring, "pipe(): %s", g_strerror(errno));
1214 g_string_free(gstring, TRUE);
1215 return;
1217 switch (fork())
1219 case -1:
1220 g_string_sprintf(gstring, "fork(): %s",
1221 g_strerror(errno));
1222 gtk_label_set_text(GTK_LABEL(file_label), gstring->str);
1223 g_string_free(gstring, TRUE);
1224 close(file_data[0]);
1225 close(file_data[1]);
1226 break;
1227 case 0:
1228 /* We are the child */
1229 close(file_data[0]);
1230 dup2(file_data[1], STDOUT_FILENO);
1231 dup2(file_data[1], STDERR_FILENO);
1232 #ifdef FILE_B_FLAG
1233 argv[2] = path;
1234 #else
1235 argv[1] = file->leafname;
1236 chdir(window_with_focus->path);
1237 #endif
1238 if (execvp(argv[0], argv))
1239 fprintf(stderr, "execvp() error: %s\n",
1240 g_strerror(errno));
1241 _exit(0);
1242 default:
1243 /* We are the parent */
1244 close(file_data[1]);
1245 fs = g_new(FileStatus, 1);
1246 fs->label = GTK_LABEL(file_label);
1247 fs->fd = file_data[0];
1248 fs->start = TRUE;
1249 fs->input = gdk_input_add(fs->fd, GDK_INPUT_READ,
1250 (GdkInputFunction) add_file_output, fs);
1251 gtk_signal_connect(GTK_OBJECT(window), "destroy",
1252 GTK_SIGNAL_FUNC(file_info_destroyed), fs);
1253 g_string_free(gstring, TRUE);
1254 break;
1258 static void help(gpointer data, guint action, GtkWidget *widget)
1260 Collection *collection;
1261 DirItem *item;
1263 g_return_if_fail(window_with_focus != NULL);
1265 collection = window_with_focus->collection;
1266 if (collection->number_selected > 1)
1268 report_error(PROJECT, _("You cannot do this to more than "
1269 "one item at a time"));
1270 return;
1272 else if (collection->number_selected != 1)
1274 collection_target(collection, target_callback, help);
1275 return;
1277 item = selected_item(collection);
1279 show_item_help(make_path(window_with_focus->path, item->leafname)->str,
1280 item);
1283 #define OPEN_VFS(fs) \
1284 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1286 Collection *collection; \
1288 g_return_if_fail(window_with_focus != NULL); \
1290 collection = window_with_focus->collection; \
1291 if (collection->number_selected < 1) \
1292 collection_target(collection, target_callback, \
1293 open_vfs_ ## fs); \
1294 else \
1295 real_vfs_open(#fs); \
1298 static void real_vfs_open(char *fs)
1300 gchar *path;
1301 DirItem *item;
1303 if (window_with_focus->collection->number_selected != 1)
1305 report_error(PROJECT, _("You must select a single file "
1306 "to open as a Virtual File System"));
1307 return;
1310 item = selected_item(window_with_focus->collection);
1312 path = g_strconcat(window_with_focus->path,
1313 "/",
1314 item->leafname,
1315 "#", fs, NULL);
1317 filer_change_to(window_with_focus, path, NULL);
1318 g_free(path);
1321 OPEN_VFS(rpm)
1322 OPEN_VFS(utar)
1323 OPEN_VFS(uzip)
1325 static void select_all(gpointer data, guint action, GtkWidget *widget)
1327 g_return_if_fail(window_with_focus != NULL);
1329 collection_select_all(window_with_focus->collection);
1330 window_with_focus->temp_item_selected = FALSE;
1333 static void clear_selection(gpointer data, guint action, GtkWidget *widget)
1335 g_return_if_fail(window_with_focus != NULL);
1337 collection_clear_selection(window_with_focus->collection);
1338 window_with_focus->temp_item_selected = FALSE;
1341 static void show_options(gpointer data, guint action, GtkWidget *widget)
1343 options_show();
1346 static gboolean new_directory_cb(guchar *initial, guchar *path)
1348 if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO))
1350 report_error("mkdir", g_strerror(errno));
1351 return FALSE;
1354 dir_check_this(path);
1355 return TRUE;
1358 static void new_directory(gpointer data, guint action, GtkWidget *widget)
1360 g_return_if_fail(window_with_focus != NULL);
1362 savebox_show(_("New Directory"),
1363 make_path(window_with_focus->path, _("NewDir"))->str,
1364 type_to_icon(&special_directory),
1365 new_directory_cb);
1368 static void xterm_here(gpointer data, guint action, GtkWidget *widget)
1370 char *argv[] = {NULL, NULL};
1372 argv[0] = xterm_here_value;
1374 g_return_if_fail(window_with_focus != NULL);
1376 if (!spawn_full(argv, window_with_focus->path))
1377 report_error(PROJECT, "Failed to fork() child "
1378 "process");
1381 static void open_parent(gpointer data, guint action, GtkWidget *widget)
1383 g_return_if_fail(window_with_focus != NULL);
1385 filer_open_parent(window_with_focus);
1388 static void open_parent_same(gpointer data, guint action, GtkWidget *widget)
1390 g_return_if_fail(window_with_focus != NULL);
1392 change_to_parent(window_with_focus);
1395 static void new_window(gpointer data, guint action, GtkWidget *widget)
1397 g_return_if_fail(window_with_focus != NULL);
1399 if (o_unique_filer_windows)
1400 report_error(PROJECT, _("You can't open a second view onto "
1401 "this directory because the `Unique Windows' option "
1402 "is turned on in the Options window."));
1403 else
1404 filer_opendir(window_with_focus->path, PANEL_NO);
1407 static void close_window(gpointer data, guint action, GtkWidget *widget)
1409 g_return_if_fail(window_with_focus != NULL);
1411 gtk_widget_destroy(window_with_focus->window);
1414 static void enter_path(gpointer data, guint action, GtkWidget *widget)
1416 g_return_if_fail(window_with_focus != NULL);
1418 minibuffer_show(window_with_focus, MINI_PATH);
1421 static void shell_command(gpointer data, guint action, GtkWidget *widget)
1423 g_return_if_fail(window_with_focus != NULL);
1425 minibuffer_show(window_with_focus, MINI_SHELL);
1428 static void run_action(gpointer data, guint action, GtkWidget *widget)
1430 g_return_if_fail(window_with_focus != NULL);
1432 minibuffer_show(window_with_focus, MINI_RUN_ACTION);
1435 static void select_if(gpointer data, guint action, GtkWidget *widget)
1437 g_return_if_fail(window_with_focus != NULL);
1439 minibuffer_show(window_with_focus, MINI_SELECT_IF);
1442 void rox_help(gpointer data, guint action, GtkWidget *widget)
1444 filer_opendir(make_path(app_dir, "Help")->str, PANEL_NO);
1447 static void open_as_dir(gpointer data, guint action, GtkWidget *widget)
1449 g_return_if_fail(window_with_focus != NULL);
1451 filer_opendir(window_with_focus->path, PANEL_NO);
1454 static void close_panel(gpointer data, guint action, GtkWidget *widget)
1456 g_return_if_fail(window_with_focus != NULL);
1458 gtk_widget_destroy(window_with_focus->window);
1461 /* Return a list of full paths of all the selected items */
1462 static GList *list_paths(FilerWindow *filer_window)
1464 Collection *collection = filer_window->collection;
1465 GList *paths = NULL;
1466 int i;
1468 for (i = 0; i < collection->number_of_items; i++)
1470 CollectionItem *colitem = &collection->items[i];
1472 if (colitem->selected)
1474 DirItem *item = (DirItem *) colitem->data;
1476 paths = g_list_prepend(paths,
1477 g_strdup(make_path(filer_window->path,
1478 item->leafname)->str));
1482 return paths;
1485 static void free_paths(GList *paths)
1487 GList *next;
1489 if (!paths)
1490 return;
1492 for (next = paths; next; next = next->next)
1493 g_free(next->data);
1495 g_list_free(paths);
1498 static void pin_help(gpointer data, guint action, GtkWidget *widget)
1500 PinIcon *icon;
1502 icon = pinboard_selected_icon();
1504 if (icon)
1505 pinboard_show_help(icon);
1506 else
1507 delayed_error(PROJECT,
1508 _("You must first select a single pinned icon to get "
1509 "help on."));
1512 static void pin_remove(gpointer data, guint action, GtkWidget *widget)
1514 pinboard_unpin_selection();
1517 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1518 static void set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n)
1520 GList *items, *item;
1522 items = gtk_container_children(GTK_CONTAINER(menu));
1524 item = g_list_nth(items, from);
1525 while (item && n--)
1527 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, !shaded);
1528 item = item->next;
1530 g_list_free(items);
1533 static void save_menus(void)
1535 char *menurc;
1537 menurc = choices_find_path_save("menus", PROJECT, TRUE);
1538 if (menurc)
1539 gtk_item_factory_dump_rc(menurc, NULL, TRUE);