4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2003, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* menu.c - code for handling the popup menus */
29 #include <sys/param.h>
46 #include "gui_support.h"
49 #include "gtksavebox.h"
51 #include "minibuffer.h"
58 #include "usericons.h"
60 #include "view_iface.h"
62 #include "bookmarks.h"
81 typedef 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
;
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 hidden(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
136 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
140 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
148 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
149 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
152 /* (action used in this - MiniType) */
153 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
154 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
156 #define MENUS_NAME "menus2"
158 static GtkWidget
*filer_menu
; /* The popup filer menu */
159 static GtkWidget
*filer_file_item
; /* The File '' label */
160 static GtkWidget
*filer_file_menu
; /* The File '' menu */
161 static GtkWidget
*file_shift_item
; /* Shift Open label */
162 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
163 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
164 static GtkWidget
*filer_reverse_menu
; /* The Reversed item */
165 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
166 static GtkWidget
*filer_new_window
; /* The New Window item */
167 static GtkWidget
*filer_new_menu
; /* The New submenu */
168 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
173 static GtkItemFactoryEntry filer_menu_def
[] = {
174 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
175 {">" N_("Icons View"), NULL
, view_type
, VIEW_TYPE_COLLECTION
, NULL
},
176 {">" N_("Icons, With..."), NULL
, NULL
, 0, "<Branch>"},
177 {">>" N_("Sizes"), NULL
, set_with
, DETAILS_SIZE
, NULL
},
178 {">>" N_("Permissions"), NULL
, set_with
, DETAILS_PERMISSIONS
, NULL
},
179 {">>" N_("Types"), NULL
, set_with
, DETAILS_TYPE
, NULL
},
180 {">>" N_("Times"), NULL
, set_with
, DETAILS_TIMES
, NULL
},
181 {">" N_("List View"), NULL
, view_type
, VIEW_TYPE_DETAILS
, "<StockItem>", ROX_STOCK_SHOW_DETAILS
},
182 {">", NULL
, NULL
, 0, "<Separator>"},
183 {">" N_("Bigger Icons"), NULL
, change_size
, 1, "<StockItem>", GTK_STOCK_ZOOM_IN
},
184 {">" N_("Smaller Icons"), NULL
, change_size
, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT
},
185 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
186 {">", NULL
, NULL
, 0, "<Separator>"},
187 {">" N_("Sort by Name"), NULL
, set_sort
, SORT_NAME
, NULL
},
188 {">" N_("Sort by Type"), NULL
, set_sort
, SORT_TYPE
, NULL
},
189 {">" N_("Sort by Date"), NULL
, set_sort
, SORT_DATE
, NULL
},
190 {">" N_("Sort by Size"), NULL
, set_sort
, SORT_SIZE
, NULL
},
191 {">" N_("Sort by Owner"), NULL
, set_sort
, SORT_OWNER
, NULL
},
192 {">" N_("Sort by Group"), NULL
, set_sort
, SORT_GROUP
, NULL
},
193 {">" N_("Reversed"), NULL
, reverse_sort
, 0, "<ToggleItem>"},
194 {">", NULL
, NULL
, 0, "<Separator>"},
195 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
196 {">" N_("Filter files"), NULL
, mini_buffer
, MINI_FILTER
, NULL
},
197 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
198 {">" N_("Refresh"), NULL
, refresh
, 0, "<StockItem>", GTK_STOCK_REFRESH
},
199 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
200 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, "<StockItem>", GTK_STOCK_COPY
},
201 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
202 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
203 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, "<StockItem>", GTK_STOCK_DELETE
},
204 {">", NULL
, NULL
, 0, "<Separator>"},
205 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
},
206 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, "<StockItem>", GTK_STOCK_OPEN
},
207 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
208 {">", NULL
, NULL
, 0, "<Separator>"},
209 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, "<StockItem>", GTK_STOCK_EXECUTE
},
210 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
211 {">" N_("Properties"), NULL
, file_op
, FILE_PROPERTIES
, "<StockItem>", GTK_STOCK_PROPERTIES
},
212 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
213 {">" N_("Set Type..."), NULL
, file_op
, FILE_SET_TYPE
, NULL
},
214 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
215 {">", NULL
, NULL
, 0, "<Separator>"},
216 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, "<StockItem>", GTK_STOCK_FIND
},
217 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
218 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
219 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
220 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
221 {">" N_("Select by Name..."), "period", mini_buffer
, MINI_SELECT_BY_NAME
, NULL
},
222 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
223 {N_("Options..."), NULL
, menu_show_options
, 0, "<StockItem>", GTK_STOCK_PREFERENCES
},
224 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
225 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
226 {">" N_("Blank file"), NULL
, new_file
, 0, "<StockItem>", GTK_STOCK_NEW
},
227 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
228 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, "<StockItem>", GTK_STOCK_GO_UP
},
229 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
230 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
231 {">" N_("Home Directory"), NULL
, home_directory
, 0, "<StockItem>", GTK_STOCK_HOME
},
232 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, "<StockItem>", ROX_STOCK_BOOKMARKS
},
233 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
234 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
235 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
237 {">" N_("Close Window"), NULL
, close_window
, 0, "<StockItem>", GTK_STOCK_CLOSE
},
238 {">", NULL
, NULL
, 0, "<Separator>"},
239 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
240 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
241 {">" N_("Xterm Here"), NULL
, xterm_here
, FALSE
, NULL
},
242 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, NULL
},
243 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
244 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
245 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, "<StockItem>", GTK_STOCK_HELP
},
246 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
250 #define GET_MENU_ITEM(var, menu) \
251 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
253 #define GET_SMENU_ITEM(var, menu, sub) \
255 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
256 var = gtk_item_factory_get_widget(item_factory, tmp); \
260 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
262 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
263 var = gtk_item_factory_get_widget(item_factory, tmp); \
267 /* Returns TRUE if the keys were installed (first call only) */
268 gboolean
ensure_filer_menu(void)
273 GtkItemFactory
*item_factory
;
275 if (!filer_keys_need_init
)
277 filer_keys_need_init
= FALSE
;
279 item_factory
= menu_create(filer_menu_def
,
280 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
281 "<filer>", filer_keys
);
283 GET_MENU_ITEM(filer_menu
, "filer");
284 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
285 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
286 GET_SSMENU_ITEM(filer_reverse_menu
, "filer", "Display", "Reversed");
287 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
288 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
291 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
292 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
293 filer_follow_sym
= GTK_BIN(item
)->child
;
295 /* File '' label... */
296 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
297 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
300 /* Shift Open... label */
301 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
302 file_shift_item
= GTK_BIN(g_list_nth(items
, 5)->data
)->child
;
305 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
306 filer_new_window
= GTK_BIN(item
)->child
;
308 g_signal_connect(filer_menu
, "unmap_event",
309 G_CALLBACK(menu_closed
), NULL
);
310 g_signal_connect(filer_file_menu
, "unmap_event",
311 G_CALLBACK(menu_closed
), NULL
);
313 g_signal_connect(filer_keys
, "accel_changed",
314 G_CALLBACK(save_menus
), NULL
);
323 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
326 gtk_accel_map_load(menurc
);
330 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
331 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
332 option_add_saver(save_menus
);
334 option_register_widget("menu-set-keys", set_keys_button
);
336 filer_keys
= gtk_accel_group_new();
339 /* Name is in the form "<panel>" */
340 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
341 const gchar
*name
, GtkAccelGroup
*keys
)
343 GtkItemFactory
*item_factory
;
344 GtkItemFactoryEntry
*translated
;
348 keys
= gtk_accel_group_new();
349 gtk_accel_group_lock(keys
);
352 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
354 translated
= translate_entries(def
, n_entries
);
355 gtk_item_factory_create_items(item_factory
, n_entries
,
357 free_translated_entries(translated
, n_entries
);
362 /* Prevent the user from setting a short-cut on this item */
363 static void menuitem_no_shortcuts(GtkWidget
*item
)
367 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
369 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
370 null_g_free(&menuitem
->accel_path
);
374 /* Shade items that only work on single files */
375 static void shade_file_menu_items(gboolean shaded
)
377 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 3);
378 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 2);
379 menu_set_items_shaded(filer_file_menu
, shaded
, 9, 2);
382 /* 'data' is an array of three ints:
383 * [ pointer_x, pointer_y, item_under_pointer ]
385 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
386 gboolean
*push_in
, gpointer data
)
388 int *pos
= (int *) data
;
389 GtkRequisition requisition
;
394 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
396 while (item
>= 0 && next
)
398 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
411 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
413 *x
= pos
[0] - (requisition
.width
* 7 / 8);
414 *y
= pos
[1] - y_shift
;
416 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
417 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
422 GtkWidget
*make_send_to_item(DirItem
*ditem
, const char *label
,
427 if (ditem
->image
&& style
!= MIS_NONE
)
434 pixbuf
= ditem
->image
->pixbuf
;
437 if (!ditem
->image
->sm_pixbuf
)
438 pixmap_make_small(ditem
->image
);
439 pixbuf
= ditem
->image
->sm_pixbuf
;
443 item
= gtk_image_menu_item_new_with_label(label
);
444 /* TODO: Find a way to allow short-cuts */
445 menuitem_no_shortcuts(item
);
447 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
448 gtk_image_new_from_pixbuf(pixbuf
));
449 gtk_widget_show_all(item
);
452 item
= gtk_menu_item_new_with_label(label
);
457 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
458 MenuIconStyle style
, CallbackFn func
,
459 gboolean separator
, gboolean strip_ext
,
462 GList
*widgets
= NULL
;
469 dname
= pathdup(dir_name
);
471 names
= list_dir(dname
);
477 item
= gtk_menu_item_new();
478 widgets
= g_list_append(widgets
, item
);
479 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
482 for (i
= 0; i
< names
->len
; i
++)
484 char *leaf
= names
->pdata
[i
];
487 fname
= g_strconcat(dname
, "/", leaf
, NULL
);
489 /* Strip off extension, if any */
493 dot
= strchr(leaf
, '.');
498 ditem
= diritem_new("");
499 diritem_restat(fname
, ditem
, NULL
);
501 item
= make_send_to_item(ditem
, leaf
, style
);
505 /* If it is a directory (but NOT an AppDir) and we are
506 * recursing then set up a sub menu.
508 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
509 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
514 sub
= gtk_menu_new();
515 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
516 separator
, strip_ext
, FALSE
);
517 g_list_free(new_widgets
);
518 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
521 g_signal_connect_swapped(item
, "activate",
522 G_CALLBACK(func
), fname
);
526 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
527 g_signal_connect_swapped(item
, "destroy",
528 G_CALLBACK(g_free
), fname
);
530 widgets
= g_list_append(widgets
, item
);
533 g_ptr_array_free(names
, TRUE
);
540 /* Scan the templates dir and create entries for the New menu */
541 static void update_new_files_menu(MenuIconStyle style
)
543 static GList
*widgets
= NULL
;
545 gchar
*templ_dname
= NULL
;
551 for (next
= widgets
; next
; next
= next
->next
)
552 gtk_widget_destroy((GtkWidget
*) next
->data
);
554 g_list_free(widgets
);
558 templ_dname
= choices_find_path_load("Templates", "");
561 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
562 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
566 gtk_widget_show_all(filer_new_menu
);
569 /* 'item' is the number of the item to appear under the pointer. */
570 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
576 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
577 event
->type
== GDK_BUTTON_RELEASE
))
579 GdkEventButton
*bev
= (GdkEventButton
*) event
;
581 pos
[0] = bev
->x_root
;
582 pos
[1] = bev
->y_root
;
583 button
= bev
->button
;
586 else if (event
&& event
->type
== GDK_KEY_PRESS
)
588 GdkEventKey
*kev
= (GdkEventKey
*) event
;
590 get_pointer_xy(pos
, pos
+ 1);
594 get_pointer_xy(pos
, pos
+ 1);
598 gtk_widget_show_all(menu
);
599 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
600 position_menu
, (gpointer
) pos
, button
, time
);
601 select_nth_item(GTK_MENU_SHELL(menu
), item
);
604 /* Hide the popup menu, if any */
605 void menu_popdown(void)
608 gtk_menu_popdown(GTK_MENU(popup_menu
));
611 static MenuIconStyle
get_menu_icon_style(void)
616 mis
= o_menu_iconsize
.int_value
;
620 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
626 if (mis
== MIS_CURRENT
&& window_with_focus
)
628 switch (window_with_focus
->display_style
)
640 display
= o_display_size
.int_value
;
655 /* iter->peek() is the clicked item, or NULL if none */
656 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
658 DirItem
*file_item
= NULL
;
659 GdkModifierType state
= 0;
663 n_selected
= view_count_selected(filer_window
->view
);
669 /* Remove previous AppMenu, if any */
672 window_with_focus
= filer_window
;
675 event
= gtk_get_current_event();
677 if (event
->type
== GDK_BUTTON_PRESS
)
678 state
= ((GdkEventButton
*) event
)->state
;
679 else if (event
->type
== GDK_KEY_PRESS
)
680 state
= ((GdkEventKey
*) event
)->state
;
682 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
684 filer_window
->temp_item_selected
= TRUE
;
685 view_set_selected(filer_window
->view
, iter
, TRUE
);
686 n_selected
= view_count_selected(filer_window
->view
);
690 filer_window
->temp_item_selected
= FALSE
;
693 /* Short-cut to the Send To menu */
694 if (state
& GDK_SHIFT_MASK
)
703 _("You should Shift+Menu click over a file to "
704 "send it somewhere"));
708 paths
= filer_selected_items(filer_window
);
710 show_send_to_menu(paths
, event
); /* (paths eaten) */
716 GtkWidget
*file_label
, *file_menu
;
720 file_label
= filer_file_item
;
721 file_menu
= filer_file_menu
;
722 gtk_check_menu_item_set_active(
723 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
724 filer_window
->show_thumbs
);
725 gtk_check_menu_item_set_active(
726 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
727 filer_window
->show_hidden
);
728 gtk_check_menu_item_set_active(
729 GTK_CHECK_MENU_ITEM(filer_reverse_menu
),
730 filer_window
->sort_order
!= GTK_SORT_ASCENDING
);
731 gtk_check_menu_item_set_active(
732 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
733 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
734 buffer
= g_string_new(NULL
);
739 g_string_assign(buffer
, _("Next Click"));
740 shade_file_menu_items(FALSE
);
743 item
= filer_selected_item(filer_window
);
745 dir_update_item(filer_window
->directory
,
747 shade_file_menu_items(FALSE
);
748 file_item
= filer_selected_item(filer_window
);
749 g_string_printf(buffer
, _("%s '%s'"),
750 basetype_name(file_item
),
751 g_utf8_validate(file_item
->leafname
,
753 ? file_item
->leafname
755 if (!can_set_run_action(file_item
))
756 menu_set_items_shaded(filer_file_menu
,
760 shade_file_menu_items(TRUE
);
761 g_string_printf(buffer
, _("%d items"),
765 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
766 g_string_free(buffer
, TRUE
);
768 menu_show_shift_action(file_shift_item
, file_item
,
771 n_added
= appmenu_add(make_path(filer_window
->sym_path
,
772 file_item
->leafname
),
773 file_item
, filer_file_menu
);
776 update_new_files_menu(get_menu_icon_style());
778 gtk_widget_set_sensitive(filer_new_window
,
779 !o_unique_filer_windows
.int_value
);
780 gtk_widget_set_sensitive(filer_follow_sym
,
781 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
783 popup_menu
= (state
& GDK_CONTROL_MASK
)
789 show_popup_menu(popup_menu
, event
,
790 popup_menu
== filer_file_menu
? (n_added
+ 7) : 1);
793 static void menu_closed(GtkWidget
*widget
)
795 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
796 return; /* Close panel item chosen? */
800 if (window_with_focus
->temp_item_selected
)
802 view_clear_selection(window_with_focus
->view
);
803 window_with_focus
->temp_item_selected
= FALSE
;
809 static void target_callback(FilerWindow
*filer_window
,
813 g_return_if_fail(filer_window
!= NULL
);
815 window_with_focus
= filer_window
;
817 /* Don't grab the primary selection */
818 filer_window
->temp_item_selected
= TRUE
;
820 view_wink_item(filer_window
->view
, iter
);
821 view_select_only(filer_window
->view
, iter
);
822 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
824 view_clear_selection(filer_window
->view
);
825 filer_window
->temp_item_selected
= FALSE
;
828 /* Set the text of the 'Shift Open...' menu item.
829 * If icon is NULL, reset the text and also shade it, unless 'next'.
831 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
833 guchar
*shift_action
= NULL
;
837 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
839 if (item
->flags
& ITEM_FLAG_MOUNTED
)
840 shift_action
= N_("Unmount");
842 shift_action
= N_("Open unmounted");
844 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
845 shift_action
= N_("Show Target");
846 else if (item
->base_type
== TYPE_DIRECTORY
)
847 shift_action
= N_("Look Inside");
848 else if (item
->base_type
== TYPE_FILE
)
849 shift_action
= N_("Open As Text");
851 gtk_label_set_text(GTK_LABEL(menu_item
),
852 shift_action
? _(shift_action
)
854 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
859 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
861 ViewType view_type
= (ViewType
) action
;
863 g_return_if_fail(window_with_focus
!= NULL
);
865 if (view_type
== VIEW_TYPE_COLLECTION
)
866 display_set_layout(window_with_focus
,
867 window_with_focus
->display_style_wanted
,
868 DETAILS_NONE
, FALSE
);
870 filer_set_view_type(window_with_focus
, (ViewType
) action
);
873 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
875 g_return_if_fail(window_with_focus
!= NULL
);
877 display_change_size(window_with_focus
, action
== 1);
880 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
882 g_return_if_fail(window_with_focus
!= NULL
);
887 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
888 display_set_layout(window_with_focus
,
889 window_with_focus
->display_style
,
890 window_with_focus
->details_type
, FALSE
);
892 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
893 window_with_focus
->details_type
, FALSE
);
896 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
900 g_return_if_fail(window_with_focus
!= NULL
);
902 size
= window_with_focus
->display_style_wanted
;
904 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
905 display_set_layout(window_with_focus
, size
, action
, FALSE
);
908 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
)
913 g_return_if_fail(window_with_focus
!= NULL
);
915 display_set_sort_type(window_with_focus
, action
, GTK_SORT_ASCENDING
);
918 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
)
925 g_return_if_fail(window_with_focus
!= NULL
);
927 order
= window_with_focus
->sort_order
;
928 if (order
== GTK_SORT_ASCENDING
)
929 order
= GTK_SORT_DESCENDING
;
931 order
= GTK_SORT_ASCENDING
;
933 display_set_sort_type(window_with_focus
, window_with_focus
->sort_type
,
937 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
942 g_return_if_fail(window_with_focus
!= NULL
);
944 display_set_hidden(window_with_focus
,
945 !window_with_focus
->show_hidden
);
948 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
953 g_return_if_fail(window_with_focus
!= NULL
);
955 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
958 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
960 g_return_if_fail(window_with_focus
!= NULL
);
962 filer_refresh(window_with_focus
);
965 static void delete(FilerWindow
*filer_window
)
968 paths
= filer_selected_items(filer_window
);
969 action_delete(paths
);
970 destroy_glist(&paths
);
973 static void usage(FilerWindow
*filer_window
)
976 paths
= filer_selected_items(filer_window
);
978 destroy_glist(&paths
);
981 static void chmod_items(FilerWindow
*filer_window
)
984 paths
= filer_selected_items(filer_window
);
985 action_chmod(paths
, FALSE
, NULL
);
986 destroy_glist(&paths
);
989 static void set_type_items(FilerWindow
*filer_window
)
992 paths
= filer_selected_items(filer_window
);
993 action_settype(paths
, FALSE
, NULL
);
994 destroy_glist(&paths
);
997 static void find(FilerWindow
*filer_window
)
1000 paths
= filer_selected_items(filer_window
);
1002 destroy_glist(&paths
);
1005 /* This creates a new savebox widget, and allows the user to pick a new path
1007 * Once the new path has been picked, the callback will be called with
1008 * both the current and new paths.
1009 * NOTE: This function unrefs 'image'!
1011 static void savebox_show(const gchar
*action
, const gchar
*path
,
1012 MaskedPixmap
*image
, SaveCb callback
,
1013 GdkDragAction dnd_action
)
1015 GtkWidget
*savebox
= NULL
;
1016 GtkWidget
*check_relative
= NULL
;
1018 g_return_if_fail(image
!= NULL
);
1020 savebox
= gtk_savebox_new(action
);
1021 gtk_savebox_set_action(GTK_SAVEBOX(savebox
), dnd_action
);
1023 if (callback
== link_cb
)
1025 check_relative
= gtk_check_button_new_with_mnemonic(
1026 _("_Relative link"));
1027 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1030 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1031 gtk_tooltips_set_tip(tooltips
, check_relative
,
1032 _("If on, the symlink will store the path from the "
1033 "symlink to the target file. Use this if the symlink "
1034 "and the target will be moved together.\n"
1035 "If off, the path from the root directory is stored - "
1036 "use this if the symlink may move but the target will "
1037 "stay put."), NULL
);
1038 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1039 check_relative
, FALSE
, TRUE
, 0);
1040 gtk_widget_show(check_relative
);
1043 g_signal_connect(savebox
, "save_to_file",
1044 G_CALLBACK(save_to_file
), NULL
);
1046 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1047 g_strdup(path
), g_free
);
1048 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1049 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1051 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1053 if (g_utf8_validate(path
, -1, NULL
))
1054 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1058 dir
= g_path_get_dirname(path
);
1059 u8
= to_utf8(g_basename(path
));
1060 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
),
1061 make_path(dir
, u8
));
1065 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1066 g_object_unref(image
);
1068 gtk_widget_show(savebox
);
1071 static gint
save_to_file(GObject
*savebox
,
1072 const gchar
*pathname
, gpointer data
)
1075 const gchar
*current_path
;
1077 callback
= g_object_get_data(savebox
, "action_callback");
1078 current_path
= g_object_get_data(savebox
, "current_path");
1080 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1081 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1083 return callback(savebox
, current_path
, pathname
)
1084 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1087 static gboolean
copy_cb(GObject
*savebox
,
1088 const gchar
*current
, const gchar
*new)
1090 return action_with_leaf(action_copy
, current
, new);
1093 static gboolean
action_with_leaf(ActionFn action
,
1094 const gchar
*current
, const gchar
*new)
1102 report_error(_("New pathname is not absolute"));
1106 if (new[strlen(new) - 1] == '/')
1108 new_dir
= g_strdup(new);
1115 slash
= strrchr(new, '/');
1116 new_dir
= g_strndup(new, slash
- new);
1120 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1121 action(local_paths
, new_dir
, leaf
, -1);
1122 g_list_free(local_paths
);
1129 /* Open a savebox to act on the selected file.
1130 * Call 'callback' later to perform the operation.
1132 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1133 const gchar
*action
, SaveCb callback
,
1134 GdkDragAction dnd_action
)
1136 g_object_ref(image
);
1137 savebox_show(action
, path
, image
, callback
, dnd_action
);
1140 static gboolean
rename_cb(GObject
*savebox
,
1141 const gchar
*current
, const gchar
*new)
1143 return action_with_leaf(action_move
, current
, new);
1146 static gboolean
link_cb(GObject
*savebox
,
1147 const gchar
*initial
, const gchar
*path
)
1149 GtkToggleButton
*check_relative
;
1154 check_relative
= g_object_get_data(savebox
, "check_relative");
1156 if (gtk_toggle_button_get_active(check_relative
))
1157 link_path
= get_relative_path(path
, initial
);
1159 link_path
= g_strdup(initial
);
1161 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1163 GtkWidget
*box
, *button
;
1166 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1168 _("Symlink from '%s' already exists. "
1169 "Replace it with a link to '%s'?"),
1172 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1174 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1175 gtk_widget_show(button
);
1176 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1177 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1178 button
, GTK_RESPONSE_OK
);
1179 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1182 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1183 gtk_widget_destroy(box
);
1185 if (ans
!= GTK_RESPONSE_OK
)
1194 err
= symlink(link_path
, path
);
1199 report_error("symlink: %s", g_strerror(errno
));
1203 dir_check_this(path
);
1208 static void run_action(DirItem
*item
)
1210 if (can_set_run_action(item
))
1211 type_set_handler_dialog(item
->mime_type
);
1214 _("You can only set the run action for a "
1218 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1220 filer_opendir(home_dir
, NULL
, NULL
);
1223 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1227 path
= g_strconcat(filer_window
->sym_path
,
1228 "/", item
->leafname
, "#", NULL
);
1230 filer_change_to(filer_window
, path
, NULL
);
1234 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1236 g_return_if_fail(window_with_focus
!= NULL
);
1238 window_with_focus
->temp_item_selected
= FALSE
;
1239 view_select_all(window_with_focus
->view
);
1242 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1244 g_return_if_fail(window_with_focus
!= NULL
);
1246 window_with_focus
->temp_item_selected
= FALSE
;
1247 view_clear_selection(window_with_focus
->view
);
1250 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1252 return !view_get_selected((ViewIface
*) data
, iter
);
1255 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1257 g_return_if_fail(window_with_focus
!= NULL
);
1259 window_with_focus
->temp_item_selected
= FALSE
;
1261 view_select_if(window_with_focus
->view
, invert_cb
,
1262 window_with_focus
->view
);
1265 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1269 win
= options_show();
1273 number_of_windows
++;
1274 g_signal_connect(win
, "destroy",
1275 G_CALLBACK(one_less_window
), NULL
);
1279 static gboolean
new_directory_cb(GObject
*savebox
,
1280 const gchar
*initial
, const gchar
*path
)
1282 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1284 report_error("mkdir: %s", g_strerror(errno
));
1288 dir_check_this(path
);
1290 if (filer_exists(window_with_focus
))
1293 leaf
= strrchr(path
, '/');
1295 display_set_autoselect(window_with_focus
, leaf
+ 1);
1301 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1303 g_return_if_fail(window_with_focus
!= NULL
);
1305 savebox_show(_("Create"),
1306 make_path(window_with_focus
->sym_path
, _("NewDir")),
1307 type_to_icon(inode_directory
), new_directory_cb
,
1311 static gboolean
new_file_cb(GObject
*savebox
,
1312 const gchar
*initial
, const gchar
*path
)
1316 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1320 report_error(_("Error creating '%s': %s"),
1321 path
, g_strerror(errno
));
1326 report_error(_("Error creating '%s': %s"),
1327 path
, g_strerror(errno
));
1329 dir_check_this(path
);
1331 if (filer_exists(window_with_focus
))
1334 leaf
= strrchr(path
, '/');
1336 display_set_autoselect(window_with_focus
, leaf
+ 1);
1342 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1344 g_return_if_fail(window_with_focus
!= NULL
);
1346 savebox_show(_("Create"),
1347 make_path(window_with_focus
->sym_path
, _("NewFile")),
1348 type_to_icon(text_plain
),
1349 new_file_cb
, GDK_ACTION_COPY
);
1352 static gboolean
new_file_type_cb(GObject
*savebox
,
1353 const gchar
*initial
, const gchar
*path
)
1355 const gchar
*oleaf
, *leaf
;
1356 gchar
*templ
, *templ_dname
, *dest
;
1359 /* We can work out the template path from the initial name */
1360 oleaf
= g_basename(initial
);
1361 templ_dname
= choices_find_path_load("Templates", "");
1365 _("Error creating file: could not find the template for %s"),
1370 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1371 g_free(templ_dname
);
1373 dest
= g_path_get_dirname(path
);
1374 leaf
= g_basename(path
);
1375 paths
= g_list_append(NULL
, templ
);
1377 action_copy(paths
, dest
, leaf
, TRUE
);
1383 if (filer_exists(window_with_focus
))
1384 display_set_autoselect(window_with_focus
, leaf
);
1389 static void do_send_to(gchar
*templ
)
1391 g_return_if_fail(send_to_paths
!= NULL
);
1393 run_with_files(templ
, send_to_paths
);
1396 static void new_file_type(gchar
*templ
)
1401 g_return_if_fail(window_with_focus
!= NULL
);
1403 leaf
= g_basename(templ
);
1404 type
= type_get_type(templ
);
1406 savebox_show(_("Create"),
1407 make_path(window_with_focus
->sym_path
, leaf
),
1409 new_file_type_cb
, GDK_ACTION_COPY
);
1412 static void customise_send_to(gpointer data
)
1419 dirs
= g_string_new(NULL
);
1421 path
= choices_list_dirs("");
1422 for (i
= 0; i
< path
->len
; i
++)
1424 guchar
*old
= (guchar
*) path
->pdata
[i
];
1426 g_string_append(dirs
, old
);
1427 g_string_append(dirs
, "SendTo\n");
1429 choices_free_list(path
);
1431 save
= choices_find_path_save("", "SendTo", TRUE
);
1436 _("The `Send To' menu provides a quick way to send some files "
1437 "to an application. The applications listed are those in "
1438 "the following directories:\n\n%s\n%s\n"
1439 "The `Send To' menu may be opened by Shift+Menu clicking "
1442 "You can also create subdirectories called "
1443 "`.text_html', `.text', etc which will only be "
1444 "shown for files of that type. `.group' is shown "
1445 "only when multiple files are selected."),
1447 save
? _("I'll show you your SendTo directory now; you should "
1448 "symlink (Ctrl+Shift drag) any applications you want "
1450 : _("Your CHOICESPATH variable setting prevents "
1451 "customisations - sorry."));
1453 g_string_free(dirs
, TRUE
);
1456 filer_opendir(save
, NULL
, NULL
);
1459 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1462 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1469 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1471 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1473 searchdir
= g_strdup("SendTo");
1475 paths
= choices_list_dirs(searchdir
);
1478 for (i
= 0; i
< paths
->len
; i
++)
1480 GList
*widgets
= NULL
;
1481 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1483 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1484 (CallbackFn
) do_send_to
,
1485 FALSE
, FALSE
, TRUE
);
1488 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1489 gtk_menu_item_new());
1491 g_list_free(widgets
); /* TODO: Get rid of this */
1494 choices_free_list(paths
);
1497 /* Scan the SendTo dir and create and show the Send To menu.
1498 * The 'paths' list and every path in it is claimed, and will be
1499 * freed later -- don't free it yourself!
1501 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1503 GtkWidget
*menu
, *item
;
1505 menu
= gtk_menu_new();
1507 if (g_list_length(paths
) == 1)
1511 item
= diritem_new("");
1512 diritem_restat(paths
->data
, item
, NULL
);
1515 item
->mime_type
->media_type
,
1516 item
->mime_type
->subtype
);
1518 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1523 add_sendto(menu
, "group", NULL
);
1525 add_sendto(menu
, NULL
, NULL
);
1527 item
= gtk_menu_item_new_with_label(_("Customise"));
1528 g_signal_connect_swapped(item
, "activate",
1529 G_CALLBACK(customise_send_to
), NULL
);
1530 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1533 destroy_glist(&send_to_paths
);
1535 send_to_paths
= paths
;
1537 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1540 show_popup_menu(menu
, event
, 0);
1543 static void send_to(FilerWindow
*filer_window
)
1548 paths
= filer_selected_items(filer_window
);
1549 event
= gtk_get_current_event();
1552 show_send_to_menu(paths
, event
);
1554 gdk_event_free(event
);
1557 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1559 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1560 gboolean close
= action
;
1562 argv
[2] = o_menu_xterm
.value
;
1564 g_return_if_fail(window_with_focus
!= NULL
);
1566 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1567 gtk_widget_destroy(window_with_focus
->window
);
1570 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1572 g_return_if_fail(window_with_focus
!= NULL
);
1574 filer_change_to(window_with_focus
, home_dir
, NULL
);
1577 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1579 g_return_if_fail(window_with_focus
!= NULL
);
1581 bookmarks_show_menu(window_with_focus
);
1584 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1586 g_return_if_fail(window_with_focus
!= NULL
);
1588 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1589 filer_change_to(window_with_focus
,
1590 window_with_focus
->real_path
, NULL
);
1592 delayed_error(_("This is already the canonical name "
1593 "for this directory."));
1596 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1598 g_return_if_fail(window_with_focus
!= NULL
);
1600 filer_open_parent(window_with_focus
);
1603 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1605 g_return_if_fail(window_with_focus
!= NULL
);
1607 change_to_parent(window_with_focus
);
1610 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1612 g_return_if_fail(window_with_focus
!= NULL
);
1614 view_autosize(window_with_focus
->view
);
1617 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1619 g_return_if_fail(window_with_focus
!= NULL
);
1621 if (o_unique_filer_windows
.int_value
)
1623 report_error(_("You can't open a second view onto "
1624 "this directory because the `Unique Windows' option "
1625 "is turned on in the Options window."));
1628 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1631 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1633 g_return_if_fail(window_with_focus
!= NULL
);
1635 if (!filer_window_delete(window_with_focus
->window
, NULL
,
1637 gtk_widget_destroy(window_with_focus
->window
);
1640 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1642 MiniType type
= (MiniType
) action
;
1644 g_return_if_fail(window_with_focus
!= NULL
);
1646 /* Item needs to remain selected... */
1647 if (type
== MINI_SHELL
)
1648 window_with_focus
->temp_item_selected
= FALSE
;
1650 minibuffer_show(window_with_focus
, type
);
1653 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1655 if (action
== HELP_ABOUT
)
1656 infobox_new(app_dir
);
1657 else if (action
== HELP_DIR
)
1658 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1659 else if (action
== HELP_MANUAL
)
1661 gchar
*manual
= NULL
;
1665 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1666 current_lang
, ".html", NULL
);
1667 if (access(manual
, F_OK
))
1668 null_g_free(&manual
);
1672 manual
= g_strconcat(app_dir
,
1673 "/Help/Manual.html", NULL
);
1675 run_by_path(manual
);
1680 g_warning("Unknown help action %d\n", action
);
1683 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1684 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1686 GList
*items
, *item
;
1688 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1690 item
= g_list_nth(items
, from
);
1693 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1699 static void save_menus(void)
1703 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1706 gtk_accel_map_save(menurc
);
1711 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1716 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1717 item
= g_list_nth_data(items
, n
);
1719 g_return_if_fail(item
!= NULL
);
1723 gtk_menu_shell_select_item(shell
, item
);
1726 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1733 g_return_if_fail(window_with_focus
!= NULL
);
1735 n_selected
= view_count_selected(window_with_focus
->view
);
1743 case FILE_COPY_ITEM
:
1744 prompt
= _("Copy ... ?");
1746 case FILE_RENAME_ITEM
:
1747 prompt
= _("Rename ... ?");
1749 case FILE_LINK_ITEM
:
1750 prompt
= _("Symlink ... ?");
1752 case FILE_OPEN_FILE
:
1753 prompt
= _("Shift Open ... ?");
1755 case FILE_PROPERTIES
:
1756 prompt
= _("Properties of ... ?");
1759 prompt
= _("Set type of ... ?");
1761 case FILE_RUN_ACTION
:
1762 prompt
= _("Set run action for ... ?");
1765 prompt
= _("Set icon for ... ?");
1768 prompt
= _("Send ... to ... ?");
1771 prompt
= _("DELETE ... ?");
1774 prompt
= _("Count the size of ... ?");
1776 case FILE_CHMOD_ITEMS
:
1777 prompt
= _("Set permissions on ... ?");
1780 prompt
= _("Search inside ... ?");
1782 case FILE_OPEN_VFS_AVFS
:
1783 prompt
= _("Look inside ... ?");
1786 g_warning("Unknown action!");
1789 filer_target_mode(window_with_focus
, target_callback
,
1790 GINT_TO_POINTER(action
), prompt
);
1797 send_to(window_with_focus
);
1800 delete(window_with_focus
);
1803 usage(window_with_focus
);
1805 case FILE_CHMOD_ITEMS
:
1806 chmod_items(window_with_focus
);
1809 set_type_items(window_with_focus
);
1812 find(window_with_focus
);
1814 case FILE_PROPERTIES
:
1818 items
= filer_selected_items(window_with_focus
);
1819 infobox_show_list(items
);
1820 destroy_glist(&items
);
1827 /* All the following actions require exactly one file selected */
1831 report_error(_("You cannot do this to more than "
1832 "one item at a time"));
1836 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1838 item
= iter
.next(&iter
);
1839 g_return_if_fail(item
!= NULL
);
1840 /* iter may be passed to filer_openitem... */
1843 item
= dir_update_item(window_with_focus
->directory
,
1848 report_error(_("Item no longer exists!"));
1852 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
1856 case FILE_COPY_ITEM
:
1857 src_dest_action_item(path
, item
->image
,
1861 case FILE_RENAME_ITEM
:
1862 src_dest_action_item(path
, item
->image
,
1863 _("Rename"), rename_cb
,
1866 case FILE_LINK_ITEM
:
1867 src_dest_action_item(path
, item
->image
,
1868 _("Symlink"), link_cb
,
1871 case FILE_OPEN_FILE
:
1872 filer_openitem(window_with_focus
, &iter
,
1873 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1875 case FILE_RUN_ACTION
:
1879 icon_set_handler_dialog(item
, path
);
1881 case FILE_OPEN_VFS_AVFS
:
1882 open_vfs_avfs(window_with_focus
, item
);
1885 g_warning("Unknown action!");
1890 static void show_key_help(GtkWidget
*button
, gpointer data
)
1892 gboolean can_change_accels
;
1894 g_object_get(G_OBJECT(gtk_settings_get_default()),
1895 "gtk-can-change-accels", &can_change_accels
,
1898 if (!can_change_accels
)
1900 info_message(_("User-definable shortcuts are disabled by "
1901 "default in Gtk2, and you have not enabled "
1902 "them. You can turn this feature on by:\n\n"
1903 "1) using an XSettings manager, such as ROX-Session "
1904 "or gnome-settings-daemon, or\n\n"
1905 "2) adding this line to ~/.gtkrc-2.0:\n"
1906 "\tgtk-can-change-accels = 1\n"
1907 "\t(this only works if NOT using XSETTINGS)"));
1911 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1912 "- Open the menu over a filer window,\n"
1913 "- Move the pointer over the item you want to use,\n"
1914 "- Press the key you want attached to it.\n\n"
1915 "The key will appear next to the menu item and you can just press "
1916 "that key without opening the menu in future."));
1919 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1921 GtkWidget
*button
, *align
;
1923 g_return_val_if_fail(option
== NULL
, NULL
);
1925 align
= gtk_alignment_new(0, 0.5, 0, 0);
1926 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
1927 gtk_container_add(GTK_CONTAINER(align
), button
);
1928 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1930 return g_list_append(NULL
, align
);