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 menus */
29 #include <sys/param.h>
46 #include "gui_support.h"
49 #include "gtksavebox.h"
51 #include "minibuffer.h"
58 #include "usericons.h"
60 #include "view_iface.h"
62 #include "bookmarks.h"
81 typedef enum menu_icon_style
{
82 MIS_NONE
, MIS_SMALL
, MIS_LARGE
,
84 MIS_CURRENT
, /* As per current filer window */
88 typedef void (*ActionFn
)(GList
*paths
,
89 const char *dest_dir
, const char *leaf
, int quiet
);
90 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
92 typedef gboolean (*SaveCb
)(GObject
*savebox
,
93 const gchar
*current
, const gchar
*new);
95 GtkAccelGroup
*filer_keys
= NULL
;
97 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
99 static gint updating_menu
= 0; /* Non-zero => ignore activations */
100 static GList
*send_to_paths
= NULL
;
102 static Option o_menu_iconsize
, o_menu_xterm
;
104 /* Static prototypes */
106 static void save_menus(void);
107 static void menu_closed(GtkWidget
*widget
);
108 static void shade_file_menu_items(gboolean shaded
);
109 static void savebox_show(const gchar
*action
, const gchar
*path
,
110 MaskedPixmap
*image
, SaveCb callback
);
111 static gint
save_to_file(GObject
*savebox
,
112 const gchar
*pathname
, gpointer data
);
113 static gboolean
action_with_leaf(ActionFn action
,
114 const gchar
*current
, const gchar
*new);
115 static gboolean
link_cb(GObject
*savebox
,
116 const gchar
*initial
, const gchar
*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
);
121 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
123 /* Note that for most of these callbacks none of the arguments are used. */
125 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
);
127 /* (action used in these three - DetailsType) */
128 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
143 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
151 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
152 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
153 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
154 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
155 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
156 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
157 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
159 /* (action used in this - MiniType) */
160 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
161 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
163 #define MENUS_NAME "menus2"
165 static GtkWidget
*filer_menu
; /* The popup filer menu */
166 static GtkWidget
*filer_file_item
; /* The File '' label */
167 static GtkWidget
*filer_file_menu
; /* The File '' menu */
168 static GtkWidget
*file_shift_item
; /* Shift Open label */
169 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
170 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
171 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
172 static GtkWidget
*filer_new_window
; /* The New Window item */
173 static GtkWidget
*filer_new_menu
; /* The New submenu */
174 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
179 static GtkItemFactoryEntry filer_menu_def
[] = {
180 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
181 {">" N_("Icons View"), NULL
, view_type
, VIEW_TYPE_COLLECTION
, NULL
},
182 {">" N_("Icons, With..."), NULL
, NULL
, 0, "<Branch>"},
183 {">>" N_("Sizes"), NULL
, set_with
, DETAILS_SIZE
, NULL
},
184 {">>" N_("Permissions"), NULL
, set_with
, DETAILS_PERMISSIONS
, NULL
},
185 {">>" N_("Type"), NULL
, set_with
, DETAILS_TYPE
, NULL
},
186 {">>" N_("Times"), NULL
, set_with
, DETAILS_TIMES
, NULL
},
187 {">" N_("List View"), NULL
, view_type
, VIEW_TYPE_DETAILS
, NULL
},
188 {">", NULL
, NULL
, 0, "<Separator>"},
189 {">" N_("Bigger Icons"), NULL
, change_size
, 1, NULL
},
190 {">" N_("Smaller Icons"), NULL
, change_size
, -1, NULL
},
191 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
192 {">", NULL
, NULL
, 0, "<Separator>"},
193 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
194 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
195 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
196 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
197 {">", NULL
, NULL
, 0, "<Separator>"},
198 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
199 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
200 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
201 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
202 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, NULL
},
203 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
204 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
205 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
206 {">", NULL
, NULL
, 0, "<Separator>"},
207 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
208 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
209 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
210 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
211 {">", NULL
, NULL
, 0, "<Separator>"},
212 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
213 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
214 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
215 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
216 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
217 {">", NULL
, NULL
, 0, "<Separator>"},
218 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
219 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
220 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
221 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
222 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
223 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
224 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
225 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
226 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
227 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
228 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
229 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
230 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
231 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
232 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
233 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, NULL
},
234 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
235 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
236 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
238 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
239 {">", NULL
, NULL
, 0, "<Separator>"},
240 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
241 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
242 {">" N_("Xterm Here"), NULL
, xterm_here
, FALSE
, NULL
},
243 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, NULL
},
244 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
245 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
246 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, NULL
},
247 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
251 #define GET_MENU_ITEM(var, menu) \
252 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
254 #define GET_SMENU_ITEM(var, menu, sub) \
256 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
257 var = gtk_item_factory_get_widget(item_factory, tmp); \
261 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
263 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
264 var = gtk_item_factory_get_widget(item_factory, tmp); \
268 void ensure_filer_menu(void)
273 GtkItemFactory
*item_factory
;
278 filer_keys
= gtk_accel_group_new();
279 item_factory
= menu_create(filer_menu_def
,
280 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
281 "<filer>", filer_keys
);
283 GET_MENU_ITEM(filer_menu
, "filer");
284 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
285 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
286 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
287 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
290 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
291 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
292 filer_follow_sym
= GTK_BIN(item
)->child
;
294 /* File '' label... */
295 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
296 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
299 /* Shift Open... label */
300 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
301 file_shift_item
= GTK_BIN(g_list_nth(items
, 6)->data
)->child
;
304 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
305 filer_new_window
= GTK_BIN(item
)->child
;
307 g_signal_connect(filer_menu
, "unmap_event",
308 G_CALLBACK(menu_closed
), NULL
);
309 g_signal_connect(filer_file_menu
, "unmap_event",
310 G_CALLBACK(menu_closed
), NULL
);
312 g_signal_connect(filer_keys
, "accel_changed",
313 G_CALLBACK(save_menus
), NULL
);
320 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
323 gtk_accel_map_load(menurc
);
327 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
328 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
329 option_add_saver(save_menus
);
331 option_register_widget("menu-set-keys", set_keys_button
);
334 /* Name is in the form "<panel>" */
335 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
336 const gchar
*name
, GtkAccelGroup
*keys
)
338 GtkItemFactory
*item_factory
;
339 GtkItemFactoryEntry
*translated
;
343 keys
= gtk_accel_group_new();
344 gtk_accel_group_lock(keys
);
347 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
349 translated
= translate_entries(def
, n_entries
);
350 gtk_item_factory_create_items(item_factory
, n_entries
,
352 free_translated_entries(translated
, n_entries
);
357 /* Prevent the user from setting a short-cut on this item */
358 static void menuitem_no_shortcuts(GtkWidget
*item
)
362 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
364 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
365 null_g_free(&menuitem
->accel_path
);
369 /* Shade items that only work on single files */
370 static void shade_file_menu_items(gboolean shaded
)
372 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 3);
373 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 3);
374 menu_set_items_shaded(filer_file_menu
, shaded
, 10, 2);
377 /* 'data' is an array of three ints:
378 * [ pointer_x, pointer_y, item_under_pointer ]
380 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
381 gboolean
*push_in
, gpointer data
)
383 int *pos
= (int *) data
;
384 GtkRequisition requisition
;
389 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
391 while (item
>= 0 && next
)
393 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
406 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
408 *x
= pos
[0] - (requisition
.width
* 7 / 8);
409 *y
= pos
[1] - y_shift
;
411 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
412 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
418 /* Used when you menu-click on the Large or Small toolbar tools */
419 void show_style_menu(FilerWindow
*filer_window
,
420 GdkEventButton
*event
,
425 pos
[0] = event
->x_root
;
426 pos
[1] = event
->y_root
;
429 window_with_focus
= filer_window
;
433 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
434 (gpointer
) pos
, event
->button
, event
->time
);
438 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
439 MenuIconStyle style
, CallbackFn func
,
440 gboolean separator
, gboolean strip_ext
,
443 GList
*widgets
= NULL
;
450 dname
= pathdup(dir_name
);
452 dir
= opendir(dname
);
458 item
= gtk_menu_item_new();
459 widgets
= g_list_append(widgets
, item
);
460 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
463 while ((ent
= readdir(dir
)))
471 /* Ignore hidden files */
472 if (ent
->d_name
[0] == '.')
475 /* Strip off extension, if any */
476 dot
= strchr(ent
->d_name
, '.');
477 if (strip_ext
&& dot
)
478 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
480 leaf
= g_strdup(ent
->d_name
);
482 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
483 ditem
= diritem_new("");
484 diritem_restat(fname
, ditem
, NULL
);
486 if (ditem
->image
&& style
!= MIS_NONE
)
492 pixbuf
= ditem
->image
->pixbuf
;
495 if (!ditem
->image
->sm_pixbuf
)
496 pixmap_make_small(ditem
->image
);
497 pixbuf
= ditem
->image
->sm_pixbuf
;
501 item
= gtk_menu_item_new();
502 /* TODO: Find a way to allow short-cuts */
503 menuitem_no_shortcuts(item
);
505 hbox
= gtk_hbox_new(FALSE
, 2);
506 gtk_container_add(GTK_CONTAINER(item
), hbox
);
508 img
= gtk_image_new_from_pixbuf(pixbuf
);
510 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
512 label
= gtk_label_new(leaf
);
513 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
514 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
518 item
= gtk_menu_item_new_with_label(leaf
);
520 /* If it is a directory (but NOT an AppDir) and we are
521 * recursing then set up a sub menu.
523 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
524 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
529 sub
= gtk_menu_new();
530 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
531 separator
, strip_ext
, FALSE
);
532 g_list_free(new_widgets
);
533 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
536 g_signal_connect_swapped(item
, "activate",
537 G_CALLBACK(func
), fname
);
542 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
543 g_signal_connect_swapped(item
, "destroy",
544 G_CALLBACK(g_free
), fname
);
546 widgets
= g_list_append(widgets
, item
);
556 /* Scan the templates dir and create entries for the New menu */
557 static void update_new_files_menu(MenuIconStyle style
)
559 static GList
*widgets
= NULL
;
561 gchar
*templ_dname
= NULL
;
567 for (next
= widgets
; next
; next
= next
->next
)
568 gtk_widget_destroy((GtkWidget
*) next
->data
);
570 g_list_free(widgets
);
574 templ_dname
= choices_find_path_load("Templates", "");
577 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
578 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
582 gtk_widget_show_all(filer_new_menu
);
585 /* 'item' is the number of the item to appear under the pointer. */
586 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
592 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
593 event
->type
== GDK_BUTTON_RELEASE
))
595 GdkEventButton
*bev
= (GdkEventButton
*) event
;
597 pos
[0] = bev
->x_root
;
598 pos
[1] = bev
->y_root
;
599 button
= bev
->button
;
602 else if (event
&& event
->type
== GDK_KEY_PRESS
)
604 GdkEventKey
*kev
= (GdkEventKey
*) event
;
606 get_pointer_xy(pos
, pos
+ 1);
610 get_pointer_xy(pos
, pos
+ 1);
614 gtk_widget_show_all(menu
);
615 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
616 position_menu
, (gpointer
) pos
, button
, time
);
617 select_nth_item(GTK_MENU_SHELL(menu
), item
);
620 /* Hide the popup menu, if any */
621 void menu_popdown(void)
624 gtk_menu_popdown(GTK_MENU(popup_menu
));
627 static MenuIconStyle
get_menu_icon_style(void)
632 mis
= o_menu_iconsize
.int_value
;
636 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
642 if (mis
== MIS_CURRENT
&& window_with_focus
)
644 switch (window_with_focus
->display_style
)
656 display
= o_display_size
.int_value
;
671 /* iter->peek() is the clicked item, or NULL if none */
672 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
674 DirItem
*file_item
= NULL
;
675 GdkModifierType state
= 0;
678 n_selected
= view_count_selected(filer_window
->view
);
684 /* Remove previous AppMenu, if any */
687 window_with_focus
= filer_window
;
690 event
= gtk_get_current_event();
692 if (event
->type
== GDK_BUTTON_PRESS
)
693 state
= ((GdkEventButton
*) event
)->state
;
694 else if (event
->type
== GDK_KEY_PRESS
)
695 state
= ((GdkEventKey
*) event
)->state
;
697 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
699 filer_window
->temp_item_selected
= TRUE
;
700 view_set_selected(filer_window
->view
, iter
, TRUE
);
701 n_selected
= view_count_selected(filer_window
->view
);
705 filer_window
->temp_item_selected
= FALSE
;
708 /* Short-cut to the Send To menu */
709 if (state
& GDK_SHIFT_MASK
)
718 _("You should Shift+Menu click over a file to "
719 "send it somewhere"));
723 paths
= filer_selected_items(filer_window
);
725 show_send_to_menu(paths
, event
); /* (paths eaten) */
731 GtkWidget
*file_label
, *file_menu
;
735 file_label
= filer_file_item
;
736 file_menu
= filer_file_menu
;
737 gtk_check_menu_item_set_active(
738 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
739 filer_window
->show_thumbs
);
740 gtk_check_menu_item_set_active(
741 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
742 filer_window
->show_hidden
);
743 gtk_check_menu_item_set_active(
744 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
745 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
746 buffer
= g_string_new(NULL
);
751 g_string_assign(buffer
, _("Next Click"));
752 shade_file_menu_items(FALSE
);
755 item
= filer_selected_item(filer_window
);
757 dir_update_item(filer_window
->directory
,
759 shade_file_menu_items(FALSE
);
760 file_item
= filer_selected_item(filer_window
);
761 g_string_printf(buffer
, "%s '%s'",
762 basetype_name(file_item
),
763 g_utf8_validate(file_item
->leafname
,
765 ? file_item
->leafname
767 if (!can_set_run_action(file_item
))
768 menu_set_items_shaded(filer_file_menu
,
772 shade_file_menu_items(TRUE
);
773 g_string_printf(buffer
, _("%d items"),
777 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
778 g_string_free(buffer
, TRUE
);
780 menu_show_shift_action(file_shift_item
, file_item
,
783 appmenu_add(make_path(filer_window
->sym_path
,
784 file_item
->leafname
),
785 file_item
, filer_file_menu
);
788 update_new_files_menu(get_menu_icon_style());
790 gtk_widget_set_sensitive(filer_new_window
,
791 !o_unique_filer_windows
.int_value
);
792 gtk_widget_set_sensitive(filer_follow_sym
,
793 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
795 popup_menu
= (state
& GDK_CONTROL_MASK
)
801 show_popup_menu(popup_menu
, event
,
802 popup_menu
== filer_file_menu
? 5 : 1);
805 static void menu_closed(GtkWidget
*widget
)
807 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
808 return; /* Close panel item chosen? */
812 if (window_with_focus
->temp_item_selected
)
814 view_clear_selection(window_with_focus
->view
);
815 window_with_focus
->temp_item_selected
= FALSE
;
819 static void target_callback(FilerWindow
*filer_window
,
823 g_return_if_fail(filer_window
!= NULL
);
825 window_with_focus
= filer_window
;
827 /* Don't grab the primary selection */
828 filer_window
->temp_item_selected
= TRUE
;
830 view_wink_item(filer_window
->view
, iter
);
831 view_select_only(filer_window
->view
, iter
);
832 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
834 view_clear_selection(filer_window
->view
);
835 filer_window
->temp_item_selected
= FALSE
;
838 /* Set the text of the 'Shift Open...' menu item.
839 * If icon is NULL, reset the text and also shade it, unless 'next'.
841 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
843 guchar
*shift_action
= NULL
;
847 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
849 if (item
->flags
& ITEM_FLAG_MOUNTED
)
850 shift_action
= N_("Unmount");
852 shift_action
= N_("Open unmounted");
854 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
855 shift_action
= N_("Show Target");
856 else if (item
->base_type
== TYPE_DIRECTORY
)
857 shift_action
= N_("Look Inside");
858 else if (item
->base_type
== TYPE_FILE
)
859 shift_action
= N_("Open As Text");
861 gtk_label_set_text(GTK_LABEL(menu_item
),
862 shift_action
? _(shift_action
)
864 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
869 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
871 ViewType view_type
= (ViewType
) action
;
873 g_return_if_fail(window_with_focus
!= NULL
);
875 if (view_type
== VIEW_TYPE_COLLECTION
)
876 display_set_layout(window_with_focus
,
877 window_with_focus
->display_style_wanted
,
880 filer_set_view_type(window_with_focus
, (ViewType
) action
);
883 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
885 g_return_if_fail(window_with_focus
!= NULL
);
887 display_change_size(window_with_focus
, action
== 1);
890 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
892 g_return_if_fail(window_with_focus
!= NULL
);
897 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
898 display_set_layout(window_with_focus
,
899 window_with_focus
->display_style
,
900 window_with_focus
->details_type
);
902 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
903 window_with_focus
->details_type
);
906 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
910 g_return_if_fail(window_with_focus
!= NULL
);
912 size
= window_with_focus
->display_style_wanted
;
914 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
915 display_set_layout(window_with_focus
, size
, action
);
918 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
920 g_return_if_fail(window_with_focus
!= NULL
);
922 display_set_sort_fn(window_with_focus
, sort_by_name
);
925 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
927 g_return_if_fail(window_with_focus
!= NULL
);
929 display_set_sort_fn(window_with_focus
, sort_by_type
);
932 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
934 g_return_if_fail(window_with_focus
!= NULL
);
936 display_set_sort_fn(window_with_focus
, sort_by_date
);
939 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
941 g_return_if_fail(window_with_focus
!= NULL
);
943 display_set_sort_fn(window_with_focus
, sort_by_size
);
946 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
951 g_return_if_fail(window_with_focus
!= NULL
);
953 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
956 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
961 g_return_if_fail(window_with_focus
!= NULL
);
963 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
966 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
968 g_return_if_fail(window_with_focus
!= NULL
);
971 filer_update_dir(window_with_focus
, TRUE
);
974 static void delete(FilerWindow
*filer_window
)
977 paths
= filer_selected_items(filer_window
);
978 action_delete(paths
);
979 destroy_glist(&paths
);
982 static void usage(FilerWindow
*filer_window
)
985 paths
= filer_selected_items(filer_window
);
987 destroy_glist(&paths
);
990 static void chmod_items(FilerWindow
*filer_window
)
993 paths
= filer_selected_items(filer_window
);
994 action_chmod(paths
, FALSE
, NULL
);
995 destroy_glist(&paths
);
998 static void find(FilerWindow
*filer_window
)
1001 paths
= filer_selected_items(filer_window
);
1003 destroy_glist(&paths
);
1006 /* This creates a new savebox widget, and allows the user to pick a new path
1008 * Once the new path has been picked, the callback will be called with
1009 * both the current and new paths.
1010 * NOTE: This function unrefs 'image'!
1012 static void savebox_show(const gchar
*action
, const gchar
*path
,
1013 MaskedPixmap
*image
, SaveCb callback
)
1015 GtkWidget
*savebox
= NULL
;
1016 GtkWidget
*check_relative
= NULL
;
1018 g_return_if_fail(image
!= NULL
);
1020 savebox
= gtk_savebox_new(action
);
1022 if (callback
== link_cb
)
1024 check_relative
= gtk_check_button_new_with_mnemonic(
1025 _("_Relative link"));
1026 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1029 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1030 gtk_tooltips_set_tip(tooltips
, check_relative
,
1031 _("If on, the symlink will store the path from the "
1032 "symlink to the target file. Use this if the symlink "
1033 "and the target will be moved together.\n"
1034 "If off, the path from the root directory is stored - "
1035 "use this if the symlink may move but the target will "
1036 "stay put."), NULL
);
1037 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1038 check_relative
, FALSE
, TRUE
, 0);
1039 gtk_widget_show(check_relative
);
1042 g_signal_connect(savebox
, "save_to_file",
1043 G_CALLBACK(save_to_file
), NULL
);
1045 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1046 g_strdup(path
), g_free
);
1047 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1048 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1050 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1052 if (g_utf8_validate(path
, -1, NULL
))
1053 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1058 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1061 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1062 g_object_unref(image
);
1064 gtk_widget_show(savebox
);
1067 static gint
save_to_file(GObject
*savebox
,
1068 const gchar
*pathname
, gpointer data
)
1071 const gchar
*current_path
;
1073 callback
= g_object_get_data(savebox
, "action_callback");
1074 current_path
= g_object_get_data(savebox
, "current_path");
1076 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1077 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1079 return callback(savebox
, current_path
, pathname
)
1080 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1083 static gboolean
copy_cb(GObject
*savebox
,
1084 const gchar
*current
, const gchar
*new)
1086 return action_with_leaf(action_copy
, current
, new);
1089 static gboolean
action_with_leaf(ActionFn action
,
1090 const gchar
*current
, const gchar
*new)
1098 report_error(_("New pathname is not absolute"));
1102 if (new[strlen(new) - 1] == '/')
1104 new_dir
= g_strdup(new);
1111 slash
= strrchr(new, '/');
1112 new_dir
= g_strndup(new, slash
- new);
1116 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1117 action(local_paths
, new_dir
, leaf
, -1);
1118 g_list_free(local_paths
);
1125 /* Open a savebox to act on the selected file.
1126 * Call 'callback' later to perform the operation.
1128 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1129 const gchar
*action
, SaveCb callback
)
1131 g_object_ref(image
);
1132 savebox_show(action
, path
, image
, callback
);
1135 static gboolean
rename_cb(GObject
*savebox
,
1136 const gchar
*current
, const gchar
*new)
1138 return action_with_leaf(action_move
, current
, new);
1141 static gboolean
link_cb(GObject
*savebox
,
1142 const gchar
*initial
, const gchar
*path
)
1144 GtkToggleButton
*check_relative
;
1149 check_relative
= g_object_get_data(savebox
, "check_relative");
1151 if (gtk_toggle_button_get_active(check_relative
))
1152 link_path
= get_relative_path(path
, initial
);
1154 link_path
= g_strdup(initial
);
1156 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1158 GtkWidget
*box
, *button
;
1161 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1163 _("Symlink from '%s' already exists. "
1164 "Replace it with a link to '%s'?"),
1167 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1169 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1170 gtk_widget_show(button
);
1171 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1172 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1173 button
, GTK_RESPONSE_OK
);
1174 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1177 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1178 gtk_widget_destroy(box
);
1180 if (ans
!= GTK_RESPONSE_OK
)
1189 err
= symlink(link_path
, path
);
1194 report_error("symlink: %s", g_strerror(errno
));
1198 dir_check_this(path
);
1203 static void run_action(DirItem
*item
)
1205 if (can_set_run_action(item
))
1206 type_set_handler_dialog(item
->mime_type
);
1209 _("You can only set the run action for a "
1213 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1215 filer_opendir(home_dir
, NULL
, NULL
);
1218 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1222 path
= g_strconcat(filer_window
->sym_path
,
1223 "/", item
->leafname
, "#", NULL
);
1225 filer_change_to(filer_window
, path
, NULL
);
1229 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1231 g_return_if_fail(window_with_focus
!= NULL
);
1233 window_with_focus
->temp_item_selected
= FALSE
;
1234 view_select_all(window_with_focus
->view
);
1237 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1239 g_return_if_fail(window_with_focus
!= NULL
);
1241 window_with_focus
->temp_item_selected
= FALSE
;
1242 view_clear_selection(window_with_focus
->view
);
1245 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1247 return !view_get_selected((ViewIface
*) data
, iter
);
1250 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1252 g_return_if_fail(window_with_focus
!= NULL
);
1254 window_with_focus
->temp_item_selected
= FALSE
;
1256 view_select_if(window_with_focus
->view
, invert_cb
,
1257 window_with_focus
->view
);
1260 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1264 win
= options_show();
1268 number_of_windows
++;
1269 g_signal_connect(win
, "destroy",
1270 G_CALLBACK(one_less_window
), NULL
);
1274 static gboolean
new_directory_cb(GObject
*savebox
,
1275 const gchar
*initial
, const gchar
*path
)
1277 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1279 report_error("mkdir: %s", g_strerror(errno
));
1283 dir_check_this(path
);
1285 if (filer_exists(window_with_focus
))
1288 leaf
= strrchr(path
, '/');
1290 display_set_autoselect(window_with_focus
, leaf
+ 1);
1296 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1298 g_return_if_fail(window_with_focus
!= NULL
);
1300 savebox_show(_("Create"),
1301 make_path(window_with_focus
->sym_path
, _("NewDir")),
1302 type_to_icon(inode_directory
), new_directory_cb
);
1305 static gboolean
new_file_cb(GObject
*savebox
,
1306 const gchar
*initial
, const gchar
*path
)
1310 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1314 report_error(_("Error creating '%s': %s"),
1315 path
, g_strerror(errno
));
1320 report_error(_("Error creating '%s': %s"),
1321 path
, g_strerror(errno
));
1323 dir_check_this(path
);
1325 if (filer_exists(window_with_focus
))
1328 leaf
= strrchr(path
, '/');
1330 display_set_autoselect(window_with_focus
, leaf
+ 1);
1336 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1338 g_return_if_fail(window_with_focus
!= NULL
);
1340 savebox_show(_("Create"),
1341 make_path(window_with_focus
->sym_path
, _("NewFile")),
1342 type_to_icon(text_plain
),
1346 static gboolean
new_file_type_cb(GObject
*savebox
,
1347 const gchar
*initial
, const gchar
*path
)
1349 const gchar
*oleaf
, *leaf
;
1350 gchar
*templ
, *templ_dname
, *dest
;
1353 /* We can work out the template path from the initial name */
1354 oleaf
= g_basename(initial
);
1355 templ_dname
= choices_find_path_load("Templates", "");
1359 _("Error creating file: could not find the template for %s"),
1364 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1365 g_free(templ_dname
);
1367 dest
= g_path_get_dirname(path
);
1368 leaf
= g_basename(path
);
1369 paths
= g_list_append(NULL
, templ
);
1371 action_copy(paths
, dest
, leaf
, TRUE
);
1377 if (filer_exists(window_with_focus
))
1378 display_set_autoselect(window_with_focus
, leaf
);
1383 static void do_send_to(gchar
*templ
)
1385 g_return_if_fail(send_to_paths
!= NULL
);
1387 run_with_files(templ
, send_to_paths
);
1390 static void new_file_type(gchar
*templ
)
1395 g_return_if_fail(window_with_focus
!= NULL
);
1397 leaf
= g_basename(templ
);
1398 type
= type_get_type(templ
);
1400 savebox_show(_("Create"),
1401 make_path(window_with_focus
->sym_path
, leaf
),
1406 static void customise_send_to(gpointer data
)
1413 dirs
= g_string_new(NULL
);
1415 path
= choices_list_dirs("");
1416 for (i
= 0; i
< path
->len
; i
++)
1418 guchar
*old
= (guchar
*) path
->pdata
[i
];
1420 g_string_append(dirs
, old
);
1421 g_string_append(dirs
, "SendTo\n");
1423 choices_free_list(path
);
1425 save
= choices_find_path_save("", "SendTo", TRUE
);
1430 _("The `Send To' menu provides a quick way to send some files "
1431 "to an application. The applications listed are those in "
1432 "the following directories:\n\n%s\n%s\n"
1433 "The `Send To' menu may be opened by Shift+Menu clicking "
1436 "You can also create subdirectories called "
1437 "`.text_html', `.text', etc which will only be "
1438 "shown for files of that type. `.group' is shown "
1439 "only when multiple files are selected."),
1441 save
? _("I'll show you your SendTo directory now; you should "
1442 "symlink (Ctrl+Shift drag) any applications you want "
1444 : _("Your CHOICESPATH variable setting prevents "
1445 "customisations - sorry."));
1447 g_string_free(dirs
, TRUE
);
1450 filer_opendir(save
, NULL
, NULL
);
1453 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1456 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1463 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1465 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1467 searchdir
= g_strdup("SendTo");
1469 paths
= choices_list_dirs(searchdir
);
1472 for (i
= 0; i
< paths
->len
; i
++)
1474 GList
*widgets
= NULL
;
1475 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1477 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1478 (CallbackFn
) do_send_to
,
1479 FALSE
, FALSE
, TRUE
);
1482 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1483 gtk_menu_item_new());
1485 g_list_free(widgets
); /* TODO: Get rid of this */
1488 choices_free_list(paths
);
1491 /* Scan the SendTo dir and create and show the Send To menu.
1492 * The 'paths' list and every path in it is claimed, and will be
1493 * freed later -- don't free it yourself!
1495 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1497 GtkWidget
*menu
, *item
;
1499 menu
= gtk_menu_new();
1501 if (g_list_length(paths
) == 1)
1505 item
= diritem_new("");
1506 diritem_restat(paths
->data
, item
, NULL
);
1509 item
->mime_type
->media_type
,
1510 item
->mime_type
->subtype
);
1512 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1517 add_sendto(menu
, "group", NULL
);
1519 add_sendto(menu
, NULL
, NULL
);
1521 item
= gtk_menu_item_new_with_label(_("Customise"));
1522 g_signal_connect_swapped(item
, "activate",
1523 G_CALLBACK(customise_send_to
), NULL
);
1524 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1527 destroy_glist(&send_to_paths
);
1529 send_to_paths
= paths
;
1531 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1534 show_popup_menu(menu
, event
, 0);
1537 static void send_to(FilerWindow
*filer_window
)
1542 paths
= filer_selected_items(filer_window
);
1543 event
= gtk_get_current_event();
1546 show_send_to_menu(paths
, event
);
1548 gdk_event_free(event
);
1551 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1553 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1554 gboolean close
= action
;
1556 argv
[2] = o_menu_xterm
.value
;
1558 g_return_if_fail(window_with_focus
!= NULL
);
1560 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1561 gtk_widget_destroy(window_with_focus
->window
);
1564 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1566 g_return_if_fail(window_with_focus
!= NULL
);
1568 filer_change_to(window_with_focus
, home_dir
, NULL
);
1571 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1573 g_return_if_fail(window_with_focus
!= NULL
);
1575 bookmarks_show_menu(window_with_focus
);
1578 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1580 g_return_if_fail(window_with_focus
!= NULL
);
1582 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1583 filer_change_to(window_with_focus
,
1584 window_with_focus
->real_path
, NULL
);
1586 delayed_error(_("This is already the canonical name "
1587 "for this directory."));
1590 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1592 g_return_if_fail(window_with_focus
!= NULL
);
1594 filer_open_parent(window_with_focus
);
1597 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1599 g_return_if_fail(window_with_focus
!= NULL
);
1601 change_to_parent(window_with_focus
);
1604 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1606 g_return_if_fail(window_with_focus
!= NULL
);
1608 view_autosize(window_with_focus
->view
);
1611 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1613 g_return_if_fail(window_with_focus
!= NULL
);
1615 if (o_unique_filer_windows
.int_value
)
1617 report_error(_("You can't open a second view onto "
1618 "this directory because the `Unique Windows' option "
1619 "is turned on in the Options window."));
1622 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1625 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1627 g_return_if_fail(window_with_focus
!= NULL
);
1629 gtk_widget_destroy(window_with_focus
->window
);
1632 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1634 MiniType type
= (MiniType
) action
;
1636 g_return_if_fail(window_with_focus
!= NULL
);
1638 /* Item needs to remain selected... */
1639 if (type
== MINI_SHELL
)
1640 window_with_focus
->temp_item_selected
= FALSE
;
1642 minibuffer_show(window_with_focus
, type
);
1645 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1647 if (action
== HELP_ABOUT
)
1648 infobox_new(app_dir
);
1649 else if (action
== HELP_DIR
)
1650 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1651 else if (action
== HELP_MANUAL
)
1653 gchar
*manual
= NULL
;
1657 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1658 current_lang
, ".html", NULL
);
1659 if (access(manual
, F_OK
))
1660 null_g_free(&manual
);
1664 manual
= g_strconcat(app_dir
,
1665 "/Help/Manual.html", NULL
);
1667 run_by_path(manual
);
1672 g_warning("Unknown help action %d\n", action
);
1675 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1676 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1678 GList
*items
, *item
;
1680 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1682 item
= g_list_nth(items
, from
);
1685 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1691 static void save_menus(void)
1695 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1698 gtk_accel_map_save(menurc
);
1703 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1708 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1709 item
= g_list_nth_data(items
, n
);
1711 g_return_if_fail(item
!= NULL
);
1715 gtk_menu_shell_select_item(shell
, item
);
1718 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1725 g_return_if_fail(window_with_focus
!= NULL
);
1727 n_selected
= view_count_selected(window_with_focus
->view
);
1735 case FILE_COPY_ITEM
:
1736 prompt
= _("Copy ... ?");
1738 case FILE_RENAME_ITEM
:
1739 prompt
= _("Rename ... ?");
1741 case FILE_LINK_ITEM
:
1742 prompt
= _("Symlink ... ?");
1744 case FILE_OPEN_FILE
:
1745 prompt
= _("Shift Open ... ?");
1748 prompt
= _("Help about ... ?");
1750 case FILE_SHOW_FILE_INFO
:
1751 prompt
= _("Examine ... ?");
1753 case FILE_RUN_ACTION
:
1754 prompt
= _("Set run action for ... ?");
1757 prompt
= _("Set icon for ... ?");
1760 prompt
= _("Send ... to ... ?");
1763 prompt
= _("DELETE ... ?");
1766 prompt
= _("Count the size of ... ?");
1768 case FILE_CHMOD_ITEMS
:
1769 prompt
= _("Set permissions on ... ?");
1772 prompt
= _("Search inside ... ?");
1774 case FILE_OPEN_VFS_AVFS
:
1775 prompt
= _("Look inside ... ?");
1778 g_warning("Unknown action!");
1781 filer_target_mode(window_with_focus
, target_callback
,
1782 GINT_TO_POINTER(action
), prompt
);
1789 send_to(window_with_focus
);
1792 delete(window_with_focus
);
1795 usage(window_with_focus
);
1797 case FILE_CHMOD_ITEMS
:
1798 chmod_items(window_with_focus
);
1801 find(window_with_focus
);
1803 case FILE_SHOW_FILE_INFO
:
1807 items
= filer_selected_items(window_with_focus
);
1808 infobox_show_list(items
);
1809 destroy_glist(&items
);
1816 /* All the following actions require exactly one file selected */
1820 report_error(_("You cannot do this to more than "
1821 "one item at a time"));
1825 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1827 item
= iter
.next(&iter
);
1828 g_return_if_fail(item
!= NULL
);
1829 /* iter may be passed to filer_openitem... */
1832 item
= dir_update_item(window_with_focus
->directory
,
1837 report_error(_("Item no longer exists!"));
1841 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
1845 case FILE_COPY_ITEM
:
1846 src_dest_action_item(path
, item
->image
,
1847 _("Copy"), copy_cb
);
1849 case FILE_RENAME_ITEM
:
1850 src_dest_action_item(path
, item
->image
,
1851 _("Rename"), rename_cb
);
1853 case FILE_LINK_ITEM
:
1854 src_dest_action_item(path
, item
->image
,
1855 _("Symlink"), link_cb
);
1857 case FILE_OPEN_FILE
:
1858 filer_openitem(window_with_focus
, &iter
,
1859 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1862 show_item_help(path
, item
);
1864 case FILE_RUN_ACTION
:
1868 icon_set_handler_dialog(item
, path
);
1870 case FILE_OPEN_VFS_AVFS
:
1871 open_vfs_avfs(window_with_focus
, item
);
1874 g_warning("Unknown action!");
1879 static void show_key_help(GtkWidget
*button
, gpointer data
)
1881 gboolean can_change_accels
;
1883 g_object_get(G_OBJECT(gtk_settings_get_default()),
1884 "gtk-can-change-accels", &can_change_accels
,
1887 if (!can_change_accels
)
1889 info_message(_("User-definable shortcuts are disabled by "
1890 "default in Gtk2, and you have not enabled "
1891 "them. You can turn this feature on by:\n"
1892 "1) using an XSettings manager, such as ROX-Session\n"
1894 "2) adding this line to ~/.gtkrc-2.0:\n"
1895 "\tgtk-can-change-accels = 1"));
1899 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1900 "- Open the menu over a filer window,\n"
1901 "- Move the pointer over the item you want to use,\n"
1902 "- Press the key you want attached to it.\n\n"
1903 "The key will appear next to the menu item and you can just press "
1904 "that key without opening the menu in future."));
1907 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1909 GtkWidget
*button
, *align
;
1911 g_return_val_if_fail(option
== NULL
, NULL
);
1913 align
= gtk_alignment_new(0, 0.5, 0, 0);
1914 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
1915 gtk_container_add(GTK_CONTAINER(align
), button
);
1916 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1918 return g_list_append(NULL
, align
);