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"
80 typedef void (*ActionFn
)(GList
*paths
,
81 const char *dest_dir
, const char *leaf
, int quiet
);
82 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
84 typedef gboolean (*SaveCb
)(GObject
*savebox
,
85 const gchar
*current
, const gchar
*new);
87 GtkAccelGroup
*filer_keys
= NULL
;
88 static gboolean filer_keys_need_init
= TRUE
;
90 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
92 static gint updating_menu
= 0; /* Non-zero => ignore activations */
93 static GList
*send_to_paths
= NULL
;
95 static Option o_menu_iconsize
, o_menu_xterm
;
97 /* Static prototypes */
99 static void save_menus(void);
100 static void menu_closed(GtkWidget
*widget
);
101 static void shade_file_menu_items(gboolean shaded
);
102 static void savebox_show(const gchar
*action
, const gchar
*path
,
103 MaskedPixmap
*image
, SaveCb callback
,
104 GdkDragAction dnd_action
);
105 static gint
save_to_file(GObject
*savebox
,
106 const gchar
*pathname
, gpointer data
);
107 static gboolean
action_with_leaf(ActionFn action
,
108 const gchar
*current
, const gchar
*new);
109 static gboolean
link_cb(GObject
*savebox
,
110 const gchar
*initial
, const gchar
*path
);
111 static void select_nth_item(GtkMenuShell
*shell
, int n
);
112 static void new_file_type(gchar
*templ
);
113 static void do_send_to(gchar
*templ
);
114 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
115 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
117 /* Note that for most of these callbacks none of the arguments are used. */
119 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
);
121 /* (action used in these three - DetailsType) */
122 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
);
123 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
);
124 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
);
126 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
135 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
140 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
147 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
148 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
151 /* (action used in this - MiniType) */
152 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
153 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
155 #define MENUS_NAME "menus2"
157 static GtkWidget
*filer_menu
; /* The popup filer menu */
158 static GtkWidget
*filer_file_item
; /* The File '' label */
159 static GtkWidget
*filer_file_menu
; /* The File '' menu */
160 static GtkWidget
*file_shift_item
; /* Shift Open label */
161 static GtkWidget
*filer_auto_size_menu
; /* The Automatic item */
162 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
163 static GtkWidget
*filer_reverse_menu
; /* The Reversed item */
164 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
165 static GtkWidget
*filer_new_window
; /* The New Window item */
166 static GtkWidget
*filer_new_menu
; /* The New submenu */
167 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
172 static GtkItemFactoryEntry filer_menu_def
[] = {
173 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
174 {">" N_("Icons View"), NULL
, view_type
, VIEW_TYPE_COLLECTION
, NULL
},
175 {">" N_("Icons, With..."), NULL
, NULL
, 0, "<Branch>"},
176 {">>" N_("Sizes"), NULL
, set_with
, DETAILS_SIZE
, NULL
},
177 {">>" N_("Permissions"), NULL
, set_with
, DETAILS_PERMISSIONS
, NULL
},
178 {">>" N_("Types"), NULL
, set_with
, DETAILS_TYPE
, NULL
},
179 {">>" N_("Times"), NULL
, set_with
, DETAILS_TIMES
, NULL
},
180 {">" N_("List View"), NULL
, view_type
, VIEW_TYPE_DETAILS
, "<StockItem>", ROX_STOCK_SHOW_DETAILS
},
181 {">", NULL
, NULL
, 0, "<Separator>"},
182 {">" N_("Bigger Icons"), NULL
, change_size
, 1, "<StockItem>", GTK_STOCK_ZOOM_IN
},
183 {">" N_("Smaller Icons"), NULL
, change_size
, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT
},
184 {">" N_("Automatic"), NULL
, change_size_auto
, 0, "<ToggleItem>"},
185 {">", NULL
, NULL
, 0, "<Separator>"},
186 {">" N_("Sort by Name"), NULL
, set_sort
, SORT_NAME
, NULL
},
187 {">" N_("Sort by Type"), NULL
, set_sort
, SORT_TYPE
, NULL
},
188 {">" N_("Sort by Date"), NULL
, set_sort
, SORT_DATE
, NULL
},
189 {">" N_("Sort by Size"), NULL
, set_sort
, SORT_SIZE
, NULL
},
190 {">" N_("Sort by Owner"), NULL
, set_sort
, SORT_OWNER
, NULL
},
191 {">" N_("Sort by Group"), NULL
, set_sort
, SORT_GROUP
, NULL
},
192 {">" N_("Reversed"), NULL
, reverse_sort
, 0, "<ToggleItem>"},
193 {">", NULL
, NULL
, 0, "<Separator>"},
194 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
195 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
196 {">" N_("Refresh"), NULL
, refresh
, 0, "<StockItem>", GTK_STOCK_REFRESH
},
197 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
198 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, "<StockItem>", GTK_STOCK_COPY
},
199 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
200 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
201 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, "<StockItem>", GTK_STOCK_DELETE
},
202 {">", NULL
, NULL
, 0, "<Separator>"},
203 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
},
204 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, "<StockItem>", GTK_STOCK_OPEN
},
205 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
206 {">", NULL
, NULL
, 0, "<Separator>"},
207 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, "<StockItem>", GTK_STOCK_EXECUTE
},
208 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
209 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, "<StockItem>", GTK_STOCK_DIALOG_INFO
},
210 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
211 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
212 {">", NULL
, NULL
, 0, "<Separator>"},
213 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, "<StockItem>", GTK_STOCK_FIND
},
214 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
215 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
216 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
217 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
218 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
219 {N_("Options..."), NULL
, menu_show_options
, 0, "<StockItem>", GTK_STOCK_PREFERENCES
},
220 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
221 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
222 {">" N_("Blank file"), NULL
, new_file
, 0, "<StockItem>", GTK_STOCK_NEW
},
223 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
224 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, "<StockItem>", GTK_STOCK_GO_UP
},
225 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
226 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
227 {">" N_("Home Directory"), NULL
, home_directory
, 0, "<StockItem>", GTK_STOCK_HOME
},
228 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, "<StockItem>", ROX_STOCK_BOOKMARKS
},
229 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
230 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
231 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
233 {">" N_("Close Window"), NULL
, close_window
, 0, "<StockItem>", GTK_STOCK_CLOSE
},
234 {">", NULL
, NULL
, 0, "<Separator>"},
235 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
236 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
237 {">" N_("Xterm Here"), NULL
, xterm_here
, FALSE
, NULL
},
238 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, NULL
},
239 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
240 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
241 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, "<StockItem>", GTK_STOCK_HELP
},
242 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
246 #define GET_MENU_ITEM(var, menu) \
247 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
249 #define GET_SMENU_ITEM(var, menu, sub) \
251 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
252 var = gtk_item_factory_get_widget(item_factory, tmp); \
256 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
258 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
259 var = gtk_item_factory_get_widget(item_factory, tmp); \
263 /* Returns TRUE if the keys were installed (first call only) */
264 gboolean
ensure_filer_menu(void)
269 GtkItemFactory
*item_factory
;
271 if (!filer_keys_need_init
)
273 filer_keys_need_init
= FALSE
;
275 item_factory
= menu_create(filer_menu_def
,
276 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
277 "<filer>", filer_keys
);
279 GET_MENU_ITEM(filer_menu
, "filer");
280 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
281 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
282 GET_SSMENU_ITEM(filer_reverse_menu
, "filer", "Display", "Reversed");
283 GET_SSMENU_ITEM(filer_auto_size_menu
, "filer", "Display", "Automatic");
284 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
287 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
288 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
289 filer_follow_sym
= GTK_BIN(item
)->child
;
291 /* File '' label... */
292 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
293 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
296 /* Shift Open... label */
297 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
298 file_shift_item
= GTK_BIN(g_list_nth(items
, 5)->data
)->child
;
301 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
302 filer_new_window
= GTK_BIN(item
)->child
;
304 g_signal_connect(filer_menu
, "unmap_event",
305 G_CALLBACK(menu_closed
), NULL
);
306 g_signal_connect(filer_file_menu
, "unmap_event",
307 G_CALLBACK(menu_closed
), NULL
);
309 g_signal_connect(filer_keys
, "accel_changed",
310 G_CALLBACK(save_menus
), NULL
);
319 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
322 gtk_accel_map_load(menurc
);
326 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
327 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
328 option_add_saver(save_menus
);
330 option_register_widget("menu-set-keys", set_keys_button
);
332 filer_keys
= gtk_accel_group_new();
335 /* Name is in the form "<panel>" */
336 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
337 const gchar
*name
, GtkAccelGroup
*keys
)
339 GtkItemFactory
*item_factory
;
340 GtkItemFactoryEntry
*translated
;
344 keys
= gtk_accel_group_new();
345 gtk_accel_group_lock(keys
);
348 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
350 translated
= translate_entries(def
, n_entries
);
351 gtk_item_factory_create_items(item_factory
, n_entries
,
353 free_translated_entries(translated
, n_entries
);
358 /* Prevent the user from setting a short-cut on this item */
359 static void menuitem_no_shortcuts(GtkWidget
*item
)
363 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
365 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
366 null_g_free(&menuitem
->accel_path
);
370 /* Shade items that only work on single files */
371 static void shade_file_menu_items(gboolean shaded
)
373 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 3);
374 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 2);
375 menu_set_items_shaded(filer_file_menu
, shaded
, 9, 2);
378 /* 'data' is an array of three ints:
379 * [ pointer_x, pointer_y, item_under_pointer ]
381 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
382 gboolean
*push_in
, gpointer data
)
384 int *pos
= (int *) data
;
385 GtkRequisition requisition
;
390 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
392 while (item
>= 0 && next
)
394 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
407 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
409 *x
= pos
[0] - (requisition
.width
* 7 / 8);
410 *y
= pos
[1] - y_shift
;
412 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
413 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
418 GtkWidget
*make_send_to_item(DirItem
*ditem
, const char *label
,
423 if (ditem
->image
&& style
!= MIS_NONE
)
430 pixbuf
= ditem
->image
->pixbuf
;
433 if (!ditem
->image
->sm_pixbuf
)
434 pixmap_make_small(ditem
->image
);
435 pixbuf
= ditem
->image
->sm_pixbuf
;
439 item
= gtk_image_menu_item_new_with_label(label
);
440 /* TODO: Find a way to allow short-cuts */
441 menuitem_no_shortcuts(item
);
443 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item
),
444 gtk_image_new_from_pixbuf(pixbuf
));
447 item
= gtk_menu_item_new_with_label(label
);
452 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
453 MenuIconStyle style
, CallbackFn func
,
454 gboolean separator
, gboolean strip_ext
,
457 GList
*widgets
= NULL
;
464 dname
= pathdup(dir_name
);
466 names
= list_dir(dname
);
472 item
= gtk_menu_item_new();
473 widgets
= g_list_append(widgets
, item
);
474 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
477 for (i
= 0; i
< names
->len
; i
++)
479 char *leaf
= names
->pdata
[i
];
482 fname
= g_strconcat(dname
, "/", leaf
, NULL
);
484 /* Strip off extension, if any */
488 dot
= strchr(leaf
, '.');
493 ditem
= diritem_new("");
494 diritem_restat(fname
, ditem
, NULL
);
496 item
= make_send_to_item(ditem
, leaf
, style
);
500 /* If it is a directory (but NOT an AppDir) and we are
501 * recursing then set up a sub menu.
503 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
504 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
509 sub
= gtk_menu_new();
510 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
511 separator
, strip_ext
, FALSE
);
512 g_list_free(new_widgets
);
513 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
516 g_signal_connect_swapped(item
, "activate",
517 G_CALLBACK(func
), fname
);
521 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
522 g_signal_connect_swapped(item
, "destroy",
523 G_CALLBACK(g_free
), fname
);
525 widgets
= g_list_append(widgets
, item
);
528 g_ptr_array_free(names
, TRUE
);
535 /* Scan the templates dir and create entries for the New menu */
536 static void update_new_files_menu(MenuIconStyle style
)
538 static GList
*widgets
= NULL
;
540 gchar
*templ_dname
= NULL
;
546 for (next
= widgets
; next
; next
= next
->next
)
547 gtk_widget_destroy((GtkWidget
*) next
->data
);
549 g_list_free(widgets
);
553 templ_dname
= choices_find_path_load("Templates", "");
556 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
557 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
561 gtk_widget_show_all(filer_new_menu
);
564 /* 'item' is the number of the item to appear under the pointer. */
565 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
571 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
572 event
->type
== GDK_BUTTON_RELEASE
))
574 GdkEventButton
*bev
= (GdkEventButton
*) event
;
576 pos
[0] = bev
->x_root
;
577 pos
[1] = bev
->y_root
;
578 button
= bev
->button
;
581 else if (event
&& event
->type
== GDK_KEY_PRESS
)
583 GdkEventKey
*kev
= (GdkEventKey
*) event
;
585 get_pointer_xy(pos
, pos
+ 1);
589 get_pointer_xy(pos
, pos
+ 1);
593 gtk_widget_show_all(menu
);
594 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
595 position_menu
, (gpointer
) pos
, button
, time
);
596 select_nth_item(GTK_MENU_SHELL(menu
), item
);
599 /* Hide the popup menu, if any */
600 void menu_popdown(void)
603 gtk_menu_popdown(GTK_MENU(popup_menu
));
606 static MenuIconStyle
get_menu_icon_style(void)
611 mis
= o_menu_iconsize
.int_value
;
615 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
621 if (mis
== MIS_CURRENT
&& window_with_focus
)
623 switch (window_with_focus
->display_style
)
635 display
= o_display_size
.int_value
;
650 /* iter->peek() is the clicked item, or NULL if none */
651 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
653 DirItem
*file_item
= NULL
;
654 GdkModifierType state
= 0;
657 n_selected
= view_count_selected(filer_window
->view
);
663 /* Remove previous AppMenu, if any */
666 window_with_focus
= filer_window
;
669 event
= gtk_get_current_event();
671 if (event
->type
== GDK_BUTTON_PRESS
)
672 state
= ((GdkEventButton
*) event
)->state
;
673 else if (event
->type
== GDK_KEY_PRESS
)
674 state
= ((GdkEventKey
*) event
)->state
;
676 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
678 filer_window
->temp_item_selected
= TRUE
;
679 view_set_selected(filer_window
->view
, iter
, TRUE
);
680 n_selected
= view_count_selected(filer_window
->view
);
684 filer_window
->temp_item_selected
= FALSE
;
687 /* Short-cut to the Send To menu */
688 if (state
& GDK_SHIFT_MASK
)
697 _("You should Shift+Menu click over a file to "
698 "send it somewhere"));
702 paths
= filer_selected_items(filer_window
);
704 show_send_to_menu(paths
, event
); /* (paths eaten) */
710 GtkWidget
*file_label
, *file_menu
;
714 file_label
= filer_file_item
;
715 file_menu
= filer_file_menu
;
716 gtk_check_menu_item_set_active(
717 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
718 filer_window
->show_thumbs
);
719 gtk_check_menu_item_set_active(
720 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
721 filer_window
->show_hidden
);
722 gtk_check_menu_item_set_active(
723 GTK_CHECK_MENU_ITEM(filer_reverse_menu
),
724 filer_window
->sort_order
!= GTK_SORT_ASCENDING
);
725 gtk_check_menu_item_set_active(
726 GTK_CHECK_MENU_ITEM(filer_auto_size_menu
),
727 filer_window
->display_style_wanted
== AUTO_SIZE_ICONS
);
728 buffer
= g_string_new(NULL
);
733 g_string_assign(buffer
, _("Next Click"));
734 shade_file_menu_items(FALSE
);
737 item
= filer_selected_item(filer_window
);
739 dir_update_item(filer_window
->directory
,
741 shade_file_menu_items(FALSE
);
742 file_item
= filer_selected_item(filer_window
);
743 g_string_printf(buffer
, _("%s '%s'"),
744 basetype_name(file_item
),
745 g_utf8_validate(file_item
->leafname
,
747 ? file_item
->leafname
749 if (!can_set_run_action(file_item
))
750 menu_set_items_shaded(filer_file_menu
,
754 shade_file_menu_items(TRUE
);
755 g_string_printf(buffer
, _("%d items"),
759 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
760 g_string_free(buffer
, TRUE
);
762 menu_show_shift_action(file_shift_item
, file_item
,
765 appmenu_add(make_path(filer_window
->sym_path
,
766 file_item
->leafname
),
767 file_item
, filer_file_menu
);
770 update_new_files_menu(get_menu_icon_style());
772 gtk_widget_set_sensitive(filer_new_window
,
773 !o_unique_filer_windows
.int_value
);
774 gtk_widget_set_sensitive(filer_follow_sym
,
775 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
777 popup_menu
= (state
& GDK_CONTROL_MASK
)
783 show_popup_menu(popup_menu
, event
,
784 popup_menu
== filer_file_menu
? 5 : 1);
787 static void menu_closed(GtkWidget
*widget
)
789 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
790 return; /* Close panel item chosen? */
794 if (window_with_focus
->temp_item_selected
)
796 view_clear_selection(window_with_focus
->view
);
797 window_with_focus
->temp_item_selected
= FALSE
;
803 static void target_callback(FilerWindow
*filer_window
,
807 g_return_if_fail(filer_window
!= NULL
);
809 window_with_focus
= filer_window
;
811 /* Don't grab the primary selection */
812 filer_window
->temp_item_selected
= TRUE
;
814 view_wink_item(filer_window
->view
, iter
);
815 view_select_only(filer_window
->view
, iter
);
816 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
818 view_clear_selection(filer_window
->view
);
819 filer_window
->temp_item_selected
= FALSE
;
822 /* Set the text of the 'Shift Open...' menu item.
823 * If icon is NULL, reset the text and also shade it, unless 'next'.
825 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
827 guchar
*shift_action
= NULL
;
831 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
833 if (item
->flags
& ITEM_FLAG_MOUNTED
)
834 shift_action
= N_("Unmount");
836 shift_action
= N_("Open unmounted");
838 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
839 shift_action
= N_("Show Target");
840 else if (item
->base_type
== TYPE_DIRECTORY
)
841 shift_action
= N_("Look Inside");
842 else if (item
->base_type
== TYPE_FILE
)
843 shift_action
= N_("Open As Text");
845 gtk_label_set_text(GTK_LABEL(menu_item
),
846 shift_action
? _(shift_action
)
848 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
853 static void view_type(gpointer data
, guint action
, GtkWidget
*widget
)
855 ViewType view_type
= (ViewType
) action
;
857 g_return_if_fail(window_with_focus
!= NULL
);
859 if (view_type
== VIEW_TYPE_COLLECTION
)
860 display_set_layout(window_with_focus
,
861 window_with_focus
->display_style_wanted
,
862 DETAILS_NONE
, FALSE
);
864 filer_set_view_type(window_with_focus
, (ViewType
) action
);
867 static void change_size(gpointer data
, guint action
, GtkWidget
*widget
)
869 g_return_if_fail(window_with_focus
!= NULL
);
871 display_change_size(window_with_focus
, action
== 1);
874 static void change_size_auto(gpointer data
, guint action
, GtkWidget
*widget
)
876 g_return_if_fail(window_with_focus
!= NULL
);
881 if (window_with_focus
->display_style_wanted
== AUTO_SIZE_ICONS
)
882 display_set_layout(window_with_focus
,
883 window_with_focus
->display_style
,
884 window_with_focus
->details_type
, FALSE
);
886 display_set_layout(window_with_focus
, AUTO_SIZE_ICONS
,
887 window_with_focus
->details_type
, FALSE
);
890 static void set_with(gpointer data
, guint action
, GtkWidget
*widget
)
894 g_return_if_fail(window_with_focus
!= NULL
);
896 size
= window_with_focus
->display_style_wanted
;
898 filer_set_view_type(window_with_focus
, VIEW_TYPE_COLLECTION
);
899 display_set_layout(window_with_focus
, size
, action
, FALSE
);
902 static void set_sort(gpointer data
, guint action
, GtkWidget
*widget
)
907 g_return_if_fail(window_with_focus
!= NULL
);
909 display_set_sort_type(window_with_focus
, action
, GTK_SORT_ASCENDING
);
912 static void reverse_sort(gpointer data
, guint action
, GtkWidget
*widget
)
919 g_return_if_fail(window_with_focus
!= NULL
);
921 order
= window_with_focus
->sort_order
;
922 if (order
== GTK_SORT_ASCENDING
)
923 order
= GTK_SORT_DESCENDING
;
925 order
= GTK_SORT_ASCENDING
;
927 display_set_sort_type(window_with_focus
, window_with_focus
->sort_type
,
931 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
936 g_return_if_fail(window_with_focus
!= NULL
);
938 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
941 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
946 g_return_if_fail(window_with_focus
!= NULL
);
948 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
951 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
953 g_return_if_fail(window_with_focus
!= NULL
);
955 filer_refresh(window_with_focus
);
958 static void delete(FilerWindow
*filer_window
)
961 paths
= filer_selected_items(filer_window
);
962 action_delete(paths
);
963 destroy_glist(&paths
);
966 static void usage(FilerWindow
*filer_window
)
969 paths
= filer_selected_items(filer_window
);
971 destroy_glist(&paths
);
974 static void chmod_items(FilerWindow
*filer_window
)
977 paths
= filer_selected_items(filer_window
);
978 action_chmod(paths
, FALSE
, NULL
);
979 destroy_glist(&paths
);
982 static void find(FilerWindow
*filer_window
)
985 paths
= filer_selected_items(filer_window
);
987 destroy_glist(&paths
);
990 /* This creates a new savebox widget, and allows the user to pick a new path
992 * Once the new path has been picked, the callback will be called with
993 * both the current and new paths.
994 * NOTE: This function unrefs 'image'!
996 static void savebox_show(const gchar
*action
, const gchar
*path
,
997 MaskedPixmap
*image
, SaveCb callback
,
998 GdkDragAction dnd_action
)
1000 GtkWidget
*savebox
= NULL
;
1001 GtkWidget
*check_relative
= NULL
;
1003 g_return_if_fail(image
!= NULL
);
1005 savebox
= gtk_savebox_new(action
);
1006 gtk_savebox_set_action(GTK_SAVEBOX(savebox
), dnd_action
);
1008 if (callback
== link_cb
)
1010 check_relative
= gtk_check_button_new_with_mnemonic(
1011 _("_Relative link"));
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
1015 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1016 gtk_tooltips_set_tip(tooltips
, check_relative
,
1017 _("If on, the symlink will store the path from the "
1018 "symlink to the target file. Use this if the symlink "
1019 "and the target will be moved together.\n"
1020 "If off, the path from the root directory is stored - "
1021 "use this if the symlink may move but the target will "
1022 "stay put."), NULL
);
1023 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1024 check_relative
, FALSE
, TRUE
, 0);
1025 gtk_widget_show(check_relative
);
1028 g_signal_connect(savebox
, "save_to_file",
1029 G_CALLBACK(save_to_file
), NULL
);
1031 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1032 g_strdup(path
), g_free
);
1033 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1034 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1036 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1038 if (g_utf8_validate(path
, -1, NULL
))
1039 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1043 dir
= g_path_get_dirname(path
);
1044 u8
= to_utf8(g_basename(path
));
1045 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
),
1046 make_path(dir
, u8
));
1050 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1051 g_object_unref(image
);
1053 gtk_widget_show(savebox
);
1056 static gint
save_to_file(GObject
*savebox
,
1057 const gchar
*pathname
, gpointer data
)
1060 const gchar
*current_path
;
1062 callback
= g_object_get_data(savebox
, "action_callback");
1063 current_path
= g_object_get_data(savebox
, "current_path");
1065 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1066 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1068 return callback(savebox
, current_path
, pathname
)
1069 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1072 static gboolean
copy_cb(GObject
*savebox
,
1073 const gchar
*current
, const gchar
*new)
1075 return action_with_leaf(action_copy
, current
, new);
1078 static gboolean
action_with_leaf(ActionFn action
,
1079 const gchar
*current
, const gchar
*new)
1087 report_error(_("New pathname is not absolute"));
1091 if (new[strlen(new) - 1] == '/')
1093 new_dir
= g_strdup(new);
1100 slash
= strrchr(new, '/');
1101 new_dir
= g_strndup(new, slash
- new);
1105 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1106 action(local_paths
, new_dir
, leaf
, -1);
1107 g_list_free(local_paths
);
1114 /* Open a savebox to act on the selected file.
1115 * Call 'callback' later to perform the operation.
1117 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1118 const gchar
*action
, SaveCb callback
,
1119 GdkDragAction dnd_action
)
1121 g_object_ref(image
);
1122 savebox_show(action
, path
, image
, callback
, dnd_action
);
1125 static gboolean
rename_cb(GObject
*savebox
,
1126 const gchar
*current
, const gchar
*new)
1128 return action_with_leaf(action_move
, current
, new);
1131 static gboolean
link_cb(GObject
*savebox
,
1132 const gchar
*initial
, const gchar
*path
)
1134 GtkToggleButton
*check_relative
;
1139 check_relative
= g_object_get_data(savebox
, "check_relative");
1141 if (gtk_toggle_button_get_active(check_relative
))
1142 link_path
= get_relative_path(path
, initial
);
1144 link_path
= g_strdup(initial
);
1146 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1148 GtkWidget
*box
, *button
;
1151 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1153 _("Symlink from '%s' already exists. "
1154 "Replace it with a link to '%s'?"),
1157 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1159 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1160 gtk_widget_show(button
);
1161 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1162 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1163 button
, GTK_RESPONSE_OK
);
1164 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1167 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1168 gtk_widget_destroy(box
);
1170 if (ans
!= GTK_RESPONSE_OK
)
1179 err
= symlink(link_path
, path
);
1184 report_error("symlink: %s", g_strerror(errno
));
1188 dir_check_this(path
);
1193 static void run_action(DirItem
*item
)
1195 if (can_set_run_action(item
))
1196 type_set_handler_dialog(item
->mime_type
);
1199 _("You can only set the run action for a "
1203 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1205 filer_opendir(home_dir
, NULL
, NULL
);
1208 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1212 path
= g_strconcat(filer_window
->sym_path
,
1213 "/", item
->leafname
, "#", NULL
);
1215 filer_change_to(filer_window
, path
, NULL
);
1219 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1221 g_return_if_fail(window_with_focus
!= NULL
);
1223 window_with_focus
->temp_item_selected
= FALSE
;
1224 view_select_all(window_with_focus
->view
);
1227 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1229 g_return_if_fail(window_with_focus
!= NULL
);
1231 window_with_focus
->temp_item_selected
= FALSE
;
1232 view_clear_selection(window_with_focus
->view
);
1235 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1237 return !view_get_selected((ViewIface
*) data
, iter
);
1240 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1242 g_return_if_fail(window_with_focus
!= NULL
);
1244 window_with_focus
->temp_item_selected
= FALSE
;
1246 view_select_if(window_with_focus
->view
, invert_cb
,
1247 window_with_focus
->view
);
1250 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1254 win
= options_show();
1258 number_of_windows
++;
1259 g_signal_connect(win
, "destroy",
1260 G_CALLBACK(one_less_window
), NULL
);
1264 static gboolean
new_directory_cb(GObject
*savebox
,
1265 const gchar
*initial
, const gchar
*path
)
1267 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1269 report_error("mkdir: %s", g_strerror(errno
));
1273 dir_check_this(path
);
1275 if (filer_exists(window_with_focus
))
1278 leaf
= strrchr(path
, '/');
1280 display_set_autoselect(window_with_focus
, leaf
+ 1);
1286 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1288 g_return_if_fail(window_with_focus
!= NULL
);
1290 savebox_show(_("Create"),
1291 make_path(window_with_focus
->sym_path
, _("NewDir")),
1292 type_to_icon(inode_directory
), new_directory_cb
,
1296 static gboolean
new_file_cb(GObject
*savebox
,
1297 const gchar
*initial
, const gchar
*path
)
1301 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1305 report_error(_("Error creating '%s': %s"),
1306 path
, g_strerror(errno
));
1311 report_error(_("Error creating '%s': %s"),
1312 path
, g_strerror(errno
));
1314 dir_check_this(path
);
1316 if (filer_exists(window_with_focus
))
1319 leaf
= strrchr(path
, '/');
1321 display_set_autoselect(window_with_focus
, leaf
+ 1);
1327 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1329 g_return_if_fail(window_with_focus
!= NULL
);
1331 savebox_show(_("Create"),
1332 make_path(window_with_focus
->sym_path
, _("NewFile")),
1333 type_to_icon(text_plain
),
1334 new_file_cb
, GDK_ACTION_COPY
);
1337 static gboolean
new_file_type_cb(GObject
*savebox
,
1338 const gchar
*initial
, const gchar
*path
)
1340 const gchar
*oleaf
, *leaf
;
1341 gchar
*templ
, *templ_dname
, *dest
;
1344 /* We can work out the template path from the initial name */
1345 oleaf
= g_basename(initial
);
1346 templ_dname
= choices_find_path_load("Templates", "");
1350 _("Error creating file: could not find the template for %s"),
1355 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1356 g_free(templ_dname
);
1358 dest
= g_path_get_dirname(path
);
1359 leaf
= g_basename(path
);
1360 paths
= g_list_append(NULL
, templ
);
1362 action_copy(paths
, dest
, leaf
, TRUE
);
1368 if (filer_exists(window_with_focus
))
1369 display_set_autoselect(window_with_focus
, leaf
);
1374 static void do_send_to(gchar
*templ
)
1376 g_return_if_fail(send_to_paths
!= NULL
);
1378 run_with_files(templ
, send_to_paths
);
1381 static void new_file_type(gchar
*templ
)
1386 g_return_if_fail(window_with_focus
!= NULL
);
1388 leaf
= g_basename(templ
);
1389 type
= type_get_type(templ
);
1391 savebox_show(_("Create"),
1392 make_path(window_with_focus
->sym_path
, leaf
),
1394 new_file_type_cb
, GDK_ACTION_COPY
);
1397 static void customise_send_to(gpointer data
)
1404 dirs
= g_string_new(NULL
);
1406 path
= choices_list_dirs("");
1407 for (i
= 0; i
< path
->len
; i
++)
1409 guchar
*old
= (guchar
*) path
->pdata
[i
];
1411 g_string_append(dirs
, old
);
1412 g_string_append(dirs
, "SendTo\n");
1414 choices_free_list(path
);
1416 save
= choices_find_path_save("", "SendTo", TRUE
);
1421 _("The `Send To' menu provides a quick way to send some files "
1422 "to an application. The applications listed are those in "
1423 "the following directories:\n\n%s\n%s\n"
1424 "The `Send To' menu may be opened by Shift+Menu clicking "
1427 "You can also create subdirectories called "
1428 "`.text_html', `.text', etc which will only be "
1429 "shown for files of that type. `.group' is shown "
1430 "only when multiple files are selected."),
1432 save
? _("I'll show you your SendTo directory now; you should "
1433 "symlink (Ctrl+Shift drag) any applications you want "
1435 : _("Your CHOICESPATH variable setting prevents "
1436 "customisations - sorry."));
1438 g_string_free(dirs
, TRUE
);
1441 filer_opendir(save
, NULL
, NULL
);
1444 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1447 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1454 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1456 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1458 searchdir
= g_strdup("SendTo");
1460 paths
= choices_list_dirs(searchdir
);
1463 for (i
= 0; i
< paths
->len
; i
++)
1465 GList
*widgets
= NULL
;
1466 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1468 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1469 (CallbackFn
) do_send_to
,
1470 FALSE
, FALSE
, TRUE
);
1473 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1474 gtk_menu_item_new());
1476 g_list_free(widgets
); /* TODO: Get rid of this */
1479 choices_free_list(paths
);
1482 /* Scan the SendTo dir and create and show the Send To menu.
1483 * The 'paths' list and every path in it is claimed, and will be
1484 * freed later -- don't free it yourself!
1486 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1488 GtkWidget
*menu
, *item
;
1490 menu
= gtk_menu_new();
1492 if (g_list_length(paths
) == 1)
1496 item
= diritem_new("");
1497 diritem_restat(paths
->data
, item
, NULL
);
1500 item
->mime_type
->media_type
,
1501 item
->mime_type
->subtype
);
1503 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1508 add_sendto(menu
, "group", NULL
);
1510 add_sendto(menu
, NULL
, NULL
);
1512 item
= gtk_menu_item_new_with_label(_("Customise"));
1513 g_signal_connect_swapped(item
, "activate",
1514 G_CALLBACK(customise_send_to
), NULL
);
1515 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1518 destroy_glist(&send_to_paths
);
1520 send_to_paths
= paths
;
1522 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1525 show_popup_menu(menu
, event
, 0);
1528 static void send_to(FilerWindow
*filer_window
)
1533 paths
= filer_selected_items(filer_window
);
1534 event
= gtk_get_current_event();
1537 show_send_to_menu(paths
, event
);
1539 gdk_event_free(event
);
1542 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1544 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1545 gboolean close
= action
;
1547 argv
[2] = o_menu_xterm
.value
;
1549 g_return_if_fail(window_with_focus
!= NULL
);
1551 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1552 gtk_widget_destroy(window_with_focus
->window
);
1555 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1557 g_return_if_fail(window_with_focus
!= NULL
);
1559 filer_change_to(window_with_focus
, home_dir
, NULL
);
1562 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1564 g_return_if_fail(window_with_focus
!= NULL
);
1566 bookmarks_show_menu(window_with_focus
);
1569 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1571 g_return_if_fail(window_with_focus
!= NULL
);
1573 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1574 filer_change_to(window_with_focus
,
1575 window_with_focus
->real_path
, NULL
);
1577 delayed_error(_("This is already the canonical name "
1578 "for this directory."));
1581 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1583 g_return_if_fail(window_with_focus
!= NULL
);
1585 filer_open_parent(window_with_focus
);
1588 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1590 g_return_if_fail(window_with_focus
!= NULL
);
1592 change_to_parent(window_with_focus
);
1595 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1597 g_return_if_fail(window_with_focus
!= NULL
);
1599 view_autosize(window_with_focus
->view
);
1602 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1604 g_return_if_fail(window_with_focus
!= NULL
);
1606 if (o_unique_filer_windows
.int_value
)
1608 report_error(_("You can't open a second view onto "
1609 "this directory because the `Unique Windows' option "
1610 "is turned on in the Options window."));
1613 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1616 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1618 g_return_if_fail(window_with_focus
!= NULL
);
1620 if (!filer_window_delete(window_with_focus
->window
, NULL
,
1622 gtk_widget_destroy(window_with_focus
->window
);
1625 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1627 MiniType type
= (MiniType
) action
;
1629 g_return_if_fail(window_with_focus
!= NULL
);
1631 /* Item needs to remain selected... */
1632 if (type
== MINI_SHELL
)
1633 window_with_focus
->temp_item_selected
= FALSE
;
1635 minibuffer_show(window_with_focus
, type
);
1638 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1640 if (action
== HELP_ABOUT
)
1641 infobox_new(app_dir
);
1642 else if (action
== HELP_DIR
)
1643 filer_opendir(make_path(app_dir
, "Help"), NULL
, NULL
);
1644 else if (action
== HELP_MANUAL
)
1646 gchar
*manual
= NULL
;
1650 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1651 current_lang
, ".html", NULL
);
1652 if (access(manual
, F_OK
))
1653 null_g_free(&manual
);
1657 manual
= g_strconcat(app_dir
,
1658 "/Help/Manual.html", NULL
);
1660 run_by_path(manual
);
1665 g_warning("Unknown help action %d\n", action
);
1668 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1669 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1671 GList
*items
, *item
;
1673 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1675 item
= g_list_nth(items
, from
);
1678 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1684 static void save_menus(void)
1688 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1691 gtk_accel_map_save(menurc
);
1696 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1701 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1702 item
= g_list_nth_data(items
, n
);
1704 g_return_if_fail(item
!= NULL
);
1708 gtk_menu_shell_select_item(shell
, item
);
1711 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1718 g_return_if_fail(window_with_focus
!= NULL
);
1720 n_selected
= view_count_selected(window_with_focus
->view
);
1728 case FILE_COPY_ITEM
:
1729 prompt
= _("Copy ... ?");
1731 case FILE_RENAME_ITEM
:
1732 prompt
= _("Rename ... ?");
1734 case FILE_LINK_ITEM
:
1735 prompt
= _("Symlink ... ?");
1737 case FILE_OPEN_FILE
:
1738 prompt
= _("Shift Open ... ?");
1740 case FILE_SHOW_FILE_INFO
:
1741 prompt
= _("Examine ... ?");
1743 case FILE_RUN_ACTION
:
1744 prompt
= _("Set run action for ... ?");
1747 prompt
= _("Set icon for ... ?");
1750 prompt
= _("Send ... to ... ?");
1753 prompt
= _("DELETE ... ?");
1756 prompt
= _("Count the size of ... ?");
1758 case FILE_CHMOD_ITEMS
:
1759 prompt
= _("Set permissions on ... ?");
1762 prompt
= _("Search inside ... ?");
1764 case FILE_OPEN_VFS_AVFS
:
1765 prompt
= _("Look inside ... ?");
1768 g_warning("Unknown action!");
1771 filer_target_mode(window_with_focus
, target_callback
,
1772 GINT_TO_POINTER(action
), prompt
);
1779 send_to(window_with_focus
);
1782 delete(window_with_focus
);
1785 usage(window_with_focus
);
1787 case FILE_CHMOD_ITEMS
:
1788 chmod_items(window_with_focus
);
1791 find(window_with_focus
);
1793 case FILE_SHOW_FILE_INFO
:
1797 items
= filer_selected_items(window_with_focus
);
1798 infobox_show_list(items
);
1799 destroy_glist(&items
);
1806 /* All the following actions require exactly one file selected */
1810 report_error(_("You cannot do this to more than "
1811 "one item at a time"));
1815 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1817 item
= iter
.next(&iter
);
1818 g_return_if_fail(item
!= NULL
);
1819 /* iter may be passed to filer_openitem... */
1822 item
= dir_update_item(window_with_focus
->directory
,
1827 report_error(_("Item no longer exists!"));
1831 path
= make_path(window_with_focus
->sym_path
, item
->leafname
);
1835 case FILE_COPY_ITEM
:
1836 src_dest_action_item(path
, item
->image
,
1840 case FILE_RENAME_ITEM
:
1841 src_dest_action_item(path
, item
->image
,
1842 _("Rename"), rename_cb
,
1845 case FILE_LINK_ITEM
:
1846 src_dest_action_item(path
, item
->image
,
1847 _("Symlink"), link_cb
,
1850 case FILE_OPEN_FILE
:
1851 filer_openitem(window_with_focus
, &iter
,
1852 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1854 case FILE_RUN_ACTION
:
1858 icon_set_handler_dialog(item
, path
);
1860 case FILE_OPEN_VFS_AVFS
:
1861 open_vfs_avfs(window_with_focus
, item
);
1864 g_warning("Unknown action!");
1869 static void show_key_help(GtkWidget
*button
, gpointer data
)
1871 gboolean can_change_accels
;
1873 g_object_get(G_OBJECT(gtk_settings_get_default()),
1874 "gtk-can-change-accels", &can_change_accels
,
1877 if (!can_change_accels
)
1879 info_message(_("User-definable shortcuts are disabled by "
1880 "default in Gtk2, and you have not enabled "
1881 "them. You can turn this feature on by:\n"
1882 "1) using an XSettings manager, such as ROX-Session\n"
1884 "2) adding this line to ~/.gtkrc-2.0:\n"
1885 "\tgtk-can-change-accels = 1"));
1889 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1890 "- Open the menu over a filer window,\n"
1891 "- Move the pointer over the item you want to use,\n"
1892 "- Press the key you want attached to it.\n\n"
1893 "The key will appear next to the menu item and you can just press "
1894 "that key without opening the menu in future."));
1897 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1899 GtkWidget
*button
, *align
;
1901 g_return_val_if_fail(option
== NULL
, NULL
);
1903 align
= gtk_alignment_new(0, 0.5, 0, 0);
1904 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
1905 gtk_container_add(GTK_CONTAINER(align
), button
);
1906 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1908 return g_list_append(NULL
, align
);