4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, the ROX-Filer team.
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>
45 #include "gui_support.h"
48 #include "gtksavebox.h"
50 #include "minibuffer.h"
57 #include "usericons.h"
59 #include "collection.h"
62 #define C_ "<control>"
88 typedef enum menu_icon_style
{
89 MIS_NONE
, MIS_SMALL
, MIS_LARGE
, MIS_HUGE
,
90 MIS_CURRENT
, /* As per current filer window */
94 typedef void (*ActionFn
)(GList
*paths
, char *dest_dir
, char *leaf
, int quiet
);
95 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
97 GtkAccelGroup
*filer_keys
;
98 GtkAccelGroup
*pinboard_keys
;
100 GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
102 static gint updating_menu
= 0; /* Non-zero => ignore activations */
103 static GList
*send_to_paths
= NULL
;
105 static Option o_menu_iconsize
, o_menu_xterm
;
107 /* Static prototypes */
109 static void save_menus(void);
110 static void menu_closed(GtkWidget
*widget
);
111 static void items_sensitive(gboolean state
);
112 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
113 gboolean (*callback
)(guchar
*current
, guchar
*new));
114 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
);
115 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new);
116 static gboolean
link_cb(guchar
*initial
, guchar
*path
);
117 static void select_nth_item(GtkMenuShell
*shell
, int n
);
118 static void new_file_type(gchar
*templ
);
119 static void do_send_to(gchar
*templ
);
120 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
122 /* Note that for most of these callbacks none of the arguments are used. */
124 /* (action used in these three - DetailsType) */
125 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
);
126 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
140 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
151 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
152 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
154 /* (action used in this - MiniType) */
155 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
156 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
159 #define MENUS_NAME "menus2"
160 static void keys_changed(gpointer data
);
162 # define MENUS_NAME "menus"
163 static void mark_menus_modified(gboolean mod
);
166 static GtkWidget
*filer_menu
; /* The popup filer menu */
167 static GtkWidget
*filer_file_item
; /* The File '' label */
168 static GtkWidget
*filer_file_menu
; /* The File '' menu */
169 static GtkWidget
*file_shift_item
; /* Shift Open label */
170 GtkWidget
*display_large_menu
; /* Display->Large With... */
171 GtkWidget
*display_small_menu
; /* Display->Small With... */
173 static GtkWidget
*filer_vfs_menu
; /* The Open VFS menu */
175 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
176 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
177 static GtkWidget
*filer_new_window
; /* The New Window item */
178 static GtkWidget
*filer_new_menu
; /* The New submenu */
180 /* Used for Copy, etc */
181 static GtkWidget
*savebox
= NULL
;
182 static GtkWidget
*check_relative
= NULL
;
183 static guchar
*current_path
= NULL
;
184 static gboolean (*current_savebox_callback
)(guchar
*current
, guchar
*new);
189 static GtkItemFactoryEntry filer_menu_def
[] = {
190 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
191 {">" N_("Huge Icons"), NULL
, huge_with
, DETAILS_NONE
, NULL
},
192 {">" N_("Large Icons"), NULL
, large_with
, DETAILS_NONE
, NULL
},
193 {">" N_("Small Icons"), NULL
, small_with
, DETAILS_NONE
, NULL
},
194 {">" N_("Huge, With..."), NULL
, NULL
, 0, "<Branch>"},
195 {">>" N_("Summary"), NULL
, huge_with
, DETAILS_SUMMARY
, NULL
},
196 {">>" N_("Sizes"), NULL
, huge_with
, DETAILS_SIZE
, NULL
},
197 {">>" N_("Permissions"), NULL
, huge_with
, DETAILS_PERMISSIONS
, NULL
},
198 {">>" N_("Type"), NULL
, huge_with
, DETAILS_TYPE
, NULL
},
199 {">>" N_("Times"), NULL
, huge_with
, DETAILS_TIMES
, NULL
},
200 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
201 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
202 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
203 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
204 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
205 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
206 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
207 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
208 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
209 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
210 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
211 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, NULL
},
212 {">", NULL
, NULL
, 0, "<Separator>"},
213 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
214 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
215 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
216 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
217 {">", NULL
, NULL
, 0, "<Separator>"},
218 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
219 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
220 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
221 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
222 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, NULL
},
223 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
224 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
225 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
226 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
227 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
228 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
229 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
231 {">" N_("Open VFS"), NULL
, NULL
, 0, "<Branch>"},
232 {">>" N_("Unzip"), NULL
, file_op
, FILE_OPEN_VFS_UZIP
, NULL
},
233 {">>" N_("Untar"), NULL
, file_op
, FILE_OPEN_VFS_UTAR
, NULL
},
234 {">>" N_("Deb"), NULL
, file_op
, FILE_OPEN_VFS_DEB
, NULL
},
235 {">>" N_("RPM"), NULL
, file_op
, FILE_OPEN_VFS_RPM
, NULL
},
237 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
239 {">", NULL
, NULL
, 0, "<Separator>"},
240 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
241 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
242 {">" N_("Disk Usage"), NULL
, file_op
, FILE_USAGE
, NULL
},
243 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
244 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
245 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
246 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
247 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
248 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
249 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
250 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
251 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
252 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
253 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
254 {N_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
255 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
256 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
257 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
258 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
259 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
260 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
261 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
263 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
264 {">", NULL
, NULL
, 0, "<Separator>"},
265 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
266 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
267 {">", NULL
, NULL
, 0, "<Separator>"},
268 {">" N_("Show ROX-Filer Help"), "F1", menu_rox_help
, 0, NULL
},
272 #define GET_MENU_ITEM(var, menu) \
273 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
275 #define GET_SMENU_ITEM(var, menu, sub) \
277 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
278 var = gtk_item_factory_get_widget(item_factory, tmp); \
282 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
284 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
285 var = gtk_item_factory_get_widget(item_factory, tmp); \
296 GtkItemFactory
*item_factory
;
298 filer_keys
= gtk_accel_group_new();
299 item_factory
= menu_create(filer_menu_def
,
300 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
301 "<filer>", filer_keys
);
303 GET_MENU_ITEM(filer_menu
, "filer");
304 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
306 GET_SSMENU_ITEM(filer_vfs_menu
, "filer", "File", "Open VFS");
308 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
309 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
312 GET_SSMENU_ITEM(display_large_menu
, "filer",
313 "Display", "Large, With...");
314 GET_SSMENU_ITEM(display_small_menu
, "filer",
315 "Display", "Small, With...");
317 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
319 /* File '' label... */
320 items
= gtk_container_children(GTK_CONTAINER(filer_menu
));
321 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
324 /* Shift Open... label */
325 items
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
326 file_shift_item
= GTK_BIN(g_list_nth(items
, 3)->data
)->child
;
329 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
330 filer_new_window
= GTK_BIN(item
)->child
;
332 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
336 gtk_accel_map_load(menurc
);
338 gtk_item_factory_parse_rc(menurc
);
339 mark_menus_modified(FALSE
);
344 gtk_signal_connect(GTK_OBJECT(filer_menu
), "unmap_event",
345 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
346 gtk_signal_connect(GTK_OBJECT(filer_file_menu
), "unmap_event",
347 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
349 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
350 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
351 option_add_saver(save_menus
);
353 tips
= gtk_tooltips_new();
354 check_relative
= gtk_check_button_new_with_label(_("Relative link"));
355 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
), TRUE
);
356 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
357 gtk_tooltips_set_tip(tips
, check_relative
,
358 _("If on, the symlink will store the path from the "
359 "symlink to the target file. Use this if the symlink "
360 "and the target will be moved together.\n"
361 "If off, the path from the root directory is stored - "
362 "use this if the symlink may move but the target will "
365 savebox
= gtk_savebox_new();
366 gtk_box_pack_start(GTK_BOX(GTK_SAVEBOX(savebox
)->vbox
),
367 check_relative
, FALSE
, TRUE
, 0);
368 gtk_widget_show(check_relative
);
370 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_to_file",
371 GTK_SIGNAL_FUNC(save_to_file
), NULL
);
372 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_done",
373 GTK_SIGNAL_FUNC(gtk_widget_hide
),
374 GTK_OBJECT(savebox
));
377 g_signal_connect_object(G_OBJECT(filer_keys
), "accel_changed",
378 (GCallback
) keys_changed
, NULL
, 0);
384 /* Name is in the form "<panel>" */
385 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
386 guchar
*name
, GtkAccelGroup
*keys
)
388 GtkItemFactory
*item_factory
;
389 GtkItemFactoryEntry
*translated
;
393 keys
= gtk_accel_group_new();
394 gtk_accel_group_lock(keys
);
397 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
399 translated
= translate_entries(def
, n_entries
);
400 gtk_item_factory_create_items(item_factory
, n_entries
,
402 free_translated_entries(translated
, n_entries
);
407 /* Prevent the user from setting a short-cut on this item */
408 void menuitem_no_shortcuts(GtkWidget
*item
)
412 GtkMenuItem *menuitem = GTK_MENU_ITEM(item);
414 _gtk_widget_set_accel_path(item, NULL, NULL);
415 g_free(menuitem->accel_path);
416 menuitem->accel_path = NULL;
419 gtk_widget_lock_accelerators(item
);
423 static void items_sensitive(gboolean state
)
428 items
= item
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
431 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
437 items
= item
= gtk_container_children(GTK_CONTAINER(filer_vfs_menu
));
440 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
447 /* 'data' is an array of three ints:
448 * [ pointer_x, pointer_y, item_under_pointer ]
450 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
456 int *pos
= (int *) data
;
457 GtkRequisition requisition
;
462 next
= items
= gtk_container_children(GTK_CONTAINER(menu
));
464 while (item
>= 0 && next
)
466 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
479 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
481 *x
= pos
[0] - (requisition
.width
* 7 / 8);
482 *y
= pos
[1] - y_shift
;
484 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
485 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
493 /* Used when you menu-click on the Large or Small toolbar tools */
494 void show_style_menu(FilerWindow
*filer_window
,
495 GdkEventButton
*event
,
500 pos
[0] = event
->x_root
;
501 pos
[1] = event
->y_root
;
504 window_with_focus
= filer_window
;
508 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
509 (gpointer
) pos
, event
->button
, event
->time
);
513 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dname
,
514 MenuIconStyle style
, CallbackFn func
,
515 gboolean separator
, gboolean strip_ext
)
517 GList
*widgets
= NULL
;
523 dir
= opendir(dname
);
529 item
= gtk_menu_item_new();
530 widgets
= g_list_append(widgets
, item
);
531 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
534 while ((ent
= readdir(dir
)))
544 /* Ignore hidden files */
545 if (ent
->d_name
[0] == '.')
548 /* Strip off extension, if any */
549 dot
= strchr(ent
->d_name
, '.');
550 if (strip_ext
&& dot
)
551 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
553 leaf
= g_strdup(ent
->d_name
);
555 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
556 ditem
= diritem_new(NULL
);
557 diritem_restat(fname
, ditem
);
559 if (ditem
->image
&& style
!= MIS_NONE
)
563 if (!ditem
->image
->huge_pixmap
)
564 pixmap_make_huge(ditem
->image
);
565 icon
= ditem
->image
->huge_pixmap
;
566 mask
= ditem
->image
->huge_mask
;
569 icon
= ditem
->image
->pixmap
;
570 mask
= ditem
->image
->mask
;
575 if (!ditem
->image
->sm_pixmap
)
576 pixmap_make_small(ditem
->image
);
577 icon
= ditem
->image
->sm_pixmap
;
578 mask
= ditem
->image
->sm_mask
;
582 item
= gtk_menu_item_new();
583 /* TODO: Find a way to allow short-cuts */
584 menuitem_no_shortcuts(item
);
586 hbox
= gtk_hbox_new(FALSE
, 2);
587 gtk_container_add(GTK_CONTAINER(item
), hbox
);
589 img
= gtk_pixmap_new(icon
, mask
);
590 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
592 label
= gtk_label_new(leaf
);
593 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
594 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
599 item
= gtk_menu_item_new_with_label(leaf
);
603 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
604 GTK_SIGNAL_FUNC(func
), (GtkObject
*) fname
);
605 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
606 gtk_signal_connect_object(GTK_OBJECT(item
), "destroy",
607 GTK_SIGNAL_FUNC(g_free
), (GtkObject
*) fname
);
609 widgets
= g_list_append(widgets
, item
);
618 /* Scan the templates dir and create entries for the New menu */
619 static void update_new_files_menu(MenuIconStyle style
)
621 static GList
*widgets
= NULL
;
623 gchar
*templ_dname
= NULL
;
629 for (next
= widgets
; next
; next
= next
->next
)
630 gtk_widget_destroy((GtkWidget
*) next
->data
);
632 g_list_free(widgets
);
636 templ_dname
= choices_find_path_load("Templates", "");
639 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
640 (CallbackFn
) new_file_type
, TRUE
, TRUE
);
643 gtk_widget_show_all(filer_new_menu
);
646 /* 'item' is the number of the item to appear under the pointer. */
647 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
653 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
654 event
->type
== GDK_BUTTON_RELEASE
))
656 GdkEventButton
*bev
= (GdkEventButton
*) event
;
658 pos
[0] = bev
->x_root
;
659 pos
[1] = bev
->y_root
;
660 button
= bev
->button
;
663 else if (event
&& event
->type
== GDK_KEY_PRESS
)
665 GdkEventKey
*kev
= (GdkEventKey
*) event
;
667 get_pointer_xy(pos
, pos
+ 1);
671 get_pointer_xy(pos
, pos
+ 1);
675 gtk_widget_show_all(menu
);
676 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
677 position_menu
, (gpointer
) pos
, button
, time
);
678 select_nth_item(GTK_MENU_SHELL(menu
), item
);
681 static MenuIconStyle
get_menu_icon_style(void)
686 mis
= o_menu_iconsize
.int_value
;
690 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
: case MIS_HUGE
:
696 if (mis
== MIS_CURRENT
&& window_with_focus
)
698 switch (window_with_focus
->display_style
)
711 display
= o_display_size
.int_value
;
727 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
729 DirItem
*file_item
= NULL
;
730 GdkModifierType state
= 0;
734 /* Remove previous AppMenu, if any */
737 window_with_focus
= filer_window
;
739 if (event
->type
== GDK_BUTTON_PRESS
)
740 state
= ((GdkEventButton
*) event
)->state
;
741 else if (event
->type
== GDK_KEY_PRESS
)
742 state
= ((GdkEventKey
*) event
)->state
;
744 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
746 filer_window
->temp_item_selected
= TRUE
;
747 collection_select_item(filer_window
->collection
, item
);
751 filer_window
->temp_item_selected
= FALSE
;
754 /* Short-cut to the Send To menu */
755 if (state
& GDK_SHIFT_MASK
)
761 if (filer_window
->collection
->number_selected
== 0)
764 _("You should Shift+Menu click over a file to "
765 "send it somewhere"));
769 paths
= filer_selected_items(filer_window
);
771 show_send_to_menu(paths
, event
); /* (paths eaten) */
777 GtkWidget
*file_label
, *file_menu
;
778 Collection
*collection
= filer_window
->collection
;
782 file_label
= filer_file_item
;
783 file_menu
= filer_file_menu
;
784 gtk_check_menu_item_set_active(
785 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
786 filer_window
->show_thumbs
);
787 gtk_check_menu_item_set_active(
788 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
789 filer_window
->show_hidden
);
790 buffer
= g_string_new(NULL
);
792 switch (collection
->number_selected
)
795 g_string_assign(buffer
, _("Next Click"));
796 items_sensitive(TRUE
);
799 item
= selected_item(filer_window
->collection
);
801 dir_update_item(filer_window
->directory
,
803 items_sensitive(TRUE
);
804 file_item
= selected_item(
805 filer_window
->collection
);
806 g_string_sprintf(buffer
, "%s '%s'",
807 basetype_name(file_item
),
808 file_item
->leafname
);
809 if (!can_set_run_action(file_item
))
810 menu_set_items_shaded(filer_file_menu
,
814 items_sensitive(FALSE
);
815 g_string_sprintf(buffer
, _("%d items"),
816 collection
->number_selected
);
819 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
820 g_string_free(buffer
, TRUE
);
822 menu_show_shift_action(file_shift_item
, file_item
,
823 collection
->number_selected
== 0);
825 appmenu_add(make_path(filer_window
->path
,
826 file_item
->leafname
)->str
,
827 file_item
, filer_file_menu
);
830 update_new_files_menu(get_menu_icon_style());
832 gtk_widget_set_sensitive(filer_new_window
,
833 !o_unique_filer_windows
.int_value
);
835 popup_menu
= (state
& GDK_CONTROL_MASK
)
841 show_popup_menu(popup_menu
, event
,
842 popup_menu
== filer_file_menu
? 5 : 1);
845 static void menu_closed(GtkWidget
*widget
)
847 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
848 return; /* Close panel item chosen? */
852 if (window_with_focus
->temp_item_selected
)
854 collection_clear_selection(window_with_focus
->collection
);
855 window_with_focus
->temp_item_selected
= FALSE
;
859 void target_callback(FilerWindow
*filer_window
,
863 Collection
*collection
= filer_window
->collection
;
865 g_return_if_fail(window_with_focus
!= NULL
);
866 g_return_if_fail(window_with_focus
== filer_window
);
868 /* Don't grab the primary selection */
869 filer_window
->temp_item_selected
= TRUE
;
871 collection_wink_item(collection
, item
);
872 collection_clear_except(collection
, item
);
873 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
875 if (item
< collection
->number_of_items
)
876 collection_unselect_item(collection
, item
);
877 filer_window
->temp_item_selected
= FALSE
;
880 /* Set the text of the 'Shift Open...' menu item.
881 * If icon is NULL, reset the text and also shade it, unless 'next'.
883 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
885 guchar
*shift_action
= NULL
;
889 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
891 if (item
->flags
& ITEM_FLAG_MOUNTED
)
892 shift_action
= N_("Unmount");
894 shift_action
= N_("Mount");
896 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
897 shift_action
= N_("Show Target");
898 else if (item
->base_type
== TYPE_DIRECTORY
)
899 shift_action
= N_("Look Inside");
900 else if (item
->base_type
== TYPE_FILE
)
901 shift_action
= N_("Open As Text");
903 gtk_label_set_text(GTK_LABEL(menu_item
),
904 shift_action
? _(shift_action
)
906 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
911 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
913 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
916 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
918 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
921 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
923 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
926 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
928 g_return_if_fail(window_with_focus
!= NULL
);
930 display_set_sort_fn(window_with_focus
, sort_by_name
);
933 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
935 g_return_if_fail(window_with_focus
!= NULL
);
937 display_set_sort_fn(window_with_focus
, sort_by_type
);
940 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
942 g_return_if_fail(window_with_focus
!= NULL
);
944 display_set_sort_fn(window_with_focus
, sort_by_date
);
947 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
949 g_return_if_fail(window_with_focus
!= NULL
);
951 display_set_sort_fn(window_with_focus
, sort_by_size
);
954 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
959 g_return_if_fail(window_with_focus
!= NULL
);
961 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
964 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
969 g_return_if_fail(window_with_focus
!= NULL
);
971 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
974 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
976 g_return_if_fail(window_with_focus
!= NULL
);
979 filer_update_dir(window_with_focus
, TRUE
);
982 static void delete(FilerWindow
*filer_window
)
985 paths
= filer_selected_items(filer_window
);
986 action_delete(paths
);
987 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
991 static void usage(FilerWindow
*filer_window
)
994 paths
= filer_selected_items(filer_window
);
996 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
1000 static void chmod_items(FilerWindow
*filer_window
)
1003 paths
= filer_selected_items(filer_window
);
1004 action_chmod(paths
);
1005 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
1009 static void find(FilerWindow
*filer_window
)
1012 paths
= filer_selected_items(filer_window
);
1014 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
1018 /* This pops up our savebox widget, cancelling any currently open one,
1019 * and allows the user to pick a new path for it.
1020 * Once the new path has been picked, the callback will be called with
1021 * both the current and new paths.
1022 * NOTE: This function unrefs 'image'!
1024 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
1025 gboolean (*callback
)(guchar
*current
, guchar
*new))
1027 g_return_if_fail(image
!= NULL
);
1029 if (GTK_WIDGET_VISIBLE(savebox
))
1030 gtk_widget_hide(savebox
);
1032 if (callback
== link_cb
)
1033 gtk_widget_show(check_relative
);
1035 gtk_widget_hide(check_relative
);
1038 g_free(current_path
);
1039 current_path
= g_strdup(path
);
1040 current_savebox_callback
= callback
;
1042 gtk_window_set_title(GTK_WINDOW(savebox
), title
);
1043 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), current_path
);
1044 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
1045 pixmap_unref(image
);
1047 gtk_widget_show(savebox
);
1050 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
)
1052 g_return_val_if_fail(current_savebox_callback
!= NULL
,
1053 GTK_XDS_SAVE_ERROR
);
1055 return current_savebox_callback(current_path
, pathname
)
1056 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1059 static gboolean
copy_cb(guchar
*current
, guchar
*new)
1061 return action_with_leaf(action_copy
, current
, new);
1064 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new)
1066 char *new_dir
, *leaf
;
1071 report_error(_("New pathname is not absolute"));
1075 if (new[strlen(new) - 1] == '/')
1077 new_dir
= g_strdup(new);
1084 slash
= strrchr(new, '/');
1085 new_dir
= g_strndup(new, slash
- new);
1089 local_paths
= g_list_append(NULL
, current
);
1090 action(local_paths
, new_dir
, leaf
, -1);
1091 g_list_free(local_paths
);
1098 /* Open a savebox to act on the selected file.
1099 * Call 'callback' later to perform the operation.
1101 static void src_dest_action_item(guchar
*path
, MaskedPixmap
*image
,
1103 gboolean (*callback
)(guchar
*, guchar
*))
1106 savebox_show(title
, path
, image
, callback
);
1109 static gboolean
rename_cb(guchar
*current
, guchar
*new)
1111 return action_with_leaf(action_move
, current
, new);
1114 static gboolean
link_cb(guchar
*initial
, guchar
*path
)
1118 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_relative
)))
1122 rpath
= get_relative_path(path
, initial
);
1123 err
= symlink(rpath
, path
);
1128 err
= symlink(initial
, path
);
1132 report_error("symlink: %s", g_strerror(errno
));
1136 dir_check_this(path
);
1141 static void run_action(DirItem
*item
)
1143 if (can_set_run_action(item
))
1144 type_set_handler_dialog(item
->mime_type
);
1147 _("You can only set the run action for a "
1151 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1153 filer_opendir(home_dir
, NULL
);
1157 static void real_vfs_open(FilerWindow
*filer_window
, DirItem
*item
, char *fs
)
1161 path
= g_strconcat(filer_window
->path
,
1166 filer_change_to(filer_window
, path
, NULL
);
1170 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1174 path
= g_strconcat(filer_window
->path
,
1175 "/", item
->leafname
, "#", NULL
);
1177 filer_change_to(filer_window
, path
, NULL
);
1182 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1184 g_return_if_fail(window_with_focus
!= NULL
);
1186 window_with_focus
->temp_item_selected
= FALSE
;
1187 collection_select_all(window_with_focus
->collection
);
1190 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1192 g_return_if_fail(window_with_focus
!= NULL
);
1194 window_with_focus
->temp_item_selected
= FALSE
;
1195 collection_clear_selection(window_with_focus
->collection
);
1198 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1200 g_return_if_fail(window_with_focus
!= NULL
);
1202 window_with_focus
->temp_item_selected
= FALSE
;
1203 collection_invert_selection(window_with_focus
->collection
);
1206 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1211 static gboolean
new_directory_cb(guchar
*initial
, guchar
*path
)
1213 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1215 report_error("mkdir: %s", g_strerror(errno
));
1219 dir_check_this(path
);
1221 if (filer_exists(window_with_focus
))
1224 leaf
= strrchr(path
, '/');
1226 display_set_autoselect(window_with_focus
, leaf
+ 1);
1232 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1234 g_return_if_fail(window_with_focus
!= NULL
);
1236 savebox_show(_("New Directory"),
1237 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1238 type_to_icon(special_directory
),
1242 static gboolean
new_file_cb(guchar
*initial
, guchar
*path
)
1246 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1250 report_error(_("Error creating '%s': %s"),
1251 path
, g_strerror(errno
));
1256 report_error(_("Error creating '%s': %s"),
1257 path
, g_strerror(errno
));
1259 dir_check_this(path
);
1261 if (filer_exists(window_with_focus
))
1264 leaf
= strrchr(path
, '/');
1266 display_set_autoselect(window_with_focus
, leaf
+ 1);
1272 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1274 g_return_if_fail(window_with_focus
!= NULL
);
1276 savebox_show(_("New File"),
1277 make_path(window_with_focus
->path
, _("NewFile"))->str
,
1278 type_to_icon(text_plain
),
1282 static gboolean
new_file_type_cb(guchar
*initial
, guchar
*path
)
1284 gchar
*templ
, *templ_dname
, *oleaf
, *dest
, *leaf
;
1287 /* We can work out the template path from the initial name */
1288 oleaf
= g_basename(initial
);
1289 templ_dname
= choices_find_path_load("Templates", "");
1293 _("Error creating file: could not find the template for %s"),
1298 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1299 g_free(templ_dname
);
1301 dest
= g_dirname(path
);
1302 leaf
= g_basename(path
);
1303 paths
= g_list_append(NULL
, templ
);
1305 action_copy(paths
, dest
, leaf
, -1);
1311 if (filer_exists(window_with_focus
))
1312 display_set_autoselect(window_with_focus
, leaf
);
1317 static void do_send_to(gchar
*templ
)
1319 g_return_if_fail(send_to_paths
!= NULL
);
1321 run_with_files(templ
, send_to_paths
);
1324 static void new_file_type(gchar
*templ
)
1329 g_return_if_fail(window_with_focus
!= NULL
);
1331 leaf
= g_basename(templ
);
1332 type
= type_get_type(templ
);
1334 savebox_show(_("New File"),
1335 make_path(window_with_focus
->path
, leaf
)->str
,
1340 static void customise_send_to(gpointer data
)
1347 dirs
= g_string_new(NULL
);
1349 path
= choices_list_dirs("");
1350 for (i
= 0; i
< path
->len
; i
++)
1352 guchar
*old
= (guchar
*) path
->pdata
[i
];
1354 g_string_append(dirs
, old
);
1355 g_string_append(dirs
, "SendTo\n");
1357 choices_free_list(path
);
1359 save
= choices_find_path_save("", "SendTo", TRUE
);
1364 _("The `Send To' menu provides a quick way to send some files "
1365 "to an application. The applications listed are those in "
1366 "the following directories:\n\n%s\n%s\n"
1367 "The `Send To' menu may be opened by Shift+Menu clicking "
1370 save
? _("I'll show you your SendTo directory now; you should "
1371 "symlink (Ctrl+Shift drag) any applications you want "
1373 : _("Your CHOICESPATH variable setting prevents "
1374 "customisations - sorry."));
1376 g_string_free(dirs
, TRUE
);
1379 filer_opendir(save
, NULL
);
1382 /* Scan the SendTo dir and create and show the Send To menu.
1383 * The 'paths' list and every path in it is claimed, and will be
1384 * freed later -- don't free it yourself!
1386 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1388 GtkWidget
*menu
, *item
;
1392 menu
= gtk_menu_new();
1394 path
= choices_list_dirs("SendTo");
1396 for (i
= 0; i
< path
->len
; i
++)
1398 GList
*widgets
= NULL
;
1399 guchar
*dir
= (guchar
*) path
->pdata
[i
];
1401 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1402 (CallbackFn
) do_send_to
,
1406 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1407 gtk_menu_item_new());
1409 g_list_free(widgets
); /* TODO: Get rid of this */
1412 choices_free_list(path
);
1414 item
= gtk_menu_item_new_with_label(_("Customise"));
1415 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
1416 GTK_SIGNAL_FUNC(customise_send_to
), NULL
);
1417 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1421 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1422 g_list_free(send_to_paths
);
1424 send_to_paths
= paths
;
1426 gtk_signal_connect(GTK_OBJECT(menu
), "unmap_event",
1427 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
1430 show_popup_menu(menu
, event
, 0);
1433 static void send_to(FilerWindow
*filer_window
)
1438 paths
= filer_selected_items(filer_window
);
1439 event
= gtk_get_current_event();
1442 show_send_to_menu(paths
, event
);
1444 gdk_event_free(event
);
1447 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1449 char *argv
[] = {"sh", "-c", NULL
, NULL
};
1451 argv
[2] = o_menu_xterm
.value
;
1453 g_return_if_fail(window_with_focus
!= NULL
);
1455 rox_spawn(window_with_focus
->path
, argv
);
1458 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1460 g_return_if_fail(window_with_focus
!= NULL
);
1462 filer_change_to(window_with_focus
, home_dir
, NULL
);
1465 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1467 g_return_if_fail(window_with_focus
!= NULL
);
1469 filer_open_parent(window_with_focus
);
1472 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1474 g_return_if_fail(window_with_focus
!= NULL
);
1476 change_to_parent(window_with_focus
);
1479 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1481 g_return_if_fail(window_with_focus
!= NULL
);
1483 filer_window_autosize(window_with_focus
, TRUE
);
1486 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1488 g_return_if_fail(window_with_focus
!= NULL
);
1490 if (o_unique_filer_windows
.int_value
)
1492 report_error(_("You can't open a second view onto "
1493 "this directory because the `Unique Windows' option "
1494 "is turned on in the Options window."));
1497 filer_opendir(window_with_focus
->path
, window_with_focus
);
1501 static void su_to_user(GtkWidget
*dialog
)
1504 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1508 g_return_if_fail(dialog
!= NULL
);
1510 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1511 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1513 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1515 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1516 argv
[3] = gtk_entry_get_text(user
);
1517 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1521 report_error(_("fork: %s"), g_strerror(errno
));
1526 gtk_widget_destroy(dialog
);
1529 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1531 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1533 g_return_if_fail(window_with_focus
!= NULL
);
1535 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1536 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1537 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1538 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1539 g_strdup(window_with_focus
->path
), g_free
);
1541 vbox
= gtk_vbox_new(FALSE
, 4);
1542 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1543 gtk_box_pack_start(GTK_BOX(vbox
),
1544 gtk_label_new(_("Browse as which user?")),
1547 hbox
= gtk_hbox_new(FALSE
, 4);
1548 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1550 gtk_box_pack_start(GTK_BOX(hbox
),
1551 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1553 entry
= gtk_entry_new();
1554 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1555 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1556 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1557 gtk_widget_grab_focus(entry
);
1558 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1559 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1560 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1562 hbox
= gtk_hbox_new(TRUE
, 0);
1563 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1565 button
= gtk_button_new_with_label(_("OK"));
1566 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1567 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1568 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1569 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1570 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1572 button
= gtk_button_new_with_label(_("Cancel"));
1573 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1574 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1575 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1576 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1577 GTK_OBJECT(dialog
));
1579 gtk_widget_show_all(dialog
);
1583 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1585 g_return_if_fail(window_with_focus
!= NULL
);
1587 gtk_widget_destroy(window_with_focus
->window
);
1590 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1592 MiniType type
= (MiniType
) action
;
1594 g_return_if_fail(window_with_focus
!= NULL
);
1596 /* Item needs to remain selected... */
1597 if (type
== MINI_SHELL
)
1598 window_with_focus
->temp_item_selected
= FALSE
;
1600 minibuffer_show(window_with_focus
, type
);
1603 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1605 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1608 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1609 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1611 GList
*items
, *item
;
1613 items
= gtk_container_children(GTK_CONTAINER(menu
));
1615 item
= g_list_nth(items
, from
);
1618 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1625 /* This is called for every modified menu entry. We just use it to
1626 * find out if the menu has changed at all.
1628 static void set_mod(gboolean
*mod
, guchar
*str
)
1630 if (str
&& str
[0] == '(')
1635 static void save_menus(void)
1640 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1643 gtk_accel_map_save(menurc
);
1647 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, FALSE
);
1650 gboolean mod
= FALSE
;
1654 /* Find out if anything changed... */
1655 gtk_item_factory_dump_items(NULL
, TRUE
,
1656 (GtkPrintFunc
) set_mod
, &mod
);
1658 /* Dump out if so... */
1661 menurc
= choices_find_path_save(MENUS_NAME
,
1663 g_return_if_fail(menurc
!= NULL
);
1664 mark_menus_modified(TRUE
);
1665 gtk_item_factory_dump_rc(menurc
, NULL
, TRUE
);
1666 mark_menus_modified(FALSE
);
1674 static void keys_changed(gpointer data
)
1679 static void mark_modified(gpointer hash_key
,
1683 GtkItemFactoryItem
*item
= (GtkItemFactoryItem
*) value
;
1685 item
->modified
= (gboolean
) GPOINTER_TO_INT(user_data
);
1688 /* Set or clear the 'modified' flag in all menu items. Messy... */
1689 static void mark_menus_modified(gboolean mod
)
1691 GtkItemFactoryClass
*class;
1693 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY
);
1695 g_hash_table_foreach(class->item_ht
, mark_modified
,
1696 GINT_TO_POINTER(mod
));
1700 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1703 GtkWidget
*item
= NULL
;
1705 items
= gtk_container_children(GTK_CONTAINER(shell
));
1706 nth
= g_list_nth(items
, n
);
1708 g_return_if_fail(nth
!= NULL
);
1710 item
= (GtkWidget
*) (nth
->data
);
1713 gtk_menu_shell_select_item(shell
, item
);
1716 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1718 Collection
*collection
;
1722 g_return_if_fail(window_with_focus
!= NULL
);
1724 collection
= window_with_focus
->collection
;
1726 if (collection
->number_selected
< 1)
1732 case FILE_COPY_ITEM
:
1733 prompt
= _("Copy ... ?");
1735 case FILE_RENAME_ITEM
:
1736 prompt
= _("Rename ... ?");
1738 case FILE_LINK_ITEM
:
1739 prompt
= _("Symlink ... ?");
1741 case FILE_OPEN_FILE
:
1742 prompt
= _("Shift Open ... ?");
1745 prompt
= _("Help about ... ?");
1747 case FILE_SHOW_FILE_INFO
:
1748 prompt
= _("Examine ... ?");
1750 case FILE_RUN_ACTION
:
1751 prompt
= _("Set run action for ... ?");
1754 prompt
= _("Set icon for ... ?");
1757 prompt
= _("Send ... to ... ?");
1760 prompt
= _("DELETE ... ?");
1763 prompt
= _("Count the size of ... ?");
1765 case FILE_CHMOD_ITEMS
:
1766 prompt
= _("Set permissions on ... ?");
1769 prompt
= _("Search inside ... ?");
1772 case FILE_OPEN_VFS_RPM
:
1773 case FILE_OPEN_VFS_UTAR
:
1774 case FILE_OPEN_VFS_UZIP
:
1775 case FILE_OPEN_VFS_DEB
:
1777 case FILE_OPEN_VFS_AVFS
:
1779 prompt
= _("Look inside ... ?");
1782 g_warning("Unknown action!");
1785 filer_target_mode(window_with_focus
, target_callback
,
1786 GINT_TO_POINTER(action
), prompt
);
1793 send_to(window_with_focus
);
1796 delete(window_with_focus
);
1799 usage(window_with_focus
);
1801 case FILE_CHMOD_ITEMS
:
1802 chmod_items(window_with_focus
);
1805 find(window_with_focus
);
1811 /* All the following actions require exactly one file selected */
1813 if (collection
->number_selected
> 1)
1815 report_error(_("You cannot do this to more than "
1816 "one item at a time"));
1820 item
= selected_item(collection
);
1821 g_return_if_fail(item
!= NULL
);
1823 item
= dir_update_item(window_with_focus
->directory
,
1828 report_error(_("Item no longer exists!"));
1832 path
= make_path(window_with_focus
->path
, item
->leafname
)->str
;
1836 case FILE_COPY_ITEM
:
1837 src_dest_action_item(path
, item
->image
,
1838 _("Copy"), copy_cb
);
1840 case FILE_RENAME_ITEM
:
1841 src_dest_action_item(path
, item
->image
,
1842 _("Rename"), rename_cb
);
1844 case FILE_LINK_ITEM
:
1845 src_dest_action_item(path
, item
->image
,
1846 _("Symlink"), link_cb
);
1848 case FILE_OPEN_FILE
:
1849 filer_openitem(window_with_focus
,
1850 selected_item_number(collection
),
1851 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1854 show_item_help(path
, item
);
1856 case FILE_SHOW_FILE_INFO
:
1859 case FILE_RUN_ACTION
:
1863 icon_set_handler_dialog(item
, path
);
1866 case FILE_OPEN_VFS_RPM
:
1867 real_vfs_open(window_with_focus
, item
, "rpm");
1869 case FILE_OPEN_VFS_UTAR
:
1870 real_vfs_open(window_with_focus
, item
, "utar");
1872 case FILE_OPEN_VFS_UZIP
:
1873 real_vfs_open(window_with_focus
, item
, "uzip");
1875 case FILE_OPEN_VFS_DEB
:
1876 real_vfs_open(window_with_focus
, item
, "deb");
1879 case FILE_OPEN_VFS_AVFS
:
1880 open_vfs_avfs(window_with_focus
, item
);
1884 g_warning("Unknown action!");