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 */
27 #include <sys/param.h>
44 #include "gui_support.h"
47 #include "gtksavebox.h"
49 #include "minibuffer.h"
56 #include "usericons.h"
58 #include "view_iface.h"
60 #include "bookmarks.h"
62 #include "bulk_rename.h"
81 typedef void (*ActionFn
)(GList
*paths
,
82 const char *dest_dir
, const char *leaf
, int quiet
);
83 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
85 typedef gboolean (*SaveCb
)(GObject
*savebox
,
86 const gchar
*current
, const gchar
*new);
88 GtkAccelGroup
*filer_keys
= NULL
;
89 static gboolean filer_keys_need_init
= TRUE
;
91 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
93 static gint updating_menu
= 0; /* Non-zero => ignore activations */
94 static GList
*send_to_paths
= NULL
;
96 static Option o_menu_iconsize
, o_menu_xterm
, o_menu_quick
;
98 /* Static prototypes */
100 static void save_menus(void);
101 static void menu_closed(GtkWidget
*widget
);
102 static void shade_file_menu_items(gboolean shaded
);
103 static void savebox_show(const gchar
*action
, const gchar
*path
,
104 MaskedPixmap
*image
, SaveCb callback
,
105 GdkDragAction dnd_action
);
106 static gint
save_to_file(GObject
*savebox
,
107 const gchar
*pathname
, gpointer data
);
108 static gboolean
action_with_leaf(ActionFn action
,
109 const gchar
*current
, const gchar
*new);
110 static gboolean
link_cb(GObject
*savebox
,
111 const gchar
*initial
, const gchar
*path
);
112 static void select_nth_item(GtkMenuShell
*shell
, int n
);
113 static void new_file_type(gchar
*templ
);
114 static void do_send_to(gchar
*templ
);
115 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
116 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
118 /* Note that for most of these callbacks none of the arguments are used. */
120 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
);
122 /* (action used in these three - DetailsType) */
123 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
);
124 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
);
125 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void filter_directories(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void save_settings(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
138 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
140 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void customise_new(gpointer data
);
144 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
151 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
152 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
153 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
155 /* (action used in this - MiniType) */
156 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
157 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
159 #define MENUS_NAME "menus2"
161 static GtkWidget
*filer_menu
; /* The popup filer menu */
162 static GtkWidget
*filer_file_item
; /* The File '' label */
163 static GtkWidget
*filer_file_menu
; /* The File '' menu */
164 static GtkWidget
*file_shift_item
; /* Shift Open label */
165 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
166 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
167 static GtkWidget
*filer_filter_dirs_menu
;/* The Filter Dirs item */
168 static GtkWidget
*filer_reverse_menu
; /* The Reversed item */
169 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
170 static GtkWidget
*filer_new_window
; /* The New Window item */
171 static GtkWidget
*filer_new_menu
; /* The New submenu */
172 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
173 static GtkWidget
*filer_set_type
; /* Set type item */
178 static GtkItemFactoryEntry filer_menu_def
[] = {
179 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
180 {">" N_("Icons View"), NULL
, view_type
, VIEW_TYPE_COLLECTION
, NULL
},
181 {">" N_("Icons, With..."), NULL
, NULL
, 0, "<Branch>"},
182 {">>" N_("Sizes"), NULL
, set_with
, DETAILS_SIZE
, NULL
},
183 {">>" N_("Permissions"), NULL
, set_with
, DETAILS_PERMISSIONS
, NULL
},
184 {">>" N_("Types"), NULL
, set_with
, DETAILS_TYPE
, NULL
},
185 {">>" N_("Times"), NULL
, set_with
, DETAILS_TIMES
, NULL
},
186 {">" N_("List View"), NULL
, view_type
, VIEW_TYPE_DETAILS
, "<StockItem>", ROX_STOCK_SHOW_DETAILS
},
187 {">", NULL
, NULL
, 0, "<Separator>"},
188 {">" N_("Bigger Icons"), "equal", change_size
, 1, "<StockItem>", GTK_STOCK_ZOOM_IN
},
189 {">" N_("Smaller Icons"), "minus", change_size
, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT
},
190 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
191 {">", NULL
, NULL
, 0, "<Separator>"},
192 {">" N_("Sort by Name"), NULL
, set_sort
, SORT_NAME
, NULL
},
193 {">" N_("Sort by Type"), NULL
, set_sort
, SORT_TYPE
, NULL
},
194 {">" N_("Sort by Date"), NULL
, set_sort
, SORT_DATE
, NULL
},
195 {">" N_("Sort by Size"), NULL
, set_sort
, SORT_SIZE
, NULL
},
196 {">" N_("Sort by Owner"), NULL
, set_sort
, SORT_OWNER
, NULL
},
197 {">" N_("Sort by Group"), NULL
, set_sort
, SORT_GROUP
, NULL
},
198 {">" N_("Reversed"), NULL
, reverse_sort
, 0, "<ToggleItem>"},
199 {">", NULL
, NULL
, 0, "<Separator>"},
200 {">" N_("Show Hidden"), "<Ctrl>H", hidden
, 0, "<ToggleItem>"},
201 {">" N_("Filter Files..."), NULL
, mini_buffer
, MINI_FILTER
, NULL
},
202 {">" N_("Filter Directories With Files"), NULL
, filter_directories
, 0, "<ToggleItem>"},
203 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
204 {">" N_("Refresh"), NULL
, refresh
, 0, "<StockItem>", GTK_STOCK_REFRESH
},
205 {">" N_("Save Current Display Settings..."), NULL
, save_settings
, 0, NULL
},
206 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
207 {">" N_("Copy..."), "<Ctrl>C", file_op
, FILE_COPY_ITEM
, "<StockItem>", GTK_STOCK_COPY
},
208 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
209 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
210 {">" N_("Delete"), "<Ctrl>X", file_op
, FILE_DELETE
, "<StockItem>", GTK_STOCK_DELETE
},
211 {">", NULL
, NULL
, 0, "<Separator>"},
212 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
},
213 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
214 {">", NULL
, NULL
, 0, "<Separator>"},
215 {">" N_("Set Run Action..."), "asterisk", file_op
, FILE_RUN_ACTION
, "<StockItem>", GTK_STOCK_EXECUTE
},
216 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
217 {">" N_("Properties"), "<Ctrl>P", file_op
, FILE_PROPERTIES
, "<StockItem>", GTK_STOCK_PROPERTIES
},
218 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
219 {">" N_("Set Type..."), NULL
, file_op
, FILE_SET_TYPE
, NULL
},
220 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
221 {">", NULL
, NULL
, 0, "<Separator>"},
222 {">" N_("Find"), "<Ctrl>F", file_op
, FILE_FIND
, "<StockItem>", GTK_STOCK_FIND
},
223 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
224 {">" N_("Select All"), "<Ctrl>A", select_all
, 0, NULL
},
225 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
226 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
227 {">" N_("Select by Name..."), "period", mini_buffer
, MINI_SELECT_BY_NAME
, NULL
},
228 {">" N_("Select If..."), "<Shift>question", mini_buffer
, MINI_SELECT_IF
, NULL
},
229 {N_("Options..."), NULL
, menu_show_options
, 0, "<StockItem>", GTK_STOCK_PREFERENCES
},
230 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
231 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
232 {">" N_("Blank file"), NULL
, new_file
, 0, "<StockItem>", GTK_STOCK_NEW
},
233 {">" N_("Customise Menu..."), NULL
, customise_new
, 0, NULL
},
234 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
235 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, "<StockItem>", GTK_STOCK_GO_UP
},
236 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
237 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
238 {">" N_("Home Directory"), "<Ctrl>Home", home_directory
, 0, "<StockItem>", GTK_STOCK_HOME
},
239 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, "<StockItem>", ROX_STOCK_BOOKMARKS
},
240 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
241 {">" N_("Resize Window"), "<Ctrl>E", resize
, 0, NULL
},
242 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
244 {">" N_("Close Window"), "<Ctrl>Q", close_window
, 0, "<StockItem>", GTK_STOCK_CLOSE
},
245 {">", NULL
, NULL
, 0, "<Separator>"},
246 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
247 {">" N_("Shell Command..."), "<Shift>exclam", mini_buffer
, MINI_SHELL
, NULL
},
248 {">" N_("Terminal Here"), "grave", xterm_here
, FALSE
, NULL
},
249 {">" N_("Switch to Terminal"), NULL
, xterm_here
, TRUE
, NULL
},
250 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
251 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
252 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, "<StockItem>", GTK_STOCK_HELP
},
253 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
257 #define GET_MENU_ITEM(var, menu) \
258 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
260 #define GET_SMENU_ITEM(var, menu, sub) \
262 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
263 var = gtk_item_factory_get_widget(item_factory, tmp); \
267 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
269 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
270 var = gtk_item_factory_get_widget(item_factory, tmp); \
274 /* Returns TRUE if the keys were installed (first call only) */
275 gboolean
ensure_filer_menu(void)
280 GtkItemFactory
*item_factory
;
282 if (!filer_keys_need_init
)
284 filer_keys_need_init
= FALSE
;
286 item_factory
= menu_create(filer_menu_def
,
287 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
288 "<filer>", filer_keys
);
290 GET_MENU_ITEM(filer_menu
, "filer");
291 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
292 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
293 GET_SSMENU_ITEM(filer_filter_dirs_menu
, "filer", "Display", "Filter Directories With Files");
294 GET_SSMENU_ITEM(filer_reverse_menu
, "filer", "Display", "Reversed");
295 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
296 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
298 GET_SSMENU_ITEM(item
, "filer", "File", "Set Type...");
299 filer_set_type
= GTK_BIN(item
)->child
;
301 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
302 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
303 filer_follow_sym
= GTK_BIN(item
)->child
;
305 /* File '' label... */
306 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
307 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
310 /* Shift Open... label */
311 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
312 file_shift_item
= GTK_BIN(g_list_nth(items
, 5)->data
)->child
;
315 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
316 filer_new_window
= GTK_BIN(item
)->child
;
318 g_signal_connect(filer_menu
, "unmap_event",
319 G_CALLBACK(menu_closed
), NULL
);
320 g_signal_connect(filer_file_menu
, "unmap_event",
321 G_CALLBACK(menu_closed
), NULL
);
323 g_signal_connect(filer_keys
, "accel_changed",
324 G_CALLBACK(save_menus
), NULL
);
333 menurc
= choices_find_xdg_path_load(MENUS_NAME
, PROJECT
, SITE
);
336 gtk_accel_map_load(menurc
);
340 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
341 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
342 option_add_int(&o_menu_quick
, "menu_quick", FALSE
);
343 option_add_saver(save_menus
);
345 option_register_widget("menu-set-keys", set_keys_button
);
347 filer_keys
= gtk_accel_group_new();
350 /* Name is in the form "<panel>" */
351 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
352 const gchar
*name
, GtkAccelGroup
*keys
)
354 GtkItemFactory
*item_factory
;
355 GtkItemFactoryEntry
*translated
;
359 keys
= gtk_accel_group_new();
360 gtk_accel_group_lock(keys
);
363 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
365 translated
= translate_entries(def
, n_entries
);
366 gtk_item_factory_create_items(item_factory
, n_entries
,
368 free_translated_entries(translated
, n_entries
);
373 /* Prevent the user from setting a short-cut on this item */
374 static void menuitem_no_shortcuts(GtkWidget
*item
)
378 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
380 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
381 null_g_free(&menuitem
->accel_path
);
385 /* Shade items that only work on single files */
386 static void shade_file_menu_items(gboolean shaded
)
388 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 1);
389 menu_set_items_shaded(filer_file_menu
, shaded
, 2, 1);
390 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 1);
391 menu_set_items_shaded(filer_file_menu
, shaded
, 8, 2);
394 /* 'data' is an array of three ints:
395 * [ pointer_x, pointer_y, item_under_pointer ]
397 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
398 gboolean
*push_in
, gpointer data
)
400 int *pos
= (int *) data
;
401 GtkRequisition requisition
;
406 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
408 while (item
>= 0 && next
)
410 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
423 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
425 *x
= pos
[0] - (requisition
.width
* 7 / 8);
426 *y
= pos
[1] - y_shift
;
428 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
429 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
434 GtkWidget
*make_send_to_item(DirItem
*ditem
, const char *label
,
439 if (style
!= MIS_NONE
&& di_image(ditem
))
444 image
= di_image(ditem
);
449 pixbuf
= image
->pixbuf
;
452 if (!image
->sm_pixbuf
)
453 pixmap_make_small(image
);
454 pixbuf
= image
->sm_pixbuf
;
458 item
= gtk_image_menu_item_new_with_label(label
);
459 /* TODO: Find a way to allow short-cuts */
460 menuitem_no_shortcuts(item
);
462 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
463 gtk_image_new_from_pixbuf(pixbuf
));
464 gtk_widget_show_all(item
);
467 item
= gtk_menu_item_new_with_label(label
);
472 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
473 MenuIconStyle style
, CallbackFn func
,
474 gboolean separator
, gboolean strip_ext
,
477 GList
*widgets
= NULL
;
484 dname
= pathdup(dir_name
);
486 names
= list_dir(dname
);
490 for (i
= 0; i
< names
->len
; i
++)
492 char *leaf
= names
->pdata
[i
];
497 item
= gtk_menu_item_new();
498 widgets
= g_list_append(widgets
, item
);
499 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
503 fname
= g_strconcat(dname
, "/", leaf
, NULL
);
505 /* Strip off extension, if any */
509 dot
= strchr(leaf
, '.');
514 ditem
= diritem_new("");
515 diritem_restat(fname
, ditem
, NULL
);
517 if (ditem
->mime_type
== application_x_desktop
)
519 GError
*error
= NULL
;
522 name
= get_value_from_desktop_file(fname
,
535 item
= make_send_to_item(ditem
, leaf
, style
);
539 /* If it is a directory (but NOT an AppDir) and we are
540 * recursing then set up a sub menu.
542 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
543 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
548 sub
= gtk_menu_new();
549 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
550 separator
, strip_ext
, TRUE
);
551 g_list_free(new_widgets
);
552 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
555 g_signal_connect_swapped(item
, "activate",
556 G_CALLBACK(func
), fname
);
560 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
561 g_signal_connect_swapped(item
, "destroy",
562 G_CALLBACK(g_free
), fname
);
564 widgets
= g_list_append(widgets
, item
);
567 g_ptr_array_free(names
, TRUE
);
574 /* Scan the templates dir and create entries for the New menu */
575 static void update_new_files_menu(MenuIconStyle style
)
577 static GList
*widgets
= NULL
;
579 gchar
*templ_dname
= NULL
;
585 for (next
= widgets
; next
; next
= next
->next
)
586 gtk_widget_destroy((GtkWidget
*) next
->data
);
588 g_list_free(widgets
);
592 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
595 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
596 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
600 gtk_widget_show_all(filer_new_menu
);
603 /* 'item' is the number of the item to appear under the pointer. */
604 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
610 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
611 event
->type
== GDK_BUTTON_RELEASE
))
613 GdkEventButton
*bev
= (GdkEventButton
*) event
;
615 pos
[0] = bev
->x_root
;
616 pos
[1] = bev
->y_root
;
617 button
= bev
->button
;
620 else if (event
&& event
->type
== GDK_KEY_PRESS
)
622 GdkEventKey
*kev
= (GdkEventKey
*) event
;
624 get_pointer_xy(pos
, pos
+ 1);
628 get_pointer_xy(pos
, pos
+ 1);
632 gtk_widget_show_all(menu
);
633 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
634 position_menu
, (gpointer
) pos
, button
, time
);
635 select_nth_item(GTK_MENU_SHELL(menu
), item
);
638 /* Hide the popup menu, if any */
639 void menu_popdown(void)
642 gtk_menu_popdown(GTK_MENU(popup_menu
));
645 static MenuIconStyle
get_menu_icon_style(void)
650 mis
= o_menu_iconsize
.int_value
;
654 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
660 if (mis
== MIS_CURRENT
&& window_with_focus
)
662 switch (window_with_focus
->display_style
)
674 display
= o_display_size
.int_value
;
689 /* iter->peek() is the clicked item, or NULL if none */
690 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
692 DirItem
*file_item
= NULL
;
693 GdkModifierType state
= 0;
697 g_return_if_fail(event
!= NULL
);
699 n_selected
= view_count_selected(filer_window
->view
);
705 /* Remove previous AppMenu, if any */
708 window_with_focus
= filer_window
;
710 if (event
->type
== GDK_BUTTON_PRESS
)
711 state
= ((GdkEventButton
*) event
)->state
;
712 else if (event
->type
== GDK_KEY_PRESS
)
713 state
= ((GdkEventKey
*) event
)->state
;
715 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
717 filer_window
->temp_item_selected
= TRUE
;
718 view_set_selected(filer_window
->view
, iter
, TRUE
);
719 n_selected
= view_count_selected(filer_window
->view
);
723 filer_window
->temp_item_selected
= FALSE
;
726 /* Short-cut to the Send To menu */
727 if (state
& GDK_SHIFT_MASK
)
736 _("You should Shift+Menu click over a file to "
737 "send it somewhere"));
741 paths
= filer_selected_items(filer_window
);
743 show_send_to_menu(paths
, event
); /* (paths eaten) */
749 GtkWidget
*file_label
, *file_menu
;
753 file_label
= filer_file_item
;
754 file_menu
= filer_file_menu
;
755 gtk_check_menu_item_set_active(
756 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
757 filer_window
->show_thumbs
);
758 gtk_check_menu_item_set_active(
759 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
760 filer_window
->show_hidden
);
761 gtk_check_menu_item_set_active(
762 GTK_CHECK_MENU_ITEM(filer_filter_dirs_menu
),
763 filer_window
->filter_directories
);
764 gtk_check_menu_item_set_active(
765 GTK_CHECK_MENU_ITEM(filer_reverse_menu
),
766 filer_window
->sort_order
!= GTK_SORT_ASCENDING
);
767 gtk_check_menu_item_set_active(
768 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
769 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
770 buffer
= g_string_new(NULL
);
775 g_string_assign(buffer
, _("Next Click"));
776 shade_file_menu_items(FALSE
);
779 item
= filer_selected_item(filer_window
);
780 if (item
->base_type
== TYPE_UNKNOWN
)
781 dir_update_item(filer_window
->directory
,
783 shade_file_menu_items(FALSE
);
784 file_item
= filer_selected_item(filer_window
);
785 g_string_printf(buffer
, _("%s '%s'"),
786 basetype_name(file_item
),
787 g_utf8_validate(file_item
->leafname
,
789 ? file_item
->leafname
791 if (!can_set_run_action(file_item
))
792 menu_set_items_shaded(filer_file_menu
,
796 shade_file_menu_items(TRUE
);
797 g_string_printf(buffer
, _("%d items"),
801 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
802 g_string_free(buffer
, TRUE
);
804 menu_show_shift_action(file_shift_item
, file_item
,
807 n_added
= appmenu_add(make_path(filer_window
->sym_path
,
808 file_item
->leafname
),
809 file_item
, filer_file_menu
);
812 update_new_files_menu(get_menu_icon_style());
814 gtk_widget_set_sensitive(filer_new_window
,
815 !o_unique_filer_windows
.int_value
);
816 gtk_widget_set_sensitive(filer_follow_sym
,
817 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
818 gtk_widget_set_sensitive(filer_set_type
,
819 xattr_supported(filer_window
->real_path
));
821 if (n_selected
&& o_menu_quick
.int_value
)
822 popup_menu
= (state
& GDK_CONTROL_MASK
)
826 popup_menu
= (state
& GDK_CONTROL_MASK
)
832 show_popup_menu(popup_menu
, event
,
833 popup_menu
== filer_file_menu
? n_added
: 1);
836 static void menu_closed(GtkWidget
*widget
)
838 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
839 return; /* Close panel item chosen? */
843 if (window_with_focus
->temp_item_selected
)
845 view_clear_selection(window_with_focus
->view
);
846 window_with_focus
->temp_item_selected
= FALSE
;
852 static void target_callback(FilerWindow
*filer_window
,
856 g_return_if_fail(filer_window
!= NULL
);
858 window_with_focus
= filer_window
;
860 /* Don't grab the primary selection */
861 filer_window
->temp_item_selected
= TRUE
;
863 view_wink_item(filer_window
->view
, iter
);
864 view_select_only(filer_window
->view
, iter
);
865 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
867 view_clear_selection(filer_window
->view
);
868 filer_window
->temp_item_selected
= FALSE
;
871 /* Set the text of the 'Shift Open...' menu item.
872 * If icon is NULL, reset the text and also shade it, unless 'next'.
874 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
876 guchar
*shift_action
= NULL
;
880 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
882 if (item
->flags
& ITEM_FLAG_MOUNTED
)
883 shift_action
= N_("Unmount");
885 shift_action
= N_("Open unmounted");
887 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
888 shift_action
= N_("Show Target");
889 else if (item
->base_type
== TYPE_DIRECTORY
)
890 shift_action
= N_("Look Inside");
891 else if (item
->base_type
== TYPE_FILE
)
892 shift_action
= N_("Open As Text");
894 gtk_label_set_text(GTK_LABEL(menu_item
),
895 shift_action
? _(shift_action
)
897 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
902 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
904 ViewType view_type
= (ViewType
) action
;
906 g_return_if_fail(window_with_focus
!= NULL
);
908 if (view_type
== VIEW_TYPE_COLLECTION
)
909 display_set_layout(window_with_focus
,
910 window_with_focus
->display_style_wanted
,
911 DETAILS_NONE
, FALSE
);
913 filer_set_view_type(window_with_focus
, (ViewType
) action
);
916 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
918 g_return_if_fail(window_with_focus
!= NULL
);
920 display_change_size(window_with_focus
, action
== 1);
923 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
925 g_return_if_fail(window_with_focus
!= NULL
);
930 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
931 display_set_layout(window_with_focus
,
932 window_with_focus
->display_style
,
933 window_with_focus
->details_type
, FALSE
);
935 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
936 window_with_focus
->details_type
, FALSE
);
939 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
943 g_return_if_fail(window_with_focus
!= NULL
);
945 size
= window_with_focus
->display_style_wanted
;
947 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
948 display_set_layout(window_with_focus
, size
, action
, FALSE
);
951 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
)
956 g_return_if_fail(window_with_focus
!= NULL
);
958 display_set_sort_type(window_with_focus
, action
, GTK_SORT_ASCENDING
);
961 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
)
968 g_return_if_fail(window_with_focus
!= NULL
);
970 order
= window_with_focus
->sort_order
;
971 if (order
== GTK_SORT_ASCENDING
)
972 order
= GTK_SORT_DESCENDING
;
974 order
= GTK_SORT_ASCENDING
;
976 display_set_sort_type(window_with_focus
, window_with_focus
->sort_type
,
980 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
985 g_return_if_fail(window_with_focus
!= NULL
);
987 display_set_hidden(window_with_focus
,
988 !window_with_focus
->show_hidden
);
991 static void filter_directories(gpointer data
, guint action
, GtkWidget
*widget
)
996 g_return_if_fail(window_with_focus
!= NULL
);
998 display_set_filter_directories(window_with_focus
,
999 !window_with_focus
->filter_directories
);
1002 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
1007 g_return_if_fail(window_with_focus
!= NULL
);
1009 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
1012 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
1014 g_return_if_fail(window_with_focus
!= NULL
);
1016 filer_refresh(window_with_focus
);
1019 static void save_settings(gpointer data
, guint action
, GtkWidget
*widget
)
1021 g_return_if_fail(window_with_focus
!= NULL
);
1023 filer_save_settings(window_with_focus
);
1026 static void delete(FilerWindow
*filer_window
)
1029 paths
= filer_selected_items(filer_window
);
1030 action_delete(paths
);
1031 destroy_glist(&paths
);
1034 static void usage(FilerWindow
*filer_window
)
1037 paths
= filer_selected_items(filer_window
);
1038 action_usage(paths
);
1039 destroy_glist(&paths
);
1042 static void chmod_items(FilerWindow
*filer_window
)
1045 paths
= filer_selected_items(filer_window
);
1046 action_chmod(paths
, FALSE
, NULL
);
1047 destroy_glist(&paths
);
1050 static void set_type_items(FilerWindow
*filer_window
)
1053 int npass
=0, nfail
=0;
1055 paths
= filer_selected_items(filer_window
);
1056 for(p
=paths
; p
; p
=g_list_next(p
)) {
1057 if(xattr_supported((const char *) p
->data
))
1063 report_error(_("Extended attributes, used to store types, are not supported for this "
1065 "This may be due to lack of support from the filesystem or the C library, "
1066 "or it may simply be that the filesystem needs to be mounted with "
1067 "the right mount option ('user_xattr' on Linux)."));
1069 report_error(_("Setting type not supported for some of these files"));
1071 action_settype(paths
, FALSE
, NULL
);
1072 destroy_glist(&paths
);
1075 static void find(FilerWindow
*filer_window
)
1078 paths
= filer_selected_items(filer_window
);
1080 destroy_glist(&paths
);
1083 /* This creates a new savebox widget, and allows the user to pick a new path
1085 * Once the new path has been picked, the callback will be called with
1086 * both the current and new paths.
1087 * NOTE: This function unrefs 'image'!
1089 static void savebox_show(const gchar
*action
, const gchar
*path
,
1090 MaskedPixmap
*image
, SaveCb callback
,
1091 GdkDragAction dnd_action
)
1093 GtkWidget
*savebox
= NULL
;
1094 GtkWidget
*check_relative
= NULL
;
1096 g_return_if_fail(image
!= NULL
);
1098 savebox
= gtk_savebox_new(action
);
1099 gtk_savebox_set_action(GTK_SAVEBOX(savebox
), dnd_action
);
1101 if (callback
== link_cb
)
1103 check_relative
= gtk_check_button_new_with_mnemonic(
1104 _("_Relative link"));
1105 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1108 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1109 gtk_tooltips_set_tip(tooltips
, check_relative
,
1110 _("If on, the symlink will store the path from the "
1111 "symlink to the target file. Use this if the symlink "
1112 "and the target will be moved together.\n"
1113 "If off, the path from the root directory is stored - "
1114 "use this if the symlink may move but the target will "
1115 "stay put."), NULL
);
1116 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1117 check_relative
, FALSE
, TRUE
, 0);
1118 gtk_widget_show(check_relative
);
1121 g_signal_connect(savebox
, "save_to_file",
1122 G_CALLBACK(save_to_file
), NULL
);
1124 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1125 g_strdup(path
), g_free
);
1126 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1127 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1129 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1131 if (g_utf8_validate(path
, -1, NULL
))
1132 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1136 dir
= g_path_get_dirname(path
);
1137 u8
= to_utf8(g_basename(path
));
1138 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
),
1139 make_path(dir
, u8
));
1143 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1144 g_object_unref(image
);
1146 gtk_widget_show(savebox
);
1149 static gint
save_to_file(GObject
*savebox
,
1150 const gchar
*pathname
, gpointer data
)
1153 const gchar
*current_path
;
1155 callback
= g_object_get_data(savebox
, "action_callback");
1156 current_path
= g_object_get_data(savebox
, "current_path");
1158 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1159 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1161 return callback(savebox
, current_path
, pathname
)
1162 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1165 static gboolean
copy_cb(GObject
*savebox
,
1166 const gchar
*current
, const gchar
*new)
1168 return action_with_leaf(action_copy
, current
, new);
1171 static gboolean
action_with_leaf(ActionFn action
,
1172 const gchar
*current
, const gchar
*new)
1180 report_error(_("New pathname is not absolute"));
1184 if (new[strlen(new) - 1] == '/')
1186 new_dir
= g_strdup(new);
1193 slash
= strrchr(new, '/');
1194 new_dir
= g_strndup(new, slash
- new);
1198 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1199 action(local_paths
, new_dir
, leaf
, -1);
1200 g_list_free(local_paths
);
1207 /* Open a savebox to act on the selected file.
1208 * Call 'callback' later to perform the operation.
1210 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1211 const gchar
*action
, SaveCb callback
,
1212 GdkDragAction dnd_action
)
1214 g_object_ref(image
);
1215 savebox_show(action
, path
, image
, callback
, dnd_action
);
1218 static gboolean
rename_cb(GObject
*savebox
,
1219 const gchar
*current
, const gchar
*new)
1221 return action_with_leaf(action_move
, current
, new);
1224 static gboolean
link_cb(GObject
*savebox
,
1225 const gchar
*initial
, const gchar
*path
)
1227 GtkToggleButton
*check_relative
;
1232 check_relative
= g_object_get_data(savebox
, "check_relative");
1234 if (gtk_toggle_button_get_active(check_relative
))
1235 link_path
= get_relative_path(path
, initial
);
1237 link_path
= g_strdup(initial
);
1239 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1241 GtkWidget
*box
, *button
;
1244 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1246 _("Symlink from '%s' already exists. "
1247 "Replace it with a link to '%s'?"),
1250 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1252 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1253 gtk_widget_show(button
);
1254 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1255 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1256 button
, GTK_RESPONSE_OK
);
1257 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1260 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1261 gtk_widget_destroy(box
);
1263 if (ans
!= GTK_RESPONSE_OK
)
1272 err
= symlink(link_path
, path
);
1277 report_error("symlink: %s", g_strerror(errno
));
1281 dir_check_this(path
);
1286 static void run_action(DirItem
*item
)
1288 if (can_set_run_action(item
))
1289 type_set_handler_dialog(item
->mime_type
);
1292 _("You can only set the run action for a "
1296 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1298 filer_opendir(home_dir
, NULL
, NULL
);
1301 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1303 g_return_if_fail(window_with_focus
!= NULL
);
1305 window_with_focus
->temp_item_selected
= FALSE
;
1306 view_select_all(window_with_focus
->view
);
1309 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1311 g_return_if_fail(window_with_focus
!= NULL
);
1313 window_with_focus
->temp_item_selected
= FALSE
;
1314 view_clear_selection(window_with_focus
->view
);
1317 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1319 return !view_get_selected((ViewIface
*) data
, iter
);
1322 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1324 g_return_if_fail(window_with_focus
!= NULL
);
1326 window_with_focus
->temp_item_selected
= FALSE
;
1328 view_select_if(window_with_focus
->view
, invert_cb
,
1329 window_with_focus
->view
);
1332 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1336 win
= options_show();
1340 number_of_windows
++;
1341 g_signal_connect(win
, "destroy",
1342 G_CALLBACK(one_less_window
), NULL
);
1346 static gboolean
new_directory_cb(GObject
*savebox
,
1347 const gchar
*initial
, const gchar
*path
)
1349 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1351 report_error("mkdir: %s", g_strerror(errno
));
1355 dir_check_this(path
);
1357 if (filer_exists(window_with_focus
))
1360 leaf
= strrchr(path
, '/');
1362 display_set_autoselect(window_with_focus
, leaf
+ 1);
1368 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1370 g_return_if_fail(window_with_focus
!= NULL
);
1372 savebox_show(_("Create"),
1373 make_path(window_with_focus
->sym_path
, _("NewDir")),
1374 type_to_icon(inode_directory
), new_directory_cb
,
1378 static gboolean
new_file_cb(GObject
*savebox
,
1379 const gchar
*initial
, const gchar
*path
)
1383 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1387 report_error(_("Error creating '%s': %s"),
1388 path
, g_strerror(errno
));
1393 report_error(_("Error creating '%s': %s"),
1394 path
, g_strerror(errno
));
1396 dir_check_this(path
);
1398 if (filer_exists(window_with_focus
))
1401 leaf
= strrchr(path
, '/');
1403 display_set_autoselect(window_with_focus
, leaf
+ 1);
1409 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1411 g_return_if_fail(window_with_focus
!= NULL
);
1413 savebox_show(_("Create"),
1414 make_path(window_with_focus
->sym_path
, _("NewFile")),
1415 type_to_icon(text_plain
),
1416 new_file_cb
, GDK_ACTION_COPY
);
1419 static gboolean
new_file_type_cb(GObject
*savebox
,
1420 const gchar
*initial
, const gchar
*path
)
1422 const gchar
*oleaf
, *leaf
;
1423 gchar
*templ
, *templ_dname
, *dest
;
1426 /* We can work out the template path from the initial name */
1427 oleaf
= g_basename(initial
);
1428 templ_dname
= choices_find_xdg_path_load("Templates", "", SITE
);
1432 _("Error creating file: could not find the template for %s"),
1437 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1438 g_free(templ_dname
);
1440 dest
= g_path_get_dirname(path
);
1441 leaf
= g_basename(path
);
1442 paths
= g_list_append(NULL
, templ
);
1444 action_copy(paths
, dest
, leaf
, TRUE
);
1450 if (filer_exists(window_with_focus
))
1451 display_set_autoselect(window_with_focus
, leaf
);
1456 static void do_send_to(gchar
*templ
)
1458 g_return_if_fail(send_to_paths
!= NULL
);
1460 run_with_files(templ
, send_to_paths
);
1463 static void new_file_type(gchar
*templ
)
1468 g_return_if_fail(window_with_focus
!= NULL
);
1470 leaf
= g_basename(templ
);
1471 type
= type_get_type(templ
);
1473 savebox_show(_("Create"),
1474 make_path(window_with_focus
->sym_path
, leaf
),
1476 new_file_type_cb
, GDK_ACTION_COPY
);
1479 static void customise_send_to(gpointer data
)
1486 dirs
= g_string_new(NULL
);
1488 path
= choices_list_xdg_dirs("", SITE
);
1489 for (i
= 0; i
< path
->len
; i
++)
1491 guchar
*old
= (guchar
*) path
->pdata
[i
];
1493 g_string_append(dirs
, old
);
1494 g_string_append(dirs
, "/SendTo\n");
1496 choices_free_list(path
);
1498 save
= choices_find_xdg_path_save("", "SendTo", SITE
, TRUE
);
1503 _("The `Send To' menu provides a quick way to send some files "
1504 "to an application. The applications listed are those in "
1505 "the following directories:\n\n%s\n%s\n"
1506 "The `Send To' menu may be opened by Shift+Menu clicking "
1509 "You can also create subdirectories called "
1510 "`.text_html', `.text', etc which will only be "
1511 "shown for files of that type. `.group' is shown "
1512 "only when multiple files are selected."),
1514 save
? _("I'll show you your SendTo directory now; you should "
1515 "symlink (Ctrl+Shift drag) any applications you want "
1517 : _("Your CHOICESPATH variable setting prevents "
1518 "customisations - sorry."));
1520 g_string_free(dirs
, TRUE
);
1523 filer_opendir(save
, NULL
, NULL
);
1526 static void customise_new(gpointer data
)
1533 dirs
= g_string_new(NULL
);
1535 path
= choices_list_xdg_dirs("", SITE
);
1536 for (i
= 0; i
< path
->len
; i
++)
1538 guchar
*old
= (guchar
*) path
->pdata
[i
];
1540 g_string_append(dirs
, old
);
1541 g_string_append(dirs
, "/Templates\n");
1543 choices_free_list(path
);
1545 save
= choices_find_xdg_path_save("", "Templates", SITE
, TRUE
);
1550 _("Any files placed in your Templates directories will "
1551 "appear on the `New' menu. Choosing one of them will make "
1552 "a copy of it as the new file.\n\n"
1553 "The following directories contain templates:\n\n%s\n%s\n"),
1555 save
? _("I'll show you your Templates directory now; you "
1556 "should place any template files you want inside it.")
1557 : _("Your CHOICESPATH variable setting prevents "
1558 "customisations - sorry."));
1560 g_string_free(dirs
, TRUE
);
1563 filer_opendir(save
, NULL
, NULL
);
1566 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1569 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1576 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1578 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1580 searchdir
= g_strdup("SendTo");
1582 paths
= choices_list_xdg_dirs(searchdir
, SITE
);
1585 for (i
= 0; i
< paths
->len
; i
++)
1587 GList
*widgets
= NULL
;
1588 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1590 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1591 (CallbackFn
) do_send_to
,
1592 FALSE
, FALSE
, TRUE
);
1595 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1596 gtk_menu_item_new());
1598 g_list_free(widgets
); /* TODO: Get rid of this */
1601 choices_free_list(paths
);
1604 /* Scan the SendTo dir and create and show the Send To menu.
1605 * The 'paths' list and every path in it is claimed, and will be
1606 * freed later -- don't free it yourself!
1608 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1610 GtkWidget
*menu
, *item
;
1612 menu
= gtk_menu_new();
1614 if (g_list_length(paths
) == 1)
1618 item
= diritem_new("");
1619 diritem_restat(paths
->data
, item
, NULL
);
1622 item
->mime_type
->media_type
,
1623 item
->mime_type
->subtype
);
1625 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1632 gboolean same
=TRUE
, same_media
=TRUE
;
1633 MIME_type
*type
=NULL
;
1636 item
= diritem_new("");
1637 for(rover
=paths
; rover
; rover
=g_list_next(rover
))
1639 diritem_restat(rover
->data
, item
, NULL
);
1641 type
=item
->mime_type
;
1644 if(type
!=item
->mime_type
)
1647 if(strcmp(type
->media_type
,
1648 item
->mime_type
->media_type
)!=0)
1661 add_sendto(menu
, type
->media_type
,
1664 add_sendto(menu
, type
->media_type
, NULL
);
1667 add_sendto(menu
, "group", NULL
);
1670 add_sendto(menu
, NULL
, NULL
);
1672 item
= gtk_menu_item_new_with_label(_("Customise"));
1673 g_signal_connect_swapped(item
, "activate",
1674 G_CALLBACK(customise_send_to
), NULL
);
1675 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1678 destroy_glist(&send_to_paths
);
1680 send_to_paths
= paths
;
1682 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1685 show_popup_menu(menu
, event
, 0);
1688 static void send_to(FilerWindow
*filer_window
)
1693 paths
= filer_selected_items(filer_window
);
1694 event
= gtk_get_current_event();
1697 show_send_to_menu(paths
, event
);
1700 gdk_event_free(event
);
1703 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1705 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1706 gboolean close
= action
;
1708 argv
[2] = o_menu_xterm
.value
;
1710 g_return_if_fail(window_with_focus
!= NULL
);
1712 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1713 gtk_widget_destroy(window_with_focus
->window
);
1716 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1718 g_return_if_fail(window_with_focus
!= NULL
);
1720 filer_change_to(window_with_focus
, home_dir
, NULL
);
1723 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1725 g_return_if_fail(window_with_focus
!= NULL
);
1727 bookmarks_show_menu(window_with_focus
);
1730 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1732 g_return_if_fail(window_with_focus
!= NULL
);
1734 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1735 filer_change_to(window_with_focus
,
1736 window_with_focus
->real_path
, NULL
);
1738 delayed_error(_("This is already the canonical name "
1739 "for this directory."));
1742 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1744 g_return_if_fail(window_with_focus
!= NULL
);
1746 filer_open_parent(window_with_focus
);
1749 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1751 g_return_if_fail(window_with_focus
!= NULL
);
1753 change_to_parent(window_with_focus
);
1756 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1758 g_return_if_fail(window_with_focus
!= NULL
);
1760 view_autosize(window_with_focus
->view
);
1763 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1765 g_return_if_fail(window_with_focus
!= NULL
);
1767 if (o_unique_filer_windows
.int_value
)
1769 report_error(_("You can't open a second view onto "
1770 "this directory because the `Unique Windows' option "
1771 "is turned on in the Options window."));
1774 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1777 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1779 g_return_if_fail(window_with_focus
!= NULL
);
1781 if (!filer_window_delete(window_with_focus
->window
, NULL
,
1783 gtk_widget_destroy(window_with_focus
->window
);
1786 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1788 MiniType type
= (MiniType
) action
;
1790 g_return_if_fail(window_with_focus
!= NULL
);
1792 /* Item needs to remain selected... */
1793 if (type
== MINI_SHELL
)
1794 window_with_focus
->temp_item_selected
= FALSE
;
1796 minibuffer_show(window_with_focus
, type
);
1799 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1801 if (action
== HELP_ABOUT
)
1802 infobox_new(app_dir
);
1803 else if (action
== HELP_DIR
)
1804 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1805 else if (action
== HELP_MANUAL
)
1807 gchar
*manual
= NULL
;
1811 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1812 current_lang
, ".html", NULL
);
1813 if (!file_exists(manual
) && strchr(current_lang
, '_'))
1815 /* Try again without the territory */
1816 strcpy(strrchr(manual
, '_'), ".html");
1818 if (!file_exists(manual
))
1819 null_g_free(&manual
);
1823 manual
= g_strconcat(app_dir
,
1824 "/Help/Manual.html", NULL
);
1826 run_by_path(manual
);
1831 g_warning("Unknown help action %d\n", action
);
1834 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1835 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1837 GList
*items
, *item
;
1839 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1841 item
= g_list_nth(items
, from
);
1844 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1850 static void save_menus(void)
1854 menurc
= choices_find_xdg_path_save(MENUS_NAME
, PROJECT
, SITE
, TRUE
);
1857 gtk_accel_map_save(menurc
);
1862 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1867 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1868 item
= g_list_nth_data(items
, n
);
1870 g_return_if_fail(item
!= NULL
);
1874 gtk_menu_shell_select_item(shell
, item
);
1877 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1884 g_return_if_fail(window_with_focus
!= NULL
);
1886 n_selected
= view_count_selected(window_with_focus
->view
);
1894 case FILE_COPY_ITEM
:
1895 prompt
= _("Copy ... ?");
1897 case FILE_RENAME_ITEM
:
1898 prompt
= _("Rename ... ?");
1900 case FILE_LINK_ITEM
:
1901 prompt
= _("Symlink ... ?");
1903 case FILE_OPEN_FILE
:
1904 prompt
= _("Shift Open ... ?");
1906 case FILE_PROPERTIES
:
1907 prompt
= _("Properties of ... ?");
1910 prompt
= _("Set type of ... ?");
1912 case FILE_RUN_ACTION
:
1913 prompt
= _("Set run action for ... ?");
1916 prompt
= _("Set icon for ... ?");
1919 prompt
= _("Send ... to ... ?");
1922 prompt
= _("DELETE ... ?");
1925 prompt
= _("Count the size of ... ?");
1927 case FILE_CHMOD_ITEMS
:
1928 prompt
= _("Set permissions on ... ?");
1931 prompt
= _("Search inside ... ?");
1934 g_warning("Unknown action!");
1937 filer_target_mode(window_with_focus
, target_callback
,
1938 GINT_TO_POINTER(action
), prompt
);
1945 send_to(window_with_focus
);
1948 delete(window_with_focus
);
1951 usage(window_with_focus
);
1953 case FILE_CHMOD_ITEMS
:
1954 chmod_items(window_with_focus
);
1957 set_type_items(window_with_focus
);
1960 find(window_with_focus
);
1962 case FILE_PROPERTIES
:
1966 items
= filer_selected_items(window_with_focus
);
1967 infobox_show_list(items
);
1968 destroy_glist(&items
);
1971 case FILE_RENAME_ITEM
:
1974 GList
*items
= NULL
;
1977 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1978 while ((item
= iter
.next(&iter
)))
1979 items
= g_list_prepend(items
, item
->leafname
);
1980 items
= g_list_reverse(items
);
1982 bulk_rename(window_with_focus
->sym_path
, items
);
1986 break; /* Not a bulk rename... see below */
1991 /* All the following actions require exactly one file selected */
1995 report_error(_("You cannot do this to more than "
1996 "one item at a time"));
2000 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
2002 item
= iter
.next(&iter
);
2003 g_return_if_fail(item
!= NULL
);
2004 /* iter may be passed to filer_openitem... */
2006 if (item
->base_type
== TYPE_UNKNOWN
)
2007 item
= dir_update_item(window_with_focus
->directory
,
2012 report_error(_("Item no longer exists!"));
2016 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
2020 case FILE_COPY_ITEM
:
2021 src_dest_action_item(path
, di_image(item
),
2025 case FILE_RENAME_ITEM
:
2026 src_dest_action_item(path
, di_image(item
),
2027 _("Rename"), rename_cb
,
2030 case FILE_LINK_ITEM
:
2031 src_dest_action_item(path
, di_image(item
),
2032 _("Symlink"), link_cb
,
2035 case FILE_OPEN_FILE
:
2036 filer_openitem(window_with_focus
, &iter
,
2037 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
2039 case FILE_RUN_ACTION
:
2043 icon_set_handler_dialog(item
, path
);
2046 g_warning("Unknown action!");
2051 static void show_key_help(GtkWidget
*button
, gpointer data
)
2053 gboolean can_change_accels
;
2055 g_object_get(G_OBJECT(gtk_settings_get_default()),
2056 "gtk-can-change-accels", &can_change_accels
,
2059 if (!can_change_accels
)
2061 info_message(_("User-definable shortcuts are disabled by "
2062 "default in Gtk2, and you have not enabled "
2063 "them. You can turn this feature on by:\n\n"
2064 "1) using an XSettings manager, such as ROX-Session "
2065 "or gnome-settings-daemon, or\n\n"
2066 "2) adding this line to ~/.gtkrc-2.0:\n"
2067 "\tgtk-can-change-accels = 1\n"
2068 "\t(this only works if NOT using XSETTINGS)"));
2072 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
2073 "- Open the menu over a filer window,\n"
2074 "- Move the pointer over the item you want to use,\n"
2075 "- Press the key you want attached to it.\n\n"
2076 "The key will appear next to the menu item and you can just press "
2077 "that key without opening the menu in future."));
2080 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
2082 GtkWidget
*button
, *align
;
2084 g_return_val_if_fail(option
== NULL
, NULL
);
2086 align
= gtk_alignment_new(0, 0.5, 0, 0);
2087 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
2088 gtk_container_add(GTK_CONTAINER(align
), button
);
2089 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
2091 return g_list_append(NULL
, align
);