4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, 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"
64 #include "bulk_rename.h"
84 typedef void (*ActionFn
)(GList
*paths
,
85 const char *dest_dir
, const char *leaf
, int quiet
);
86 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
88 typedef gboolean (*SaveCb
)(GObject
*savebox
,
89 const gchar
*current
, const gchar
*new);
91 GtkAccelGroup
*filer_keys
= NULL
;
92 static gboolean filer_keys_need_init
= TRUE
;
94 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
96 static gint updating_menu
= 0; /* Non-zero => ignore activations */
97 static GList
*send_to_paths
= NULL
;
99 static Option o_menu_iconsize
, o_menu_xterm
, o_menu_quick
;
101 /* Static prototypes */
103 static void save_menus(void);
104 static void menu_closed(GtkWidget
*widget
);
105 static void shade_file_menu_items(gboolean shaded
);
106 static void savebox_show(const gchar
*action
, const gchar
*path
,
107 MaskedPixmap
*image
, SaveCb callback
,
108 GdkDragAction dnd_action
);
109 static gint
save_to_file(GObject
*savebox
,
110 const gchar
*pathname
, gpointer data
);
111 static gboolean
action_with_leaf(ActionFn action
,
112 const gchar
*current
, const gchar
*new);
113 static gboolean
link_cb(GObject
*savebox
,
114 const gchar
*initial
, const gchar
*path
);
115 static void select_nth_item(GtkMenuShell
*shell
, int n
);
116 static void new_file_type(gchar
*templ
);
117 static void do_send_to(gchar
*templ
);
118 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
119 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
121 /* Note that for most of these callbacks none of the arguments are used. */
123 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
);
125 /* (action used in these three - DetailsType) */
126 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void save_settings(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 customise_new(gpointer data
);
146 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
151 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
152 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
153 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
154 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
155 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
157 /* (action used in this - MiniType) */
158 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
159 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
161 #define MENUS_NAME "menus2"
163 static GtkWidget
*filer_menu
; /* The popup filer menu */
164 static GtkWidget
*filer_file_item
; /* The File '' label */
165 static GtkWidget
*filer_file_menu
; /* The File '' menu */
166 static GtkWidget
*file_shift_item
; /* Shift Open label */
167 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
168 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
169 static GtkWidget
*filer_reverse_menu
; /* The Reversed item */
170 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
171 static GtkWidget
*filer_new_window
; /* The New Window item */
172 static GtkWidget
*filer_new_menu
; /* The New submenu */
173 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
174 static GtkWidget
*filer_set_type
; /* Set type 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_("Types"), 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
, "<StockItem>", ROX_STOCK_SHOW_DETAILS
},
188 {">", NULL
, NULL
, 0, "<Separator>"},
189 {">" N_("Bigger Icons"), "equal", change_size
, 1, "<StockItem>", GTK_STOCK_ZOOM_IN
},
190 {">" N_("Smaller Icons"), "minus", change_size
, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT
},
191 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
192 {">", NULL
, NULL
, 0, "<Separator>"},
193 {">" N_("Sort by Name"), NULL
, set_sort
, SORT_NAME
, NULL
},
194 {">" N_("Sort by Type"), NULL
, set_sort
, SORT_TYPE
, NULL
},
195 {">" N_("Sort by Date"), NULL
, set_sort
, SORT_DATE
, NULL
},
196 {">" N_("Sort by Size"), NULL
, set_sort
, SORT_SIZE
, NULL
},
197 {">" N_("Sort by Owner"), NULL
, set_sort
, SORT_OWNER
, NULL
},
198 {">" N_("Sort by Group"), NULL
, set_sort
, SORT_GROUP
, NULL
},
199 {">" N_("Reversed"), NULL
, reverse_sort
, 0, "<ToggleItem>"},
200 {">", NULL
, NULL
, 0, "<Separator>"},
201 {">" N_("Show Hidden"), "<Ctrl>H", hidden
, 0, "<ToggleItem>"},
202 {">" N_("Filter Files..."), NULL
, mini_buffer
, MINI_FILTER
, NULL
},
203 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
204 {">" N_("Refresh"), NULL
, refresh
, 0, "<StockItem>", GTK_STOCK_REFRESH
},
205 {">" N_("Save Display Settings..."), NULL
, save_settings
, 0, NULL
},
206 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
207 {">" N_("Copy..."), "<Ctrl>C", file_op
, FILE_COPY_ITEM
, "<StockItem>", GTK_STOCK_COPY
},
208 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
209 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
210 {">" N_("Delete"), "<Ctrl>X", file_op
, FILE_DELETE
, "<StockItem>", GTK_STOCK_DELETE
},
211 {">", NULL
, NULL
, 0, "<Separator>"},
212 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
},
213 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, "<StockItem>", GTK_STOCK_OPEN
},
214 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
215 {">", NULL
, NULL
, 0, "<Separator>"},
216 {">" N_("Set Run Action..."), "asterisk", file_op
, FILE_RUN_ACTION
, "<StockItem>", GTK_STOCK_EXECUTE
},
217 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
218 {">" N_("Properties"), "<Ctrl>P", file_op
, FILE_PROPERTIES
, "<StockItem>", GTK_STOCK_PROPERTIES
},
219 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
220 {">" N_("Set Type..."), NULL
, file_op
, FILE_SET_TYPE
, NULL
},
221 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
222 {">", NULL
, NULL
, 0, "<Separator>"},
223 {">" N_("Find"), "<Ctrl>F", file_op
, FILE_FIND
, "<StockItem>", GTK_STOCK_FIND
},
224 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
225 {">" N_("Select All"), "<Ctrl>A", select_all
, 0, NULL
},
226 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
227 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
228 {">" N_("Select by Name..."), "period", mini_buffer
, MINI_SELECT_BY_NAME
, NULL
},
229 {">" N_("Select If..."), "<Shift>question", mini_buffer
, MINI_SELECT_IF
, NULL
},
230 {N_("Options..."), NULL
, menu_show_options
, 0, "<StockItem>", GTK_STOCK_PREFERENCES
},
231 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
232 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
233 {">" N_("Blank file"), NULL
, new_file
, 0, "<StockItem>", GTK_STOCK_NEW
},
234 {">" N_("Customise Menu..."), NULL
, customise_new
, 0, NULL
},
235 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
236 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, "<StockItem>", GTK_STOCK_GO_UP
},
237 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
238 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
239 {">" N_("Home Directory"), "<Ctrl>Home", home_directory
, 0, "<StockItem>", GTK_STOCK_HOME
},
240 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, "<StockItem>", ROX_STOCK_BOOKMARKS
},
241 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
242 {">" N_("Resize Window"), "<Ctrl>E", resize
, 0, NULL
},
243 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
245 {">" N_("Close Window"), "<Ctrl>Q", close_window
, 0, "<StockItem>", GTK_STOCK_CLOSE
},
246 {">", NULL
, NULL
, 0, "<Separator>"},
247 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
248 {">" N_("Shell Command..."), "<Shift>exclam", mini_buffer
, MINI_SHELL
, NULL
},
249 {">" N_("Xterm Here"), "grave", xterm_here
, FALSE
, NULL
},
250 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, NULL
},
251 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
252 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
253 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, "<StockItem>", GTK_STOCK_HELP
},
254 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
258 #define GET_MENU_ITEM(var, menu) \
259 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
261 #define GET_SMENU_ITEM(var, menu, sub) \
263 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
264 var = gtk_item_factory_get_widget(item_factory, tmp); \
268 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
270 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
271 var = gtk_item_factory_get_widget(item_factory, tmp); \
275 /* Returns TRUE if the keys were installed (first call only) */
276 gboolean
ensure_filer_menu(void)
281 GtkItemFactory
*item_factory
;
283 if (!filer_keys_need_init
)
285 filer_keys_need_init
= FALSE
;
287 item_factory
= menu_create(filer_menu_def
,
288 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
289 "<filer>", filer_keys
);
291 GET_MENU_ITEM(filer_menu
, "filer");
292 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
293 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
294 GET_SSMENU_ITEM(filer_reverse_menu
, "filer", "Display", "Reversed");
295 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
296 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
298 GET_SSMENU_ITEM(item
, "filer", "File", "Set Type...");
299 filer_set_type
= GTK_BIN(item
)->child
;
301 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
302 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
303 filer_follow_sym
= GTK_BIN(item
)->child
;
305 /* File '' label... */
306 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
307 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
310 /* Shift Open... label */
311 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
312 file_shift_item
= GTK_BIN(g_list_nth(items
, 5)->data
)->child
;
315 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
316 filer_new_window
= GTK_BIN(item
)->child
;
318 g_signal_connect(filer_menu
, "unmap_event",
319 G_CALLBACK(menu_closed
), NULL
);
320 g_signal_connect(filer_file_menu
, "unmap_event",
321 G_CALLBACK(menu_closed
), NULL
);
323 g_signal_connect(filer_keys
, "accel_changed",
324 G_CALLBACK(save_menus
), NULL
);
333 menurc
= choices_find_xdg_path_load(MENUS_NAME
, PROJECT
, SITE
);
336 gtk_accel_map_load(menurc
);
340 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
341 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
342 option_add_int(&o_menu_quick
, "menu_quick", FALSE
);
343 option_add_saver(save_menus
);
345 option_register_widget("menu-set-keys", set_keys_button
);
347 filer_keys
= gtk_accel_group_new();
350 /* Name is in the form "<panel>" */
351 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
352 const gchar
*name
, GtkAccelGroup
*keys
)
354 GtkItemFactory
*item_factory
;
355 GtkItemFactoryEntry
*translated
;
359 keys
= gtk_accel_group_new();
360 gtk_accel_group_lock(keys
);
363 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
365 translated
= translate_entries(def
, n_entries
);
366 gtk_item_factory_create_items(item_factory
, n_entries
,
368 free_translated_entries(translated
, n_entries
);
373 /* Prevent the user from setting a short-cut on this item */
374 static void menuitem_no_shortcuts(GtkWidget
*item
)
378 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
380 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
381 null_g_free(&menuitem
->accel_path
);
385 /* Shade items that only work on single files */
386 static void shade_file_menu_items(gboolean shaded
)
388 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 1);
389 menu_set_items_shaded(filer_file_menu
, shaded
, 2, 1);
390 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 2);
391 menu_set_items_shaded(filer_file_menu
, shaded
, 9, 2);
394 /* 'data' is an array of three ints:
395 * [ pointer_x, pointer_y, item_under_pointer ]
397 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
398 gboolean
*push_in
, gpointer data
)
400 int *pos
= (int *) data
;
401 GtkRequisition requisition
;
406 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
408 while (item
>= 0 && next
)
410 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
423 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
425 *x
= pos
[0] - (requisition
.width
* 7 / 8);
426 *y
= pos
[1] - y_shift
;
428 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
429 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
434 GtkWidget
*make_send_to_item(DirItem
*ditem
, const char *label
,
439 if (style
!= MIS_NONE
&& di_image(ditem
))
444 image
= di_image(ditem
);
449 pixbuf
= image
->pixbuf
;
452 if (!image
->sm_pixbuf
)
453 pixmap_make_small(image
);
454 pixbuf
= image
->sm_pixbuf
;
458 item
= gtk_image_menu_item_new_with_label(label
);
459 /* TODO: Find a way to allow short-cuts */
460 menuitem_no_shortcuts(item
);
462 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
463 gtk_image_new_from_pixbuf(pixbuf
));
464 gtk_widget_show_all(item
);
467 item
= gtk_menu_item_new_with_label(label
);
472 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
473 MenuIconStyle style
, CallbackFn func
,
474 gboolean separator
, gboolean strip_ext
,
477 GList
*widgets
= NULL
;
484 dname
= pathdup(dir_name
);
486 names
= list_dir(dname
);
490 for (i
= 0; i
< names
->len
; i
++)
492 char *leaf
= names
->pdata
[i
];
497 item
= gtk_menu_item_new();
498 widgets
= g_list_append(widgets
, item
);
499 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
503 fname
= g_strconcat(dname
, "/", leaf
, NULL
);
505 /* Strip off extension, if any */
509 dot
= strchr(leaf
, '.');
514 ditem
= diritem_new("");
515 diritem_restat(fname
, ditem
, NULL
);
517 item
= make_send_to_item(ditem
, leaf
, style
);
521 /* If it is a directory (but NOT an AppDir) and we are
522 * recursing then set up a sub menu.
524 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
525 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
530 sub
= gtk_menu_new();
531 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
532 separator
, strip_ext
, TRUE
);
533 g_list_free(new_widgets
);
534 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
537 g_signal_connect_swapped(item
, "activate",
538 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
);
549 g_ptr_array_free(names
, TRUE
);
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_xdg_path_load("Templates", "", SITE
);
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;
679 n_selected
= view_count_selected(filer_window
->view
);
685 /* Remove previous AppMenu, if any */
688 window_with_focus
= filer_window
;
691 event
= gtk_get_current_event();
693 if (event
->type
== GDK_BUTTON_PRESS
)
694 state
= ((GdkEventButton
*) event
)->state
;
695 else if (event
->type
== GDK_KEY_PRESS
)
696 state
= ((GdkEventKey
*) event
)->state
;
698 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
700 filer_window
->temp_item_selected
= TRUE
;
701 view_set_selected(filer_window
->view
, iter
, TRUE
);
702 n_selected
= view_count_selected(filer_window
->view
);
706 filer_window
->temp_item_selected
= FALSE
;
709 /* Short-cut to the Send To menu */
710 if (state
& GDK_SHIFT_MASK
)
719 _("You should Shift+Menu click over a file to "
720 "send it somewhere"));
724 paths
= filer_selected_items(filer_window
);
726 show_send_to_menu(paths
, event
); /* (paths eaten) */
732 GtkWidget
*file_label
, *file_menu
;
736 file_label
= filer_file_item
;
737 file_menu
= filer_file_menu
;
738 gtk_check_menu_item_set_active(
739 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
740 filer_window
->show_thumbs
);
741 gtk_check_menu_item_set_active(
742 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
743 filer_window
->show_hidden
);
744 gtk_check_menu_item_set_active(
745 GTK_CHECK_MENU_ITEM(filer_reverse_menu
),
746 filer_window
->sort_order
!= GTK_SORT_ASCENDING
);
747 gtk_check_menu_item_set_active(
748 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
749 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
750 buffer
= g_string_new(NULL
);
755 g_string_assign(buffer
, _("Next Click"));
756 shade_file_menu_items(FALSE
);
759 item
= filer_selected_item(filer_window
);
760 if (item
->base_type
== TYPE_UNKNOWN
)
761 dir_update_item(filer_window
->directory
,
763 shade_file_menu_items(FALSE
);
764 file_item
= filer_selected_item(filer_window
);
765 g_string_printf(buffer
, _("%s '%s'"),
766 basetype_name(file_item
),
767 g_utf8_validate(file_item
->leafname
,
769 ? file_item
->leafname
771 if (!can_set_run_action(file_item
))
772 menu_set_items_shaded(filer_file_menu
,
776 shade_file_menu_items(TRUE
);
777 g_string_printf(buffer
, _("%d items"),
781 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
782 g_string_free(buffer
, TRUE
);
784 menu_show_shift_action(file_shift_item
, file_item
,
787 n_added
= appmenu_add(make_path(filer_window
->sym_path
,
788 file_item
->leafname
),
789 file_item
, filer_file_menu
);
792 update_new_files_menu(get_menu_icon_style());
794 gtk_widget_set_sensitive(filer_new_window
,
795 !o_unique_filer_windows
.int_value
);
796 gtk_widget_set_sensitive(filer_follow_sym
,
797 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
798 gtk_widget_set_sensitive(filer_set_type
,
799 xtype_supported(filer_window
->real_path
));
801 if (n_selected
&& o_menu_quick
.int_value
)
802 popup_menu
= (state
& GDK_CONTROL_MASK
)
806 popup_menu
= (state
& GDK_CONTROL_MASK
)
812 show_popup_menu(popup_menu
, event
,
813 popup_menu
== filer_file_menu
? n_added
: 1);
816 static void menu_closed(GtkWidget
*widget
)
818 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
819 return; /* Close panel item chosen? */
823 if (window_with_focus
->temp_item_selected
)
825 view_clear_selection(window_with_focus
->view
);
826 window_with_focus
->temp_item_selected
= FALSE
;
832 static void target_callback(FilerWindow
*filer_window
,
836 g_return_if_fail(filer_window
!= NULL
);
838 window_with_focus
= filer_window
;
840 /* Don't grab the primary selection */
841 filer_window
->temp_item_selected
= TRUE
;
843 view_wink_item(filer_window
->view
, iter
);
844 view_select_only(filer_window
->view
, iter
);
845 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
847 view_clear_selection(filer_window
->view
);
848 filer_window
->temp_item_selected
= FALSE
;
851 /* Set the text of the 'Shift Open...' menu item.
852 * If icon is NULL, reset the text and also shade it, unless 'next'.
854 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
856 guchar
*shift_action
= NULL
;
860 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
862 if (item
->flags
& ITEM_FLAG_MOUNTED
)
863 shift_action
= N_("Unmount");
865 shift_action
= N_("Open unmounted");
867 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
868 shift_action
= N_("Show Target");
869 else if (item
->base_type
== TYPE_DIRECTORY
)
870 shift_action
= N_("Look Inside");
871 else if (item
->base_type
== TYPE_FILE
)
872 shift_action
= N_("Open As Text");
874 gtk_label_set_text(GTK_LABEL(menu_item
),
875 shift_action
? _(shift_action
)
877 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
882 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
884 ViewType view_type
= (ViewType
) action
;
886 g_return_if_fail(window_with_focus
!= NULL
);
888 if (view_type
== VIEW_TYPE_COLLECTION
)
889 display_set_layout(window_with_focus
,
890 window_with_focus
->display_style_wanted
,
891 DETAILS_NONE
, FALSE
);
893 filer_set_view_type(window_with_focus
, (ViewType
) action
);
896 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
898 g_return_if_fail(window_with_focus
!= NULL
);
900 display_change_size(window_with_focus
, action
== 1);
903 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
905 g_return_if_fail(window_with_focus
!= NULL
);
910 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
911 display_set_layout(window_with_focus
,
912 window_with_focus
->display_style
,
913 window_with_focus
->details_type
, FALSE
);
915 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
916 window_with_focus
->details_type
, FALSE
);
919 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
923 g_return_if_fail(window_with_focus
!= NULL
);
925 size
= window_with_focus
->display_style_wanted
;
927 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
928 display_set_layout(window_with_focus
, size
, action
, FALSE
);
931 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
)
936 g_return_if_fail(window_with_focus
!= NULL
);
938 display_set_sort_type(window_with_focus
, action
, GTK_SORT_ASCENDING
);
941 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
)
948 g_return_if_fail(window_with_focus
!= NULL
);
950 order
= window_with_focus
->sort_order
;
951 if (order
== GTK_SORT_ASCENDING
)
952 order
= GTK_SORT_DESCENDING
;
954 order
= GTK_SORT_ASCENDING
;
956 display_set_sort_type(window_with_focus
, window_with_focus
->sort_type
,
960 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
965 g_return_if_fail(window_with_focus
!= NULL
);
967 display_set_hidden(window_with_focus
,
968 !window_with_focus
->show_hidden
);
971 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
976 g_return_if_fail(window_with_focus
!= NULL
);
978 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
981 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
983 g_return_if_fail(window_with_focus
!= NULL
);
985 filer_refresh(window_with_focus
);
988 static void save_settings(gpointer data
, guint action
, GtkWidget
*widget
)
990 g_return_if_fail(window_with_focus
!= NULL
);
992 filer_save_settings(window_with_focus
);
995 static void delete(FilerWindow
*filer_window
)
998 paths
= filer_selected_items(filer_window
);
999 action_delete(paths
);
1000 destroy_glist(&paths
);
1003 static void usage(FilerWindow
*filer_window
)
1006 paths
= filer_selected_items(filer_window
);
1007 action_usage(paths
);
1008 destroy_glist(&paths
);
1011 static void chmod_items(FilerWindow
*filer_window
)
1014 paths
= filer_selected_items(filer_window
);
1015 action_chmod(paths
, FALSE
, NULL
);
1016 destroy_glist(&paths
);
1019 static void set_type_items(FilerWindow
*filer_window
)
1022 int npass
=0, nfail
=0;
1024 paths
= filer_selected_items(filer_window
);
1025 for(p
=paths
; p
; p
=g_list_next(p
)) {
1026 if(xtype_supported((const char *) p
->data
))
1032 report_error(_("Extended attributes, used to store types, are not supported for this "
1034 "This may be due to lack of support from the filesystem or the C library, "
1035 "or it may simply be that the filesystem needs to be mounted with "
1036 "the right mount option ('user_xattr' on Linux)."));
1038 report_error(_("Setting type not supported for some of these files"));
1040 action_settype(paths
, FALSE
, NULL
);
1041 destroy_glist(&paths
);
1044 static void find(FilerWindow
*filer_window
)
1047 paths
= filer_selected_items(filer_window
);
1049 destroy_glist(&paths
);
1052 /* This creates a new savebox widget, and allows the user to pick a new path
1054 * Once the new path has been picked, the callback will be called with
1055 * both the current and new paths.
1056 * NOTE: This function unrefs 'image'!
1058 static void savebox_show(const gchar
*action
, const gchar
*path
,
1059 MaskedPixmap
*image
, SaveCb callback
,
1060 GdkDragAction dnd_action
)
1062 GtkWidget
*savebox
= NULL
;
1063 GtkWidget
*check_relative
= NULL
;
1065 g_return_if_fail(image
!= NULL
);
1067 savebox
= gtk_savebox_new(action
);
1068 gtk_savebox_set_action(GTK_SAVEBOX(savebox
), dnd_action
);
1070 if (callback
== link_cb
)
1072 check_relative
= gtk_check_button_new_with_mnemonic(
1073 _("_Relative link"));
1074 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1077 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1078 gtk_tooltips_set_tip(tooltips
, check_relative
,
1079 _("If on, the symlink will store the path from the "
1080 "symlink to the target file. Use this if the symlink "
1081 "and the target will be moved together.\n"
1082 "If off, the path from the root directory is stored - "
1083 "use this if the symlink may move but the target will "
1084 "stay put."), NULL
);
1085 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1086 check_relative
, FALSE
, TRUE
, 0);
1087 gtk_widget_show(check_relative
);
1090 g_signal_connect(savebox
, "save_to_file",
1091 G_CALLBACK(save_to_file
), NULL
);
1093 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1094 g_strdup(path
), g_free
);
1095 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1096 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1098 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1100 if (g_utf8_validate(path
, -1, NULL
))
1101 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1105 dir
= g_path_get_dirname(path
);
1106 u8
= to_utf8(g_basename(path
));
1107 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
),
1108 make_path(dir
, u8
));
1112 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1113 g_object_unref(image
);
1115 gtk_widget_show(savebox
);
1118 static gint
save_to_file(GObject
*savebox
,
1119 const gchar
*pathname
, gpointer data
)
1122 const gchar
*current_path
;
1124 callback
= g_object_get_data(savebox
, "action_callback");
1125 current_path
= g_object_get_data(savebox
, "current_path");
1127 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1128 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1130 return callback(savebox
, current_path
, pathname
)
1131 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1134 static gboolean
copy_cb(GObject
*savebox
,
1135 const gchar
*current
, const gchar
*new)
1137 return action_with_leaf(action_copy
, current
, new);
1140 static gboolean
action_with_leaf(ActionFn action
,
1141 const gchar
*current
, const gchar
*new)
1149 report_error(_("New pathname is not absolute"));
1153 if (new[strlen(new) - 1] == '/')
1155 new_dir
= g_strdup(new);
1162 slash
= strrchr(new, '/');
1163 new_dir
= g_strndup(new, slash
- new);
1167 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1168 action(local_paths
, new_dir
, leaf
, -1);
1169 g_list_free(local_paths
);
1176 /* Open a savebox to act on the selected file.
1177 * Call 'callback' later to perform the operation.
1179 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1180 const gchar
*action
, SaveCb callback
,
1181 GdkDragAction dnd_action
)
1183 g_object_ref(image
);
1184 savebox_show(action
, path
, image
, callback
, dnd_action
);
1187 static gboolean
rename_cb(GObject
*savebox
,
1188 const gchar
*current
, const gchar
*new)
1190 return action_with_leaf(action_move
, current
, new);
1193 static gboolean
link_cb(GObject
*savebox
,
1194 const gchar
*initial
, const gchar
*path
)
1196 GtkToggleButton
*check_relative
;
1201 check_relative
= g_object_get_data(savebox
, "check_relative");
1203 if (gtk_toggle_button_get_active(check_relative
))
1204 link_path
= get_relative_path(path
, initial
);
1206 link_path
= g_strdup(initial
);
1208 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1210 GtkWidget
*box
, *button
;
1213 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1215 _("Symlink from '%s' already exists. "
1216 "Replace it with a link to '%s'?"),
1219 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1221 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1222 gtk_widget_show(button
);
1223 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1224 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1225 button
, GTK_RESPONSE_OK
);
1226 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1229 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1230 gtk_widget_destroy(box
);
1232 if (ans
!= GTK_RESPONSE_OK
)
1241 err
= symlink(link_path
, path
);
1246 report_error("symlink: %s", g_strerror(errno
));
1250 dir_check_this(path
);
1255 static void run_action(DirItem
*item
)
1257 if (can_set_run_action(item
))
1258 type_set_handler_dialog(item
->mime_type
);
1261 _("You can only set the run action for a "
1265 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1267 filer_opendir(home_dir
, NULL
, NULL
);
1270 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1274 path
= g_strconcat(filer_window
->sym_path
,
1275 "/", item
->leafname
, "#", NULL
);
1277 filer_change_to(filer_window
, path
, NULL
);
1281 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1283 g_return_if_fail(window_with_focus
!= NULL
);
1285 window_with_focus
->temp_item_selected
= FALSE
;
1286 view_select_all(window_with_focus
->view
);
1289 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1291 g_return_if_fail(window_with_focus
!= NULL
);
1293 window_with_focus
->temp_item_selected
= FALSE
;
1294 view_clear_selection(window_with_focus
->view
);
1297 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1299 return !view_get_selected((ViewIface
*) data
, iter
);
1302 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1304 g_return_if_fail(window_with_focus
!= NULL
);
1306 window_with_focus
->temp_item_selected
= FALSE
;
1308 view_select_if(window_with_focus
->view
, invert_cb
,
1309 window_with_focus
->view
);
1312 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1316 win
= options_show();
1320 number_of_windows
++;
1321 g_signal_connect(win
, "destroy",
1322 G_CALLBACK(one_less_window
), NULL
);
1326 static gboolean
new_directory_cb(GObject
*savebox
,
1327 const gchar
*initial
, const gchar
*path
)
1329 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1331 report_error("mkdir: %s", g_strerror(errno
));
1335 dir_check_this(path
);
1337 if (filer_exists(window_with_focus
))
1340 leaf
= strrchr(path
, '/');
1342 display_set_autoselect(window_with_focus
, leaf
+ 1);
1348 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1350 g_return_if_fail(window_with_focus
!= NULL
);
1352 savebox_show(_("Create"),
1353 make_path(window_with_focus
->sym_path
, _("NewDir")),
1354 type_to_icon(inode_directory
), new_directory_cb
,
1358 static gboolean
new_file_cb(GObject
*savebox
,
1359 const gchar
*initial
, const gchar
*path
)
1363 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1367 report_error(_("Error creating '%s': %s"),
1368 path
, g_strerror(errno
));
1373 report_error(_("Error creating '%s': %s"),
1374 path
, g_strerror(errno
));
1376 dir_check_this(path
);
1378 if (filer_exists(window_with_focus
))
1381 leaf
= strrchr(path
, '/');
1383 display_set_autoselect(window_with_focus
, leaf
+ 1);
1389 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1391 g_return_if_fail(window_with_focus
!= NULL
);
1393 savebox_show(_("Create"),
1394 make_path(window_with_focus
->sym_path
, _("NewFile")),
1395 type_to_icon(text_plain
),
1396 new_file_cb
, GDK_ACTION_COPY
);
1399 static gboolean
new_file_type_cb(GObject
*savebox
,
1400 const gchar
*initial
, const gchar
*path
)
1402 const gchar
*oleaf
, *leaf
;
1403 gchar
*templ
, *templ_dname
, *dest
;
1406 /* We can work out the template path from the initial name */
1407 oleaf
= g_basename(initial
);
1408 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
1412 _("Error creating file: could not find the template for %s"),
1417 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1418 g_free(templ_dname
);
1420 dest
= g_path_get_dirname(path
);
1421 leaf
= g_basename(path
);
1422 paths
= g_list_append(NULL
, templ
);
1424 action_copy(paths
, dest
, leaf
, TRUE
);
1430 if (filer_exists(window_with_focus
))
1431 display_set_autoselect(window_with_focus
, leaf
);
1436 static void do_send_to(gchar
*templ
)
1438 g_return_if_fail(send_to_paths
!= NULL
);
1440 run_with_files(templ
, send_to_paths
);
1443 static void new_file_type(gchar
*templ
)
1448 g_return_if_fail(window_with_focus
!= NULL
);
1450 leaf
= g_basename(templ
);
1451 type
= type_get_type(templ
);
1453 savebox_show(_("Create"),
1454 make_path(window_with_focus
->sym_path
, leaf
),
1456 new_file_type_cb
, GDK_ACTION_COPY
);
1459 static void customise_send_to(gpointer data
)
1466 dirs
= g_string_new(NULL
);
1468 path
= choices_list_xdg_dirs("", SITE
);
1469 for (i
= 0; i
< path
->len
; i
++)
1471 guchar
*old
= (guchar
*) path
->pdata
[i
];
1473 g_string_append(dirs
, old
);
1474 g_string_append(dirs
, "/SendTo\n");
1476 choices_free_list(path
);
1478 save
= choices_find_xdg_path_save("", "SendTo", SITE
, TRUE
);
1483 _("The `Send To' menu provides a quick way to send some files "
1484 "to an application. The applications listed are those in "
1485 "the following directories:\n\n%s\n%s\n"
1486 "The `Send To' menu may be opened by Shift+Menu clicking "
1489 "You can also create subdirectories called "
1490 "`.text_html', `.text', etc which will only be "
1491 "shown for files of that type. `.group' is shown "
1492 "only when multiple files are selected."),
1494 save
? _("I'll show you your SendTo directory now; you should "
1495 "symlink (Ctrl+Shift drag) any applications you want "
1497 : _("Your CHOICESPATH variable setting prevents "
1498 "customisations - sorry."));
1500 g_string_free(dirs
, TRUE
);
1503 filer_opendir(save
, NULL
, NULL
);
1506 static void customise_new(gpointer data
)
1513 dirs
= g_string_new(NULL
);
1515 path
= choices_list_xdg_dirs("", SITE
);
1516 for (i
= 0; i
< path
->len
; i
++)
1518 guchar
*old
= (guchar
*) path
->pdata
[i
];
1520 g_string_append(dirs
, old
);
1521 g_string_append(dirs
, "/Templates\n");
1523 choices_free_list(path
);
1525 save
= choices_find_xdg_path_save("", "Templates", SITE
, TRUE
);
1530 _("Any files placed in your Templates directories will "
1531 "appear on the `New' menu. Choosing one of them will make "
1532 "a copy of it as the new file.\n\n"
1533 "The following directories contain templates:\n\n%s\n%s\n"),
1535 save
? _("I'll show you your Templates directory now; you "
1536 "should place any template files you want inside it.")
1537 : _("Your CHOICESPATH variable setting prevents "
1538 "customisations - sorry."));
1540 g_string_free(dirs
, TRUE
);
1543 filer_opendir(save
, NULL
, NULL
);
1546 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1549 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1556 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1558 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1560 searchdir
= g_strdup("SendTo");
1562 paths
= choices_list_xdg_dirs(searchdir
, SITE
);
1565 for (i
= 0; i
< paths
->len
; i
++)
1567 GList
*widgets
= NULL
;
1568 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1570 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1571 (CallbackFn
) do_send_to
,
1572 FALSE
, FALSE
, TRUE
);
1575 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1576 gtk_menu_item_new());
1578 g_list_free(widgets
); /* TODO: Get rid of this */
1581 choices_free_list(paths
);
1584 /* Scan the SendTo dir and create and show the Send To menu.
1585 * The 'paths' list and every path in it is claimed, and will be
1586 * freed later -- don't free it yourself!
1588 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1590 GtkWidget
*menu
, *item
;
1592 menu
= gtk_menu_new();
1594 if (g_list_length(paths
) == 1)
1598 item
= diritem_new("");
1599 diritem_restat(paths
->data
, item
, NULL
);
1602 item
->mime_type
->media_type
,
1603 item
->mime_type
->subtype
);
1605 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1612 gboolean same
=TRUE
, same_media
=TRUE
;
1613 MIME_type
*type
=NULL
;
1616 item
= diritem_new("");
1617 for(rover
=paths
; rover
; rover
=g_list_next(rover
))
1619 diritem_restat(rover
->data
, item
, NULL
);
1621 type
=item
->mime_type
;
1624 if(type
!=item
->mime_type
)
1627 if(strcmp(type
->media_type
,
1628 item
->mime_type
->media_type
)!=0)
1641 add_sendto(menu
, type
->media_type
,
1644 add_sendto(menu
, type
->media_type
, NULL
);
1647 add_sendto(menu
, "group", NULL
);
1650 add_sendto(menu
, NULL
, NULL
);
1652 item
= gtk_menu_item_new_with_label(_("Customise"));
1653 g_signal_connect_swapped(item
, "activate",
1654 G_CALLBACK(customise_send_to
), NULL
);
1655 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1658 destroy_glist(&send_to_paths
);
1660 send_to_paths
= paths
;
1662 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1665 show_popup_menu(menu
, event
, 0);
1668 static void send_to(FilerWindow
*filer_window
)
1673 paths
= filer_selected_items(filer_window
);
1674 event
= gtk_get_current_event();
1677 show_send_to_menu(paths
, event
);
1679 gdk_event_free(event
);
1682 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1684 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1685 gboolean close
= action
;
1687 argv
[2] = o_menu_xterm
.value
;
1689 g_return_if_fail(window_with_focus
!= NULL
);
1691 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1692 gtk_widget_destroy(window_with_focus
->window
);
1695 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1697 g_return_if_fail(window_with_focus
!= NULL
);
1699 filer_change_to(window_with_focus
, home_dir
, NULL
);
1702 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1704 g_return_if_fail(window_with_focus
!= NULL
);
1706 bookmarks_show_menu(window_with_focus
);
1709 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1711 g_return_if_fail(window_with_focus
!= NULL
);
1713 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1714 filer_change_to(window_with_focus
,
1715 window_with_focus
->real_path
, NULL
);
1717 delayed_error(_("This is already the canonical name "
1718 "for this directory."));
1721 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1723 g_return_if_fail(window_with_focus
!= NULL
);
1725 filer_open_parent(window_with_focus
);
1728 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1730 g_return_if_fail(window_with_focus
!= NULL
);
1732 change_to_parent(window_with_focus
);
1735 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1737 g_return_if_fail(window_with_focus
!= NULL
);
1739 view_autosize(window_with_focus
->view
);
1742 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1744 g_return_if_fail(window_with_focus
!= NULL
);
1746 if (o_unique_filer_windows
.int_value
)
1748 report_error(_("You can't open a second view onto "
1749 "this directory because the `Unique Windows' option "
1750 "is turned on in the Options window."));
1753 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1756 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1758 g_return_if_fail(window_with_focus
!= NULL
);
1760 if (!filer_window_delete(window_with_focus
->window
, NULL
,
1762 gtk_widget_destroy(window_with_focus
->window
);
1765 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1767 MiniType type
= (MiniType
) action
;
1769 g_return_if_fail(window_with_focus
!= NULL
);
1771 /* Item needs to remain selected... */
1772 if (type
== MINI_SHELL
)
1773 window_with_focus
->temp_item_selected
= FALSE
;
1775 minibuffer_show(window_with_focus
, type
);
1778 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1780 if (action
== HELP_ABOUT
)
1781 infobox_new(app_dir
);
1782 else if (action
== HELP_DIR
)
1783 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1784 else if (action
== HELP_MANUAL
)
1786 gchar
*manual
= NULL
;
1790 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1791 current_lang
, ".html", NULL
);
1792 if (access(manual
, F_OK
))
1793 null_g_free(&manual
);
1797 manual
= g_strconcat(app_dir
,
1798 "/Help/Manual.html", NULL
);
1800 run_by_path(manual
);
1805 g_warning("Unknown help action %d\n", action
);
1808 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1809 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1811 GList
*items
, *item
;
1813 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1815 item
= g_list_nth(items
, from
);
1818 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1824 static void save_menus(void)
1828 menurc
= choices_find_xdg_path_save(MENUS_NAME
, PROJECT
, SITE
, TRUE
);
1831 gtk_accel_map_save(menurc
);
1836 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1841 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1842 item
= g_list_nth_data(items
, n
);
1844 g_return_if_fail(item
!= NULL
);
1848 gtk_menu_shell_select_item(shell
, item
);
1851 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1858 g_return_if_fail(window_with_focus
!= NULL
);
1860 n_selected
= view_count_selected(window_with_focus
->view
);
1868 case FILE_COPY_ITEM
:
1869 prompt
= _("Copy ... ?");
1871 case FILE_RENAME_ITEM
:
1872 prompt
= _("Rename ... ?");
1874 case FILE_LINK_ITEM
:
1875 prompt
= _("Symlink ... ?");
1877 case FILE_OPEN_FILE
:
1878 prompt
= _("Shift Open ... ?");
1880 case FILE_PROPERTIES
:
1881 prompt
= _("Properties of ... ?");
1884 prompt
= _("Set type of ... ?");
1886 case FILE_RUN_ACTION
:
1887 prompt
= _("Set run action for ... ?");
1890 prompt
= _("Set icon for ... ?");
1893 prompt
= _("Send ... to ... ?");
1896 prompt
= _("DELETE ... ?");
1899 prompt
= _("Count the size of ... ?");
1901 case FILE_CHMOD_ITEMS
:
1902 prompt
= _("Set permissions on ... ?");
1905 prompt
= _("Search inside ... ?");
1907 case FILE_OPEN_VFS_AVFS
:
1908 prompt
= _("Look inside ... ?");
1911 g_warning("Unknown action!");
1914 filer_target_mode(window_with_focus
, target_callback
,
1915 GINT_TO_POINTER(action
), prompt
);
1922 send_to(window_with_focus
);
1925 delete(window_with_focus
);
1928 usage(window_with_focus
);
1930 case FILE_CHMOD_ITEMS
:
1931 chmod_items(window_with_focus
);
1934 set_type_items(window_with_focus
);
1937 find(window_with_focus
);
1939 case FILE_PROPERTIES
:
1943 items
= filer_selected_items(window_with_focus
);
1944 infobox_show_list(items
);
1945 destroy_glist(&items
);
1948 case FILE_RENAME_ITEM
:
1951 GList
*items
= NULL
;
1954 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1955 while ((item
= iter
.next(&iter
)))
1956 items
= g_list_prepend(items
, item
->leafname
);
1957 items
= g_list_reverse(items
);
1959 bulk_rename(window_with_focus
->sym_path
, items
);
1963 break; /* Not a bulk rename... see below */
1968 /* All the following actions require exactly one file selected */
1972 report_error(_("You cannot do this to more than "
1973 "one item at a time"));
1977 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1979 item
= iter
.next(&iter
);
1980 g_return_if_fail(item
!= NULL
);
1981 /* iter may be passed to filer_openitem... */
1983 if (item
->base_type
== TYPE_UNKNOWN
)
1984 item
= dir_update_item(window_with_focus
->directory
,
1989 report_error(_("Item no longer exists!"));
1993 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
1997 case FILE_COPY_ITEM
:
1998 src_dest_action_item(path
, di_image(item
),
2002 case FILE_RENAME_ITEM
:
2003 src_dest_action_item(path
, di_image(item
),
2004 _("Rename"), rename_cb
,
2007 case FILE_LINK_ITEM
:
2008 src_dest_action_item(path
, di_image(item
),
2009 _("Symlink"), link_cb
,
2012 case FILE_OPEN_FILE
:
2013 filer_openitem(window_with_focus
, &iter
,
2014 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
2016 case FILE_RUN_ACTION
:
2020 icon_set_handler_dialog(item
, path
);
2022 case FILE_OPEN_VFS_AVFS
:
2023 open_vfs_avfs(window_with_focus
, item
);
2026 g_warning("Unknown action!");
2031 static void show_key_help(GtkWidget
*button
, gpointer data
)
2033 gboolean can_change_accels
;
2035 g_object_get(G_OBJECT(gtk_settings_get_default()),
2036 "gtk-can-change-accels", &can_change_accels
,
2039 if (!can_change_accels
)
2041 info_message(_("User-definable shortcuts are disabled by "
2042 "default in Gtk2, and you have not enabled "
2043 "them. You can turn this feature on by:\n\n"
2044 "1) using an XSettings manager, such as ROX-Session "
2045 "or gnome-settings-daemon, or\n\n"
2046 "2) adding this line to ~/.gtkrc-2.0:\n"
2047 "\tgtk-can-change-accels = 1\n"
2048 "\t(this only works if NOT using XSETTINGS)"));
2052 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
2053 "- Open the menu over a filer window,\n"
2054 "- Move the pointer over the item you want to use,\n"
2055 "- Press the key you want attached to it.\n\n"
2056 "The key will appear next to the menu item and you can just press "
2057 "that key without opening the menu in future."));
2060 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
2062 GtkWidget
*button
, *align
;
2064 g_return_val_if_fail(option
== NULL
, NULL
);
2066 align
= gtk_alignment_new(0, 0.5, 0, 0);
2067 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
2068 gtk_container_add(GTK_CONTAINER(align
), button
);
2069 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
2071 return g_list_append(NULL
, align
);