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 customise_new(gpointer data
);
149 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
151 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
152 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
153 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
154 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
155 static void show_log(gpointer data
, guint action
, GtkWidget
*widget
);
156 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
157 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
158 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
159 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
161 /* (action used in this - MiniType) */
162 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
163 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
165 #define MENUS_NAME "menus2"
167 static GtkWidget
*filer_menu
; /* The popup filer menu */
168 static GtkWidget
*filer_file_item
; /* The File '' label */
169 static GtkWidget
*filer_file_menu
; /* The File '' menu */
170 static GtkWidget
*file_shift_item
; /* Shift Open label */
171 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
172 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
173 static GtkWidget
*filer_filter_dirs_menu
; /* The Filter Dirs item */
174 static GtkWidget
*filer_sort_by_name_menu
; /* The Sort by Name item */
175 static GtkWidget
*filer_sort_by_type_menu
; /* The Sort by Type item */
176 static GtkWidget
*filer_sort_by_date_menu
; /* The Sort by Date item */
177 static GtkWidget
*filer_sort_by_size_menu
; /* The Sort by Size item */
178 static GtkWidget
*filer_sort_by_owner_menu
; /* The Sort by Owner item */
179 static GtkWidget
*filer_sort_by_group_menu
; /* The Sort by Group item */
180 static GtkWidget
*filer_reverse_menu
; /* The Reversed item */
181 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
182 static GtkWidget
*filer_new_window
; /* The New Window item */
183 static GtkWidget
*filer_new_menu
; /* The New submenu */
184 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
185 static GtkWidget
*filer_set_type
; /* Set type item */
190 static GtkItemFactoryEntry filer_menu_def
[] = {
191 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
192 {">" N_("Icons View"), NULL
, view_type
, VIEW_TYPE_COLLECTION
, NULL
},
193 {">" N_("Icons, With..."), NULL
, NULL
, 0, "<Branch>"},
194 {">>" N_("Sizes"), NULL
, set_with
, DETAILS_SIZE
, NULL
},
195 {">>" N_("Permissions"), NULL
, set_with
, DETAILS_PERMISSIONS
, NULL
},
196 {">>" N_("Types"), NULL
, set_with
, DETAILS_TYPE
, NULL
},
197 {">>" N_("Times"), NULL
, set_with
, DETAILS_TIMES
, NULL
},
198 {">" N_("List View"), NULL
, view_type
, VIEW_TYPE_DETAILS
, "<StockItem>", ROX_STOCK_SHOW_DETAILS
},
199 {">", NULL
, NULL
, 0, "<Separator>"},
200 {">" N_("Bigger Icons"), "equal", change_size
, 1, "<StockItem>", GTK_STOCK_ZOOM_IN
},
201 {">" N_("Smaller Icons"), "minus", change_size
, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT
},
202 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
203 {">", NULL
, NULL
, 0, "<Separator>"},
204 {">" N_("Sort by Name"), NULL
, set_sort
, SORT_NAME
, "<ToggleItem>"},
205 {">" N_("Sort by Type"), NULL
, set_sort
, SORT_TYPE
, "<ToggleItem>"},
206 {">" N_("Sort by Date"), NULL
, set_sort
, SORT_DATE
, "<ToggleItem>"},
207 {">" N_("Sort by Size"), NULL
, set_sort
, SORT_SIZE
, "<ToggleItem>"},
208 {">" N_("Sort by Owner"), NULL
, set_sort
, SORT_OWNER
, "<ToggleItem>"},
209 {">" N_("Sort by Group"), NULL
, set_sort
, SORT_GROUP
, "<ToggleItem>"},
210 {">" N_("Reversed"), NULL
, reverse_sort
, 0, "<ToggleItem>"},
211 {">", NULL
, NULL
, 0, "<Separator>"},
212 {">" N_("Show Hidden"), "<Ctrl>H", hidden
, 0, "<ToggleItem>"},
213 {">" N_("Filter Files..."), NULL
, mini_buffer
, MINI_FILTER
, NULL
},
214 {">" N_("Filter Directories With Files"), NULL
, filter_directories
, 0, "<ToggleItem>"},
215 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
216 {">" N_("Refresh"), NULL
, refresh
, 0, "<StockItem>", GTK_STOCK_REFRESH
},
217 {">" N_("Save Current Display Settings..."), NULL
, save_settings
, 0, NULL
},
218 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
219 {">" N_("Copy..."), "<Ctrl>C", file_op
, FILE_COPY_ITEM
, "<StockItem>", GTK_STOCK_COPY
},
220 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
221 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
222 {">" N_("Delete"), "<Ctrl>X", file_op
, FILE_DELETE
, "<StockItem>", GTK_STOCK_DELETE
},
223 {">", NULL
, NULL
, 0, "<Separator>"},
224 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
},
225 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
226 {">", NULL
, NULL
, 0, "<Separator>"},
227 {">" N_("Set Run Action..."), "asterisk", file_op
, FILE_RUN_ACTION
, "<StockItem>", GTK_STOCK_EXECUTE
},
228 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
229 {">" N_("Properties"), "<Ctrl>P", file_op
, FILE_PROPERTIES
, "<StockItem>", GTK_STOCK_PROPERTIES
},
230 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
231 {">" N_("Set Type..."), NULL
, file_op
, FILE_SET_TYPE
, NULL
},
232 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
233 {">", NULL
, NULL
, 0, "<Separator>"},
234 {">" N_("Find"), "<Ctrl>F", file_op
, FILE_FIND
, "<StockItem>", GTK_STOCK_FIND
},
235 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
236 {">" N_("Select All"), "<Ctrl>A", select_all
, 0, NULL
},
237 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
238 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
239 {">" N_("Select by Name..."), "period", mini_buffer
, MINI_SELECT_BY_NAME
, NULL
},
240 {">" N_("Select If..."), "<Shift>question", mini_buffer
, MINI_SELECT_IF
, NULL
},
241 {N_("Options..."), NULL
, menu_show_options
, 0, "<StockItem>", GTK_STOCK_PREFERENCES
},
242 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
243 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
244 {">" N_("Blank file"), NULL
, new_file
, 0, "<StockItem>", GTK_STOCK_NEW
},
245 {">" N_("Customise Menu..."), NULL
, customise_new
, 0, NULL
},
246 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
247 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, "<StockItem>", GTK_STOCK_GO_UP
},
248 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
249 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
250 {">" N_("Home Directory"), "<Ctrl>Home", home_directory
, 0, "<StockItem>", GTK_STOCK_HOME
},
251 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, "<StockItem>", ROX_STOCK_BOOKMARKS
},
252 {">" N_("Show Log"), NULL
, show_log
, 0, "<StockItem>", GTK_STOCK_INFO
},
253 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
254 {">" N_("Resize Window"), "<Ctrl>E", resize
, 0, NULL
},
255 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
257 {">" N_("Close Window"), "<Ctrl>Q", close_window
, 0, "<StockItem>", GTK_STOCK_CLOSE
},
258 {">", NULL
, NULL
, 0, "<Separator>"},
259 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
260 {">" N_("Shell Command..."), "<Shift>exclam", mini_buffer
, MINI_SHELL
, NULL
},
261 {">" N_("Terminal Here"), "grave", xterm_here
, FALSE
, NULL
},
262 {">" N_("Switch to Terminal"), NULL
, xterm_here
, TRUE
, NULL
},
263 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
264 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
265 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, "<StockItem>", GTK_STOCK_HELP
},
266 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
270 #define GET_MENU_ITEM(var, menu) \
271 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
273 #define GET_SMENU_ITEM(var, menu, sub) \
275 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
276 var = gtk_item_factory_get_widget(item_factory, tmp); \
280 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
282 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
283 var = gtk_item_factory_get_widget(item_factory, tmp); \
287 /* Returns TRUE if the keys were installed (first call only) */
288 gboolean
ensure_filer_menu(void)
293 GtkItemFactory
*item_factory
;
295 if (!filer_keys_need_init
)
297 filer_keys_need_init
= FALSE
;
299 item_factory
= menu_create(filer_menu_def
,
300 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
301 "<filer>", filer_keys
);
303 GET_MENU_ITEM(filer_menu
, "filer");
304 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
305 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
306 GET_SSMENU_ITEM(filer_sort_by_name_menu
, "filer", "Display", "Sort by Name");
307 GET_SSMENU_ITEM(filer_sort_by_type_menu
, "filer", "Display", "Sort by Type");
308 GET_SSMENU_ITEM(filer_sort_by_date_menu
, "filer", "Display", "Sort by Date");
309 GET_SSMENU_ITEM(filer_sort_by_size_menu
, "filer", "Display", "Sort by Size");
310 GET_SSMENU_ITEM(filer_sort_by_owner_menu
, "filer", "Display", "Sort by Owner");
311 GET_SSMENU_ITEM(filer_sort_by_group_menu
, "filer", "Display", "Sort by Group");
312 GET_SSMENU_ITEM(filer_filter_dirs_menu
, "filer", "Display", "Filter Directories With Files");
313 GET_SSMENU_ITEM(filer_reverse_menu
, "filer", "Display", "Reversed");
314 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
315 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
317 GET_SSMENU_ITEM(item
, "filer", "File", "Set Type...");
318 filer_set_type
= GTK_BIN(item
)->child
;
320 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
321 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
322 filer_follow_sym
= GTK_BIN(item
)->child
;
324 /* File '' label... */
325 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
326 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
329 /* Shift Open... label */
330 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
331 file_shift_item
= GTK_BIN(g_list_nth(items
, 5)->data
)->child
;
334 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
335 filer_new_window
= GTK_BIN(item
)->child
;
337 g_signal_connect(filer_menu
, "unmap_event",
338 G_CALLBACK(menu_closed
), NULL
);
339 g_signal_connect(filer_file_menu
, "unmap_event",
340 G_CALLBACK(menu_closed
), NULL
);
342 g_signal_connect(filer_keys
, "accel_changed",
343 G_CALLBACK(save_menus
), NULL
);
352 menurc
= choices_find_xdg_path_load(MENUS_NAME
, PROJECT
, SITE
);
355 gtk_accel_map_load(menurc
);
359 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
360 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
361 option_add_int(&o_menu_quick
, "menu_quick", FALSE
);
362 option_add_saver(save_menus
);
364 option_register_widget("menu-set-keys", set_keys_button
);
366 filer_keys
= gtk_accel_group_new();
369 /* Name is in the form "<panel>" */
370 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
371 const gchar
*name
, GtkAccelGroup
*keys
)
373 GtkItemFactory
*item_factory
;
374 GtkItemFactoryEntry
*translated
;
378 keys
= gtk_accel_group_new();
379 gtk_accel_group_lock(keys
);
382 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
384 translated
= translate_entries(def
, n_entries
);
385 gtk_item_factory_create_items(item_factory
, n_entries
,
387 free_translated_entries(translated
, n_entries
);
392 /* Prevent the user from setting a short-cut on this item */
393 static void menuitem_no_shortcuts(GtkWidget
*item
)
397 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
399 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
400 null_g_free(&menuitem
->accel_path
);
404 /* Shade items that only work on single files */
405 static void shade_file_menu_items(gboolean shaded
)
407 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 1);
408 menu_set_items_shaded(filer_file_menu
, shaded
, 2, 1);
409 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 1);
410 menu_set_items_shaded(filer_file_menu
, shaded
, 8, 2);
413 /* 'data' is an array of three ints:
414 * [ pointer_x, pointer_y, item_under_pointer ]
416 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
417 gboolean
*push_in
, gpointer data
)
419 int *pos
= (int *) data
;
420 GtkRequisition requisition
;
425 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
427 while (item
>= 0 && next
)
429 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
442 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
444 *x
= pos
[0] - (requisition
.width
* 7 / 8);
445 *y
= pos
[1] - y_shift
;
447 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
448 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
453 GtkWidget
*make_send_to_item(DirItem
*ditem
, const char *label
,
458 if (style
!= MIS_NONE
&& di_image(ditem
))
463 image
= di_image(ditem
);
468 pixbuf
= image
->pixbuf
;
471 if (!image
->sm_pixbuf
)
472 pixmap_make_small(image
);
473 pixbuf
= image
->sm_pixbuf
;
477 item
= gtk_image_menu_item_new_with_label(label
);
478 /* TODO: Find a way to allow short-cuts */
479 menuitem_no_shortcuts(item
);
481 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
482 gtk_image_new_from_pixbuf(pixbuf
));
483 gtk_widget_show_all(item
);
486 item
= gtk_menu_item_new_with_label(label
);
491 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
492 MenuIconStyle style
, CallbackFn func
,
493 gboolean separator
, gboolean strip_ext
,
496 GList
*widgets
= NULL
;
503 dname
= pathdup(dir_name
);
505 names
= list_dir(dname
);
509 ditem
= diritem_new("");
511 for (i
= 0; i
< names
->len
; i
++)
513 char *leaf
= names
->pdata
[i
];
518 item
= gtk_menu_item_new();
519 widgets
= g_list_append(widgets
, item
);
520 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
524 fname
= g_build_filename(dname
, leaf
, NULL
);
526 /* Strip off extension, if any */
530 dot
= strchr(leaf
, '.');
535 diritem_restat(fname
, ditem
, NULL
);
537 if (ditem
->base_type
!= TYPE_FILE
538 && (ditem
->base_type
!= TYPE_DIRECTORY
539 || (!recurse
&& !(ditem
->flags
& ITEM_FLAG_APPDIR
))))
545 item
= make_send_to_item(ditem
, leaf
, style
);
547 /* If it is a directory (but NOT an AppDir) and we are
548 * recursing then set up a sub menu.
550 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
551 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
556 sub
= gtk_menu_new();
557 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
558 separator
, strip_ext
, TRUE
);
559 g_list_free(new_widgets
);
560 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
563 g_signal_connect_swapped(item
, "activate",
564 G_CALLBACK(func
), fname
);
566 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
567 g_signal_connect_swapped(item
, "destroy",
568 G_CALLBACK(g_free
), fname
);
570 widgets
= g_list_append(widgets
, item
);
577 g_ptr_array_free(names
, TRUE
);
584 /* Scan the templates dir and create entries for the New menu */
585 static void update_new_files_menu(MenuIconStyle style
)
587 static GList
*widgets
= NULL
;
589 gchar
*templ_dname
= NULL
;
595 for (next
= widgets
; next
; next
= next
->next
)
596 gtk_widget_destroy((GtkWidget
*) next
->data
);
598 g_list_free(widgets
);
602 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
605 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
606 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
610 gtk_widget_show_all(filer_new_menu
);
613 /* 'item' is the number of the item to appear under the pointer. */
614 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
620 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
621 event
->type
== GDK_BUTTON_RELEASE
))
623 GdkEventButton
*bev
= (GdkEventButton
*) event
;
625 pos
[0] = bev
->x_root
;
626 pos
[1] = bev
->y_root
;
627 button
= bev
->button
;
630 else if (event
&& event
->type
== GDK_KEY_PRESS
)
632 GdkEventKey
*kev
= (GdkEventKey
*) event
;
634 get_pointer_xy(pos
, pos
+ 1);
638 get_pointer_xy(pos
, pos
+ 1);
642 gtk_widget_show_all(menu
);
643 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
644 position_menu
, (gpointer
) pos
, button
, time
);
645 select_nth_item(GTK_MENU_SHELL(menu
), item
);
648 /* Hide the popup menu, if any */
649 void menu_popdown(void)
652 gtk_menu_popdown(GTK_MENU(popup_menu
));
655 static MenuIconStyle
get_menu_icon_style(void)
660 mis
= o_menu_iconsize
.int_value
;
664 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
670 if (mis
== MIS_CURRENT
&& window_with_focus
)
672 switch (window_with_focus
->display_style
)
684 display
= o_display_size
.int_value
;
699 /* iter->peek() is the clicked item, or NULL if none */
700 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
702 DirItem
*file_item
= NULL
;
703 GdkModifierType state
= 0;
707 g_return_if_fail(event
!= NULL
);
709 n_selected
= view_count_selected(filer_window
->view
);
715 /* Remove previous AppMenu, if any */
718 window_with_focus
= filer_window
;
720 if (event
->type
== GDK_BUTTON_PRESS
)
721 state
= ((GdkEventButton
*) event
)->state
;
722 else if (event
->type
== GDK_KEY_PRESS
)
723 state
= ((GdkEventKey
*) event
)->state
;
725 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
727 filer_window
->temp_item_selected
= TRUE
;
728 view_set_selected(filer_window
->view
, iter
, TRUE
);
729 n_selected
= view_count_selected(filer_window
->view
);
733 filer_window
->temp_item_selected
= FALSE
;
736 /* Short-cut to the Send To menu */
737 if (state
& GDK_SHIFT_MASK
)
746 _("You should Shift+Menu click over a file to "
747 "send it somewhere"));
751 paths
= filer_selected_items(filer_window
);
753 show_send_to_menu(paths
, event
); /* (paths eaten) */
759 GtkWidget
*file_label
, *file_menu
;
763 file_label
= filer_file_item
;
764 file_menu
= filer_file_menu
;
765 gtk_check_menu_item_set_active(
766 GTK_CHECK_MENU_ITEM(filer_sort_by_name_menu
),
767 filer_window
->sort_type
== SORT_NAME
);
768 gtk_check_menu_item_set_active(
769 GTK_CHECK_MENU_ITEM(filer_sort_by_type_menu
),
770 filer_window
->sort_type
== SORT_TYPE
);
771 gtk_check_menu_item_set_active(
772 GTK_CHECK_MENU_ITEM(filer_sort_by_date_menu
),
773 filer_window
->sort_type
== SORT_DATE
);
774 gtk_check_menu_item_set_active(
775 GTK_CHECK_MENU_ITEM(filer_sort_by_size_menu
),
776 filer_window
->sort_type
== SORT_SIZE
);
777 gtk_check_menu_item_set_active(
778 GTK_CHECK_MENU_ITEM(filer_sort_by_owner_menu
),
779 filer_window
->sort_type
== SORT_OWNER
);
780 gtk_check_menu_item_set_active(
781 GTK_CHECK_MENU_ITEM(filer_sort_by_group_menu
),
782 filer_window
->sort_type
== SORT_GROUP
);
783 gtk_check_menu_item_set_active(
784 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
785 filer_window
->show_thumbs
);
786 gtk_check_menu_item_set_active(
787 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
788 filer_window
->show_hidden
);
789 gtk_check_menu_item_set_active(
790 GTK_CHECK_MENU_ITEM(filer_filter_dirs_menu
),
791 filer_window
->filter_directories
);
792 gtk_check_menu_item_set_active(
793 GTK_CHECK_MENU_ITEM(filer_reverse_menu
),
794 filer_window
->sort_order
!= GTK_SORT_ASCENDING
);
795 gtk_check_menu_item_set_active(
796 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
797 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
798 buffer
= g_string_new(NULL
);
803 g_string_assign(buffer
, _("Next Click"));
804 shade_file_menu_items(FALSE
);
807 item
= filer_selected_item(filer_window
);
808 if (item
->base_type
== TYPE_UNKNOWN
)
809 dir_update_item(filer_window
->directory
,
811 shade_file_menu_items(FALSE
);
812 file_item
= filer_selected_item(filer_window
);
813 g_string_printf(buffer
, _("%s '%s'"),
814 basetype_name(file_item
),
815 g_utf8_validate(file_item
->leafname
,
817 ? file_item
->leafname
819 if (!can_set_run_action(file_item
))
820 menu_set_items_shaded(filer_file_menu
,
824 shade_file_menu_items(TRUE
);
825 g_string_printf(buffer
, _("%d items"),
829 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
830 g_string_free(buffer
, TRUE
);
832 menu_show_shift_action(file_shift_item
, file_item
,
835 n_added
= appmenu_add(make_path(filer_window
->sym_path
,
836 file_item
->leafname
),
837 file_item
, filer_file_menu
);
840 update_new_files_menu(get_menu_icon_style());
842 gtk_widget_set_sensitive(filer_new_window
,
843 !o_unique_filer_windows
.int_value
);
844 gtk_widget_set_sensitive(filer_follow_sym
,
845 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
846 gtk_widget_set_sensitive(filer_set_type
,
847 xattr_supported(filer_window
->real_path
));
849 if (n_selected
&& o_menu_quick
.int_value
)
850 popup_menu
= (state
& GDK_CONTROL_MASK
)
854 popup_menu
= (state
& GDK_CONTROL_MASK
)
860 show_popup_menu(popup_menu
, event
,
861 popup_menu
== filer_file_menu
? n_added
: 1);
864 static void menu_closed(GtkWidget
*widget
)
866 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
867 return; /* Close panel item chosen? */
871 if (window_with_focus
->temp_item_selected
)
873 view_clear_selection(window_with_focus
->view
);
874 window_with_focus
->temp_item_selected
= FALSE
;
880 static void target_callback(FilerWindow
*filer_window
,
884 g_return_if_fail(filer_window
!= NULL
);
886 window_with_focus
= filer_window
;
888 /* Don't grab the primary selection */
889 filer_window
->temp_item_selected
= TRUE
;
891 view_wink_item(filer_window
->view
, iter
);
892 view_select_only(filer_window
->view
, iter
);
893 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
895 view_clear_selection(filer_window
->view
);
896 filer_window
->temp_item_selected
= FALSE
;
899 /* Set the text of the 'Shift Open...' menu item.
900 * If icon is NULL, reset the text and also shade it, unless 'next'.
902 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
904 guchar
*shift_action
= NULL
;
908 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
910 if (item
->flags
& ITEM_FLAG_MOUNTED
)
911 shift_action
= N_("Unmount");
913 shift_action
= N_("Open unmounted");
915 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
916 shift_action
= N_("Show Target");
917 else if (item
->base_type
== TYPE_DIRECTORY
)
918 shift_action
= N_("Look Inside");
919 else if (item
->base_type
== TYPE_FILE
)
920 shift_action
= N_("Open As Text");
922 gtk_label_set_text(GTK_LABEL(menu_item
),
923 shift_action
? _(shift_action
)
925 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
930 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
932 ViewType view_type
= (ViewType
) action
;
934 g_return_if_fail(window_with_focus
!= NULL
);
936 if (view_type
== VIEW_TYPE_COLLECTION
)
937 display_set_layout(window_with_focus
,
938 window_with_focus
->display_style_wanted
,
939 DETAILS_NONE
, FALSE
);
941 filer_set_view_type(window_with_focus
, (ViewType
) action
);
944 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
946 g_return_if_fail(window_with_focus
!= NULL
);
948 display_change_size(window_with_focus
, action
== 1);
951 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
953 g_return_if_fail(window_with_focus
!= NULL
);
958 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
959 display_set_layout(window_with_focus
,
960 window_with_focus
->display_style
,
961 window_with_focus
->details_type
, FALSE
);
963 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
964 window_with_focus
->details_type
, FALSE
);
967 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
971 g_return_if_fail(window_with_focus
!= NULL
);
973 size
= window_with_focus
->display_style_wanted
;
975 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
976 display_set_layout(window_with_focus
, size
, action
, FALSE
);
979 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
)
984 g_return_if_fail(window_with_focus
!= NULL
);
986 display_set_sort_type(window_with_focus
, action
, GTK_SORT_ASCENDING
);
989 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
)
996 g_return_if_fail(window_with_focus
!= NULL
);
998 order
= window_with_focus
->sort_order
;
999 if (order
== GTK_SORT_ASCENDING
)
1000 order
= GTK_SORT_DESCENDING
;
1002 order
= GTK_SORT_ASCENDING
;
1004 display_set_sort_type(window_with_focus
, window_with_focus
->sort_type
,
1008 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
1013 g_return_if_fail(window_with_focus
!= NULL
);
1015 display_set_hidden(window_with_focus
,
1016 !window_with_focus
->show_hidden
);
1019 static void filter_directories(gpointer data
, guint action
, GtkWidget
*widget
)
1024 g_return_if_fail(window_with_focus
!= NULL
);
1026 display_set_filter_directories(window_with_focus
,
1027 !window_with_focus
->filter_directories
);
1030 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
1035 g_return_if_fail(window_with_focus
!= NULL
);
1037 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
1040 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
1042 g_return_if_fail(window_with_focus
!= NULL
);
1044 filer_refresh(window_with_focus
);
1047 static void save_settings(gpointer data
, guint action
, GtkWidget
*widget
)
1049 g_return_if_fail(window_with_focus
!= NULL
);
1051 filer_save_settings(window_with_focus
);
1054 static void delete(FilerWindow
*filer_window
)
1057 paths
= filer_selected_items(filer_window
);
1058 action_delete(paths
);
1059 destroy_glist(&paths
);
1062 static void usage(FilerWindow
*filer_window
)
1065 paths
= filer_selected_items(filer_window
);
1066 action_usage(paths
);
1067 destroy_glist(&paths
);
1070 static void chmod_items(FilerWindow
*filer_window
)
1073 paths
= filer_selected_items(filer_window
);
1074 action_chmod(paths
, FALSE
, NULL
);
1075 destroy_glist(&paths
);
1078 static void set_type_items(FilerWindow
*filer_window
)
1081 int npass
=0, nfail
=0;
1083 paths
= filer_selected_items(filer_window
);
1084 for(p
=paths
; p
; p
=g_list_next(p
)) {
1085 if(xattr_supported((const char *) p
->data
))
1091 report_error(_("Extended attributes, used to store types, are not supported for this "
1093 "This may be due to lack of support from the filesystem or the C library, "
1094 "or it may simply be that the filesystem needs to be mounted with "
1095 "the right mount option ('user_xattr' on Linux)."));
1097 report_error(_("Setting type not supported for some of these files"));
1099 action_settype(paths
, FALSE
, NULL
);
1100 destroy_glist(&paths
);
1103 static void find(FilerWindow
*filer_window
)
1106 paths
= filer_selected_items(filer_window
);
1108 destroy_glist(&paths
);
1111 static gboolean last_symlink_check_relative
= TRUE
;
1113 /* This creates a new savebox widget, and allows the user to pick a new path
1115 * Once the new path has been picked, the callback will be called with
1116 * both the current and new paths.
1117 * NOTE: This function unrefs 'image'!
1119 static void savebox_show(const gchar
*action
, const gchar
*path
,
1120 MaskedPixmap
*image
, SaveCb callback
,
1121 GdkDragAction dnd_action
)
1123 GtkWidget
*savebox
= NULL
;
1124 GtkWidget
*check_relative
= NULL
;
1126 g_return_if_fail(image
!= NULL
);
1128 savebox
= gtk_savebox_new(action
);
1129 gtk_savebox_set_action(GTK_SAVEBOX(savebox
), dnd_action
);
1131 if (callback
== link_cb
)
1133 check_relative
= gtk_check_button_new_with_mnemonic(
1134 _("_Relative link"));
1135 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1136 last_symlink_check_relative
);
1138 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1139 gtk_tooltips_set_tip(tooltips
, check_relative
,
1140 _("If on, the symlink will store the path from the "
1141 "symlink to the target file. Use this if the symlink "
1142 "and the target will be moved together.\n"
1143 "If off, the path from the root directory is stored - "
1144 "use this if the symlink may move but the target will "
1145 "stay put."), NULL
);
1146 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1147 check_relative
, FALSE
, TRUE
, 0);
1148 gtk_widget_show(check_relative
);
1151 g_signal_connect(savebox
, "save_to_file",
1152 G_CALLBACK(save_to_file
), NULL
);
1154 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1155 g_strdup(path
), g_free
);
1156 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1157 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1159 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1161 if (g_utf8_validate(path
, -1, NULL
))
1162 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1166 dir
= g_path_get_dirname(path
);
1167 u8
= to_utf8(g_basename(path
));
1168 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
),
1169 make_path(dir
, u8
));
1173 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1174 g_object_unref(image
);
1176 gtk_widget_show(savebox
);
1179 static gint
save_to_file(GObject
*savebox
,
1180 const gchar
*pathname
, gpointer data
)
1183 const gchar
*current_path
;
1185 callback
= g_object_get_data(savebox
, "action_callback");
1186 current_path
= g_object_get_data(savebox
, "current_path");
1188 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1189 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1191 return callback(savebox
, current_path
, pathname
)
1192 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1195 static gboolean
copy_cb(GObject
*savebox
,
1196 const gchar
*current
, const gchar
*new)
1198 return action_with_leaf(action_copy
, current
, new);
1201 static gboolean
action_with_leaf(ActionFn action
,
1202 const gchar
*current
, const gchar
*new)
1210 report_error(_("New pathname is not absolute"));
1214 if (new[strlen(new) - 1] == '/')
1216 new_dir
= g_strdup(new);
1223 slash
= strrchr(new, '/');
1224 new_dir
= g_strndup(new, slash
- new);
1228 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1229 action(local_paths
, new_dir
, leaf
, -1);
1230 g_list_free(local_paths
);
1237 /* Open a savebox to act on the selected file.
1238 * Call 'callback' later to perform the operation.
1240 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1241 const gchar
*action
, SaveCb callback
,
1242 GdkDragAction dnd_action
)
1244 g_object_ref(image
);
1245 savebox_show(action
, path
, image
, callback
, dnd_action
);
1248 static gboolean
rename_cb(GObject
*savebox
,
1249 const gchar
*current
, const gchar
*new)
1251 return action_with_leaf(action_move
, current
, new);
1254 static gboolean
link_cb(GObject
*savebox
,
1255 const gchar
*initial
, const gchar
*path
)
1257 GtkToggleButton
*check_relative
;
1262 check_relative
= g_object_get_data(savebox
, "check_relative");
1264 last_symlink_check_relative
= gtk_toggle_button_get_active(check_relative
);
1266 if (last_symlink_check_relative
)
1267 link_path
= get_relative_path(path
, initial
);
1269 link_path
= g_strdup(initial
);
1271 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1273 GtkWidget
*box
, *button
;
1276 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1278 _("Symlink from '%s' already exists. "
1279 "Replace it with a link to '%s'?"),
1282 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1284 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1285 gtk_widget_show(button
);
1286 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1287 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1288 button
, GTK_RESPONSE_OK
);
1289 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1292 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1293 gtk_widget_destroy(box
);
1295 if (ans
!= GTK_RESPONSE_OK
)
1304 err
= symlink(link_path
, path
);
1309 report_error("symlink: %s", g_strerror(errno
));
1313 dir_check_this(path
);
1318 static void run_action(DirItem
*item
)
1320 if (can_set_run_action(item
))
1321 type_set_handler_dialog(item
->mime_type
);
1324 _("You can only set the run action for a "
1328 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1330 filer_opendir(home_dir
, NULL
, NULL
);
1333 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1335 g_return_if_fail(window_with_focus
!= NULL
);
1337 window_with_focus
->temp_item_selected
= FALSE
;
1338 view_select_all(window_with_focus
->view
);
1341 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1343 g_return_if_fail(window_with_focus
!= NULL
);
1345 window_with_focus
->temp_item_selected
= FALSE
;
1346 view_clear_selection(window_with_focus
->view
);
1349 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1351 return !view_get_selected((ViewIface
*) data
, iter
);
1354 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1356 g_return_if_fail(window_with_focus
!= NULL
);
1358 window_with_focus
->temp_item_selected
= FALSE
;
1360 view_select_if(window_with_focus
->view
, invert_cb
,
1361 window_with_focus
->view
);
1364 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1368 win
= options_show();
1372 number_of_windows
++;
1373 g_signal_connect(win
, "destroy",
1374 G_CALLBACK(one_less_window
), NULL
);
1378 static gboolean
new_directory_cb(GObject
*savebox
,
1379 const gchar
*initial
, const gchar
*path
)
1381 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1383 report_error("mkdir: %s", g_strerror(errno
));
1387 dir_check_this(path
);
1389 if (filer_exists(window_with_focus
))
1392 leaf
= strrchr(path
, '/');
1394 display_set_autoselect(window_with_focus
, leaf
+ 1);
1400 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1402 g_return_if_fail(window_with_focus
!= NULL
);
1404 savebox_show(_("Create"),
1405 make_path(window_with_focus
->sym_path
, _("NewDir")),
1406 type_to_icon(inode_directory
), new_directory_cb
,
1410 static gboolean
new_file_cb(GObject
*savebox
,
1411 const gchar
*initial
, const gchar
*path
)
1415 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1419 report_error(_("Error creating '%s': %s"),
1420 path
, g_strerror(errno
));
1425 report_error(_("Error creating '%s': %s"),
1426 path
, g_strerror(errno
));
1428 dir_check_this(path
);
1430 if (filer_exists(window_with_focus
))
1433 leaf
= strrchr(path
, '/');
1435 display_set_autoselect(window_with_focus
, leaf
+ 1);
1441 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1443 g_return_if_fail(window_with_focus
!= NULL
);
1445 savebox_show(_("Create"),
1446 make_path(window_with_focus
->sym_path
, _("NewFile")),
1447 type_to_icon(text_plain
),
1448 new_file_cb
, GDK_ACTION_COPY
);
1451 static gboolean
new_file_type_cb(GObject
*savebox
,
1452 const gchar
*initial
, const gchar
*path
)
1454 const gchar
*oleaf
, *leaf
;
1455 gchar
*templ
, *rtempl
, *templ_dname
, *dest
;
1458 /* We can work out the template path from the initial name */
1459 oleaf
= g_basename(initial
);
1460 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
1464 _("Error creating file: could not find the template for %s"),
1469 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1470 g_free(templ_dname
);
1471 rtempl
= pathdup(templ
);
1474 dest
= g_path_get_dirname(path
);
1475 leaf
= g_basename(path
);
1476 paths
= g_list_append(NULL
, rtempl
);
1478 action_copy(paths
, dest
, leaf
, TRUE
);
1484 if (filer_exists(window_with_focus
))
1485 display_set_autoselect(window_with_focus
, leaf
);
1490 static void do_send_to(gchar
*templ
)
1492 g_return_if_fail(send_to_paths
!= NULL
);
1494 run_with_files(templ
, send_to_paths
);
1497 static void new_file_type(gchar
*templ
)
1502 g_return_if_fail(window_with_focus
!= NULL
);
1504 leaf
= g_basename(templ
);
1505 type
= type_get_type(templ
);
1507 savebox_show(_("Create"),
1508 make_path(window_with_focus
->sym_path
, leaf
),
1510 new_file_type_cb
, GDK_ACTION_COPY
);
1513 static void customise_send_to(gpointer data
)
1520 dirs
= g_string_new(NULL
);
1522 path
= choices_list_xdg_dirs("", SITE
);
1523 for (i
= 0; i
< path
->len
; i
++)
1525 guchar
*old
= (guchar
*) path
->pdata
[i
];
1527 g_string_append(dirs
, old
);
1528 g_string_append(dirs
, "/SendTo\n");
1530 choices_free_list(path
);
1532 save
= choices_find_xdg_path_save("", "SendTo", SITE
, TRUE
);
1537 _("The `Send To' menu provides a quick way to send some files "
1538 "to an application. The applications listed are those in "
1539 "the following directories:\n\n%s\n%s\n"
1540 "The `Send To' menu may be opened by Shift+Menu clicking "
1543 "You can also create subdirectories called "
1544 "`.text_html', `.text', etc which will only be "
1545 "shown for files of that type. `.group' is shown "
1546 "only when multiple files are selected. `.regular' "
1547 "is shown only for regular files."),
1549 save
? _("I'll show you your SendTo directory now; you should "
1550 "symlink (Ctrl+Shift drag) any applications you want "
1552 : _("Your CHOICESPATH variable setting prevents "
1553 "customisations - sorry."));
1555 g_string_free(dirs
, TRUE
);
1558 filer_opendir(save
, NULL
, NULL
);
1561 static void customise_new(gpointer data
)
1568 dirs
= g_string_new(NULL
);
1570 path
= choices_list_xdg_dirs("", SITE
);
1571 for (i
= 0; i
< path
->len
; i
++)
1573 guchar
*old
= (guchar
*) path
->pdata
[i
];
1575 g_string_append(dirs
, old
);
1576 g_string_append(dirs
, "/Templates\n");
1578 choices_free_list(path
);
1580 save
= choices_find_xdg_path_save("", "Templates", SITE
, TRUE
);
1585 _("Any files placed in your Templates directories will "
1586 "appear on the `New' menu. Choosing one of them will make "
1587 "a copy of it as the new file.\n\n"
1588 "The following directories contain templates:\n\n%s\n%s\n"),
1590 save
? _("I'll show you your Templates directory now; you "
1591 "should place any template files you want inside it.")
1592 : _("Your CHOICESPATH variable setting prevents "
1593 "customisations - sorry."));
1595 g_string_free(dirs
, TRUE
);
1598 filer_opendir(save
, NULL
, NULL
);
1601 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1604 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1611 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1613 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1615 searchdir
= g_strdup("SendTo");
1617 paths
= choices_list_xdg_dirs(searchdir
, SITE
);
1620 for (i
= 0; i
< paths
->len
; i
++)
1622 GList
*widgets
= NULL
;
1623 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1625 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1626 (CallbackFn
) do_send_to
,
1627 FALSE
, FALSE
, TRUE
);
1630 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1631 gtk_menu_item_new());
1633 g_list_free(widgets
); /* TODO: Get rid of this */
1636 choices_free_list(paths
);
1639 /* Scan the SendTo dir and create and show the Send To menu.
1640 * The 'paths' list and every path in it is claimed, and will be
1641 * freed later -- don't free it yourself!
1643 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1645 GtkWidget
*menu
, *item
;
1647 menu
= gtk_menu_new();
1649 if (g_list_length(paths
) == 1)
1653 item
= diritem_new("");
1654 diritem_restat(paths
->data
, item
, NULL
);
1657 item
->mime_type
->media_type
,
1658 item
->mime_type
->subtype
);
1660 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1662 if (item
->base_type
== TYPE_FILE
)
1663 add_sendto(menu
, "regular", NULL
);
1670 gboolean same
=TRUE
, same_media
=TRUE
;
1671 MIME_type
*type
=NULL
;
1674 item
= diritem_new("");
1675 for(rover
=paths
; rover
; rover
=g_list_next(rover
))
1677 diritem_restat(rover
->data
, item
, NULL
);
1679 type
=item
->mime_type
;
1682 if(type
!=item
->mime_type
)
1685 if(strcmp(type
->media_type
,
1686 item
->mime_type
->media_type
)!=0)
1699 add_sendto(menu
, type
->media_type
,
1702 add_sendto(menu
, type
->media_type
, NULL
);
1705 add_sendto(menu
, "group", NULL
);
1708 add_sendto(menu
, NULL
, NULL
);
1710 item
= gtk_menu_item_new_with_label(_("Customise"));
1711 g_signal_connect_swapped(item
, "activate",
1712 G_CALLBACK(customise_send_to
), NULL
);
1713 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1716 destroy_glist(&send_to_paths
);
1718 send_to_paths
= paths
;
1720 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1723 show_popup_menu(menu
, event
, 0);
1726 static void send_to(FilerWindow
*filer_window
)
1731 paths
= filer_selected_items(filer_window
);
1732 event
= gtk_get_current_event();
1735 show_send_to_menu(paths
, event
);
1738 gdk_event_free(event
);
1741 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1743 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1744 gboolean close
= action
;
1746 argv
[2] = o_menu_xterm
.value
;
1748 g_return_if_fail(window_with_focus
!= NULL
);
1750 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1751 gtk_widget_destroy(window_with_focus
->window
);
1754 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1756 g_return_if_fail(window_with_focus
!= NULL
);
1758 filer_change_to(window_with_focus
, home_dir
, NULL
);
1761 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1763 g_return_if_fail(window_with_focus
!= NULL
);
1765 bookmarks_show_menu(window_with_focus
);
1768 static void show_log(gpointer data
, guint action
, GtkWidget
*widget
)
1770 g_return_if_fail(window_with_focus
!= NULL
);
1775 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1777 g_return_if_fail(window_with_focus
!= NULL
);
1779 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1780 filer_change_to(window_with_focus
,
1781 window_with_focus
->real_path
, NULL
);
1783 delayed_error(_("This is already the canonical name "
1784 "for this directory."));
1787 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1789 g_return_if_fail(window_with_focus
!= NULL
);
1791 filer_open_parent(window_with_focus
);
1794 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1796 g_return_if_fail(window_with_focus
!= NULL
);
1798 change_to_parent(window_with_focus
);
1801 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1803 g_return_if_fail(window_with_focus
!= NULL
);
1805 view_autosize(window_with_focus
->view
);
1808 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1810 g_return_if_fail(window_with_focus
!= NULL
);
1812 if (o_unique_filer_windows
.int_value
)
1814 report_error(_("You can't open a second view onto "
1815 "this directory because the `Unique Windows' option "
1816 "is turned on in the Options window."));
1819 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1822 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1824 g_return_if_fail(window_with_focus
!= NULL
);
1826 if (!filer_window_delete(window_with_focus
->window
, NULL
,
1828 gtk_widget_destroy(window_with_focus
->window
);
1831 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1833 MiniType type
= (MiniType
) action
;
1835 g_return_if_fail(window_with_focus
!= NULL
);
1837 /* Item needs to remain selected... */
1838 if (type
== MINI_SHELL
)
1839 window_with_focus
->temp_item_selected
= FALSE
;
1841 minibuffer_show(window_with_focus
, type
);
1844 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1846 if (action
== HELP_ABOUT
)
1847 infobox_new(app_dir
);
1848 else if (action
== HELP_DIR
)
1849 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1850 else if (action
== HELP_MANUAL
)
1852 gchar
*manual
= NULL
;
1856 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1857 current_lang
, ".html", NULL
);
1858 if (!file_exists(manual
) && strchr(current_lang
, '_'))
1860 /* Try again without the territory */
1861 strcpy(strrchr(manual
, '_'), ".html");
1863 if (!file_exists(manual
))
1864 null_g_free(&manual
);
1868 manual
= g_strconcat(app_dir
,
1869 "/Help/Manual.html", NULL
);
1871 run_by_path(manual
);
1876 g_warning("Unknown help action %d\n", action
);
1879 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1880 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1882 GList
*items
, *item
;
1884 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1886 item
= g_list_nth(items
, from
);
1889 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1895 static void save_menus(void)
1899 menurc
= choices_find_xdg_path_save(MENUS_NAME
, PROJECT
, SITE
, TRUE
);
1902 gtk_accel_map_save(menurc
);
1907 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1912 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1913 item
= g_list_nth_data(items
, n
);
1915 g_return_if_fail(item
!= NULL
);
1919 gtk_menu_shell_select_item(shell
, item
);
1922 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1929 g_return_if_fail(window_with_focus
!= NULL
);
1931 n_selected
= view_count_selected(window_with_focus
->view
);
1939 case FILE_COPY_ITEM
:
1940 prompt
= _("Copy ... ?");
1942 case FILE_RENAME_ITEM
:
1943 prompt
= _("Rename ... ?");
1945 case FILE_LINK_ITEM
:
1946 prompt
= _("Symlink ... ?");
1948 case FILE_OPEN_FILE
:
1949 prompt
= _("Shift Open ... ?");
1951 case FILE_PROPERTIES
:
1952 prompt
= _("Properties of ... ?");
1955 prompt
= _("Set type of ... ?");
1957 case FILE_RUN_ACTION
:
1958 prompt
= _("Set run action for ... ?");
1961 prompt
= _("Set icon for ... ?");
1964 prompt
= _("Send ... to ... ?");
1967 prompt
= _("DELETE ... ?");
1970 prompt
= _("Count the size of ... ?");
1972 case FILE_CHMOD_ITEMS
:
1973 prompt
= _("Set permissions on ... ?");
1976 prompt
= _("Search inside ... ?");
1979 g_warning("Unknown action!");
1982 filer_target_mode(window_with_focus
, target_callback
,
1983 GINT_TO_POINTER(action
), prompt
);
1990 send_to(window_with_focus
);
1993 delete(window_with_focus
);
1996 usage(window_with_focus
);
1998 case FILE_CHMOD_ITEMS
:
1999 chmod_items(window_with_focus
);
2002 set_type_items(window_with_focus
);
2005 find(window_with_focus
);
2007 case FILE_PROPERTIES
:
2011 items
= filer_selected_items(window_with_focus
);
2012 infobox_show_list(items
);
2013 destroy_glist(&items
);
2016 case FILE_RENAME_ITEM
:
2019 GList
*items
= NULL
;
2022 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
2023 while ((item
= iter
.next(&iter
)))
2024 items
= g_list_prepend(items
, item
->leafname
);
2025 items
= g_list_reverse(items
);
2027 bulk_rename(window_with_focus
->sym_path
, items
);
2031 break; /* Not a bulk rename... see below */
2036 /* All the following actions require exactly one file selected */
2040 report_error(_("You cannot do this to more than "
2041 "one item at a time"));
2045 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
2047 item
= iter
.next(&iter
);
2048 g_return_if_fail(item
!= NULL
);
2049 /* iter may be passed to filer_openitem... */
2051 if (item
->base_type
== TYPE_UNKNOWN
)
2052 item
= dir_update_item(window_with_focus
->directory
,
2057 report_error(_("Item no longer exists!"));
2061 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
2065 case FILE_COPY_ITEM
:
2066 src_dest_action_item(path
, di_image(item
),
2070 case FILE_RENAME_ITEM
:
2071 src_dest_action_item(path
, di_image(item
),
2072 _("Rename"), rename_cb
,
2075 case FILE_LINK_ITEM
:
2076 src_dest_action_item(path
, di_image(item
),
2077 _("Symlink"), link_cb
,
2080 case FILE_OPEN_FILE
:
2081 filer_openitem(window_with_focus
, &iter
,
2082 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
2084 case FILE_RUN_ACTION
:
2088 icon_set_handler_dialog(item
, path
);
2091 g_warning("Unknown action!");
2096 static void show_key_help(GtkWidget
*button
, gpointer data
)
2098 gboolean can_change_accels
;
2100 g_object_get(G_OBJECT(gtk_settings_get_default()),
2101 "gtk-can-change-accels", &can_change_accels
,
2104 if (!can_change_accels
)
2106 info_message(_("User-definable shortcuts are disabled by "
2107 "default in Gtk2, and you have not enabled "
2108 "them. You can turn this feature on by:\n\n"
2109 "1) using an XSettings manager, such as ROX-Session "
2110 "or gnome-settings-daemon, or\n\n"
2111 "2) adding this line to ~/.gtkrc-2.0:\n"
2112 "\tgtk-can-change-accels = 1\n"
2113 "\t(this only works if NOT using XSETTINGS)"));
2117 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
2118 "- Open the menu over a filer window,\n"
2119 "- Move the pointer over the item you want to use,\n"
2120 "- Press the key you want attached to it.\n\n"
2121 "The key will appear next to the menu item and you can just press "
2122 "that key without opening the menu in future."));
2125 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
2127 GtkWidget
*button
, *align
;
2129 g_return_val_if_fail(option
== NULL
, NULL
);
2131 align
= gtk_alignment_new(0, 0.5, 0, 0);
2132 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
2133 gtk_container_add(GTK_CONTAINER(align
), button
);
2134 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
2136 return g_list_append(NULL
, align
);