2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* menu.c - code for handling the popup menus */
22 #ifndef GTK_STOCK_INFO
23 # define GTK_STOCK_INFO "gtk-info"
31 #include <sys/param.h>
48 #include "gui_support.h"
51 #include "gtksavebox.h"
53 #include "minibuffer.h"
60 #include "usericons.h"
62 #include "view_iface.h"
64 #include "bookmarks.h"
66 #include "bulk_rename.h"
86 typedef void (*ActionFn
)(GList
*paths
,
87 const char *dest_dir
, const char *leaf
, int quiet
);
88 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
90 typedef gboolean (*SaveCb
)(GObject
*savebox
,
91 const gchar
*current
, const gchar
*new);
93 GtkAccelGroup
*filer_keys
= NULL
;
94 static gboolean filer_keys_need_init
= TRUE
;
96 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
98 static gint updating_menu
= 0; /* Non-zero => ignore activations */
99 static GList
*send_to_paths
= NULL
;
101 static Option o_menu_iconsize
, o_menu_xterm
, o_menu_quick
;
103 /* Static prototypes */
105 static void save_menus(void);
106 static void menu_closed(GtkWidget
*widget
);
107 static void shade_file_menu_items(gboolean shaded
);
108 static void savebox_show(const gchar
*action
, const gchar
*path
,
109 MaskedPixmap
*image
, SaveCb callback
,
110 GdkDragAction dnd_action
);
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 set_sort(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void filter_directories(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void save_settings(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 new_script(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void customise_new(gpointer data
);
150 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
152 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
153 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
154 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
155 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
156 static void show_log(gpointer data
, guint action
, GtkWidget
*widget
);
157 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
158 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
159 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
160 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
162 /* (action used in this - MiniType) */
163 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
164 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
166 #define MENUS_NAME "menus2"
168 static GtkWidget
*filer_menu
; /* The popup filer menu */
169 static GtkWidget
*filer_file_item
; /* The File '' label */
170 static GtkWidget
*filer_file_menu
; /* The File '' menu */
171 static GtkWidget
*file_shift_item
; /* Shift Open label */
172 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
173 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
174 static GtkWidget
*filer_filter_dirs_menu
;/* The Filter Dirs item */
175 static GtkWidget
*filer_reverse_menu
; /* The Reversed item */
176 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
177 static GtkWidget
*filer_new_window
; /* The New Window item */
178 static GtkWidget
*filer_new_menu
; /* The New submenu */
179 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
180 static GtkWidget
*filer_set_type
; /* Set type item */
185 static GtkItemFactoryEntry filer_menu_def
[] = {
186 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
187 {">" N_("Icons View"), NULL
, view_type
, VIEW_TYPE_COLLECTION
, NULL
},
188 {">" N_("Icons, With..."), NULL
, NULL
, 0, "<Branch>"},
189 {">>" N_("Sizes"), NULL
, set_with
, DETAILS_SIZE
, NULL
},
190 {">>" N_("Permissions"), NULL
, set_with
, DETAILS_PERMISSIONS
, NULL
},
191 {">>" N_("Types"), NULL
, set_with
, DETAILS_TYPE
, NULL
},
192 {">>" N_("Times"), NULL
, set_with
, DETAILS_TIMES
, NULL
},
193 {">" N_("List View"), NULL
, view_type
, VIEW_TYPE_DETAILS
, "<StockItem>", ROX_STOCK_SHOW_DETAILS
},
194 {">", NULL
, NULL
, 0, "<Separator>"},
195 {">" N_("Bigger Icons"), "equal", change_size
, 1, "<StockItem>", GTK_STOCK_ZOOM_IN
},
196 {">" N_("Smaller Icons"), "minus", change_size
, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT
},
197 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
198 {">", NULL
, NULL
, 0, "<Separator>"},
199 {">" N_("Sort by Name"), NULL
, set_sort
, SORT_NAME
, NULL
},
200 {">" N_("Sort by Type"), NULL
, set_sort
, SORT_TYPE
, NULL
},
201 {">" N_("Sort by Date"), NULL
, set_sort
, SORT_DATE
, NULL
},
202 {">" N_("Sort by Size"), NULL
, set_sort
, SORT_SIZE
, NULL
},
203 {">" N_("Sort by Owner"), NULL
, set_sort
, SORT_OWNER
, NULL
},
204 {">" N_("Sort by Group"), NULL
, set_sort
, SORT_GROUP
, NULL
},
205 {">" N_("Reversed"), NULL
, reverse_sort
, 0, "<ToggleItem>"},
206 {">", NULL
, NULL
, 0, "<Separator>"},
207 {">" N_("Show Hidden"), "<Ctrl>H", hidden
, 0, "<ToggleItem>"},
208 {">" N_("Filter Files..."), NULL
, mini_buffer
, MINI_FILTER
, NULL
},
209 {">" N_("Filter Directories With Files"), NULL
, filter_directories
, 0, "<ToggleItem>"},
210 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
211 {">" N_("Refresh"), NULL
, refresh
, 0, "<StockItem>", GTK_STOCK_REFRESH
},
212 {">" N_("Save Current Display Settings..."), NULL
, save_settings
, 0, NULL
},
213 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
214 {">" N_("Copy..."), "<Ctrl>C", file_op
, FILE_COPY_ITEM
, "<StockItem>", GTK_STOCK_COPY
},
215 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
216 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
217 {">" N_("Delete"), "<Ctrl>X", file_op
, FILE_DELETE
, "<StockItem>", GTK_STOCK_DELETE
},
218 {">", NULL
, NULL
, 0, "<Separator>"},
219 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
},
220 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
221 {">", NULL
, NULL
, 0, "<Separator>"},
222 {">" N_("Set Run Action..."), "asterisk", file_op
, FILE_RUN_ACTION
, "<StockItem>", GTK_STOCK_EXECUTE
},
223 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
224 {">" N_("Properties"), "<Ctrl>P", file_op
, FILE_PROPERTIES
, "<StockItem>", GTK_STOCK_PROPERTIES
},
225 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
226 {">" N_("Set Type..."), NULL
, file_op
, FILE_SET_TYPE
, NULL
},
227 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
228 {">", NULL
, NULL
, 0, "<Separator>"},
229 {">" N_("Find"), "<Ctrl>F", file_op
, FILE_FIND
, "<StockItem>", GTK_STOCK_FIND
},
230 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
231 {">" N_("Select All"), "<Ctrl>A", select_all
, 0, NULL
},
232 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
233 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
234 {">" N_("Select by Name..."), "period", mini_buffer
, MINI_SELECT_BY_NAME
, NULL
},
235 {">" N_("Select If..."), "<Shift>question", mini_buffer
, MINI_SELECT_IF
, NULL
},
236 {N_("Options..."), NULL
, menu_show_options
, 0, "<StockItem>", GTK_STOCK_PREFERENCES
},
237 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
238 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
239 {">" N_("Blank file"), NULL
, new_file
, 0, "<StockItem>", GTK_STOCK_NEW
},
240 {">" N_("Start script"), NULL
, new_script
, 0, NULL
},
241 {">" N_("Customise Menu..."), NULL
, customise_new
, 0, NULL
},
242 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
243 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, "<StockItem>", GTK_STOCK_GO_UP
},
244 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
245 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
246 {">" N_("Home Directory"), "<Ctrl>Home", home_directory
, 0, "<StockItem>", GTK_STOCK_HOME
},
247 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, "<StockItem>", ROX_STOCK_BOOKMARKS
},
248 {">" N_("Show Log"), NULL
, show_log
, 0, "<StockItem>", GTK_STOCK_INFO
},
249 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
250 {">" N_("Resize Window"), "<Ctrl>E", resize
, 0, NULL
},
251 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
253 {">" N_("Close Window"), "<Ctrl>Q", close_window
, 0, "<StockItem>", GTK_STOCK_CLOSE
},
254 {">", NULL
, NULL
, 0, "<Separator>"},
255 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
256 {">" N_("Shell Command..."), "<Shift>exclam", mini_buffer
, MINI_SHELL
, NULL
},
257 {">" N_("Terminal Here"), "grave", xterm_here
, FALSE
, NULL
},
258 {">" N_("Switch to Terminal"), NULL
, xterm_here
, TRUE
, NULL
},
259 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
260 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
261 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, "<StockItem>", GTK_STOCK_HELP
},
262 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
266 #define GET_MENU_ITEM(var, menu) \
267 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
269 #define GET_SMENU_ITEM(var, menu, sub) \
271 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
272 var = gtk_item_factory_get_widget(item_factory, tmp); \
276 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
278 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
279 var = gtk_item_factory_get_widget(item_factory, tmp); \
283 /* Returns TRUE if the keys were installed (first call only) */
284 gboolean
ensure_filer_menu(void)
289 GtkItemFactory
*item_factory
;
291 if (!filer_keys_need_init
)
293 filer_keys_need_init
= FALSE
;
295 item_factory
= menu_create(filer_menu_def
,
296 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
297 "<filer>", filer_keys
);
299 GET_MENU_ITEM(filer_menu
, "filer");
300 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
301 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
302 GET_SSMENU_ITEM(filer_filter_dirs_menu
, "filer", "Display", "Filter Directories With Files");
303 GET_SSMENU_ITEM(filer_reverse_menu
, "filer", "Display", "Reversed");
304 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
305 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
307 GET_SSMENU_ITEM(item
, "filer", "File", "Set Type...");
308 filer_set_type
= GTK_BIN(item
)->child
;
310 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
311 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
312 filer_follow_sym
= GTK_BIN(item
)->child
;
314 /* File '' label... */
315 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
316 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
319 /* Shift Open... label */
320 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
321 file_shift_item
= GTK_BIN(g_list_nth(items
, 5)->data
)->child
;
324 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
325 filer_new_window
= GTK_BIN(item
)->child
;
327 g_signal_connect(filer_menu
, "unmap_event",
328 G_CALLBACK(menu_closed
), NULL
);
329 g_signal_connect(filer_file_menu
, "unmap_event",
330 G_CALLBACK(menu_closed
), NULL
);
332 g_signal_connect(filer_keys
, "accel_changed",
333 G_CALLBACK(save_menus
), NULL
);
342 menurc
= choices_find_xdg_path_load(MENUS_NAME
, PROJECT
, SITE
);
345 gtk_accel_map_load(menurc
);
349 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
350 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
351 option_add_int(&o_menu_quick
, "menu_quick", FALSE
);
352 option_add_saver(save_menus
);
354 option_register_widget("menu-set-keys", set_keys_button
);
356 filer_keys
= gtk_accel_group_new();
359 /* Name is in the form "<panel>" */
360 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
361 const gchar
*name
, GtkAccelGroup
*keys
)
363 GtkItemFactory
*item_factory
;
364 GtkItemFactoryEntry
*translated
;
368 keys
= gtk_accel_group_new();
369 gtk_accel_group_lock(keys
);
372 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
374 translated
= translate_entries(def
, n_entries
);
375 gtk_item_factory_create_items(item_factory
, n_entries
,
377 free_translated_entries(translated
, n_entries
);
382 /* Prevent the user from setting a short-cut on this item */
383 static void menuitem_no_shortcuts(GtkWidget
*item
)
387 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
389 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
390 null_g_free(&menuitem
->accel_path
);
394 /* Shade items that only work on single files */
395 static void shade_file_menu_items(gboolean shaded
)
397 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 1);
398 menu_set_items_shaded(filer_file_menu
, shaded
, 2, 1);
399 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 1);
400 menu_set_items_shaded(filer_file_menu
, shaded
, 8, 2);
403 /* 'data' is an array of three ints:
404 * [ pointer_x, pointer_y, item_under_pointer ]
406 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
407 gboolean
*push_in
, gpointer data
)
409 int *pos
= (int *) data
;
410 GtkRequisition requisition
;
415 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
417 while (item
>= 0 && next
)
419 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
432 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
434 *x
= pos
[0] - (requisition
.width
* 7 / 8);
435 *y
= pos
[1] - y_shift
;
437 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
438 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
443 GtkWidget
*make_send_to_item(DirItem
*ditem
, const char *label
,
448 if (style
!= MIS_NONE
&& di_image(ditem
))
453 image
= di_image(ditem
);
458 pixbuf
= image
->pixbuf
;
461 if (!image
->sm_pixbuf
)
462 pixmap_make_small(image
);
463 pixbuf
= image
->sm_pixbuf
;
467 item
= gtk_image_menu_item_new_with_label(label
);
468 /* TODO: Find a way to allow short-cuts */
469 menuitem_no_shortcuts(item
);
471 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
472 gtk_image_new_from_pixbuf(pixbuf
));
473 gtk_widget_show_all(item
);
476 item
= gtk_menu_item_new_with_label(label
);
481 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
482 MenuIconStyle style
, CallbackFn func
,
483 gboolean separator
, gboolean strip_ext
,
486 GList
*widgets
= NULL
;
493 dname
= pathdup(dir_name
);
495 names
= list_dir(dname
);
499 for (i
= 0; i
< names
->len
; i
++)
501 char *leaf
= names
->pdata
[i
];
506 item
= gtk_menu_item_new();
507 widgets
= g_list_append(widgets
, item
);
508 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
512 fname
= g_strconcat(dname
, "/", leaf
, NULL
);
514 /* Strip off extension, if any */
518 dot
= strchr(leaf
, '.');
523 ditem
= diritem_new("");
524 diritem_restat(fname
, ditem
, NULL
);
526 item
= make_send_to_item(ditem
, leaf
, style
);
530 /* If it is a directory (but NOT an AppDir) and we are
531 * recursing then set up a sub menu.
533 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
534 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
539 sub
= gtk_menu_new();
540 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
541 separator
, strip_ext
, TRUE
);
542 g_list_free(new_widgets
);
543 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
546 g_signal_connect_swapped(item
, "activate",
547 G_CALLBACK(func
), fname
);
551 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
552 g_signal_connect_swapped(item
, "destroy",
553 G_CALLBACK(g_free
), fname
);
555 widgets
= g_list_append(widgets
, item
);
558 g_ptr_array_free(names
, TRUE
);
565 /* Scan the templates dir and create entries for the New menu */
566 static void update_new_files_menu(MenuIconStyle style
)
568 static GList
*widgets
= NULL
;
570 gchar
*templ_dname
= NULL
;
576 for (next
= widgets
; next
; next
= next
->next
)
577 gtk_widget_destroy((GtkWidget
*) next
->data
);
579 g_list_free(widgets
);
583 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
586 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
587 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
591 gtk_widget_show_all(filer_new_menu
);
594 /* 'item' is the number of the item to appear under the pointer. */
595 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
601 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
602 event
->type
== GDK_BUTTON_RELEASE
))
604 GdkEventButton
*bev
= (GdkEventButton
*) event
;
606 pos
[0] = bev
->x_root
;
607 pos
[1] = bev
->y_root
;
608 button
= bev
->button
;
611 else if (event
&& event
->type
== GDK_KEY_PRESS
)
613 GdkEventKey
*kev
= (GdkEventKey
*) event
;
615 get_pointer_xy(pos
, pos
+ 1);
619 get_pointer_xy(pos
, pos
+ 1);
623 gtk_widget_show_all(menu
);
624 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
625 position_menu
, (gpointer
) pos
, button
, time
);
626 select_nth_item(GTK_MENU_SHELL(menu
), item
);
629 /* Hide the popup menu, if any */
630 void menu_popdown(void)
633 gtk_menu_popdown(GTK_MENU(popup_menu
));
636 static MenuIconStyle
get_menu_icon_style(void)
641 mis
= o_menu_iconsize
.int_value
;
645 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
651 if (mis
== MIS_CURRENT
&& window_with_focus
)
653 switch (window_with_focus
->display_style
)
665 display
= o_display_size
.int_value
;
680 /* iter->peek() is the clicked item, or NULL if none */
681 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
683 DirItem
*file_item
= NULL
;
684 GdkModifierType state
= 0;
688 g_return_if_fail(event
!= NULL
);
690 n_selected
= view_count_selected(filer_window
->view
);
696 /* Remove previous AppMenu, if any */
699 window_with_focus
= filer_window
;
701 if (event
->type
== GDK_BUTTON_PRESS
)
702 state
= ((GdkEventButton
*) event
)->state
;
703 else if (event
->type
== GDK_KEY_PRESS
)
704 state
= ((GdkEventKey
*) event
)->state
;
706 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
708 filer_window
->temp_item_selected
= TRUE
;
709 view_set_selected(filer_window
->view
, iter
, TRUE
);
710 n_selected
= view_count_selected(filer_window
->view
);
714 filer_window
->temp_item_selected
= FALSE
;
717 /* Short-cut to the Send To menu */
718 if (state
& GDK_SHIFT_MASK
)
727 _("You should Shift+Menu click over a file to "
728 "send it somewhere"));
732 paths
= filer_selected_items(filer_window
);
734 show_send_to_menu(paths
, event
); /* (paths eaten) */
740 GtkWidget
*file_label
, *file_menu
;
744 file_label
= filer_file_item
;
745 file_menu
= filer_file_menu
;
746 gtk_check_menu_item_set_active(
747 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
748 filer_window
->show_thumbs
);
749 gtk_check_menu_item_set_active(
750 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
751 filer_window
->show_hidden
);
752 gtk_check_menu_item_set_active(
753 GTK_CHECK_MENU_ITEM(filer_filter_dirs_menu
),
754 filer_window
->filter_directories
);
755 gtk_check_menu_item_set_active(
756 GTK_CHECK_MENU_ITEM(filer_reverse_menu
),
757 filer_window
->sort_order
!= GTK_SORT_ASCENDING
);
758 gtk_check_menu_item_set_active(
759 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
760 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
761 buffer
= g_string_new(NULL
);
766 g_string_assign(buffer
, _("Next Click"));
767 shade_file_menu_items(FALSE
);
770 item
= filer_selected_item(filer_window
);
771 if (item
->base_type
== TYPE_UNKNOWN
)
772 dir_update_item(filer_window
->directory
,
774 shade_file_menu_items(FALSE
);
775 file_item
= filer_selected_item(filer_window
);
776 g_string_printf(buffer
, _("%s '%s'"),
777 basetype_name(file_item
),
778 g_utf8_validate(file_item
->leafname
,
780 ? file_item
->leafname
782 if (!can_set_run_action(file_item
))
783 menu_set_items_shaded(filer_file_menu
,
787 shade_file_menu_items(TRUE
);
788 g_string_printf(buffer
, _("%d items"),
792 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
793 g_string_free(buffer
, TRUE
);
795 menu_show_shift_action(file_shift_item
, file_item
,
798 n_added
= appmenu_add(make_path(filer_window
->sym_path
,
799 file_item
->leafname
),
800 file_item
, filer_file_menu
);
803 update_new_files_menu(get_menu_icon_style());
805 gtk_widget_set_sensitive(filer_new_window
,
806 !o_unique_filer_windows
.int_value
);
807 gtk_widget_set_sensitive(filer_follow_sym
,
808 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
809 gtk_widget_set_sensitive(filer_set_type
,
810 xattr_supported(filer_window
->real_path
));
812 if (n_selected
&& o_menu_quick
.int_value
)
813 popup_menu
= (state
& GDK_CONTROL_MASK
)
817 popup_menu
= (state
& GDK_CONTROL_MASK
)
823 show_popup_menu(popup_menu
, event
,
824 popup_menu
== filer_file_menu
? n_added
: 1);
827 static void menu_closed(GtkWidget
*widget
)
829 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
830 return; /* Close panel item chosen? */
834 if (window_with_focus
->temp_item_selected
)
836 view_clear_selection(window_with_focus
->view
);
837 window_with_focus
->temp_item_selected
= FALSE
;
843 static void target_callback(FilerWindow
*filer_window
,
847 g_return_if_fail(filer_window
!= NULL
);
849 window_with_focus
= filer_window
;
851 /* Don't grab the primary selection */
852 filer_window
->temp_item_selected
= TRUE
;
854 view_wink_item(filer_window
->view
, iter
);
855 view_select_only(filer_window
->view
, iter
);
856 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
858 view_clear_selection(filer_window
->view
);
859 filer_window
->temp_item_selected
= FALSE
;
862 /* Set the text of the 'Shift Open...' menu item.
863 * If icon is NULL, reset the text and also shade it, unless 'next'.
865 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
867 guchar
*shift_action
= NULL
;
871 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
873 if (item
->flags
& ITEM_FLAG_MOUNTED
)
874 shift_action
= N_("Unmount");
876 shift_action
= N_("Open unmounted");
878 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
879 shift_action
= N_("Show Target");
880 else if (item
->base_type
== TYPE_DIRECTORY
)
881 shift_action
= N_("Look Inside");
882 else if (item
->base_type
== TYPE_FILE
)
883 shift_action
= N_("Open As Text");
885 gtk_label_set_text(GTK_LABEL(menu_item
),
886 shift_action
? _(shift_action
)
888 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
893 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
895 ViewType view_type
= (ViewType
) action
;
897 g_return_if_fail(window_with_focus
!= NULL
);
899 if (view_type
== VIEW_TYPE_COLLECTION
)
900 display_set_layout(window_with_focus
,
901 window_with_focus
->display_style_wanted
,
902 DETAILS_NONE
, FALSE
);
904 filer_set_view_type(window_with_focus
, (ViewType
) action
);
907 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
909 g_return_if_fail(window_with_focus
!= NULL
);
911 display_change_size(window_with_focus
, action
== 1);
914 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
916 g_return_if_fail(window_with_focus
!= NULL
);
921 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
922 display_set_layout(window_with_focus
,
923 window_with_focus
->display_style
,
924 window_with_focus
->details_type
, FALSE
);
926 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
927 window_with_focus
->details_type
, FALSE
);
930 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
934 g_return_if_fail(window_with_focus
!= NULL
);
936 size
= window_with_focus
->display_style_wanted
;
938 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
939 display_set_layout(window_with_focus
, size
, action
, FALSE
);
942 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
)
947 g_return_if_fail(window_with_focus
!= NULL
);
949 display_set_sort_type(window_with_focus
, action
, GTK_SORT_ASCENDING
);
952 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
)
959 g_return_if_fail(window_with_focus
!= NULL
);
961 order
= window_with_focus
->sort_order
;
962 if (order
== GTK_SORT_ASCENDING
)
963 order
= GTK_SORT_DESCENDING
;
965 order
= GTK_SORT_ASCENDING
;
967 display_set_sort_type(window_with_focus
, window_with_focus
->sort_type
,
971 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
976 g_return_if_fail(window_with_focus
!= NULL
);
978 display_set_hidden(window_with_focus
,
979 !window_with_focus
->show_hidden
);
982 static void filter_directories(gpointer data
, guint action
, GtkWidget
*widget
)
987 g_return_if_fail(window_with_focus
!= NULL
);
989 display_set_filter_directories(window_with_focus
,
990 !window_with_focus
->filter_directories
);
993 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
998 g_return_if_fail(window_with_focus
!= NULL
);
1000 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
1003 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
1005 g_return_if_fail(window_with_focus
!= NULL
);
1007 filer_refresh(window_with_focus
);
1010 static void save_settings(gpointer data
, guint action
, GtkWidget
*widget
)
1012 g_return_if_fail(window_with_focus
!= NULL
);
1014 filer_save_settings(window_with_focus
);
1017 static void delete(FilerWindow
*filer_window
)
1020 paths
= filer_selected_items(filer_window
);
1021 action_delete(paths
);
1022 destroy_glist(&paths
);
1025 static void usage(FilerWindow
*filer_window
)
1028 paths
= filer_selected_items(filer_window
);
1029 action_usage(paths
);
1030 destroy_glist(&paths
);
1033 static void chmod_items(FilerWindow
*filer_window
)
1036 paths
= filer_selected_items(filer_window
);
1037 action_chmod(paths
, FALSE
, NULL
);
1038 destroy_glist(&paths
);
1041 static void set_type_items(FilerWindow
*filer_window
)
1044 int npass
=0, nfail
=0;
1046 paths
= filer_selected_items(filer_window
);
1047 for(p
=paths
; p
; p
=g_list_next(p
)) {
1048 if(xattr_supported((const char *) p
->data
))
1054 report_error(_("Extended attributes, used to store types, are not supported for this "
1056 "This may be due to lack of support from the filesystem or the C library, "
1057 "or it may simply be that the filesystem needs to be mounted with "
1058 "the right mount option ('user_xattr' on Linux)."));
1060 report_error(_("Setting type not supported for some of these files"));
1062 action_settype(paths
, FALSE
, NULL
);
1063 destroy_glist(&paths
);
1066 static void find(FilerWindow
*filer_window
)
1069 paths
= filer_selected_items(filer_window
);
1071 destroy_glist(&paths
);
1074 static gboolean last_symlink_check_relative
= TRUE
;
1076 /* This creates a new savebox widget, and allows the user to pick a new path
1078 * Once the new path has been picked, the callback will be called with
1079 * both the current and new paths.
1080 * NOTE: This function unrefs 'image'!
1082 static void savebox_show(const gchar
*action
, const gchar
*path
,
1083 MaskedPixmap
*image
, SaveCb callback
,
1084 GdkDragAction dnd_action
)
1086 GtkWidget
*savebox
= NULL
;
1087 GtkWidget
*check_relative
= NULL
;
1089 g_return_if_fail(image
!= NULL
);
1091 savebox
= gtk_savebox_new(action
);
1092 gtk_savebox_set_action(GTK_SAVEBOX(savebox
), dnd_action
);
1094 if (callback
== link_cb
)
1096 check_relative
= gtk_check_button_new_with_mnemonic(
1097 _("_Relative link"));
1098 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1099 last_symlink_check_relative
);
1101 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1102 gtk_tooltips_set_tip(tooltips
, check_relative
,
1103 _("If on, the symlink will store the path from the "
1104 "symlink to the target file. Use this if the symlink "
1105 "and the target will be moved together.\n"
1106 "If off, the path from the root directory is stored - "
1107 "use this if the symlink may move but the target will "
1108 "stay put."), NULL
);
1109 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1110 check_relative
, FALSE
, TRUE
, 0);
1111 gtk_widget_show(check_relative
);
1114 g_signal_connect(savebox
, "save_to_file",
1115 G_CALLBACK(save_to_file
), NULL
);
1117 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1118 g_strdup(path
), g_free
);
1119 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1120 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1122 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1124 if (g_utf8_validate(path
, -1, NULL
))
1125 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1129 dir
= g_path_get_dirname(path
);
1130 u8
= to_utf8(g_basename(path
));
1131 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
),
1132 make_path(dir
, u8
));
1136 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1137 g_object_unref(image
);
1139 gtk_widget_show(savebox
);
1142 static gint
save_to_file(GObject
*savebox
,
1143 const gchar
*pathname
, gpointer data
)
1146 const gchar
*current_path
;
1148 callback
= g_object_get_data(savebox
, "action_callback");
1149 current_path
= g_object_get_data(savebox
, "current_path");
1151 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1152 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1154 return callback(savebox
, current_path
, pathname
)
1155 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1158 static gboolean
copy_cb(GObject
*savebox
,
1159 const gchar
*current
, const gchar
*new)
1161 return action_with_leaf(action_copy
, current
, new);
1164 static gboolean
action_with_leaf(ActionFn action
,
1165 const gchar
*current
, const gchar
*new)
1173 report_error(_("New pathname is not absolute"));
1177 if (new[strlen(new) - 1] == '/')
1179 new_dir
= g_strdup(new);
1186 slash
= strrchr(new, '/');
1187 new_dir
= g_strndup(new, slash
- new);
1191 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1192 action(local_paths
, new_dir
, leaf
, -1);
1193 g_list_free(local_paths
);
1200 /* Open a savebox to act on the selected file.
1201 * Call 'callback' later to perform the operation.
1203 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1204 const gchar
*action
, SaveCb callback
,
1205 GdkDragAction dnd_action
)
1207 g_object_ref(image
);
1208 savebox_show(action
, path
, image
, callback
, dnd_action
);
1211 static gboolean
rename_cb(GObject
*savebox
,
1212 const gchar
*current
, const gchar
*new)
1214 return action_with_leaf(action_move
, current
, new);
1217 static gboolean
link_cb(GObject
*savebox
,
1218 const gchar
*initial
, const gchar
*path
)
1220 GtkToggleButton
*check_relative
;
1225 check_relative
= g_object_get_data(savebox
, "check_relative");
1227 last_symlink_check_relative
= gtk_toggle_button_get_active(check_relative
);
1229 if (last_symlink_check_relative
)
1230 link_path
= get_relative_path(path
, initial
);
1232 link_path
= g_strdup(initial
);
1234 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1236 GtkWidget
*box
, *button
;
1239 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1241 _("Symlink from '%s' already exists. "
1242 "Replace it with a link to '%s'?"),
1245 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1247 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1248 gtk_widget_show(button
);
1249 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1250 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1251 button
, GTK_RESPONSE_OK
);
1252 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1255 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1256 gtk_widget_destroy(box
);
1258 if (ans
!= GTK_RESPONSE_OK
)
1267 err
= symlink(link_path
, path
);
1272 report_error("symlink: %s", g_strerror(errno
));
1276 dir_check_this(path
);
1281 static void run_action(DirItem
*item
)
1283 if (can_set_run_action(item
))
1284 type_set_handler_dialog(item
->mime_type
);
1287 _("You can only set the run action for a "
1291 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1293 filer_opendir(home_dir
, NULL
, NULL
);
1296 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1298 g_return_if_fail(window_with_focus
!= NULL
);
1300 window_with_focus
->temp_item_selected
= FALSE
;
1301 view_select_all(window_with_focus
->view
);
1304 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1306 g_return_if_fail(window_with_focus
!= NULL
);
1308 window_with_focus
->temp_item_selected
= FALSE
;
1309 view_clear_selection(window_with_focus
->view
);
1312 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1314 return !view_get_selected((ViewIface
*) data
, iter
);
1317 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1319 g_return_if_fail(window_with_focus
!= NULL
);
1321 window_with_focus
->temp_item_selected
= FALSE
;
1323 view_select_if(window_with_focus
->view
, invert_cb
,
1324 window_with_focus
->view
);
1327 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1331 win
= options_show();
1335 number_of_windows
++;
1336 g_signal_connect(win
, "destroy",
1337 G_CALLBACK(one_less_window
), NULL
);
1341 static gboolean
new_directory_cb(GObject
*savebox
,
1342 const gchar
*initial
, const gchar
*path
)
1344 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1346 report_error("mkdir: %s", g_strerror(errno
));
1350 dir_check_this(path
);
1352 if (filer_exists(window_with_focus
))
1355 leaf
= strrchr(path
, '/');
1357 display_set_autoselect(window_with_focus
, leaf
+ 1);
1363 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1365 g_return_if_fail(window_with_focus
!= NULL
);
1367 savebox_show(_("Create"),
1368 make_path(window_with_focus
->sym_path
, _("NewDir")),
1369 type_to_icon(inode_directory
), new_directory_cb
,
1373 static gboolean
new_file_cb(GObject
*savebox
,
1374 const gchar
*initial
, const gchar
*path
)
1378 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1382 report_error(_("Error creating '%s': %s"),
1383 path
, g_strerror(errno
));
1388 report_error(_("Error creating '%s': %s"),
1389 path
, g_strerror(errno
));
1391 dir_check_this(path
);
1393 if (filer_exists(window_with_focus
))
1396 leaf
= strrchr(path
, '/');
1398 display_set_autoselect(window_with_focus
, leaf
+ 1);
1404 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1406 g_return_if_fail(window_with_focus
!= NULL
);
1408 savebox_show(_("Create"),
1409 make_path(window_with_focus
->sym_path
, _("NewFile")),
1410 type_to_icon(text_plain
),
1411 new_file_cb
, GDK_ACTION_COPY
);
1414 static gboolean
new_script_cb(GObject
*savebox
,
1415 const gchar
*initial
, const gchar
*path
)
1419 fp
= fopen(path
, "w");
1423 report_error(_("Error creating '%s': %s"),
1424 path
, g_strerror(errno
));
1428 fprintf(fp
, "#!/bin/sh\n");
1429 /* Add 0launch call here, but don't assume it will work */
1430 fprintf(fp
, "exec %s/AppRun \"$@\"\n", app_dir
);
1435 dir_check_this(path
);
1437 if (filer_exists(window_with_focus
))
1440 leaf
= strrchr(path
, '/');
1442 display_set_autoselect(window_with_focus
, leaf
+ 1);
1448 static void new_script(gpointer data
, guint action
, GtkWidget
*widget
)
1450 g_return_if_fail(window_with_focus
!= NULL
);
1452 savebox_show(_("Start script"),
1453 make_path(window_with_focus
->sym_path
, _("rox")),
1454 type_to_icon(application_x_shellscript
),
1455 new_script_cb
, GDK_ACTION_COPY
);
1458 static gboolean
new_file_type_cb(GObject
*savebox
,
1459 const gchar
*initial
, const gchar
*path
)
1461 const gchar
*oleaf
, *leaf
;
1462 gchar
*templ
, *rtempl
, *templ_dname
, *dest
;
1465 /* We can work out the template path from the initial name */
1466 oleaf
= g_basename(initial
);
1467 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
1471 _("Error creating file: could not find the template for %s"),
1476 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1477 g_free(templ_dname
);
1478 rtempl
= pathdup(templ
);
1481 dest
= g_path_get_dirname(path
);
1482 leaf
= g_basename(path
);
1483 paths
= g_list_append(NULL
, rtempl
);
1485 action_copy(paths
, dest
, leaf
, TRUE
);
1491 if (filer_exists(window_with_focus
))
1492 display_set_autoselect(window_with_focus
, leaf
);
1497 static void do_send_to(gchar
*templ
)
1499 g_return_if_fail(send_to_paths
!= NULL
);
1501 run_with_files(templ
, send_to_paths
);
1504 static void new_file_type(gchar
*templ
)
1509 g_return_if_fail(window_with_focus
!= NULL
);
1511 leaf
= g_basename(templ
);
1512 type
= type_get_type(templ
);
1514 savebox_show(_("Create"),
1515 make_path(window_with_focus
->sym_path
, leaf
),
1517 new_file_type_cb
, GDK_ACTION_COPY
);
1520 static void customise_send_to(gpointer data
)
1527 dirs
= g_string_new(NULL
);
1529 path
= choices_list_xdg_dirs("", SITE
);
1530 for (i
= 0; i
< path
->len
; i
++)
1532 guchar
*old
= (guchar
*) path
->pdata
[i
];
1534 g_string_append(dirs
, old
);
1535 g_string_append(dirs
, "/SendTo\n");
1537 choices_free_list(path
);
1539 save
= choices_find_xdg_path_save("", "SendTo", SITE
, TRUE
);
1544 _("The `Send To' menu provides a quick way to send some files "
1545 "to an application. The applications listed are those in "
1546 "the following directories:\n\n%s\n%s\n"
1547 "The `Send To' menu may be opened by Shift+Menu clicking "
1550 "You can also create subdirectories called "
1551 "`.text_html', `.text', etc which will only be "
1552 "shown for files of that type. `.group' is shown "
1553 "only when multiple files are selected."),
1555 save
? _("I'll show you your SendTo directory now; you should "
1556 "symlink (Ctrl+Shift drag) any applications you want "
1558 : _("Your CHOICESPATH variable setting prevents "
1559 "customisations - sorry."));
1561 g_string_free(dirs
, TRUE
);
1564 filer_opendir(save
, NULL
, NULL
);
1567 static void customise_new(gpointer data
)
1574 dirs
= g_string_new(NULL
);
1576 path
= choices_list_xdg_dirs("", SITE
);
1577 for (i
= 0; i
< path
->len
; i
++)
1579 guchar
*old
= (guchar
*) path
->pdata
[i
];
1581 g_string_append(dirs
, old
);
1582 g_string_append(dirs
, "/Templates\n");
1584 choices_free_list(path
);
1586 save
= choices_find_xdg_path_save("", "Templates", SITE
, TRUE
);
1591 _("Any files placed in your Templates directories will "
1592 "appear on the `New' menu. Choosing one of them will make "
1593 "a copy of it as the new file.\n\n"
1594 "The following directories contain templates:\n\n%s\n%s\n"),
1596 save
? _("I'll show you your Templates directory now; you "
1597 "should place any template files you want inside it.")
1598 : _("Your CHOICESPATH variable setting prevents "
1599 "customisations - sorry."));
1601 g_string_free(dirs
, TRUE
);
1604 filer_opendir(save
, NULL
, NULL
);
1607 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1610 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1617 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1619 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1621 searchdir
= g_strdup("SendTo");
1623 paths
= choices_list_xdg_dirs(searchdir
, SITE
);
1626 for (i
= 0; i
< paths
->len
; i
++)
1628 GList
*widgets
= NULL
;
1629 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1631 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1632 (CallbackFn
) do_send_to
,
1633 FALSE
, FALSE
, TRUE
);
1636 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1637 gtk_menu_item_new());
1639 g_list_free(widgets
); /* TODO: Get rid of this */
1642 choices_free_list(paths
);
1645 /* Scan the SendTo dir and create and show the Send To menu.
1646 * The 'paths' list and every path in it is claimed, and will be
1647 * freed later -- don't free it yourself!
1649 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1651 GtkWidget
*menu
, *item
;
1653 menu
= gtk_menu_new();
1655 if (g_list_length(paths
) == 1)
1659 item
= diritem_new("");
1660 diritem_restat(paths
->data
, item
, NULL
);
1663 item
->mime_type
->media_type
,
1664 item
->mime_type
->subtype
);
1666 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1673 gboolean same
=TRUE
, same_media
=TRUE
;
1674 MIME_type
*type
=NULL
;
1677 item
= diritem_new("");
1678 for(rover
=paths
; rover
; rover
=g_list_next(rover
))
1680 diritem_restat(rover
->data
, item
, NULL
);
1682 type
=item
->mime_type
;
1685 if(type
!=item
->mime_type
)
1688 if(strcmp(type
->media_type
,
1689 item
->mime_type
->media_type
)!=0)
1702 add_sendto(menu
, type
->media_type
,
1705 add_sendto(menu
, type
->media_type
, NULL
);
1708 add_sendto(menu
, "group", NULL
);
1711 add_sendto(menu
, NULL
, NULL
);
1713 item
= gtk_menu_item_new_with_label(_("Customise"));
1714 g_signal_connect_swapped(item
, "activate",
1715 G_CALLBACK(customise_send_to
), NULL
);
1716 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1719 destroy_glist(&send_to_paths
);
1721 send_to_paths
= paths
;
1723 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1726 show_popup_menu(menu
, event
, 0);
1729 static void send_to(FilerWindow
*filer_window
)
1734 paths
= filer_selected_items(filer_window
);
1735 event
= gtk_get_current_event();
1738 show_send_to_menu(paths
, event
);
1741 gdk_event_free(event
);
1744 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1746 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1747 gboolean close
= action
;
1749 argv
[2] = o_menu_xterm
.value
;
1751 g_return_if_fail(window_with_focus
!= NULL
);
1753 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1754 gtk_widget_destroy(window_with_focus
->window
);
1757 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1759 g_return_if_fail(window_with_focus
!= NULL
);
1761 filer_change_to(window_with_focus
, home_dir
, NULL
);
1764 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1766 g_return_if_fail(window_with_focus
!= NULL
);
1768 bookmarks_show_menu(window_with_focus
);
1771 static void show_log(gpointer data
, guint action
, GtkWidget
*widget
)
1773 g_return_if_fail(window_with_focus
!= NULL
);
1778 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1780 g_return_if_fail(window_with_focus
!= NULL
);
1782 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1783 filer_change_to(window_with_focus
,
1784 window_with_focus
->real_path
, NULL
);
1786 delayed_error(_("This is already the canonical name "
1787 "for this directory."));
1790 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1792 g_return_if_fail(window_with_focus
!= NULL
);
1794 filer_open_parent(window_with_focus
);
1797 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1799 g_return_if_fail(window_with_focus
!= NULL
);
1801 change_to_parent(window_with_focus
);
1804 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1806 g_return_if_fail(window_with_focus
!= NULL
);
1808 view_autosize(window_with_focus
->view
);
1811 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1813 g_return_if_fail(window_with_focus
!= NULL
);
1815 if (o_unique_filer_windows
.int_value
)
1817 report_error(_("You can't open a second view onto "
1818 "this directory because the `Unique Windows' option "
1819 "is turned on in the Options window."));
1822 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1825 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1827 g_return_if_fail(window_with_focus
!= NULL
);
1829 if (!filer_window_delete(window_with_focus
->window
, NULL
,
1831 gtk_widget_destroy(window_with_focus
->window
);
1834 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1836 MiniType type
= (MiniType
) action
;
1838 g_return_if_fail(window_with_focus
!= NULL
);
1840 /* Item needs to remain selected... */
1841 if (type
== MINI_SHELL
)
1842 window_with_focus
->temp_item_selected
= FALSE
;
1844 minibuffer_show(window_with_focus
, type
);
1847 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1849 if (action
== HELP_ABOUT
)
1850 infobox_new(app_dir
);
1851 else if (action
== HELP_DIR
)
1852 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1853 else if (action
== HELP_MANUAL
)
1855 gchar
*manual
= NULL
;
1859 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1860 current_lang
, ".html", NULL
);
1861 if (!file_exists(manual
) && strchr(current_lang
, '_'))
1863 /* Try again without the territory */
1864 strcpy(strrchr(manual
, '_'), ".html");
1866 if (!file_exists(manual
))
1867 null_g_free(&manual
);
1871 manual
= g_strconcat(app_dir
,
1872 "/Help/Manual.html", NULL
);
1874 run_by_path(manual
);
1879 g_warning("Unknown help action %d\n", action
);
1882 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1883 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1885 GList
*items
, *item
;
1887 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1889 item
= g_list_nth(items
, from
);
1892 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1898 static void save_menus(void)
1902 menurc
= choices_find_xdg_path_save(MENUS_NAME
, PROJECT
, SITE
, TRUE
);
1905 gtk_accel_map_save(menurc
);
1910 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1915 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1916 item
= g_list_nth_data(items
, n
);
1918 g_return_if_fail(item
!= NULL
);
1922 gtk_menu_shell_select_item(shell
, item
);
1925 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1932 g_return_if_fail(window_with_focus
!= NULL
);
1934 n_selected
= view_count_selected(window_with_focus
->view
);
1942 case FILE_COPY_ITEM
:
1943 prompt
= _("Copy ... ?");
1945 case FILE_RENAME_ITEM
:
1946 prompt
= _("Rename ... ?");
1948 case FILE_LINK_ITEM
:
1949 prompt
= _("Symlink ... ?");
1951 case FILE_OPEN_FILE
:
1952 prompt
= _("Shift Open ... ?");
1954 case FILE_PROPERTIES
:
1955 prompt
= _("Properties of ... ?");
1958 prompt
= _("Set type of ... ?");
1960 case FILE_RUN_ACTION
:
1961 prompt
= _("Set run action for ... ?");
1964 prompt
= _("Set icon for ... ?");
1967 prompt
= _("Send ... to ... ?");
1970 prompt
= _("DELETE ... ?");
1973 prompt
= _("Count the size of ... ?");
1975 case FILE_CHMOD_ITEMS
:
1976 prompt
= _("Set permissions on ... ?");
1979 prompt
= _("Search inside ... ?");
1982 g_warning("Unknown action!");
1985 filer_target_mode(window_with_focus
, target_callback
,
1986 GINT_TO_POINTER(action
), prompt
);
1993 send_to(window_with_focus
);
1996 delete(window_with_focus
);
1999 usage(window_with_focus
);
2001 case FILE_CHMOD_ITEMS
:
2002 chmod_items(window_with_focus
);
2005 set_type_items(window_with_focus
);
2008 find(window_with_focus
);
2010 case FILE_PROPERTIES
:
2014 items
= filer_selected_items(window_with_focus
);
2015 infobox_show_list(items
);
2016 destroy_glist(&items
);
2019 case FILE_RENAME_ITEM
:
2022 GList
*items
= NULL
;
2025 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
2026 while ((item
= iter
.next(&iter
)))
2027 items
= g_list_prepend(items
, item
->leafname
);
2028 items
= g_list_reverse(items
);
2030 bulk_rename(window_with_focus
->sym_path
, items
);
2034 break; /* Not a bulk rename... see below */
2039 /* All the following actions require exactly one file selected */
2043 report_error(_("You cannot do this to more than "
2044 "one item at a time"));
2048 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
2050 item
= iter
.next(&iter
);
2051 g_return_if_fail(item
!= NULL
);
2052 /* iter may be passed to filer_openitem... */
2054 if (item
->base_type
== TYPE_UNKNOWN
)
2055 item
= dir_update_item(window_with_focus
->directory
,
2060 report_error(_("Item no longer exists!"));
2064 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
2068 case FILE_COPY_ITEM
:
2069 src_dest_action_item(path
, di_image(item
),
2073 case FILE_RENAME_ITEM
:
2074 src_dest_action_item(path
, di_image(item
),
2075 _("Rename"), rename_cb
,
2078 case FILE_LINK_ITEM
:
2079 src_dest_action_item(path
, di_image(item
),
2080 _("Symlink"), link_cb
,
2083 case FILE_OPEN_FILE
:
2084 filer_openitem(window_with_focus
, &iter
,
2085 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
2087 case FILE_RUN_ACTION
:
2091 icon_set_handler_dialog(item
, path
);
2094 g_warning("Unknown action!");
2099 static void show_key_help(GtkWidget
*button
, gpointer data
)
2101 gboolean can_change_accels
;
2103 g_object_get(G_OBJECT(gtk_settings_get_default()),
2104 "gtk-can-change-accels", &can_change_accels
,
2107 if (!can_change_accels
)
2109 info_message(_("User-definable shortcuts are disabled by "
2110 "default in Gtk2, and you have not enabled "
2111 "them. You can turn this feature on by:\n\n"
2112 "1) using an XSettings manager, such as ROX-Session "
2113 "or gnome-settings-daemon, or\n\n"
2114 "2) adding this line to ~/.gtkrc-2.0:\n"
2115 "\tgtk-can-change-accels = 1\n"
2116 "\t(this only works if NOT using XSETTINGS)"));
2120 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
2121 "- Open the menu over a filer window,\n"
2122 "- Move the pointer over the item you want to use,\n"
2123 "- Press the key you want attached to it.\n\n"
2124 "The key will appear next to the menu item and you can just press "
2125 "that key without opening the menu in future."));
2128 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
2130 GtkWidget
*button
, *align
;
2132 g_return_val_if_fail(option
== NULL
, NULL
);
2134 align
= gtk_alignment_new(0, 0.5, 0, 0);
2135 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
2136 gtk_container_add(GTK_CONTAINER(align
), button
);
2137 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
2139 return g_list_append(NULL
, align
);