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"
56 #define C_ "<control>"
58 typedef void (*ActionFn
)(GSList
*paths
, char *dest_dir
, char *leaf
);
60 GtkAccelGroup
*filer_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 char *xterm_here_value
;
71 /* Static prototypes */
73 static void save_menus(void);
74 static void menu_closed(GtkWidget
*widget
);
75 static void items_sensitive(gboolean state
);
76 static char *load_xterm_here(char *data
);
77 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
78 gboolean (*callback
)(guchar
*current
, guchar
*new));
79 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
);
80 static void mark_menus_modified(gboolean mod
);
81 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new);
82 static gboolean
can_set_run_action(DirItem
*item
);
84 /* Note that for most of these callbacks none of the arguments are used. */
85 static void large(gpointer data
, guint action
, GtkWidget
*widget
);
86 static void small(gpointer data
, guint action
, GtkWidget
*widget
);
88 /* (action used in these two - DetailsType) */
89 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
90 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
92 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
93 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
94 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
95 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
97 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
98 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
99 static void create_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
101 static void copy_item(gpointer data
, guint action
, GtkWidget
*widget
);
102 static void rename_item(gpointer data
, guint action
, GtkWidget
*widget
);
103 static void link_item(gpointer data
, guint action
, GtkWidget
*widget
);
104 static void open_file(gpointer data
, guint action
, GtkWidget
*widget
);
105 static void help(gpointer data
, guint action
, GtkWidget
*widget
);
106 static void show_file_info(gpointer data
, guint action
, GtkWidget
*widget
);
107 static void delete(gpointer data
, guint action
, GtkWidget
*widget
);
108 static void usage(gpointer data
, guint action
, GtkWidget
*widget
);
109 static void chmod_items(gpointer data
, guint action
, GtkWidget
*widget
);
110 static void find(gpointer data
, guint action
, GtkWidget
*widget
);
112 static void open_vfs_rpm(gpointer data
, guint action
, GtkWidget
*widget
);
113 static void open_vfs_utar(gpointer data
, guint action
, GtkWidget
*widget
);
114 static void open_vfs_uzip(gpointer data
, guint action
, GtkWidget
*widget
);
115 static void open_vfs_deb(gpointer data
, guint action
, GtkWidget
*widget
);
117 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
118 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
119 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
120 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
122 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
123 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
124 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
125 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
126 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
133 static GtkWidget
*create_options();
134 static void update_options();
135 static void set_options();
136 static void save_options();
138 static OptionsSection options
=
148 static GtkWidget
*filer_menu
; /* The popup filer menu */
149 static GtkWidget
*filer_file_item
; /* The File '' label */
150 static GtkWidget
*filer_file_menu
; /* The File '' menu */
151 static GtkWidget
*file_shift_item
; /* Shift Open label */
152 GtkWidget
*display_large_menu
; /* Display->Large With... */
153 GtkWidget
*display_small_menu
; /* Display->Small With... */
154 static GtkWidget
*filer_vfs_menu
; /* The Open VFS menu */
155 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
156 static GtkWidget
*filer_new_window
; /* The New Window item */
158 /* Used for Copy, etc */
159 static GtkWidget
*savebox
= NULL
;
160 static guchar
*current_path
= NULL
;
161 static gboolean (*current_savebox_callback
)(guchar
*current
, guchar
*new);
166 static GtkItemFactoryEntry filer_menu_def
[] = {
167 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
168 {">" N_("Large Icons"), NULL
, large
, 0, NULL
},
169 {">" N_("Small Icons"), NULL
, small
, 0, NULL
},
170 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
171 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
172 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
173 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
174 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
175 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
176 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
177 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
178 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
179 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
180 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
181 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, 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_("Create Thumbs"), NULL
, create_thumbs
, 0, NULL
},
191 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
192 {">" N_("Copy..."), NULL
, copy_item
, 0, NULL
},
193 {">" N_("Rename..."), NULL
, rename_item
, 0, NULL
},
194 {">" N_("Link..."), NULL
, link_item
, 0, NULL
},
195 {">" N_("Shift Open"), NULL
, open_file
, 0, NULL
},
196 {">" N_("Help"), NULL
, help
, 0, NULL
},
197 {">" N_("Info"), NULL
, show_file_info
, 0, NULL
},
198 {">" N_("Set Run Action..."), NULL
, run_action
, 0, NULL
},
199 {">" N_("Open VFS"), NULL
, NULL
, 0, "<Branch>"},
200 {">>" N_("Unzip"), NULL
, open_vfs_uzip
, 0, NULL
},
201 {">>" N_("Untar"), NULL
, open_vfs_utar
, 0, NULL
},
202 {">>" N_("Deb"), NULL
, open_vfs_deb
, 0, NULL
},
203 {">>" N_("RPM"), NULL
, open_vfs_rpm
, 0, NULL
},
204 {">", NULL
, NULL
, 0, "<Separator>"},
205 {">" N_("Delete"), NULL
, delete, 0, NULL
},
206 {">" N_("Disk Usage"), NULL
, usage
, 0, NULL
},
207 {">" N_("Permissions"), NULL
, chmod_items
, 0, NULL
},
208 {">" N_("Find"), NULL
, find
, 0, NULL
},
209 {N_("Select All"), NULL
, select_all
, 0, NULL
},
210 {N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
211 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
212 {N_("New Directory..."), NULL
, new_directory
, 0, NULL
},
213 {N_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
214 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
215 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
216 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
217 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
218 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
219 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
221 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
222 {">", NULL
, NULL
, 0, "<Separator>"},
223 {">" N_("Enter Path..."), NULL
, enter_path
, 0, NULL
},
224 {">" N_("Shell Command..."), NULL
, shell_command
, 0, NULL
},
225 {">" N_("Select If..."), NULL
, select_if
, 0, NULL
},
226 {">", NULL
, NULL
, 0, "<Separator>"},
227 {">" N_("Show ROX-Filer Help"), NULL
, menu_rox_help
, 0, NULL
},
231 typedef struct _FileStatus FileStatus
;
233 /* This is for the 'file(1) says...' thing */
236 int fd
; /* FD to read from, -1 if closed */
237 int input
; /* Input watcher tag if fd valid */
238 GtkLabel
*label
; /* Widget to output to */
239 gboolean start
; /* No output yet */
242 #define GET_MENU_ITEM(var, menu) \
243 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
245 #define GET_SMENU_ITEM(var, menu, sub) \
247 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
248 var = gtk_item_factory_get_widget(item_factory, tmp); \
252 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
254 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
255 var = gtk_item_factory_get_widget(item_factory, tmp); \
259 /* Creates menu <name> from the <name>_menu_def array.
260 * The accel group <name>_keys must also have been created.
261 * All menu items are translated. Sets 'item_factory'.
263 #define MAKE_MENU(name) \
265 GtkItemFactoryEntry *translated; \
268 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, \
269 "<" #name ">", name ## _keys); \
271 n_entries = sizeof(name ## _menu_def) / sizeof(*name ## _menu_def); \
272 translated = translate_entries(name ## _menu_def, n_entries); \
273 gtk_item_factory_create_items(item_factory, n_entries, \
275 free_translated_entries(translated, n_entries); \
284 GtkItemFactory
*item_factory
;
286 filer_keys
= gtk_accel_group_new();
289 GET_MENU_ITEM(filer_menu
, "filer");
290 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
291 GET_SSMENU_ITEM(filer_vfs_menu
, "filer", "File", "Open VFS");
292 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
294 GET_SSMENU_ITEM(display_large_menu
, "filer",
295 "Display", "Large, With...");
296 GET_SSMENU_ITEM(display_small_menu
, "filer",
297 "Display", "Small, With...");
299 /* This is used for AppMenus */
300 gtk_object_set_data(GTK_OBJECT(filer_file_menu
), "last_appmenu", NULL
);
302 /* File '' label... */
303 items
= gtk_container_children(GTK_CONTAINER(filer_menu
));
304 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
307 /* Shift Open... label */
308 items
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
309 file_shift_item
= GTK_BIN(g_list_nth(items
, 3)->data
)->child
;
312 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
313 filer_new_window
= GTK_BIN(item
)->child
;
315 menurc
= choices_find_path_load("menus", PROJECT
);
318 gtk_item_factory_parse_rc(menurc
);
319 mark_menus_modified(FALSE
);
323 gtk_signal_connect(GTK_OBJECT(filer_menu
), "unmap_event",
324 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
325 gtk_signal_connect(GTK_OBJECT(filer_file_menu
), "unmap_event",
326 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
328 options_sections
= g_slist_prepend(options_sections
, &options
);
329 xterm_here_value
= g_strdup("xterm");
330 option_register("xterm_here", load_xterm_here
);
332 savebox
= gtk_savebox_new();
333 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_to_file",
334 GTK_SIGNAL_FUNC(save_to_file
), NULL
);
335 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_done",
336 GTK_SIGNAL_FUNC(gtk_widget_hide
),
337 GTK_OBJECT(savebox
));
342 /* Name is in the form "<panel>" */
343 GtkWidget
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
, guchar
*name
)
345 GtkItemFactory
*item_factory
;
346 GtkItemFactoryEntry
*translated
;
350 keys
= gtk_accel_group_new();
352 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
354 translated
= translate_entries(def
, n_entries
);
355 gtk_item_factory_create_items(item_factory
, n_entries
,
357 free_translated_entries(translated
, n_entries
);
359 menu
= gtk_item_factory_get_widget(item_factory
, name
);
361 gtk_accel_group_lock(keys
);
366 /* Build up some option widgets to go in the options dialog, but don't
369 static GtkWidget
*create_options()
371 GtkWidget
*table
, *label
;
373 table
= gtk_table_new(2, 2, FALSE
);
374 gtk_container_set_border_width(GTK_CONTAINER(table
), 4);
376 label
= gtk_label_new(
377 _("To set the keyboard short-cuts, simply open "
378 "the menu over a filer window, move the pointer over "
379 "the item you want to use and press a key. The key "
380 "will appear next to the menu item and you can just "
381 "press that key without opening the menu in future."));
382 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
383 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 2, 0, 1);
385 label
= gtk_label_new(_("'Xterm here' program:"));
386 gtk_table_attach_defaults(GTK_TABLE(table
), label
, 0, 1, 1, 2);
387 xterm_here_entry
= gtk_entry_new();
388 gtk_table_attach_defaults(GTK_TABLE(table
), xterm_here_entry
,
394 static char *load_xterm_here(char *data
)
396 g_free(xterm_here_value
);
397 xterm_here_value
= g_strdup(data
);
401 static void update_options()
403 gtk_entry_set_text(GTK_ENTRY(xterm_here_entry
), xterm_here_value
);
406 static void set_options()
408 g_free(xterm_here_value
);
409 xterm_here_value
= g_strdup(gtk_entry_get_text(
410 GTK_ENTRY(xterm_here_entry
)));
413 static void save_options()
416 option_write("xterm_here", xterm_here_value
);
420 static void items_sensitive(gboolean state
)
425 items
= item
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
428 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
433 items
= item
= gtk_container_children(GTK_CONTAINER(filer_vfs_menu
));
436 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
442 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
, gpointer data
)
444 int *pos
= (int *) data
;
445 GtkRequisition requisition
;
447 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
449 *x
= pos
[0] - (requisition
.width
>> 2);
450 *y
= pos
[1] - (requisition
.height
>> 2);
452 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
453 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
456 /* Used when you menu-click on the Large or Small toolbar tools */
457 void show_style_menu(FilerWindow
*filer_window
,
458 GdkEventButton
*event
,
463 pos
[0] = event
->x_root
;
464 pos
[1] = event
->y_root
;
466 window_with_focus
= filer_window
;
470 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
471 (gpointer
) pos
, event
->button
, event
->time
);
474 void show_filer_menu(FilerWindow
*filer_window
, GdkEventButton
*event
,
477 DirItem
*file_item
= NULL
;
479 guchar
*shift_action
;
480 AppMenus
*menus
= NULL
;
484 /* Remove previous AppMenu, if any */
485 appmenu_remove(filer_file_menu
);
487 pos
[0] = event
->x_root
;
488 pos
[1] = event
->y_root
;
490 window_with_focus
= filer_window
;
492 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
494 collection_select_item(filer_window
->collection
, item
);
495 filer_window
->temp_item_selected
= TRUE
;
499 filer_window
->temp_item_selected
= FALSE
;
503 GtkWidget
*file_label
, *file_menu
;
504 Collection
*collection
= filer_window
->collection
;
507 file_label
= filer_file_item
;
508 file_menu
= filer_file_menu
;
509 gtk_check_menu_item_set_active(
510 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
511 filer_window
->show_hidden
);
512 buffer
= g_string_new(NULL
);
513 switch (collection
->number_selected
)
516 g_string_assign(buffer
, _("Next Click"));
517 items_sensitive(TRUE
);
520 items_sensitive(TRUE
);
521 file_item
= selected_item(
522 filer_window
->collection
);
523 g_string_sprintf(buffer
, "%s '%s'",
524 basetype_name(file_item
),
525 file_item
->leafname
);
526 if (!can_set_run_action(file_item
))
527 menu_set_items_shaded(filer_file_menu
,
531 items_sensitive(FALSE
);
532 g_string_sprintf(buffer
, _("%d items"),
533 collection
->number_selected
);
536 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
537 g_string_free(buffer
, TRUE
);
540 if (collection
->number_selected
== 1)
542 if (file_item
->flags
& ITEM_FLAG_MOUNT_POINT
)
544 if (file_item
->flags
& ITEM_FLAG_MOUNTED
)
545 shift_action
= N_("Unmount");
547 shift_action
= N_("Mount");
549 else if (file_item
->flags
& ITEM_FLAG_SYMLINK
)
551 shift_action
= N_("Show Target");
552 menus
= appmenu_query(
553 make_path(filer_window
->path
,
554 file_item
->leafname
)->str
,
557 else if (file_item
->base_type
== TYPE_DIRECTORY
)
559 shift_action
= N_("Look Inside");
560 menus
= appmenu_query(
561 make_path(filer_window
->path
,
562 file_item
->leafname
)->str
,
565 else if (file_item
->base_type
== TYPE_FILE
)
566 shift_action
= N_("Open As Text");
568 gtk_widget_set_sensitive(file_shift_item
,
569 shift_action
!= NULL
||
570 collection
->number_selected
== 0);
571 gtk_label_set_text(GTK_LABEL(file_shift_item
),
572 shift_action
? _(shift_action
)
576 gtk_widget_set_sensitive(filer_new_window
, !o_unique_filer_windows
);
578 popup_menu
= (event
->state
& GDK_CONTROL_MASK
)
583 appmenu_add(menus
, filer_file_menu
);
587 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
588 (gpointer
) pos
, event
->button
, event
->time
);
591 static void menu_closed(GtkWidget
*widget
)
593 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
594 return; /* Close panel item chosen? */
598 if (window_with_focus
->temp_item_selected
)
600 collection_clear_selection(window_with_focus
->collection
);
601 window_with_focus
->temp_item_selected
= FALSE
;
605 void target_callback(FilerWindow
*filer_window
,
609 Collection
*collection
= filer_window
->collection
;
611 g_return_if_fail(window_with_focus
!= NULL
);
612 g_return_if_fail(window_with_focus
== filer_window
);
613 g_return_if_fail(real_fn
!= NULL
);
615 collection_wink_item(collection
, item
);
616 collection_clear_selection(collection
);
617 collection_select_item(collection
, item
);
618 ((GtkItemFactoryCallback1
) real_fn
)(NULL
, 0, GTK_WIDGET(collection
));
619 if (item
< collection
->number_of_items
)
620 collection_unselect_item(collection
, item
);
625 static void large(gpointer data
, guint action
, GtkWidget
*widget
)
627 g_return_if_fail(window_with_focus
!= NULL
);
629 display_set_layout(window_with_focus
, "Large");
632 static void small(gpointer data
, guint action
, GtkWidget
*widget
)
634 g_return_if_fail(window_with_focus
!= NULL
);
636 display_set_layout(window_with_focus
, "Small");
639 static void set_layout(gboolean large
, DetailsType details
)
643 g_return_if_fail(window_with_focus
!= NULL
);
645 style
= g_strdup_printf("%s+%s",
646 large
? "Large" : "Small",
647 details
== DETAILS_SUMMARY
? "Summary" :
648 details
== DETAILS_TIMES
? "Times" :
649 details
== DETAILS_PERMISSIONS
? "Permissions" :
650 details
== DETAILS_TYPE
? "Type" :
653 display_set_layout(window_with_focus
, style
);
657 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
659 set_layout(TRUE
, (DetailsType
) action
);
662 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
664 set_layout(FALSE
, (DetailsType
) action
);
667 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
669 g_return_if_fail(window_with_focus
!= NULL
);
671 display_set_sort_fn(window_with_focus
, sort_by_name
);
674 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
676 g_return_if_fail(window_with_focus
!= NULL
);
678 display_set_sort_fn(window_with_focus
, sort_by_type
);
681 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
683 g_return_if_fail(window_with_focus
!= NULL
);
685 display_set_sort_fn(window_with_focus
, sort_by_date
);
688 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
690 g_return_if_fail(window_with_focus
!= NULL
);
692 display_set_sort_fn(window_with_focus
, sort_by_size
);
695 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
700 g_return_if_fail(window_with_focus
!= NULL
);
702 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
705 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
707 g_return_if_fail(window_with_focus
!= NULL
);
710 filer_update_dir(window_with_focus
, TRUE
);
713 static void create_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
715 g_return_if_fail(window_with_focus
!= NULL
);
717 dir_rescan_with_thumbs(window_with_focus
->directory
,
718 window_with_focus
->path
);
721 static void delete(gpointer data
, guint action
, GtkWidget
*widget
)
723 g_return_if_fail(window_with_focus
!= NULL
);
725 if (window_with_focus
->collection
->number_selected
== 0)
726 filer_target_mode(window_with_focus
,
727 target_callback
, delete,
730 action_delete(window_with_focus
);
733 static void usage(gpointer data
, guint action
, GtkWidget
*widget
)
735 g_return_if_fail(window_with_focus
!= NULL
);
737 if (window_with_focus
->collection
->number_selected
== 0)
738 filer_target_mode(window_with_focus
,
739 target_callback
, usage
,
740 _("Count the size of ... ?"));
742 action_usage(window_with_focus
);
745 static void chmod_items(gpointer data
, guint action
, GtkWidget
*widget
)
747 g_return_if_fail(window_with_focus
!= NULL
);
749 if (window_with_focus
->collection
->number_selected
== 0)
750 filer_target_mode(window_with_focus
,
751 target_callback
, chmod_items
,
752 _("Set permissions on ... ?"));
754 action_chmod(window_with_focus
);
757 static void find(gpointer data
, guint action
, GtkWidget
*widget
)
759 g_return_if_fail(window_with_focus
!= NULL
);
761 if (window_with_focus
->collection
->number_selected
== 0)
762 filer_target_mode(window_with_focus
,
763 target_callback
, find
,
764 _("Search inside ... ?"));
766 action_find(window_with_focus
);
769 /* This pops up our savebox widget, cancelling any currently open one,
770 * and allows the user to pick a new path for it.
771 * Once the new path has been picked, the callback will be called with
772 * both the current and new paths.
774 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
775 gboolean (*callback
)(guchar
*current
, guchar
*new))
777 if (GTK_WIDGET_VISIBLE(savebox
))
778 gtk_widget_hide(savebox
);
781 g_free(current_path
);
782 current_path
= g_strdup(path
);
783 current_savebox_callback
= callback
;
785 gtk_window_set_title(GTK_WINDOW(savebox
), title
);
786 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), current_path
);
787 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
789 gtk_widget_grab_focus(GTK_SAVEBOX(savebox
)->entry
);
790 gtk_widget_show(savebox
);
793 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
)
795 g_return_val_if_fail(current_savebox_callback
!= NULL
,
798 return current_savebox_callback(current_path
, pathname
)
799 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
802 static gboolean
copy_cb(guchar
*current
, guchar
*new)
804 return action_with_leaf(action_copy
, current
, new);
807 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new)
809 char *new_dir
, *leaf
;
814 report_error(PROJECT
, _("New pathname is not absolute"));
818 if (new[strlen(new) - 1] == '/')
820 new_dir
= g_strdup(new);
827 slash
= strrchr(new, '/');
828 new_dir
= g_strndup(new, slash
- new);
832 local_paths
= g_slist_append(NULL
, current
);
833 action(local_paths
, new_dir
, leaf
);
834 g_slist_free(local_paths
);
841 #define SHOW_SAVEBOX(title, callback) \
845 item = selected_item(collection); \
846 path = make_path(window_with_focus->path, item->leafname)->str; \
847 savebox_show(title, path, item->image, callback); \
850 static void copy_item(gpointer data
, guint action
, GtkWidget
*widget
)
852 Collection
*collection
;
854 g_return_if_fail(window_with_focus
!= NULL
);
856 collection
= window_with_focus
->collection
;
857 if (collection
->number_selected
> 1)
859 report_error(PROJECT
, _("You cannot do this to more than "
860 "one item at a time"));
863 else if (collection
->number_selected
!= 1)
864 filer_target_mode(window_with_focus
,
865 target_callback
, copy_item
,
868 SHOW_SAVEBOX(_("Copy"), copy_cb
);
871 static gboolean
rename_cb(guchar
*current
, guchar
*new)
873 return action_with_leaf(action_move
, current
, new);
876 static void rename_item(gpointer data
, guint action
, GtkWidget
*widget
)
878 Collection
*collection
;
880 g_return_if_fail(window_with_focus
!= NULL
);
882 collection
= window_with_focus
->collection
;
883 if (collection
->number_selected
> 1)
885 report_error(PROJECT
, _("You cannot do this to more than "
886 "one item at a time"));
889 else if (collection
->number_selected
!= 1)
890 filer_target_mode(window_with_focus
,
891 target_callback
, rename_item
,
894 SHOW_SAVEBOX(_("Rename"), rename_cb
);
897 static gboolean
link_cb(guchar
*initial
, guchar
*path
)
899 if (symlink(initial
, path
))
901 report_error("ROX-Filer: symlink()", g_strerror(errno
));
907 static void link_item(gpointer data
, guint action
, GtkWidget
*widget
)
909 Collection
*collection
;
911 g_return_if_fail(window_with_focus
!= NULL
);
913 collection
= window_with_focus
->collection
;
914 if (collection
->number_selected
> 1)
916 report_error(PROJECT
, _("You cannot do this to more than "
917 "one item at a time"));
920 else if (collection
->number_selected
!= 1)
921 filer_target_mode(window_with_focus
,
922 target_callback
, link_item
,
925 SHOW_SAVEBOX(_("Symlink"), link_cb
);
928 static void open_file(gpointer data
, guint action
, GtkWidget
*widget
)
930 Collection
*collection
;
932 g_return_if_fail(window_with_focus
!= NULL
);
934 collection
= window_with_focus
->collection
;
935 if (collection
->number_selected
> 1)
937 report_error(PROJECT
, _("You cannot do this to more than "
938 "one item at a time"));
941 else if (collection
->number_selected
!= 1)
942 filer_target_mode(window_with_focus
,
943 target_callback
, open_file
,
944 _("Shift Open ... ?"));
946 filer_openitem(window_with_focus
,
947 selected_item_number(collection
),
948 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
951 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
)
953 Collection
*collection
;
955 g_return_if_fail(window_with_focus
!= NULL
);
957 collection
= window_with_focus
->collection
;
958 if (collection
->number_selected
> 1)
960 report_error(PROJECT
, _("You cannot do this to more than "
961 "one item at a time"));
964 else if (collection
->number_selected
!= 1)
965 filer_target_mode(window_with_focus
,
966 target_callback
, run_action
,
967 _("Set run action for ... ?"));
972 item
= selected_item(collection
);
973 g_return_if_fail(item
!= NULL
);
975 if (can_set_run_action(item
))
976 type_set_handler_dialog(item
->mime_type
);
978 report_error(PROJECT
,
979 _("You can only set the run action for a "
984 /* Got some data from file(1) - stick it in the window. */
985 static void add_file_output(FileStatus
*fs
,
986 gint source
, GdkInputCondition condition
)
992 got
= read(source
, buffer
, sizeof(buffer
) - 1);
996 gtk_input_remove(fs
->input
);
1000 delayed_error(_("ROX-Filer: file(1) says..."),
1012 gtk_label_get(fs
->label
, &str
);
1014 str
= g_strconcat(str
, buffer
, NULL
);
1015 gtk_label_set_text(fs
->label
, str
);
1019 static void file_info_destroyed(GtkWidget
*widget
, FileStatus
*fs
)
1023 gtk_input_remove(fs
->input
);
1030 /* g_free() the result */
1031 guchar
*pretty_type(DirItem
*file
, guchar
*path
)
1033 if (file
->flags
& ITEM_FLAG_SYMLINK
)
1035 char p
[MAXPATHLEN
+ 1];
1037 got
= readlink(path
, p
, MAXPATHLEN
);
1038 if (got
> 0 && got
<= MAXPATHLEN
)
1041 return g_strconcat(_("Symbolic link to "), p
, NULL
);
1044 return g_strdup(_("Symbolic link"));
1047 if (file
->flags
& ITEM_FLAG_APPDIR
)
1048 return g_strdup(_("ROX application"));
1050 if (file
->flags
& ITEM_FLAG_MOUNT_POINT
)
1051 return g_strdup(_("Mount point"));
1053 if (file
->mime_type
)
1054 return g_strconcat(file
->mime_type
->media_type
, "/",
1055 file
->mime_type
->subtype
, NULL
);
1057 return g_strdup("-");
1060 #define LABEL(text, row) \
1061 label = gtk_label_new(text); \
1062 gtk_misc_set_alignment(GTK_MISC(label), 1, .5); \
1063 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); \
1064 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, row, row + 1);
1066 #define VALUE(label, row) \
1067 gtk_misc_set_alignment(GTK_MISC(label), 0, .5); \
1068 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, row, row + 1);
1070 static void show_file_info(gpointer data
, guint action
, GtkWidget
*widget
)
1072 GtkWidget
*window
, *table
, *label
, *button
, *frame
, *value
;
1073 GtkWidget
*file_label
;
1077 char *argv
[] = {"file", "-b", NULL
, NULL
};
1078 Collection
*collection
;
1081 FileStatus
*fs
= NULL
;
1084 g_return_if_fail(window_with_focus
!= NULL
);
1086 collection
= window_with_focus
->collection
;
1087 if (collection
->number_selected
> 1)
1089 report_error(PROJECT
, _("You cannot do this to more than "
1090 "one item at a time"));
1093 else if (collection
->number_selected
!= 1)
1095 filer_target_mode(window_with_focus
,
1096 target_callback
, show_file_info
,
1097 _("Examine ... ?"));
1100 file
= selected_item(collection
);
1101 path
= make_path(window_with_focus
->path
,
1102 file
->leafname
)->str
;
1103 if (lstat(path
, &info
))
1105 delayed_error(PROJECT
, g_strerror(errno
));
1109 gstring
= g_string_new(NULL
);
1111 window
= gtk_window_new(GTK_WINDOW_DIALOG
);
1112 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_MOUSE
);
1113 gtk_container_set_border_width(GTK_CONTAINER(window
), 4);
1114 gtk_window_set_title(GTK_WINDOW(window
), path
);
1116 table
= gtk_table_new(10, 2, FALSE
);
1117 gtk_container_add(GTK_CONTAINER(window
), table
);
1118 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
1119 gtk_table_set_col_spacings(GTK_TABLE(table
), 4);
1121 value
= gtk_label_new(file
->leafname
);
1122 LABEL(_("Name:"), 0);
1125 g_string_sprintf(gstring
, "%s, %s", user_name(info
.st_uid
),
1126 group_name(info
.st_gid
));
1127 value
= gtk_label_new(gstring
->str
);
1128 LABEL(_("Owner, Group:"), 1);
1131 if (info
.st_size
>= PRETTY_SIZE_LIMIT
)
1133 g_string_sprintf(gstring
, "%s (%ld %s)",
1134 format_size((unsigned long) info
.st_size
),
1135 (unsigned long) info
.st_size
, _("bytes"));
1139 g_string_assign(gstring
,
1140 format_size((unsigned long) info
.st_size
));
1142 value
= gtk_label_new(gstring
->str
);
1143 LABEL(_("Size:"), 2);
1146 value
= gtk_label_new(pretty_time(&info
.st_ctime
));
1147 LABEL(_("Change time:"), 3);
1150 value
= gtk_label_new(pretty_time(&info
.st_mtime
));
1151 LABEL(_("Modify time:"), 4);
1154 value
= gtk_label_new(pretty_time(&info
.st_atime
));
1155 LABEL(_("Access time:"), 5);
1158 value
= gtk_label_new(pretty_permissions(info
.st_mode
));
1159 perm
= applicable(info
.st_uid
, info
.st_gid
);
1160 gtk_label_set_pattern(GTK_LABEL(value
),
1161 perm
== 0 ? "___ " :
1162 perm
== 1 ? " ___ " :
1164 gtk_widget_set_style(value
, fixed_style
);
1165 LABEL(_("Permissions:"), 6);
1168 tmp
= pretty_type(file
, path
);
1169 value
= gtk_label_new(tmp
);
1171 LABEL(_("Type:"), 7);
1174 frame
= gtk_frame_new(_("file(1) says..."));
1175 gtk_table_attach_defaults(GTK_TABLE(table
), frame
, 0, 2, 8, 9);
1176 file_label
= gtk_label_new(_("<nothing yet>"));
1177 gtk_misc_set_padding(GTK_MISC(file_label
), 4, 4);
1178 gtk_label_set_line_wrap(GTK_LABEL(file_label
), TRUE
);
1179 gtk_container_add(GTK_CONTAINER(frame
), file_label
);
1181 button
= gtk_button_new_with_label(_("OK"));
1182 gtk_window_set_focus(GTK_WINDOW(window
), button
);
1183 gtk_table_attach(GTK_TABLE(table
), button
, 0, 2, 10, 11,
1184 GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
, 0, 40, 4);
1185 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1186 gtk_widget_destroy
, GTK_OBJECT(window
));
1188 gtk_widget_show_all(window
);
1191 if (pipe(file_data
))
1193 g_string_sprintf(gstring
, "pipe(): %s", g_strerror(errno
));
1194 g_string_free(gstring
, TRUE
);
1200 g_string_sprintf(gstring
, "fork(): %s",
1202 gtk_label_set_text(GTK_LABEL(file_label
), gstring
->str
);
1203 g_string_free(gstring
, TRUE
);
1204 close(file_data
[0]);
1205 close(file_data
[1]);
1208 /* We are the child */
1209 close(file_data
[0]);
1210 dup2(file_data
[1], STDOUT_FILENO
);
1211 dup2(file_data
[1], STDERR_FILENO
);
1215 argv
[1] = file
->leafname
;
1216 chdir(window_with_focus
->path
);
1218 if (execvp(argv
[0], argv
))
1219 fprintf(stderr
, "execvp() error: %s\n",
1223 /* We are the parent */
1224 close(file_data
[1]);
1225 fs
= g_new(FileStatus
, 1);
1226 fs
->label
= GTK_LABEL(file_label
);
1227 fs
->fd
= file_data
[0];
1229 fs
->input
= gdk_input_add(fs
->fd
, GDK_INPUT_READ
,
1230 (GdkInputFunction
) add_file_output
, fs
);
1231 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
1232 GTK_SIGNAL_FUNC(file_info_destroyed
), fs
);
1233 g_string_free(gstring
, TRUE
);
1238 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1240 filer_opendir(home_dir
);
1243 static void help(gpointer data
, guint action
, GtkWidget
*widget
)
1245 Collection
*collection
;
1248 g_return_if_fail(window_with_focus
!= NULL
);
1250 collection
= window_with_focus
->collection
;
1251 if (collection
->number_selected
> 1)
1253 report_error(PROJECT
, _("You cannot do this to more than "
1254 "one item at a time"));
1257 else if (collection
->number_selected
!= 1)
1259 filer_target_mode(window_with_focus
, target_callback
, help
,
1260 _("Help about ... ?"));
1263 item
= selected_item(collection
);
1265 show_item_help(make_path(window_with_focus
->path
, item
->leafname
)->str
,
1269 #define OPEN_VFS(fs) \
1270 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1272 Collection *collection; \
1274 g_return_if_fail(window_with_focus != NULL); \
1276 collection = window_with_focus->collection; \
1277 if (collection->number_selected < 1) \
1278 filer_target_mode(window_with_focus, target_callback, \
1280 _("Look inside ... ?")); \
1282 real_vfs_open(#fs); \
1285 static void real_vfs_open(char *fs
)
1290 if (window_with_focus
->collection
->number_selected
!= 1)
1292 report_error(PROJECT
, _("You must select a single file "
1293 "to open as a Virtual File System"));
1297 item
= selected_item(window_with_focus
->collection
);
1299 path
= g_strconcat(window_with_focus
->path
,
1304 filer_change_to(window_with_focus
, path
, NULL
);
1313 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1315 g_return_if_fail(window_with_focus
!= NULL
);
1317 collection_select_all(window_with_focus
->collection
);
1318 window_with_focus
->temp_item_selected
= FALSE
;
1321 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1323 g_return_if_fail(window_with_focus
!= NULL
);
1325 collection_clear_selection(window_with_focus
->collection
);
1326 window_with_focus
->temp_item_selected
= FALSE
;
1329 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1334 static gboolean
new_directory_cb(guchar
*initial
, guchar
*path
)
1336 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1338 report_error("mkdir", g_strerror(errno
));
1342 dir_check_this(path
);
1346 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1348 g_return_if_fail(window_with_focus
!= NULL
);
1350 savebox_show(_("New Directory"),
1351 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1352 type_to_icon(&special_directory
),
1356 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1358 char *argv
[] = {NULL
, NULL
};
1360 argv
[0] = xterm_here_value
;
1362 g_return_if_fail(window_with_focus
!= NULL
);
1364 if (!spawn_full(argv
, window_with_focus
->path
))
1365 report_error(PROJECT
, _("Failed to fork() child process"));
1368 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1370 g_return_if_fail(window_with_focus
!= NULL
);
1372 filer_open_parent(window_with_focus
);
1375 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1377 g_return_if_fail(window_with_focus
!= NULL
);
1379 change_to_parent(window_with_focus
);
1382 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1384 g_return_if_fail(window_with_focus
!= NULL
);
1386 filer_window_autosize(window_with_focus
);
1389 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1391 g_return_if_fail(window_with_focus
!= NULL
);
1393 if (o_unique_filer_windows
)
1395 report_error(PROJECT
, _("You can't open a second view onto "
1396 "this directory because the `Unique Windows' option "
1397 "is turned on in the Options window."));
1400 filer_opendir(window_with_focus
->path
);
1404 static void su_to_user(GtkWidget
*dialog
)
1407 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1411 g_return_if_fail(dialog
!= NULL
);
1413 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1414 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1416 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1418 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1419 argv
[3] = gtk_entry_get_text(user
);
1420 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1424 report_error(_("fork() failed"), g_strerror(errno
));
1429 gtk_widget_destroy(dialog
);
1432 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1434 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1436 g_return_if_fail(window_with_focus
!= NULL
);
1438 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1439 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1440 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1441 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1442 g_strdup(window_with_focus
->path
), g_free
);
1444 vbox
= gtk_vbox_new(FALSE
, 4);
1445 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1446 gtk_box_pack_start(GTK_BOX(vbox
),
1447 gtk_label_new(_("Browse as which user?")),
1450 hbox
= gtk_hbox_new(FALSE
, 4);
1451 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1453 gtk_box_pack_start(GTK_BOX(hbox
),
1454 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1456 entry
= gtk_entry_new();
1457 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1458 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1459 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1460 gtk_widget_grab_focus(entry
);
1461 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1462 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1463 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1465 hbox
= gtk_hbox_new(TRUE
, 0);
1466 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1468 button
= gtk_button_new_with_label(_("OK"));
1469 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1470 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1471 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1472 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1473 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1475 button
= gtk_button_new_with_label(_("Cancel"));
1476 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1477 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1478 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1479 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1480 GTK_OBJECT(dialog
));
1482 gtk_widget_show_all(dialog
);
1486 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1488 g_return_if_fail(window_with_focus
!= NULL
);
1490 gtk_widget_destroy(window_with_focus
->window
);
1493 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
)
1495 g_return_if_fail(window_with_focus
!= NULL
);
1497 minibuffer_show(window_with_focus
, MINI_PATH
);
1500 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
)
1502 g_return_if_fail(window_with_focus
!= NULL
);
1504 minibuffer_show(window_with_focus
, MINI_SHELL
);
1507 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
)
1509 g_return_if_fail(window_with_focus
!= NULL
);
1511 minibuffer_show(window_with_focus
, MINI_SELECT_IF
);
1514 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1516 filer_opendir(make_path(app_dir
, "Help")->str
);
1519 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1520 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1522 GList
*items
, *item
;
1524 items
= gtk_container_children(GTK_CONTAINER(menu
));
1526 item
= g_list_nth(items
, from
);
1529 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1535 /* This is called for every modified menu entry. We just use it to
1536 * find out if the menu has changed at all.
1538 static void set_mod(gboolean
*mod
, guchar
*str
)
1540 if (str
&& str
[0] == '(')
1544 static void save_menus(void)
1548 menurc
= choices_find_path_save("menus", PROJECT
, FALSE
);
1551 gboolean mod
= FALSE
;
1555 /* Find out if anything changed... */
1556 gtk_item_factory_dump_items(NULL
, TRUE
,
1557 (GtkPrintFunc
) set_mod
, &mod
);
1559 /* Dump out if so... */
1562 menurc
= choices_find_path_save("menus", PROJECT
, TRUE
);
1563 g_return_if_fail(menurc
!= NULL
);
1564 mark_menus_modified(TRUE
);
1565 gtk_item_factory_dump_rc(menurc
, NULL
, TRUE
);
1566 mark_menus_modified(FALSE
);
1572 static void mark_modified(gpointer hash_key
,
1576 GtkItemFactoryItem
*item
= (GtkItemFactoryItem
*) value
;
1578 item
->modified
= (gboolean
) GPOINTER_TO_INT(user_data
);
1581 /* Set or clear the 'modified' flag in all menu items. Messy... */
1582 static void mark_menus_modified(gboolean mod
)
1584 GtkItemFactoryClass
*class;
1586 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY
);
1588 g_hash_table_foreach(class->item_ht
, mark_modified
,
1589 GINT_TO_POINTER(mod
));
1593 /* Returns TRUE is this is something that is run by looking up its type
1594 * in MIME-types and, hence, can have its run action set.
1596 static gboolean
can_set_run_action(DirItem
*item
)
1598 g_return_val_if_fail(item
!= NULL
, FALSE
);
1600 return item
->base_type
== TYPE_FILE
&&
1601 !(item
->mime_type
== &special_exec
);