r350: Selecting panel icons now grabs the primary selection. Pasting pastes all
[rox-filer.git] / ROX-Filer / src / menu.c
blobd1a7801e827c2d8308c021d4d0b29a930c6fc9d7
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2000, Thomas Leonard, <tal197@users.sourceforge.net>.
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/wait.h>
28 #include <sys/param.h>
29 #include <fcntl.h>
30 #include <errno.h>
31 #include <string.h>
33 #include <gtk/gtk.h>
35 #include "global.h"
37 #include "menu.h"
38 #include "run.h"
39 #include "action.h"
40 #include "filer.h"
41 #include "pixmaps.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"
52 #include "pinboard.h"
53 #include "dir.h"
55 #define C_ "<control>"
57 typedef void (*ActionFn)(GSList *paths, char *dest_dir, char *leaf);
59 GtkAccelGroup *filer_keys;
60 GtkAccelGroup *pinboard_keys;
62 GtkWidget *popup_menu = NULL; /* Currently open menu */
64 static gint updating_menu = 0; /* Non-zero => ignore activations */
66 /* Options */
67 static GtkWidget *xterm_here_entry;
68 char *xterm_here_value;
70 /* TRUE if we selected an icon automatically when the menu was opened */
71 static gboolean pin_temp_item_selected;
73 /* Static prototypes */
75 static void save_menus(void);
76 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data);
77 static void pin_menu_closed(GtkWidget *widget);
78 static void menu_closed(GtkWidget *widget);
79 static void items_sensitive(gboolean state);
80 static char *load_xterm_here(char *data);
81 static void savebox_show(guchar *title, guchar *path, MaskedPixmap *image,
82 gboolean (*callback)(guchar *current, guchar *new));
83 static gint save_to_file(GtkSavebox *savebox, guchar *pathname);
84 static GList *list_paths(FilerWindow *filer_window);
85 static void free_paths(GList *paths);
86 static void mark_menus_modified(gboolean mod);
87 static gboolean action_with_leaf(ActionFn action, guchar *current, guchar *new);
89 /* Note that for most of these callbacks none of the arguments are used. */
90 static void large(gpointer data, guint action, GtkWidget *widget);
91 static void small(gpointer data, guint action, GtkWidget *widget);
93 /* (action used in these two - (DetailsType) */
94 static void large_with(gpointer data, guint action, GtkWidget *widget);
95 static void small_with(gpointer data, guint action, GtkWidget *widget);
97 static void sort_name(gpointer data, guint action, GtkWidget *widget);
98 static void sort_type(gpointer data, guint action, GtkWidget *widget);
99 static void sort_size(gpointer data, guint action, GtkWidget *widget);
100 static void sort_date(gpointer data, guint action, GtkWidget *widget);
102 static void hidden(gpointer data, guint action, GtkWidget *widget);
103 static void refresh(gpointer data, guint action, GtkWidget *widget);
105 static void copy_item(gpointer data, guint action, GtkWidget *widget);
106 static void rename_item(gpointer data, guint action, GtkWidget *widget);
107 static void link_item(gpointer data, guint action, GtkWidget *widget);
108 static void open_file(gpointer data, guint action, GtkWidget *widget);
109 static void help(gpointer data, guint action, GtkWidget *widget);
110 static void show_file_info(gpointer data, guint action, GtkWidget *widget);
111 static void mount(gpointer data, guint action, GtkWidget *widget);
112 static void delete(gpointer data, guint action, GtkWidget *widget);
113 static void remove_link(gpointer data, guint action, GtkWidget *widget);
114 static void usage(gpointer data, guint action, GtkWidget *widget);
115 static void chmod_items(gpointer data, guint action, GtkWidget *widget);
116 static void find(gpointer data, guint action, GtkWidget *widget);
118 static void open_vfs_rpm(gpointer data, guint action, GtkWidget *widget);
119 static void open_vfs_utar(gpointer data, guint action, GtkWidget *widget);
120 static void open_vfs_uzip(gpointer data, guint action, GtkWidget *widget);
122 static void select_all(gpointer data, guint action, GtkWidget *widget);
123 static void clear_selection(gpointer data, guint action, GtkWidget *widget);
124 static void new_directory(gpointer data, guint action, GtkWidget *widget);
125 static void xterm_here(gpointer data, guint action, GtkWidget *widget);
127 static void open_parent_same(gpointer data, guint action, GtkWidget *widget);
128 static void open_parent(gpointer data, guint action, GtkWidget *widget);
129 static void new_window(gpointer data, guint action, GtkWidget *widget);
130 static void close_window(gpointer data, guint action, GtkWidget *widget);
131 static void enter_path(gpointer data, guint action, GtkWidget *widget);
132 static void shell_command(gpointer data, guint action, GtkWidget *widget);
133 static void run_action(gpointer data, guint action, GtkWidget *widget);
134 static void select_if(gpointer data, guint action, GtkWidget *widget);
136 static void pin_help(gpointer data, guint action, GtkWidget *widget);
137 static void pin_remove(gpointer data, guint action, GtkWidget *widget);
139 static GtkWidget *create_options();
140 static void update_options();
141 static void set_options();
142 static void save_options();
144 static OptionsSection options =
146 N_("Menu options"),
147 create_options,
148 update_options,
149 set_options,
150 save_options
154 static GtkWidget *filer_menu; /* The popup filer menu */
155 static GtkWidget *filer_file_item; /* The File '' label */
156 static GtkWidget *filer_file_menu; /* The File '' menu */
157 static GtkWidget *filer_vfs_menu; /* The Open VFS menu */
158 static GtkWidget *filer_hidden_menu; /* The Show Hidden item */
159 static GtkWidget *filer_new_window; /* The New Window item */
160 static GtkWidget *pinboard_menu; /* The popup pinboard menu */
162 /* Used for Copy, etc */
163 static GtkWidget *savebox = NULL;
164 static guchar *current_path = NULL;
165 static gboolean (*current_savebox_callback)(guchar *current, guchar *new);
167 #undef N_
168 #define N_(x) x
170 static GtkItemFactoryEntry filer_menu_def[] = {
171 {N_("Display"), NULL, NULL, 0, "<Branch>"},
172 {">" N_("Large Icons"), NULL, large, 0, NULL},
173 {">" N_("Small Icons"), NULL, small, 0, NULL},
174 {">" N_("Large, With..."), NULL, NULL, 0, "<Branch>"},
175 {">>" N_("Summary"), NULL, large_with, DETAILS_SUMMARY, NULL},
176 {">>" N_("Sizes"), NULL, large_with, DETAILS_SIZE, NULL},
177 {">>" N_("Size Bars"), NULL, large_with, DETAILS_SIZE_BARS, NULL},
178 {">" N_("Small, With..."), NULL, NULL, 0, "<Branch>"},
179 {">>" N_("Summary"), NULL, small_with, DETAILS_SUMMARY, NULL},
180 {">>" N_("Sizes"), NULL, small_with, DETAILS_SIZE, NULL},
181 {">>" N_("Size Bars"), NULL, small_with, DETAILS_SIZE_BARS, NULL},
182 {">", NULL, NULL, 0, "<Separator>"},
183 {">" N_("Sort by Name"), NULL, sort_name, 0, NULL},
184 {">" N_("Sort by Type"), NULL, sort_type, 0, NULL},
185 {">" N_("Sort by Date"), NULL, sort_date, 0, NULL},
186 {">" N_("Sort by Size"), NULL, sort_size, 0, NULL},
187 {">", NULL, NULL, 0, "<Separator>"},
188 {">" N_("Show Hidden"), NULL, hidden, 0, "<ToggleItem>"},
189 {">" N_("Refresh"), NULL, refresh, 0, NULL},
190 {N_("File"), NULL, NULL, 0, "<Branch>"},
191 {">" N_("Copy..."), NULL, copy_item, 0, NULL},
192 {">" N_("Rename..."), NULL, rename_item, 0, NULL},
193 {">" N_("Link..."), NULL, link_item, 0, NULL},
194 {">" N_("Shift Open"), NULL, open_file, 0, NULL},
195 {">" N_("Help"), NULL, help, 0, NULL},
196 {">" N_("Info"), NULL, show_file_info, 0, NULL},
197 {">" N_("Open VFS"), NULL, NULL, 0, "<Branch>"},
198 {">>" N_("Unzip"), NULL, open_vfs_uzip, 0, NULL},
199 {">>" N_("Untar"), NULL, open_vfs_utar, 0, NULL},
200 {">>" N_("RPM"), NULL, open_vfs_rpm, 0, NULL},
201 {">", NULL, NULL, 0, "<Separator>"},
202 {">" N_("Mount"), NULL, mount, 0, NULL},
203 {">" N_("Delete"), NULL, delete, 0, NULL},
204 {">" N_("Disk Usage"), NULL, usage, 0, NULL},
205 {">" N_("Permissions"), NULL, chmod_items, 0, NULL},
206 {">" N_("Find"), NULL, find, 0, NULL},
207 {N_("Select All"), NULL, select_all, 0, NULL},
208 {N_("Clear Selection"), NULL, clear_selection, 0, NULL},
209 {N_("Options..."), NULL, menu_show_options, 0, NULL},
210 {N_("New Directory..."), NULL, new_directory, 0, NULL},
211 {N_("Xterm Here"), NULL, xterm_here, 0, NULL},
212 {N_("Window"), NULL, NULL, 0, "<Branch>"},
213 {">" N_("Parent, New Window"), NULL, open_parent, 0, NULL},
214 {">" N_("Parent, Same Window"), NULL, open_parent_same, 0, NULL},
215 {">" N_("New Window"), NULL, new_window, 0, NULL},
216 {">" N_("Close Window"), NULL, close_window, 0, NULL},
217 {">", NULL, NULL, 0, "<Separator>"},
218 {">" N_("Enter Path..."), NULL, enter_path, 0, NULL},
219 {">" N_("Shell Command..."), NULL, shell_command, 0, NULL},
220 {">" N_("Set Run Action..."), NULL, run_action, 0, NULL},
221 {">" N_("Select If..."), NULL, select_if, 0, NULL},
222 {">", NULL, NULL, 0, "<Separator>"},
223 {">" N_("Show ROX-Filer Help"), NULL, menu_rox_help, 0, NULL},
226 static GtkItemFactoryEntry pinboard_menu_def[] = {
227 {N_("ROX-Filer Help"), NULL, menu_rox_help, 0, NULL},
228 {N_("ROX-Filer Options..."), NULL, menu_show_options, 0, NULL},
229 {"", NULL, NULL, 0, "<Separator>"},
230 {N_("Show Help"), NULL, pin_help, 0, NULL},
231 {N_("Remove Item(s)"), NULL, pin_remove, 0, NULL},
235 typedef struct _FileStatus FileStatus;
237 /* This is for the 'file(1) says...' thing */
238 struct _FileStatus
240 int fd; /* FD to read from, -1 if closed */
241 int input; /* Input watcher tag if fd valid */
242 GtkLabel *label; /* Widget to output to */
243 gboolean start; /* No output yet */
246 #define GET_MENU_ITEM(var, menu) \
247 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
249 #define GET_SMENU_ITEM(var, menu, sub) \
250 do { \
251 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
252 var = gtk_item_factory_get_widget(item_factory, tmp); \
253 g_free(tmp); \
254 } while (0)
256 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
257 do { \
258 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
259 var = gtk_item_factory_get_widget(item_factory, tmp); \
260 g_free(tmp); \
261 } while (0)
263 /* Creates menu <name> from the <name>_menu_def array.
264 * The accel group <name>_keys must also have been created.
265 * All menu items are translated. Sets 'item_factory'.
267 #define MAKE_MENU(name) \
268 do { \
269 GtkItemFactoryEntry *translated; \
270 int n_entries; \
272 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, \
273 "<" #name ">", name ## _keys); \
275 n_entries = sizeof(name ## _menu_def) / sizeof(*name ## _menu_def); \
276 translated = translate_entries(name ## _menu_def, n_entries); \
277 gtk_item_factory_create_items(item_factory, n_entries, \
278 translated, NULL); \
279 free_translated_entries(translated, n_entries); \
280 } while (0)
282 void menu_init()
284 char *menurc;
285 GList *items;
286 guchar *tmp;
287 GtkWidget *item;
288 GtkItemFactory *item_factory;
290 filer_keys = gtk_accel_group_new();
291 MAKE_MENU(filer);
293 GET_MENU_ITEM(filer_menu, "filer");
294 GET_SMENU_ITEM(filer_file_menu, "filer", "File");
295 GET_SSMENU_ITEM(filer_vfs_menu, "filer", "File", "Open VFS");
296 GET_SSMENU_ITEM(filer_hidden_menu, "filer", "Display", "Show Hidden");
298 items = gtk_container_children(GTK_CONTAINER(filer_menu));
299 filer_file_item = GTK_BIN(g_list_nth(items, 1)->data)->child;
300 g_list_free(items);
302 GET_SSMENU_ITEM(item, "filer", "Window", "New Window");
303 filer_new_window = GTK_BIN(item)->child;
305 menurc = choices_find_path_load("menus", PROJECT);
306 if (menurc)
308 gtk_item_factory_parse_rc(menurc);
309 mark_menus_modified(FALSE);
312 pinboard_keys = gtk_accel_group_new();
313 MAKE_MENU(pinboard);
314 gtk_accel_group_lock(pinboard_keys);
315 GET_MENU_ITEM(pinboard_menu, "pinboard");
317 gtk_signal_connect(GTK_OBJECT(pinboard_menu), "unmap_event",
318 GTK_SIGNAL_FUNC(pin_menu_closed), NULL);
319 gtk_signal_connect(GTK_OBJECT(filer_menu), "unmap_event",
320 GTK_SIGNAL_FUNC(menu_closed), NULL);
321 gtk_signal_connect(GTK_OBJECT(filer_file_menu), "unmap_event",
322 GTK_SIGNAL_FUNC(menu_closed), NULL);
324 options_sections = g_slist_prepend(options_sections, &options);
325 xterm_here_value = g_strdup("xterm");
326 option_register("xterm_here", load_xterm_here);
328 savebox = gtk_savebox_new();
329 gtk_signal_connect_object(GTK_OBJECT(savebox), "save_to_file",
330 GTK_SIGNAL_FUNC(save_to_file), NULL);
331 gtk_signal_connect_object(GTK_OBJECT(savebox), "save_done",
332 GTK_SIGNAL_FUNC(gtk_widget_hide),
333 GTK_OBJECT(savebox));
335 atexit(save_menus);
338 /* Name is in the form "<panel>" */
339 GtkWidget *menu_create(GtkItemFactoryEntry *def, int n_entries, guchar *name)
341 GtkItemFactory *item_factory;
342 GtkItemFactoryEntry *translated;
343 GtkAccelGroup *keys;
344 GtkWidget *menu;
346 keys = gtk_accel_group_new();
348 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, name, keys);
350 translated = translate_entries(def, n_entries);
351 gtk_item_factory_create_items(item_factory, n_entries,
352 translated, NULL);
353 free_translated_entries(translated, n_entries);
355 menu = gtk_item_factory_get_widget(item_factory, name);
357 gtk_accel_group_lock(keys);
359 gtk_signal_connect(GTK_OBJECT(menu), "unmap_event",
360 GTK_SIGNAL_FUNC(pin_menu_closed), NULL);
362 return menu;
365 /* Build up some option widgets to go in the options dialog, but don't
366 * fill them in yet.
368 static GtkWidget *create_options()
370 GtkWidget *table, *label;
372 table = gtk_table_new(2, 2, FALSE);
373 gtk_container_set_border_width(GTK_CONTAINER(table), 4);
375 label = gtk_label_new(
376 _("To set the keyboard short-cuts, simply open "
377 "the menu over a filer window, move the pointer over "
378 "the item you want to use and press a key. The key "
379 "will appear next to the menu item and you can just "
380 "press that key without opening the menu in future."));
381 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
382 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1);
384 label = gtk_label_new(_("'Xterm here' program:"));
385 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
386 xterm_here_entry = gtk_entry_new();
387 gtk_table_attach_defaults(GTK_TABLE(table), xterm_here_entry,
388 1, 2, 1, 2);
390 return table;
393 static char *load_xterm_here(char *data)
395 g_free(xterm_here_value);
396 xterm_here_value = g_strdup(data);
397 return NULL;
400 static void update_options()
402 gtk_entry_set_text(GTK_ENTRY(xterm_here_entry), xterm_here_value);
405 static void set_options()
407 g_free(xterm_here_value);
408 xterm_here_value = g_strdup(gtk_entry_get_text(
409 GTK_ENTRY(xterm_here_entry)));
412 static void save_options()
414 save_menus();
415 option_write("xterm_here", xterm_here_value);
419 static void items_sensitive(gboolean state)
421 int n = 7;
422 GList *items, *item;
424 items = item = gtk_container_children(GTK_CONTAINER(filer_file_menu));
425 while (item && n--)
427 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
428 item = item->next;
430 g_list_free(items);
432 items = item = gtk_container_children(GTK_CONTAINER(filer_vfs_menu));
433 while (item)
435 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, state);
436 item = item->next;
438 g_list_free(items);
441 static void position_menu(GtkMenu *menu, gint *x, gint *y, gpointer data)
443 int *pos = (int *) data;
444 GtkRequisition requisition;
446 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
448 *x = pos[0] - (requisition.width >> 2);
449 *y = pos[1] - (requisition.height >> 2);
451 *x = CLAMP(*x, 0, screen_width - requisition.width);
452 *y = CLAMP(*y, 0, screen_height - requisition.height);
455 /* Display the pinboard menu. Set icon to NULL if no particular icon
456 * was clicked.
458 void show_pinboard_menu(GdkEventButton *event, PinIcon *icon)
460 int pos[2];
461 GList *icons;
463 if (icon)
465 if (pinboard_is_selected(icon))
466 pin_temp_item_selected = FALSE;
467 else
469 pinboard_select_only(icon);
470 pin_temp_item_selected = TRUE;
474 icons = pinboard_get_selected();
476 pos[0] = event->x_root;
477 pos[1] = event->y_root;
479 if (icons)
481 menu_set_items_shaded(pinboard_menu,
482 icons->next ? TRUE : FALSE, 3, 1);
484 menu_set_items_shaded(pinboard_menu, FALSE, 4, 1);
486 else
487 menu_set_items_shaded(pinboard_menu, TRUE, 3, 2);
489 gtk_menu_popup(GTK_MENU(pinboard_menu), NULL, NULL, position_menu,
490 (gpointer) pos, event->button, event->time);
493 void show_filer_menu(FilerWindow *filer_window, GdkEventButton *event,
494 int item)
496 DirItem *file_item;
497 int pos[2];
499 updating_menu++;
501 pos[0] = event->x_root;
502 pos[1] = event->y_root;
504 window_with_focus = filer_window;
506 if (filer_window->collection->number_selected == 0 && item >= 0)
508 collection_select_item(filer_window->collection, item);
509 filer_window->temp_item_selected = TRUE;
511 else
512 filer_window->temp_item_selected = FALSE;
515 GtkWidget *file_label, *file_menu;
516 Collection *collection = filer_window->collection;
517 GString *buffer;
519 file_label = filer_file_item;
520 file_menu = filer_file_menu;
521 gtk_check_menu_item_set_active(
522 GTK_CHECK_MENU_ITEM(filer_hidden_menu),
523 filer_window->show_hidden);
524 buffer = g_string_new(NULL);
525 switch (collection->number_selected)
527 case 0:
528 g_string_assign(buffer, _("Next Click"));
529 items_sensitive(TRUE);
530 break;
531 case 1:
532 items_sensitive(TRUE);
533 file_item = selected_item(
534 filer_window->collection);
535 g_string_sprintf(buffer, "%s '%s'",
536 basetype_name(file_item),
537 file_item->leafname);
538 break;
539 default:
540 items_sensitive(FALSE);
541 g_string_sprintf(buffer, _("%d items"),
542 collection->number_selected);
543 break;
545 gtk_label_set_text(GTK_LABEL(file_label), buffer->str);
546 g_string_free(buffer, TRUE);
550 gtk_widget_set_sensitive(filer_new_window, !o_unique_filer_windows);
552 popup_menu = (event->state & GDK_CONTROL_MASK)
553 ? filer_file_menu
554 : filer_menu;
556 updating_menu--;
558 gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, position_menu,
559 (gpointer) pos, event->button, event->time);
562 static void pin_menu_closed(GtkWidget *widget)
564 if (pin_temp_item_selected)
565 pinboard_clear_selection();
568 static void menu_closed(GtkWidget *widget)
570 if (window_with_focus == NULL || widget != popup_menu)
571 return; /* Close panel item chosen? */
573 popup_menu = NULL;
575 if (window_with_focus->temp_item_selected)
577 collection_clear_selection(window_with_focus->collection);
578 window_with_focus->temp_item_selected = FALSE;
582 void target_callback(Collection *collection, gint item, gpointer real_fn)
584 g_return_if_fail(window_with_focus != NULL);
585 g_return_if_fail(window_with_focus->collection == collection);
586 g_return_if_fail(real_fn != NULL);
588 collection_wink_item(collection, item);
589 collection_clear_selection(collection);
590 collection_select_item(collection, item);
591 ((CollectionTargetFunc)real_fn)(NULL, 0, collection);
592 if (item < collection->number_of_items)
593 collection_unselect_item(collection, item);
596 /* Actions */
598 static void large(gpointer data, guint action, GtkWidget *widget)
600 g_return_if_fail(window_with_focus != NULL);
602 display_set_layout(window_with_focus, "Large");
605 static void small(gpointer data, guint action, GtkWidget *widget)
607 g_return_if_fail(window_with_focus != NULL);
609 display_set_layout(window_with_focus, "Small");
612 static void set_layout(gboolean large, DetailsType details)
614 guchar *style;
616 g_return_if_fail(window_with_focus != NULL);
618 style = g_strdup_printf("%s+%s",
619 large ? "Large" : "Small",
620 details == DETAILS_SUMMARY ? "Summary" :
621 details == DETAILS_SIZE_BARS ? "SizeBars" :
622 "Sizes");
624 display_set_layout(window_with_focus, style);
625 g_free(style);
628 static void large_with(gpointer data, guint action, GtkWidget *widget)
630 set_layout(TRUE, (DetailsType) action);
633 static void small_with(gpointer data, guint action, GtkWidget *widget)
635 set_layout(FALSE, (DetailsType) action);
638 static void sort_name(gpointer data, guint action, GtkWidget *widget)
640 g_return_if_fail(window_with_focus != NULL);
642 display_set_sort_fn(window_with_focus, sort_by_name);
645 static void sort_type(gpointer data, guint action, GtkWidget *widget)
647 g_return_if_fail(window_with_focus != NULL);
649 display_set_sort_fn(window_with_focus, sort_by_type);
652 static void sort_date(gpointer data, guint action, GtkWidget *widget)
654 g_return_if_fail(window_with_focus != NULL);
656 display_set_sort_fn(window_with_focus, sort_by_date);
659 static void sort_size(gpointer data, guint action, GtkWidget *widget)
661 g_return_if_fail(window_with_focus != NULL);
663 display_set_sort_fn(window_with_focus, sort_by_size);
666 static void hidden(gpointer data, guint action, GtkWidget *widget)
668 if (updating_menu)
669 return;
671 g_return_if_fail(window_with_focus != NULL);
673 display_set_hidden(window_with_focus, !window_with_focus->show_hidden);
676 static void refresh(gpointer data, guint action, GtkWidget *widget)
678 g_return_if_fail(window_with_focus != NULL);
680 full_refresh();
681 filer_update_dir(window_with_focus, TRUE);
684 static void mount(gpointer data, guint action, GtkWidget *widget)
686 g_return_if_fail(window_with_focus != NULL);
688 if (window_with_focus->collection->number_selected == 0)
689 collection_target(window_with_focus->collection,
690 target_callback, mount);
691 else
693 GList *paths;
695 paths = list_paths(window_with_focus);
696 action_mount(paths);
697 free_paths(paths);
701 static void delete(gpointer data, guint action, GtkWidget *widget)
703 g_return_if_fail(window_with_focus != NULL);
705 if (window_with_focus->collection->number_selected == 0)
706 collection_target(window_with_focus->collection,
707 target_callback, delete);
708 else
709 action_delete(window_with_focus);
712 static void remove_link(gpointer data, guint action, GtkWidget *widget)
714 g_return_if_fail(window_with_focus != NULL);
716 if (window_with_focus->collection->number_selected > 1)
718 report_error(PROJECT,
719 _("You can only remove one link at a time"));
720 return;
722 else if (window_with_focus->collection->number_selected == 0)
723 collection_target(window_with_focus->collection,
724 target_callback, remove_link);
725 else
727 struct stat info;
728 DirItem *item;
729 guchar *path;
731 item = selected_item(window_with_focus->collection);
733 path = make_path(window_with_focus->path, item->leafname)->str;
734 if (lstat(path, &info))
735 report_error(PROJECT, g_strerror(errno));
736 else if (!S_ISLNK(info.st_mode))
737 report_error(PROJECT,
738 _("You can only remove symbolic links this way - "
739 "try the 'Open Panel as Directory' item."));
740 else if (unlink(path))
741 report_error(PROJECT, g_strerror(errno));
742 else
743 filer_update_dir(window_with_focus, TRUE);
747 static void usage(gpointer data, guint action, GtkWidget *widget)
749 g_return_if_fail(window_with_focus != NULL);
751 if (window_with_focus->collection->number_selected == 0)
752 collection_target(window_with_focus->collection,
753 target_callback, usage);
754 else
755 action_usage(window_with_focus);
758 static void chmod_items(gpointer data, guint action, GtkWidget *widget)
760 g_return_if_fail(window_with_focus != NULL);
762 if (window_with_focus->collection->number_selected == 0)
763 collection_target(window_with_focus->collection,
764 target_callback, chmod_items);
765 else
766 action_chmod(window_with_focus);
769 static void find(gpointer data, guint action, GtkWidget *widget)
771 g_return_if_fail(window_with_focus != NULL);
773 if (window_with_focus->collection->number_selected == 0)
774 collection_target(window_with_focus->collection,
775 target_callback, find);
776 else
777 action_find(window_with_focus);
780 /* This pops up our savebox widget, cancelling any currently open one,
781 * and allows the user to pick a new path for it.
782 * Once the new path has been picked, the callback will be called with
783 * both the current and new paths.
785 static void savebox_show(guchar *title, guchar *path, MaskedPixmap *image,
786 gboolean (*callback)(guchar *current, guchar *new))
788 if (GTK_WIDGET_VISIBLE(savebox))
789 gtk_widget_hide(savebox);
791 if (current_path)
792 g_free(current_path);
793 current_path = g_strdup(path);
794 current_savebox_callback = callback;
796 gtk_window_set_title(GTK_WINDOW(savebox), title);
797 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox), current_path);
798 gtk_savebox_set_icon(GTK_SAVEBOX(savebox), image->pixmap, image->mask);
800 gtk_widget_grab_focus(GTK_SAVEBOX(savebox)->entry);
801 gtk_widget_show(savebox);
804 static gint save_to_file(GtkSavebox *savebox, guchar *pathname)
806 g_return_val_if_fail(current_savebox_callback != NULL,
807 GTK_XDS_SAVE_ERROR);
809 return current_savebox_callback(current_path, pathname)
810 ? GTK_XDS_SAVED : GTK_XDS_SAVE_ERROR;
813 static gboolean copy_cb(guchar *current, guchar *new)
815 return action_with_leaf(action_copy, current, new);
818 static gboolean action_with_leaf(ActionFn action, guchar *current, guchar *new)
820 char *new_dir, *leaf;
821 GSList *local_paths;
823 if (new[0] != '/')
825 report_error(PROJECT, _("New pathname is not absolute"));
826 return FALSE;
829 if (new[strlen(new) - 1] == '/')
831 new_dir = g_strdup(new);
832 leaf = NULL;
834 else
836 guchar *slash;
838 slash = strrchr(new, '/');
839 new_dir = g_strndup(new, slash - new);
840 leaf = slash + 1;
843 local_paths = g_slist_append(NULL, current);
844 action(local_paths, new_dir, leaf);
845 g_slist_free(local_paths);
847 g_free(new_dir);
849 return TRUE;
852 #define SHOW_SAVEBOX(title, callback) \
854 DirItem *item; \
855 guchar *path; \
856 item = selected_item(collection); \
857 path = make_path(window_with_focus->path, item->leafname)->str; \
858 savebox_show(title, path, item->image, callback); \
861 static void copy_item(gpointer data, guint action, GtkWidget *widget)
863 Collection *collection;
865 g_return_if_fail(window_with_focus != NULL);
867 collection = window_with_focus->collection;
868 if (collection->number_selected > 1)
870 report_error(PROJECT, _("You cannot do this to more than "
871 "one item at a time"));
872 return;
874 else if (collection->number_selected != 1)
875 collection_target(collection, target_callback, copy_item);
876 else
877 SHOW_SAVEBOX(_("Copy"), copy_cb);
880 static gboolean rename_cb(guchar *current, guchar *new)
882 return action_with_leaf(action_move, current, new);
885 static void rename_item(gpointer data, guint action, GtkWidget *widget)
887 Collection *collection;
889 g_return_if_fail(window_with_focus != NULL);
891 collection = window_with_focus->collection;
892 if (collection->number_selected > 1)
894 report_error(PROJECT, _("You cannot do this to more than "
895 "one item at a time"));
896 return;
898 else if (collection->number_selected != 1)
899 collection_target(collection, target_callback, rename_item);
900 else
901 SHOW_SAVEBOX(_("Rename"), rename_cb);
904 static gboolean link_cb(guchar *initial, guchar *path)
906 if (symlink(initial, path))
908 report_error("ROX-Filer: symlink()", g_strerror(errno));
909 return FALSE;
911 return TRUE;
914 static void link_item(gpointer data, guint action, GtkWidget *widget)
916 Collection *collection;
918 g_return_if_fail(window_with_focus != NULL);
920 collection = window_with_focus->collection;
921 if (collection->number_selected > 1)
923 report_error(PROJECT, _("You cannot do this to more than "
924 "one item at a time"));
925 return;
927 else if (collection->number_selected != 1)
928 collection_target(collection, target_callback, link_item);
929 else
930 SHOW_SAVEBOX(_("Symlink"), link_cb);
933 static void open_file(gpointer data, guint action, GtkWidget *widget)
935 Collection *collection;
937 g_return_if_fail(window_with_focus != NULL);
939 collection = window_with_focus->collection;
940 if (collection->number_selected > 1)
942 report_error(PROJECT, _("You cannot do this to more than "
943 "one item at a time"));
944 return;
946 else if (collection->number_selected != 1)
947 collection_target(collection, target_callback, open_file);
948 else
949 filer_openitem(window_with_focus,
950 selected_item_number(collection),
951 OPEN_SAME_WINDOW | OPEN_SHIFT);
954 /* Got some data from file(1) - stick it in the window. */
955 static void add_file_output(FileStatus *fs,
956 gint source, GdkInputCondition condition)
958 char buffer[20];
959 char *str;
960 int got;
962 got = read(source, buffer, sizeof(buffer) - 1);
963 if (got <= 0)
965 int err = errno;
966 gtk_input_remove(fs->input);
967 close(source);
968 fs->fd = -1;
969 if (got < 0)
970 delayed_error(_("ROX-Filer: file(1) says..."),
971 g_strerror(err));
972 return;
974 buffer[got] = '\0';
976 if (fs->start)
978 str = "";
979 fs->start = FALSE;
981 else
982 gtk_label_get(fs->label, &str);
984 str = g_strconcat(str, buffer, NULL);
985 gtk_label_set_text(fs->label, str);
986 g_free(str);
989 static void file_info_destroyed(GtkWidget *widget, FileStatus *fs)
991 if (fs->fd != -1)
993 gtk_input_remove(fs->input);
994 close(fs->fd);
997 g_free(fs);
1000 /* g_free() the result */
1001 guchar *pretty_type(DirItem *file, guchar *path)
1003 if (file->flags & ITEM_FLAG_SYMLINK)
1005 char p[MAXPATHLEN + 1];
1006 int got;
1007 got = readlink(path, p, MAXPATHLEN);
1008 if (got > 0 && got <= MAXPATHLEN)
1010 p[got] = '\0';
1011 return g_strconcat(_("Symbolic link to "), p, NULL);
1014 return g_strdup(_("Symbolic link"));
1017 if (file->flags & ITEM_FLAG_EXEC_FILE)
1018 return g_strdup(_("Executable file"));
1020 if (file->flags & ITEM_FLAG_APPDIR)
1021 return g_strdup(_("ROX application"));
1023 if (file->flags & ITEM_FLAG_MOUNT_POINT)
1025 MountPoint *mp;
1026 if ((file->flags & ITEM_FLAG_MOUNTED) &&
1027 (mp = g_hash_table_lookup(mtab_mounts, path)))
1028 return g_strconcat(_("Mount point for "),
1029 mp->name, NULL);
1031 return g_strdup(_("Mount point"));
1034 if (file->mime_type)
1035 return g_strconcat(file->mime_type->media_type, "/",
1036 file->mime_type->subtype, NULL);
1038 return g_strdup("-");
1041 #define LABEL(text, row) \
1042 label = gtk_label_new(text); \
1043 gtk_misc_set_alignment(GTK_MISC(label), 1, .5); \
1044 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); \
1045 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, row, row + 1);
1047 #define VALUE(label, row) \
1048 gtk_misc_set_alignment(GTK_MISC(label), 0, .5); \
1049 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, row, row + 1);
1051 static void show_file_info(gpointer data, guint action, GtkWidget *widget)
1053 GtkWidget *window, *table, *label, *button, *frame, *value;
1054 GtkWidget *file_label;
1055 GString *gstring;
1056 int file_data[2];
1057 guchar *path, *tmp;
1058 char *argv[] = {"file", "-b", NULL, NULL};
1059 Collection *collection;
1060 DirItem *file;
1061 struct stat info;
1062 FileStatus *fs = NULL;
1063 guint perm;
1065 g_return_if_fail(window_with_focus != NULL);
1067 collection = window_with_focus->collection;
1068 if (collection->number_selected > 1)
1070 report_error(PROJECT, _("You cannot do this to more than "
1071 "one item at a time"));
1072 return;
1074 else if (collection->number_selected != 1)
1076 collection_target(collection, target_callback, show_file_info);
1077 return;
1079 file = selected_item(collection);
1080 path = make_path(window_with_focus->path,
1081 file->leafname)->str;
1082 if (lstat(path, &info))
1084 delayed_error(PROJECT, g_strerror(errno));
1085 return;
1088 gstring = g_string_new(NULL);
1090 window = gtk_window_new(GTK_WINDOW_DIALOG);
1091 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
1092 gtk_container_set_border_width(GTK_CONTAINER(window), 4);
1093 gtk_window_set_title(GTK_WINDOW(window), path);
1095 table = gtk_table_new(10, 2, FALSE);
1096 gtk_container_add(GTK_CONTAINER(window), table);
1097 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
1098 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
1100 value = gtk_label_new(file->leafname);
1101 LABEL(_("Name:"), 0);
1102 VALUE(value, 0);
1104 g_string_sprintf(gstring, "%s, %s", user_name(info.st_uid),
1105 group_name(info.st_gid));
1106 value = gtk_label_new(gstring->str);
1107 LABEL(_("Owner, Group:"), 1);
1108 VALUE(value, 1);
1110 if (info.st_size >= PRETTY_SIZE_LIMIT)
1112 g_string_sprintf(gstring, "%s (%ld %s)",
1113 format_size((unsigned long) info.st_size),
1114 (unsigned long) info.st_size, _("bytes"));
1116 else
1118 g_string_assign(gstring,
1119 format_size((unsigned long) info.st_size));
1121 value = gtk_label_new(gstring->str);
1122 LABEL(_("Size:"), 2);
1123 VALUE(value, 2);
1125 value = gtk_label_new(pretty_time(&info.st_ctime));
1126 LABEL(_("Change time:"), 3);
1127 VALUE(value, 3);
1129 value = gtk_label_new(pretty_time(&info.st_mtime));
1130 LABEL(_("Modify time:"), 4);
1131 VALUE(value, 4);
1133 value = gtk_label_new(pretty_time(&info.st_atime));
1134 LABEL(_("Access time:"), 5);
1135 VALUE(value, 5);
1137 value = gtk_label_new(pretty_permissions(info.st_mode));
1138 perm = applicable(info.st_uid, info.st_gid);
1139 gtk_label_set_pattern(GTK_LABEL(value),
1140 perm == 0 ? "___ " :
1141 perm == 1 ? " ___ " :
1142 " ___");
1143 gtk_widget_set_style(value, fixed_style);
1144 LABEL(_("Permissions:"), 6);
1145 VALUE(value, 6);
1147 tmp = pretty_type(file, path);
1148 value = gtk_label_new(tmp);
1149 g_free(tmp);
1150 LABEL(_("Type:"), 7);
1151 VALUE(value, 7);
1153 frame = gtk_frame_new(_("file(1) says..."));
1154 gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 2, 8, 9);
1155 file_label = gtk_label_new(_("<nothing yet>"));
1156 gtk_misc_set_padding(GTK_MISC(file_label), 4, 4);
1157 gtk_label_set_line_wrap(GTK_LABEL(file_label), TRUE);
1158 gtk_container_add(GTK_CONTAINER(frame), file_label);
1160 button = gtk_button_new_with_label(_("OK"));
1161 gtk_window_set_focus(GTK_WINDOW(window), button);
1162 gtk_table_attach(GTK_TABLE(table), button, 0, 2, 10, 11,
1163 GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 40, 4);
1164 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
1165 gtk_widget_destroy, GTK_OBJECT(window));
1167 gtk_widget_show_all(window);
1168 gdk_flush();
1170 if (pipe(file_data))
1172 g_string_sprintf(gstring, "pipe(): %s", g_strerror(errno));
1173 g_string_free(gstring, TRUE);
1174 return;
1176 switch (fork())
1178 case -1:
1179 g_string_sprintf(gstring, "fork(): %s",
1180 g_strerror(errno));
1181 gtk_label_set_text(GTK_LABEL(file_label), gstring->str);
1182 g_string_free(gstring, TRUE);
1183 close(file_data[0]);
1184 close(file_data[1]);
1185 break;
1186 case 0:
1187 /* We are the child */
1188 close(file_data[0]);
1189 dup2(file_data[1], STDOUT_FILENO);
1190 dup2(file_data[1], STDERR_FILENO);
1191 #ifdef FILE_B_FLAG
1192 argv[2] = path;
1193 #else
1194 argv[1] = file->leafname;
1195 chdir(window_with_focus->path);
1196 #endif
1197 if (execvp(argv[0], argv))
1198 fprintf(stderr, "execvp() error: %s\n",
1199 g_strerror(errno));
1200 _exit(0);
1201 default:
1202 /* We are the parent */
1203 close(file_data[1]);
1204 fs = g_new(FileStatus, 1);
1205 fs->label = GTK_LABEL(file_label);
1206 fs->fd = file_data[0];
1207 fs->start = TRUE;
1208 fs->input = gdk_input_add(fs->fd, GDK_INPUT_READ,
1209 (GdkInputFunction) add_file_output, fs);
1210 gtk_signal_connect(GTK_OBJECT(window), "destroy",
1211 GTK_SIGNAL_FUNC(file_info_destroyed), fs);
1212 g_string_free(gstring, TRUE);
1213 break;
1217 static void help(gpointer data, guint action, GtkWidget *widget)
1219 Collection *collection;
1220 DirItem *item;
1222 g_return_if_fail(window_with_focus != NULL);
1224 collection = window_with_focus->collection;
1225 if (collection->number_selected > 1)
1227 report_error(PROJECT, _("You cannot do this to more than "
1228 "one item at a time"));
1229 return;
1231 else if (collection->number_selected != 1)
1233 collection_target(collection, target_callback, help);
1234 return;
1236 item = selected_item(collection);
1238 show_item_help(make_path(window_with_focus->path, item->leafname)->str,
1239 item);
1242 #define OPEN_VFS(fs) \
1243 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1245 Collection *collection; \
1247 g_return_if_fail(window_with_focus != NULL); \
1249 collection = window_with_focus->collection; \
1250 if (collection->number_selected < 1) \
1251 collection_target(collection, target_callback, \
1252 open_vfs_ ## fs); \
1253 else \
1254 real_vfs_open(#fs); \
1257 static void real_vfs_open(char *fs)
1259 gchar *path;
1260 DirItem *item;
1262 if (window_with_focus->collection->number_selected != 1)
1264 report_error(PROJECT, _("You must select a single file "
1265 "to open as a Virtual File System"));
1266 return;
1269 item = selected_item(window_with_focus->collection);
1271 path = g_strconcat(window_with_focus->path,
1272 "/",
1273 item->leafname,
1274 "#", fs, NULL);
1276 filer_change_to(window_with_focus, path, NULL);
1277 g_free(path);
1280 OPEN_VFS(rpm)
1281 OPEN_VFS(utar)
1282 OPEN_VFS(uzip)
1284 static void select_all(gpointer data, guint action, GtkWidget *widget)
1286 g_return_if_fail(window_with_focus != NULL);
1288 collection_select_all(window_with_focus->collection);
1289 window_with_focus->temp_item_selected = FALSE;
1292 static void clear_selection(gpointer data, guint action, GtkWidget *widget)
1294 g_return_if_fail(window_with_focus != NULL);
1296 collection_clear_selection(window_with_focus->collection);
1297 window_with_focus->temp_item_selected = FALSE;
1300 void menu_show_options(gpointer data, guint action, GtkWidget *widget)
1302 options_show();
1305 static gboolean new_directory_cb(guchar *initial, guchar *path)
1307 if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO))
1309 report_error("mkdir", g_strerror(errno));
1310 return FALSE;
1313 dir_check_this(path);
1314 return TRUE;
1317 static void new_directory(gpointer data, guint action, GtkWidget *widget)
1319 g_return_if_fail(window_with_focus != NULL);
1321 savebox_show(_("New Directory"),
1322 make_path(window_with_focus->path, _("NewDir"))->str,
1323 type_to_icon(&special_directory),
1324 new_directory_cb);
1327 static void xterm_here(gpointer data, guint action, GtkWidget *widget)
1329 char *argv[] = {NULL, NULL};
1331 argv[0] = xterm_here_value;
1333 g_return_if_fail(window_with_focus != NULL);
1335 if (!spawn_full(argv, window_with_focus->path))
1336 report_error(PROJECT, _("Failed to fork() child process"));
1339 static void open_parent(gpointer data, guint action, GtkWidget *widget)
1341 g_return_if_fail(window_with_focus != NULL);
1343 filer_open_parent(window_with_focus);
1346 static void open_parent_same(gpointer data, guint action, GtkWidget *widget)
1348 g_return_if_fail(window_with_focus != NULL);
1350 change_to_parent(window_with_focus);
1353 static void new_window(gpointer data, guint action, GtkWidget *widget)
1355 g_return_if_fail(window_with_focus != NULL);
1357 if (o_unique_filer_windows)
1358 report_error(PROJECT, _("You can't open a second view onto "
1359 "this directory because the `Unique Windows' option "
1360 "is turned on in the Options window."));
1361 else
1362 filer_opendir(window_with_focus->path);
1365 static void close_window(gpointer data, guint action, GtkWidget *widget)
1367 g_return_if_fail(window_with_focus != NULL);
1369 gtk_widget_destroy(window_with_focus->window);
1372 static void enter_path(gpointer data, guint action, GtkWidget *widget)
1374 g_return_if_fail(window_with_focus != NULL);
1376 minibuffer_show(window_with_focus, MINI_PATH);
1379 static void shell_command(gpointer data, guint action, GtkWidget *widget)
1381 g_return_if_fail(window_with_focus != NULL);
1383 minibuffer_show(window_with_focus, MINI_SHELL);
1386 static void run_action(gpointer data, guint action, GtkWidget *widget)
1388 g_return_if_fail(window_with_focus != NULL);
1390 minibuffer_show(window_with_focus, MINI_RUN_ACTION);
1393 static void select_if(gpointer data, guint action, GtkWidget *widget)
1395 g_return_if_fail(window_with_focus != NULL);
1397 minibuffer_show(window_with_focus, MINI_SELECT_IF);
1400 void menu_rox_help(gpointer data, guint action, GtkWidget *widget)
1402 filer_opendir(make_path(app_dir, "Help")->str);
1405 /* Return a list of full paths of all the selected items */
1406 static GList *list_paths(FilerWindow *filer_window)
1408 Collection *collection = filer_window->collection;
1409 GList *paths = NULL;
1410 int i;
1412 for (i = 0; i < collection->number_of_items; i++)
1414 CollectionItem *colitem = &collection->items[i];
1416 if (colitem->selected)
1418 DirItem *item = (DirItem *) colitem->data;
1420 paths = g_list_prepend(paths,
1421 g_strdup(make_path(filer_window->path,
1422 item->leafname)->str));
1426 return paths;
1429 static void free_paths(GList *paths)
1431 GList *next;
1433 if (!paths)
1434 return;
1436 for (next = paths; next; next = next->next)
1437 g_free(next->data);
1439 g_list_free(paths);
1442 static void pin_help(gpointer data, guint action, GtkWidget *widget)
1444 PinIcon *icon;
1446 icon = pinboard_selected_icon();
1448 if (icon)
1449 pinboard_show_help(icon);
1450 else
1451 delayed_error(PROJECT,
1452 _("You must first select a single pinned icon to get "
1453 "help on."));
1456 static void pin_remove(gpointer data, guint action, GtkWidget *widget)
1458 pinboard_unpin_selection();
1461 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1462 void menu_set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n)
1464 GList *items, *item;
1466 items = gtk_container_children(GTK_CONTAINER(menu));
1468 item = g_list_nth(items, from);
1469 while (item && n--)
1471 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, !shaded);
1472 item = item->next;
1474 g_list_free(items);
1477 /* This is called for every modified menu entry. We just use it to
1478 * find out if the menu has changed at all.
1480 static void set_mod(gboolean *mod, guchar *str)
1482 if (str && str[0] == '(')
1483 *mod = TRUE;
1486 static void save_menus(void)
1488 char *menurc;
1490 menurc = choices_find_path_save("menus", PROJECT, TRUE);
1491 if (menurc)
1493 gboolean mod = FALSE;
1495 /* Find out if anything changed... */
1496 gtk_item_factory_dump_items(NULL, TRUE,
1497 (GtkPrintFunc) set_mod, &mod);
1499 /* Dump out if so... */
1500 if (mod)
1502 mark_menus_modified(TRUE);
1503 gtk_item_factory_dump_rc(menurc, NULL, TRUE);
1504 mark_menus_modified(FALSE);
1509 static void mark_modified(gpointer hash_key,
1510 gpointer value,
1511 gpointer user_data)
1513 GtkItemFactoryItem *item = (GtkItemFactoryItem *) value;
1515 item->modified = (gboolean) user_data;
1518 /* Set or clear the 'modified' flag in all menu items. Messy... */
1519 static void mark_menus_modified(gboolean mod)
1521 GtkItemFactoryClass *class;
1523 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY);
1525 g_hash_table_foreach(class->item_ht, mark_modified, (gpointer) mod);