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)
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
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 */
28 #include <sys/param.h>
44 #include "gui_support.h"
47 #include "gtksavebox.h"
49 #include "minibuffer.h"
55 #define C_ "<control>"
57 #define MENU_MARGIN 32
59 GtkAccelGroup
*filer_keys
;
60 GtkAccelGroup
*panel_keys
;
61 GtkAccelGroup
*pinboard_keys
;
63 GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
65 static gint updating_menu
= 0; /* Non-zero => ignore activations */
68 static GtkWidget
*xterm_here_entry
;
69 static char *xterm_here_value
;
71 /* TRUE if we selected an icon automatically when the menu was opened */
72 static gboolean pin_temp_item_selected
;
74 /* Static prototypes */
76 static void save_menus(void);
77 static void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
, gpointer data
);
78 static void pin_menu_closed(GtkWidget
*widget
);
79 static void menu_closed(GtkWidget
*widget
);
80 static void items_sensitive(gboolean state
);
81 static char *load_xterm_here(char *data
);
82 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
83 gboolean (*callback
)(guchar
*current
, guchar
*new));
84 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
);
85 static GList
*list_paths(FilerWindow
*filer_window
);
86 static void free_paths(GList
*paths
);
87 static void mark_menus_unmodified(void);
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 show_options(gpointer data
, guint action
, GtkWidget
*widget
);
125 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
126 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void rox_help(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void open_as_dir(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void close_panel(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void pin_help(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void pin_remove(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
);
146 static GtkWidget
*create_options();
147 static void update_options();
148 static void set_options();
149 static void save_options();
151 static OptionsSection options
=
161 static GtkWidget
*filer_menu
; /* The popup filer menu */
162 static GtkWidget
*filer_file_item
; /* The File '' label */
163 static GtkWidget
*filer_file_menu
; /* The File '' menu */
164 static GtkWidget
*filer_vfs_menu
; /* The Open VFS menu */
165 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
166 static GtkWidget
*filer_new_window
; /* The New Window item */
167 static GtkWidget
*panel_menu
; /* The popup panel menu */
168 static GtkWidget
*panel_hidden_menu
; /* The Show Hidden item */
169 static GtkWidget
*pinboard_menu
; /* The popup pinboard menu */
171 /* Used for Copy, etc */
172 static GtkWidget
*savebox
= NULL
;
173 static guchar
*current_path
= NULL
;
174 static gboolean (*current_savebox_callback
)(guchar
*current
, guchar
*new);
179 static GtkItemFactoryEntry filer_menu_def
[] = {
180 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
181 {">" N_("Large Icons"), NULL
, large
, 0, NULL
},
182 {">" N_("Small Icons"), NULL
, small
, 0, NULL
},
183 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
184 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
185 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
186 {">>" N_("Size Bars"), NULL
, large_with
, DETAILS_SIZE_BARS
, NULL
},
187 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
188 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
189 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
190 {">>" N_("Size Bars"), NULL
, small_with
, DETAILS_SIZE_BARS
, NULL
},
191 {">", NULL
, NULL
, 0, "<Separator>"},
192 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
193 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
194 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
195 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
196 {">", NULL
, NULL
, 0, "<Separator>"},
197 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
198 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
199 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
200 {">" N_("Copy..."), NULL
, copy_item
, 0, NULL
},
201 {">" N_("Rename..."), NULL
, rename_item
, 0, NULL
},
202 {">" N_("Link..."), NULL
, link_item
, 0, NULL
},
203 {">" N_("Shift Open"), NULL
, open_file
, 0, NULL
},
204 {">" N_("Help"), NULL
, help
, 0, NULL
},
205 {">" N_("Info"), NULL
, show_file_info
, 0, NULL
},
206 {">" N_("Open VFS"), NULL
, NULL
, 0, "<Branch>"},
207 {">>" N_("Unzip"), NULL
, open_vfs_uzip
, 0, NULL
},
208 {">>" N_("Untar"), NULL
, open_vfs_utar
, 0, NULL
},
209 {">>" N_("RPM"), NULL
, open_vfs_rpm
, 0, NULL
},
210 {">", NULL
, NULL
, 0, "<Separator>"},
211 {">" N_("Mount"), NULL
, mount
, 0, NULL
},
212 {">" N_("Delete"), NULL
, delete, 0, NULL
},
213 {">" N_("Disk Usage"), NULL
, usage
, 0, NULL
},
214 {">" N_("Permissions"), NULL
, chmod_items
, 0, NULL
},
215 {">" N_("Find"), NULL
, find
, 0, NULL
},
216 {N_("Select All"), NULL
, select_all
, 0, NULL
},
217 {N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
218 {N_("Options..."), NULL
, show_options
, 0, NULL
},
219 {N_("New Directory..."), NULL
, new_directory
, 0, NULL
},
220 {N_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
221 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
222 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
223 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
224 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
225 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
226 {">", NULL
, NULL
, 0, "<Separator>"},
227 {">" N_("Enter Path..."), NULL
, enter_path
, 0, NULL
},
228 {">" N_("Shell Command..."), NULL
, shell_command
, 0, NULL
},
229 {">" N_("Set Run Action..."), NULL
, run_action
, 0, NULL
},
230 {">" N_("Select If..."), NULL
, select_if
, 0, NULL
},
231 {">", NULL
, NULL
, 0, "<Separator>"},
232 {">" N_("Show ROX-Filer Help"), NULL
, rox_help
, 0, NULL
},
235 static GtkItemFactoryEntry panel_menu_def
[] = {
236 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
237 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
238 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
239 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
240 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
241 {">", NULL
, NULL
, 0, "<Separator>"},
242 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
243 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
244 {N_("Open Panel as Directory"), NULL
, open_as_dir
, 0, NULL
},
245 {N_("Close Panel"), NULL
, close_panel
, 0, NULL
},
246 {"", NULL
, NULL
, 0, "<Separator>"},
247 {N_("ROX-Filer Help"), NULL
, rox_help
, 0, NULL
},
248 {N_("ROX-Filer Options..."), NULL
, show_options
, 0, NULL
},
249 {"", NULL
, NULL
, 0, "<Separator>"},
250 {N_("Show Help"), NULL
, help
, 0, NULL
},
251 {N_("Remove Item"), NULL
, remove_link
, 0, NULL
},
254 static GtkItemFactoryEntry pinboard_menu_def
[] = {
255 {N_("Show Help"), NULL
, pin_help
, 0, NULL
},
256 {N_("Remove Item(s)"), NULL
, pin_remove
, 0, NULL
},
257 {"", NULL
, NULL
, 0, "<Separator>"},
258 {N_("ROX-Filer Help"), NULL
, rox_help
, 0, NULL
},
259 {N_("ROX-Filer Options..."), NULL
, show_options
, 0, NULL
},
263 typedef struct _FileStatus FileStatus
;
265 /* This is for the 'file(1) says...' thing */
268 int fd
; /* FD to read from, -1 if closed */
269 int input
; /* Input watcher tag if fd valid */
270 GtkLabel
*label
; /* Widget to output to */
271 gboolean start
; /* No output yet */
274 #define GET_MENU_ITEM(var, menu) \
275 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
277 #define GET_SMENU_ITEM(var, menu, sub) \
279 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
280 var = gtk_item_factory_get_widget(item_factory, tmp); \
284 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
286 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
287 var = gtk_item_factory_get_widget(item_factory, tmp); \
291 /* Creates menu <name> from the <name>_menu_def array.
292 * The accel group <name>_keys must also have been created.
293 * All menu items are translated. Sets 'item_factory'.
295 #define MAKE_MENU(name) \
297 GtkItemFactoryEntry *translated; \
300 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, \
301 "<" #name ">", name ## _keys); \
303 n_entries = sizeof(name ## _menu_def) / sizeof(*name ## _menu_def); \
304 translated = translate_entries(name ## _menu_def, n_entries); \
305 gtk_item_factory_create_items (item_factory, n_entries, \
307 free_translated_entries(translated, n_entries); \
316 GtkItemFactory
*item_factory
; \
318 filer_keys
= gtk_accel_group_new();
321 GET_MENU_ITEM(filer_menu
, "filer");
322 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
323 GET_SSMENU_ITEM(filer_vfs_menu
, "filer", "File", "Open VFS");
324 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
326 items
= gtk_container_children(GTK_CONTAINER(filer_menu
));
327 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
330 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
331 filer_new_window
= GTK_BIN(item
)->child
;
333 panel_keys
= gtk_accel_group_new();
336 GET_MENU_ITEM(panel_menu
, "panel");
337 GET_SSMENU_ITEM(panel_hidden_menu
, "panel", "Display", "Show Hidden");
339 menurc
= choices_find_path_load("menus", PROJECT
);
342 gtk_item_factory_parse_rc(menurc
);
343 mark_menus_unmodified();
346 gtk_accel_group_lock(panel_keys
);
348 pinboard_keys
= gtk_accel_group_new();
350 gtk_accel_group_lock(pinboard_keys
);
351 GET_MENU_ITEM(pinboard_menu
, "pinboard");
353 gtk_signal_connect(GTK_OBJECT(pinboard_menu
), "unmap_event",
354 GTK_SIGNAL_FUNC(pin_menu_closed
), NULL
);
355 gtk_signal_connect(GTK_OBJECT(filer_menu
), "unmap_event",
356 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
357 gtk_signal_connect(GTK_OBJECT(panel_menu
), "unmap_event",
358 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
359 gtk_signal_connect(GTK_OBJECT(filer_file_menu
), "unmap_event",
360 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
362 options_sections
= g_slist_prepend(options_sections
, &options
);
363 xterm_here_value
= g_strdup("xterm");
364 option_register("xterm_here", load_xterm_here
);
366 savebox
= gtk_savebox_new();
367 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_to_file",
368 GTK_SIGNAL_FUNC(save_to_file
), NULL
);
369 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_done",
370 GTK_SIGNAL_FUNC(gtk_widget_hide
),
371 GTK_OBJECT(savebox
));
376 /* Build up some option widgets to go in the options dialog, but don't
379 static GtkWidget
*create_options()
381 GtkWidget
*table
, *label
;
383 table
= gtk_table_new(2, 2, FALSE
);
384 gtk_container_set_border_width(GTK_CONTAINER(table
), 4);
386 label
= gtk_label_new(
387 _("To set the keyboard short-cuts, simply open "
388 "the menu over a filer window, move the pointer over "
389 "the item you want to use and press a key. The key "
390 "will appear next to the menu item and you can just "
391 "press that key without opening the menu in future."));
392 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
393 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 2, 0, 1);
395 label
= gtk_label_new(_("'Xterm here' program:"));
396 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 1, 2);
397 xterm_here_entry
= gtk_entry_new();
398 gtk_table_attach_defaults(GTK_TABLE(table
), xterm_here_entry
,
404 static char *load_xterm_here(char *data
)
406 g_free(xterm_here_value
);
407 xterm_here_value
= g_strdup(data
);
411 static void update_options()
413 gtk_entry_set_text(GTK_ENTRY(xterm_here_entry
), xterm_here_value
);
416 static void set_options()
418 g_free(xterm_here_value
);
419 xterm_here_value
= g_strdup(gtk_entry_get_text(
420 GTK_ENTRY(xterm_here_entry
)));
423 static void save_options()
426 option_write("xterm_here", xterm_here_value
);
430 static void items_sensitive(gboolean state
)
435 items
= item
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
438 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
443 items
= item
= gtk_container_children(GTK_CONTAINER(filer_vfs_menu
));
446 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
452 static void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
, gpointer data
)
454 int *pos
= (int *) data
;
455 GtkRequisition requisition
;
457 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
460 *x
= screen_width
- MENU_MARGIN
- requisition
.width
;
461 else if (pos
[0] == -2)
464 *x
= pos
[0] - (requisition
.width
>> 2);
467 *y
= screen_height
- MENU_MARGIN
- requisition
.height
;
468 else if (pos
[1] == -2)
471 *y
= pos
[1] - (requisition
.height
>> 2);
473 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
474 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
477 /* Display the pinboard menu. Set icon to NULL if no particular icon
480 void show_pinboard_menu(GdkEventButton
*event
, PinIcon
*icon
)
487 if (pinboard_is_selected(icon
))
488 pin_temp_item_selected
= FALSE
;
491 pinboard_select_only(icon
);
492 pin_temp_item_selected
= TRUE
;
496 icons
= pinboard_get_selected();
498 pos
[0] = event
->x_root
;
499 pos
[1] = event
->y_root
;
503 set_items_shaded(pinboard_menu
,
504 icons
->next
? TRUE
: FALSE
, 0, 1);
506 set_items_shaded(pinboard_menu
, FALSE
, 1, 1);
509 set_items_shaded(pinboard_menu
, TRUE
, 0, 2);
511 gtk_menu_popup(GTK_MENU(pinboard_menu
), NULL
, NULL
, position_menu
,
512 (gpointer
) pos
, event
->button
, event
->time
);
515 void show_filer_menu(FilerWindow
*filer_window
, GdkEventButton
*event
,
523 pos
[0] = event
->x_root
;
524 pos
[1] = event
->y_root
;
526 window_with_focus
= filer_window
;
528 switch (filer_window
->panel_type
)
540 if (filer_window
->panel_type
)
541 collection_clear_selection(filer_window
->collection
); /* ??? */
543 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
545 collection_select_item(filer_window
->collection
, item
);
546 filer_window
->temp_item_selected
= TRUE
;
549 filer_window
->temp_item_selected
= FALSE
;
551 if (filer_window
->panel_type
)
553 gtk_check_menu_item_set_active(
554 GTK_CHECK_MENU_ITEM(panel_hidden_menu
),
555 filer_window
->show_hidden
);
559 GtkWidget
*file_label
, *file_menu
;
560 Collection
*collection
= filer_window
->collection
;
563 file_label
= filer_file_item
;
564 file_menu
= filer_file_menu
;
565 gtk_check_menu_item_set_active(
566 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
567 filer_window
->show_hidden
);
568 buffer
= g_string_new(NULL
);
569 switch (collection
->number_selected
)
572 g_string_assign(buffer
, _("Next Click"));
573 items_sensitive(TRUE
);
576 items_sensitive(TRUE
);
577 file_item
= selected_item(
578 filer_window
->collection
);
579 g_string_sprintf(buffer
, "%s '%s'",
580 basetype_name(file_item
),
581 file_item
->leafname
);
584 items_sensitive(FALSE
);
585 g_string_sprintf(buffer
, _("%d items"),
586 collection
->number_selected
);
589 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
590 g_string_free(buffer
, TRUE
);
594 gtk_widget_set_sensitive(filer_new_window
, !o_unique_filer_windows
);
596 if (filer_window
->panel_type
)
597 popup_menu
= panel_menu
;
599 popup_menu
= (event
->state
& GDK_CONTROL_MASK
)
605 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
606 (gpointer
) pos
, event
->button
, event
->time
);
609 static void pin_menu_closed(GtkWidget
*widget
)
611 if (pin_temp_item_selected
)
612 pinboard_clear_selection();
615 static void menu_closed(GtkWidget
*widget
)
617 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
618 return; /* Close panel item chosen? */
622 if (window_with_focus
->temp_item_selected
)
624 collection_clear_selection(window_with_focus
->collection
);
625 window_with_focus
->temp_item_selected
= FALSE
;
629 void target_callback(Collection
*collection
, gint item
, gpointer real_fn
)
631 g_return_if_fail(window_with_focus
!= NULL
);
632 g_return_if_fail(window_with_focus
->collection
== collection
);
633 g_return_if_fail(real_fn
!= NULL
);
635 collection_wink_item(collection
, item
);
636 collection_clear_selection(collection
);
637 collection_select_item(collection
, item
);
638 ((CollectionTargetFunc
)real_fn
)(NULL
, 0, collection
);
639 if (item
< collection
->number_of_items
)
640 collection_unselect_item(collection
, item
);
645 static void large(gpointer data
, guint action
, GtkWidget
*widget
)
647 g_return_if_fail(window_with_focus
!= NULL
);
649 display_set_layout(window_with_focus
, "Large");
652 static void small(gpointer data
, guint action
, GtkWidget
*widget
)
654 g_return_if_fail(window_with_focus
!= NULL
);
656 display_set_layout(window_with_focus
, "Small");
659 static void set_layout(gboolean large
, DetailsType details
)
663 g_return_if_fail(window_with_focus
!= NULL
);
665 style
= g_strdup_printf("%s+%s",
666 large
? "Large" : "Small",
667 details
== DETAILS_SUMMARY
? "Summary" :
668 details
== DETAILS_SIZE_BARS
? "SizeBars" :
671 display_set_layout(window_with_focus
, style
);
675 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
677 set_layout(TRUE
, (DetailsType
) action
);
680 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
682 set_layout(FALSE
, (DetailsType
) action
);
685 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
687 g_return_if_fail(window_with_focus
!= NULL
);
689 display_set_sort_fn(window_with_focus
, sort_by_name
);
692 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
694 g_return_if_fail(window_with_focus
!= NULL
);
696 display_set_sort_fn(window_with_focus
, sort_by_type
);
699 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
701 g_return_if_fail(window_with_focus
!= NULL
);
703 display_set_sort_fn(window_with_focus
, sort_by_date
);
706 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
708 g_return_if_fail(window_with_focus
!= NULL
);
710 display_set_sort_fn(window_with_focus
, sort_by_size
);
713 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
718 g_return_if_fail(window_with_focus
!= NULL
);
720 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
723 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
725 g_return_if_fail(window_with_focus
!= NULL
);
728 filer_update_dir(window_with_focus
, TRUE
);
731 static void mount(gpointer data
, guint action
, GtkWidget
*widget
)
733 g_return_if_fail(window_with_focus
!= NULL
);
735 if (window_with_focus
->collection
->number_selected
== 0)
736 collection_target(window_with_focus
->collection
,
737 target_callback
, mount
);
742 paths
= list_paths(window_with_focus
);
748 static void delete(gpointer data
, guint action
, GtkWidget
*widget
)
750 g_return_if_fail(window_with_focus
!= NULL
);
752 if (window_with_focus
->collection
->number_selected
== 0)
753 collection_target(window_with_focus
->collection
,
754 target_callback
, delete);
756 action_delete(window_with_focus
);
759 static void remove_link(gpointer data
, guint action
, GtkWidget
*widget
)
761 g_return_if_fail(window_with_focus
!= NULL
);
763 if (window_with_focus
->collection
->number_selected
> 1)
765 report_error(PROJECT
,
766 _("You can only remove one link at a time"));
769 else if (window_with_focus
->collection
->number_selected
== 0)
770 collection_target(window_with_focus
->collection
,
771 target_callback
, remove_link
);
778 item
= selected_item(window_with_focus
->collection
);
780 path
= make_path(window_with_focus
->path
, item
->leafname
)->str
;
781 if (lstat(path
, &info
))
782 report_error(PROJECT
, g_strerror(errno
));
783 else if (!S_ISLNK(info
.st_mode
))
784 report_error(PROJECT
,
785 _("You can only remove symbolic links this way - "
786 "try the 'Open Panel as Directory' item."));
787 else if (unlink(path
))
788 report_error(PROJECT
, g_strerror(errno
));
790 filer_update_dir(window_with_focus
, TRUE
);
794 static void usage(gpointer data
, guint action
, GtkWidget
*widget
)
796 g_return_if_fail(window_with_focus
!= NULL
);
798 if (window_with_focus
->collection
->number_selected
== 0)
799 collection_target(window_with_focus
->collection
,
800 target_callback
, usage
);
802 action_usage(window_with_focus
);
805 static void chmod_items(gpointer data
, guint action
, GtkWidget
*widget
)
807 g_return_if_fail(window_with_focus
!= NULL
);
809 if (window_with_focus
->collection
->number_selected
== 0)
810 collection_target(window_with_focus
->collection
,
811 target_callback
, chmod_items
);
813 action_chmod(window_with_focus
);
816 static void find(gpointer data
, guint action
, GtkWidget
*widget
)
818 g_return_if_fail(window_with_focus
!= NULL
);
820 if (window_with_focus
->collection
->number_selected
== 0)
821 collection_target(window_with_focus
->collection
,
822 target_callback
, find
);
824 action_find(window_with_focus
);
827 /* This pops up our savebox widget, cancelling any currently open one,
828 * and allows the user to pick a new path for it.
829 * Once the new path has been picked, the callback will be called with
830 * both the current and new paths.
832 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
833 gboolean (*callback
)(guchar
*current
, guchar
*new))
835 if (GTK_WIDGET_VISIBLE(savebox
))
836 gtk_widget_hide(savebox
);
839 g_free(current_path
);
840 current_path
= g_strdup(path
);
841 current_savebox_callback
= callback
;
843 gtk_window_set_title(GTK_WINDOW(savebox
), title
);
844 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), current_path
);
845 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
847 gtk_widget_grab_focus(GTK_SAVEBOX(savebox
)->entry
);
848 gtk_widget_show(savebox
);
851 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
)
853 g_return_val_if_fail(current_savebox_callback
!= NULL
,
856 return current_savebox_callback(current_path
, pathname
)
857 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
860 static gboolean
copy_cb(guchar
*current
, guchar
*new)
862 char *new_dir
, *leaf
;
867 report_error(PROJECT
, _("New pathname is not absolute"));
871 if (new[strlen(new) - 1] == '/')
873 new_dir
= g_strdup(new);
880 slash
= strrchr(new, '/');
881 new_dir
= g_strndup(new, slash
- new);
885 local_paths
= g_slist_append(NULL
, current
);
886 action_copy(local_paths
, new_dir
, leaf
);
887 g_slist_free(local_paths
);
894 #define SHOW_SAVEBOX(title, callback) \
898 item = selected_item(collection); \
899 path = make_path(window_with_focus->path, item->leafname)->str; \
900 savebox_show(title, path, item->image, callback); \
903 static void copy_item(gpointer data
, guint action
, GtkWidget
*widget
)
905 Collection
*collection
;
907 g_return_if_fail(window_with_focus
!= NULL
);
909 collection
= window_with_focus
->collection
;
910 if (collection
->number_selected
> 1)
912 report_error(PROJECT
, _("You cannot do this to more than "
913 "one item at a time"));
916 else if (collection
->number_selected
!= 1)
917 collection_target(collection
, target_callback
, copy_item
);
919 SHOW_SAVEBOX(_("Copy"), copy_cb
);
922 static gboolean
rename_cb(guchar
*current
, guchar
*new)
924 if (rename(current
, new))
926 report_error("ROX-Filer: rename()", g_strerror(errno
));
932 static void rename_item(gpointer data
, guint action
, GtkWidget
*widget
)
934 Collection
*collection
;
936 g_return_if_fail(window_with_focus
!= NULL
);
938 collection
= window_with_focus
->collection
;
939 if (collection
->number_selected
> 1)
941 report_error(PROJECT
, _("You cannot do this to more than "
942 "one item at a time"));
945 else if (collection
->number_selected
!= 1)
946 collection_target(collection
, target_callback
, rename_item
);
948 SHOW_SAVEBOX(_("Rename"), rename_cb
);
951 static gboolean
link_cb(guchar
*initial
, guchar
*path
)
953 if (symlink(initial
, path
))
955 report_error("ROX-Filer: symlink()", g_strerror(errno
));
961 static void link_item(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"));
974 else if (collection
->number_selected
!= 1)
975 collection_target(collection
, target_callback
, link_item
);
977 SHOW_SAVEBOX(_("Symlink"), link_cb
);
980 static void open_file(gpointer data
, guint action
, GtkWidget
*widget
)
982 Collection
*collection
;
984 g_return_if_fail(window_with_focus
!= NULL
);
986 collection
= window_with_focus
->collection
;
987 if (collection
->number_selected
> 1)
989 report_error(PROJECT
, _("You cannot do this to more than "
990 "one item at a time"));
993 else if (collection
->number_selected
!= 1)
994 collection_target(collection
, target_callback
, open_file
);
996 filer_openitem(window_with_focus
,
997 selected_item_number(collection
),
998 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1001 /* Got some data from file(1) - stick it in the window. */
1002 static void add_file_output(FileStatus
*fs
,
1003 gint source
, GdkInputCondition condition
)
1009 got
= read(source
, buffer
, sizeof(buffer
) - 1);
1013 gtk_input_remove(fs
->input
);
1017 delayed_error(_("ROX-Filer: file(1) says..."),
1029 gtk_label_get(fs
->label
, &str
);
1031 str
= g_strconcat(str
, buffer
, NULL
);
1032 gtk_label_set_text(fs
->label
, str
);
1036 static void file_info_destroyed(GtkWidget
*widget
, FileStatus
*fs
)
1040 gtk_input_remove(fs
->input
);
1047 /* g_free() the result */
1048 guchar
*pretty_type(DirItem
*file
, guchar
*path
)
1050 if (file
->flags
& ITEM_FLAG_SYMLINK
)
1052 char p
[MAXPATHLEN
+ 1];
1054 got
= readlink(path
, p
, MAXPATHLEN
);
1055 if (got
> 0 && got
<= MAXPATHLEN
)
1058 return g_strconcat(_("Symbolic link to "), p
, NULL
);
1061 return g_strdup(_("Symbolic link"));
1064 if (file
->flags
& ITEM_FLAG_EXEC_FILE
)
1065 return g_strdup(_("Executable file"));
1067 if (file
->flags
& ITEM_FLAG_APPDIR
)
1068 return g_strdup(_("ROX application"));
1070 if (file
->flags
& ITEM_FLAG_MOUNT_POINT
)
1073 if ((file
->flags
& ITEM_FLAG_MOUNTED
) &&
1074 (mp
= g_hash_table_lookup(mtab_mounts
, path
)))
1075 return g_strconcat(_("Mount point for "),
1078 return g_strdup(_("Mount point"));
1081 if (file
->mime_type
)
1082 return g_strconcat(file
->mime_type
->media_type
, "/",
1083 file
->mime_type
->subtype
, NULL
);
1085 return g_strdup("-");
1088 #define LABEL(text, row) \
1089 label = gtk_label_new(text); \
1090 gtk_misc_set_alignment(GTK_MISC(label), 1, .5); \
1091 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); \
1092 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, row, row + 1);
1094 #define VALUE(label, row) \
1095 gtk_misc_set_alignment(GTK_MISC(label), 0, .5); \
1096 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, row, row + 1);
1098 static void show_file_info(gpointer data
, guint action
, GtkWidget
*widget
)
1100 GtkWidget
*window
, *table
, *label
, *button
, *frame
, *value
;
1101 GtkWidget
*file_label
;
1105 char *argv
[] = {"file", "-b", NULL
, NULL
};
1106 Collection
*collection
;
1109 FileStatus
*fs
= NULL
;
1112 g_return_if_fail(window_with_focus
!= NULL
);
1114 collection
= window_with_focus
->collection
;
1115 if (collection
->number_selected
> 1)
1117 report_error(PROJECT
, _("You cannot do this to more than "
1118 "one item at a time"));
1121 else if (collection
->number_selected
!= 1)
1123 collection_target(collection
, target_callback
, show_file_info
);
1126 file
= selected_item(collection
);
1127 path
= make_path(window_with_focus
->path
,
1128 file
->leafname
)->str
;
1129 if (lstat(path
, &info
))
1131 delayed_error(PROJECT
, g_strerror(errno
));
1135 gstring
= g_string_new(NULL
);
1137 window
= gtk_window_new(GTK_WINDOW_DIALOG
);
1138 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_MOUSE
);
1139 gtk_container_set_border_width(GTK_CONTAINER(window
), 4);
1140 gtk_window_set_title(GTK_WINDOW(window
), path
);
1142 table
= gtk_table_new(10, 2, FALSE
);
1143 gtk_container_add(GTK_CONTAINER(window
), table
);
1144 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
1145 gtk_table_set_col_spacings(GTK_TABLE(table
), 4);
1147 value
= gtk_label_new(file
->leafname
);
1148 LABEL(_("Name:"), 0);
1151 g_string_sprintf(gstring
, "%s, %s", user_name(info
.st_uid
),
1152 group_name(info
.st_gid
));
1153 value
= gtk_label_new(gstring
->str
);
1154 LABEL(_("Owner, Group:"), 1);
1157 if (info
.st_size
>= PRETTY_SIZE_LIMIT
)
1159 g_string_sprintf(gstring
, "%s (%ld %s)",
1160 format_size((unsigned long) info
.st_size
),
1161 (unsigned long) info
.st_size
, _("bytes"));
1165 g_string_assign(gstring
,
1166 format_size((unsigned long) info
.st_size
));
1168 value
= gtk_label_new(gstring
->str
);
1169 LABEL(_("Size:"), 2);
1172 value
= gtk_label_new(pretty_time(&info
.st_ctime
));
1173 LABEL(_("Change time:"), 3);
1176 value
= gtk_label_new(pretty_time(&info
.st_mtime
));
1177 LABEL(_("Modify time:"), 4);
1180 value
= gtk_label_new(pretty_time(&info
.st_atime
));
1181 LABEL(_("Access time:"), 5);
1184 value
= gtk_label_new(pretty_permissions(info
.st_mode
));
1185 perm
= applicable(info
.st_uid
, info
.st_gid
);
1186 gtk_label_set_pattern(GTK_LABEL(value
),
1187 perm
== 0 ? "___ " :
1188 perm
== 1 ? " ___ " :
1190 gtk_widget_set_style(value
, fixed_style
);
1191 LABEL(_("Permissions:"), 6);
1194 tmp
= pretty_type(file
, path
);
1195 value
= gtk_label_new(tmp
);
1197 LABEL(_("Type:"), 7);
1200 frame
= gtk_frame_new(_("file(1) says..."));
1201 gtk_table_attach_defaults(GTK_TABLE(table
), frame
, 0, 2, 8, 9);
1202 file_label
= gtk_label_new(_("<nothing yet>"));
1203 gtk_misc_set_padding(GTK_MISC(file_label
), 4, 4);
1204 gtk_label_set_line_wrap(GTK_LABEL(file_label
), TRUE
);
1205 gtk_container_add(GTK_CONTAINER(frame
), file_label
);
1207 button
= gtk_button_new_with_label(_("OK"));
1208 gtk_window_set_focus(GTK_WINDOW(window
), button
);
1209 gtk_table_attach(GTK_TABLE(table
), button
, 0, 2, 10, 11,
1210 GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
, 0, 40, 4);
1211 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1212 gtk_widget_destroy
, GTK_OBJECT(window
));
1214 gtk_widget_show_all(window
);
1217 if (pipe(file_data
))
1219 g_string_sprintf(gstring
, "pipe(): %s", g_strerror(errno
));
1220 g_string_free(gstring
, TRUE
);
1226 g_string_sprintf(gstring
, "fork(): %s",
1228 gtk_label_set_text(GTK_LABEL(file_label
), gstring
->str
);
1229 g_string_free(gstring
, TRUE
);
1230 close(file_data
[0]);
1231 close(file_data
[1]);
1234 /* We are the child */
1235 close(file_data
[0]);
1236 dup2(file_data
[1], STDOUT_FILENO
);
1237 dup2(file_data
[1], STDERR_FILENO
);
1241 argv
[1] = file
->leafname
;
1242 chdir(window_with_focus
->path
);
1244 if (execvp(argv
[0], argv
))
1245 fprintf(stderr
, "execvp() error: %s\n",
1249 /* We are the parent */
1250 close(file_data
[1]);
1251 fs
= g_new(FileStatus
, 1);
1252 fs
->label
= GTK_LABEL(file_label
);
1253 fs
->fd
= file_data
[0];
1255 fs
->input
= gdk_input_add(fs
->fd
, GDK_INPUT_READ
,
1256 (GdkInputFunction
) add_file_output
, fs
);
1257 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
1258 GTK_SIGNAL_FUNC(file_info_destroyed
), fs
);
1259 g_string_free(gstring
, TRUE
);
1264 static void help(gpointer data
, guint action
, GtkWidget
*widget
)
1266 Collection
*collection
;
1269 g_return_if_fail(window_with_focus
!= NULL
);
1271 collection
= window_with_focus
->collection
;
1272 if (collection
->number_selected
> 1)
1274 report_error(PROJECT
, _("You cannot do this to more than "
1275 "one item at a time"));
1278 else if (collection
->number_selected
!= 1)
1280 collection_target(collection
, target_callback
, help
);
1283 item
= selected_item(collection
);
1285 show_item_help(make_path(window_with_focus
->path
, item
->leafname
)->str
,
1289 #define OPEN_VFS(fs) \
1290 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1292 Collection *collection; \
1294 g_return_if_fail(window_with_focus != NULL); \
1296 collection = window_with_focus->collection; \
1297 if (collection->number_selected < 1) \
1298 collection_target(collection, target_callback, \
1301 real_vfs_open(#fs); \
1304 static void real_vfs_open(char *fs
)
1309 if (window_with_focus
->collection
->number_selected
!= 1)
1311 report_error(PROJECT
, _("You must select a single file "
1312 "to open as a Virtual File System"));
1316 item
= selected_item(window_with_focus
->collection
);
1318 path
= g_strconcat(window_with_focus
->path
,
1323 filer_change_to(window_with_focus
, path
, NULL
);
1331 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1333 g_return_if_fail(window_with_focus
!= NULL
);
1335 collection_select_all(window_with_focus
->collection
);
1336 window_with_focus
->temp_item_selected
= FALSE
;
1339 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1341 g_return_if_fail(window_with_focus
!= NULL
);
1343 collection_clear_selection(window_with_focus
->collection
);
1344 window_with_focus
->temp_item_selected
= FALSE
;
1347 static void show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1352 static gboolean
new_directory_cb(guchar
*initial
, guchar
*path
)
1354 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1356 report_error("mkdir", g_strerror(errno
));
1360 dir_check_this(path
);
1364 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1366 g_return_if_fail(window_with_focus
!= NULL
);
1368 savebox_show(_("New Directory"),
1369 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1370 type_to_icon(&special_directory
),
1374 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1376 char *argv
[] = {NULL
, NULL
};
1378 argv
[0] = xterm_here_value
;
1380 g_return_if_fail(window_with_focus
!= NULL
);
1382 if (!spawn_full(argv
, window_with_focus
->path
))
1383 report_error(PROJECT
, "Failed to fork() child "
1387 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1389 g_return_if_fail(window_with_focus
!= NULL
);
1391 filer_open_parent(window_with_focus
);
1394 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1396 g_return_if_fail(window_with_focus
!= NULL
);
1398 change_to_parent(window_with_focus
);
1401 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1403 g_return_if_fail(window_with_focus
!= NULL
);
1405 if (o_unique_filer_windows
)
1406 report_error(PROJECT
, _("You can't open a second view onto "
1407 "this directory because the `Unique Windows' option "
1408 "is turned on in the Options window."));
1410 filer_opendir(window_with_focus
->path
);
1413 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1415 g_return_if_fail(window_with_focus
!= NULL
);
1417 gtk_widget_destroy(window_with_focus
->window
);
1420 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
)
1422 g_return_if_fail(window_with_focus
!= NULL
);
1424 minibuffer_show(window_with_focus
, MINI_PATH
);
1427 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
)
1429 g_return_if_fail(window_with_focus
!= NULL
);
1431 minibuffer_show(window_with_focus
, MINI_SHELL
);
1434 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
)
1436 g_return_if_fail(window_with_focus
!= NULL
);
1438 minibuffer_show(window_with_focus
, MINI_RUN_ACTION
);
1441 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
)
1443 g_return_if_fail(window_with_focus
!= NULL
);
1445 minibuffer_show(window_with_focus
, MINI_SELECT_IF
);
1448 void rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1450 filer_opendir(make_path(app_dir
, "Help")->str
);
1453 static void open_as_dir(gpointer data
, guint action
, GtkWidget
*widget
)
1455 g_return_if_fail(window_with_focus
!= NULL
);
1457 filer_opendir(window_with_focus
->path
);
1460 static void close_panel(gpointer data
, guint action
, GtkWidget
*widget
)
1462 g_return_if_fail(window_with_focus
!= NULL
);
1464 gtk_widget_destroy(window_with_focus
->window
);
1467 /* Return a list of full paths of all the selected items */
1468 static GList
*list_paths(FilerWindow
*filer_window
)
1470 Collection
*collection
= filer_window
->collection
;
1471 GList
*paths
= NULL
;
1474 for (i
= 0; i
< collection
->number_of_items
; i
++)
1476 CollectionItem
*colitem
= &collection
->items
[i
];
1478 if (colitem
->selected
)
1480 DirItem
*item
= (DirItem
*) colitem
->data
;
1482 paths
= g_list_prepend(paths
,
1483 g_strdup(make_path(filer_window
->path
,
1484 item
->leafname
)->str
));
1491 static void free_paths(GList
*paths
)
1498 for (next
= paths
; next
; next
= next
->next
)
1504 static void pin_help(gpointer data
, guint action
, GtkWidget
*widget
)
1508 icon
= pinboard_selected_icon();
1511 pinboard_show_help(icon
);
1513 delayed_error(PROJECT
,
1514 _("You must first select a single pinned icon to get "
1518 static void pin_remove(gpointer data
, guint action
, GtkWidget
*widget
)
1520 pinboard_unpin_selection();
1523 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1524 static void set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1526 GList
*items
, *item
;
1528 items
= gtk_container_children(GTK_CONTAINER(menu
));
1530 item
= g_list_nth(items
, from
);
1533 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1539 /* This is called for every modified menu entry. We just use it to
1540 * find out if the menu has changed at all.
1542 static void set_mod(gboolean
*mod
, guchar
*str
)
1544 if (str
&& str
[0] == '(')
1548 static void save_menus(void)
1552 menurc
= choices_find_path_save("menus", PROJECT
, TRUE
);
1555 gboolean mod
= FALSE
;
1557 /* Find out if anything changed... */
1558 gtk_item_factory_dump_items(NULL
, TRUE
,
1559 (GtkPrintFunc
) set_mod
, &mod
);
1561 /* Dump out if so... */
1563 gtk_item_factory_dump_rc(menurc
, NULL
, TRUE
);
1567 static void mark_unmodified(gpointer hash_key
,
1571 GtkItemFactoryItem
*item
= (GtkItemFactoryItem
*) value
;
1573 item
->modified
= FALSE
;
1576 /* Clear the 'modified' flag in all menu items. Messy... */
1577 static void mark_menus_unmodified(void)
1579 GtkItemFactoryClass
*class;
1581 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY
);
1583 g_hash_table_foreach(class->item_ht
, mark_unmodified
, NULL
);