4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, 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 menu */
29 #include <sys/param.h>
46 #include "gui_support.h"
49 #include "gtksavebox.h"
51 #include "minibuffer.h"
58 #include "usericons.h"
60 #include "collection.h"
63 #define C_ "<control>"
82 typedef enum menu_icon_style
{
83 MIS_NONE
, MIS_SMALL
, MIS_LARGE
, MIS_HUGE
,
84 MIS_CURRENT
, /* As per current filer window */
88 typedef void (*ActionFn
)(GList
*paths
,
89 const char *dest_dir
, const char *leaf
, int quiet
);
90 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
92 typedef gboolean (*SaveCb
)(GObject
*savebox
,
93 const gchar
*current
, const gchar
*new);
95 GtkAccelGroup
*filer_keys
;
96 GtkAccelGroup
*pinboard_keys
;
98 GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
100 static gint updating_menu
= 0; /* Non-zero => ignore activations */
101 static GList
*send_to_paths
= NULL
;
103 static Option o_menu_iconsize
, o_menu_xterm
;
105 /* Static prototypes */
107 static void save_menus(void);
108 static void menu_closed(GtkWidget
*widget
);
109 static void items_sensitive(gboolean state
);
110 static void savebox_show(const gchar
*action
, const gchar
*path
,
111 MaskedPixmap
*image
, SaveCb callback
);
112 static gint
save_to_file(GObject
*savebox
,
113 const gchar
*pathname
, gpointer data
);
114 static gboolean
action_with_leaf(ActionFn action
,
115 const gchar
*current
, const gchar
*new);
116 static gboolean
link_cb(GObject
*savebox
,
117 const gchar
*initial
, const gchar
*path
);
118 static void select_nth_item(GtkMenuShell
*shell
, int n
);
119 static void new_file_type(gchar
*templ
);
120 static void do_send_to(gchar
*templ
);
121 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
122 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
124 /* Note that for most of these callbacks none of the arguments are used. */
126 /* (action used in these three - DetailsType) */
127 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
140 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
142 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
151 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
152 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
153 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
154 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
156 /* (action used in this - MiniType) */
157 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
158 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
160 #define MENUS_NAME "menus2"
161 static void keys_changed(gpointer data
);
163 static GtkWidget
*filer_menu
; /* The popup filer menu */
164 static GtkWidget
*filer_file_item
; /* The File '' label */
165 static GtkWidget
*filer_file_menu
; /* The File '' menu */
166 static GtkWidget
*file_shift_item
; /* Shift Open label */
167 GtkWidget
*display_large_menu
; /* Display->Large With... */
168 GtkWidget
*display_small_menu
; /* Display->Small With... */
169 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
170 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
171 static GtkWidget
*filer_new_window
; /* The New Window item */
172 static GtkWidget
*filer_new_menu
; /* The New submenu */
177 static GtkItemFactoryEntry filer_menu_def
[] = {
178 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
179 {">" N_("Huge Icons"), NULL
, huge_with
, DETAILS_NONE
, NULL
},
180 {">" N_("Large Icons"), NULL
, large_with
, DETAILS_NONE
, NULL
},
181 {">" N_("Small Icons"), NULL
, small_with
, DETAILS_NONE
, NULL
},
182 {">" N_("Huge, With..."), NULL
, NULL
, 0, "<Branch>"},
183 {">>" N_("Summary"), NULL
, huge_with
, DETAILS_SUMMARY
, NULL
},
184 {">>" N_("Sizes"), NULL
, huge_with
, DETAILS_SIZE
, NULL
},
185 {">>" N_("Permissions"), NULL
, huge_with
, DETAILS_PERMISSIONS
, NULL
},
186 {">>" N_("Type"), NULL
, huge_with
, DETAILS_TYPE
, NULL
},
187 {">>" N_("Times"), NULL
, huge_with
, DETAILS_TIMES
, NULL
},
188 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
189 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
190 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
191 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
192 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
193 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
194 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
195 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
196 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
197 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
198 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
199 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, NULL
},
200 {">", NULL
, NULL
, 0, "<Separator>"},
201 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
202 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
203 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
204 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
205 {">", NULL
, NULL
, 0, "<Separator>"},
206 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
207 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
208 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
209 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
210 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, NULL
},
211 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
212 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
213 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
214 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
215 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
216 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
217 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
218 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
219 {">", NULL
, NULL
, 0, "<Separator>"},
220 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
221 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
222 {">" N_("Disk Usage"), NULL
, file_op
, FILE_USAGE
, NULL
},
223 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
224 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
225 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
226 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
227 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
228 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
229 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
230 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
231 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
232 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
233 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
234 {N_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
235 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
236 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
237 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
238 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
239 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
240 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
241 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
243 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
244 {">", NULL
, NULL
, 0, "<Separator>"},
245 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
246 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
247 {">", NULL
, NULL
, 0, "<Separator>"},
248 {">" N_("Show ROX-Filer Help"), "F1", menu_rox_help
, 0, NULL
},
252 #define GET_MENU_ITEM(var, menu) \
253 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
255 #define GET_SMENU_ITEM(var, menu, sub) \
257 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
258 var = gtk_item_factory_get_widget(item_factory, tmp); \
262 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
264 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
265 var = gtk_item_factory_get_widget(item_factory, tmp); \
275 GtkItemFactory
*item_factory
;
277 filer_keys
= gtk_accel_group_new();
278 item_factory
= menu_create(filer_menu_def
,
279 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
280 "<filer>", filer_keys
);
282 GET_MENU_ITEM(filer_menu
, "filer");
283 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
284 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
285 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
288 GET_SSMENU_ITEM(display_large_menu
, "filer",
289 "Display", "Large, With...");
290 GET_SSMENU_ITEM(display_small_menu
, "filer",
291 "Display", "Small, With...");
293 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
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
, 3)->data
)->child
;
305 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
306 filer_new_window
= GTK_BIN(item
)->child
;
308 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
311 gtk_accel_map_load(menurc
);
315 g_signal_connect(filer_menu
, "unmap_event",
316 G_CALLBACK(menu_closed
), NULL
);
317 g_signal_connect(filer_file_menu
, "unmap_event",
318 G_CALLBACK(menu_closed
), NULL
);
320 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
321 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
322 option_add_saver(save_menus
);
324 g_signal_connect_object(G_OBJECT(filer_keys
), "accel_changed",
325 (GCallback
) keys_changed
, NULL
, 0);
327 option_register_widget("menu-set-keys", set_keys_button
);
330 /* Name is in the form "<panel>" */
331 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
332 const gchar
*name
, GtkAccelGroup
*keys
)
334 GtkItemFactory
*item_factory
;
335 GtkItemFactoryEntry
*translated
;
339 keys
= gtk_accel_group_new();
340 gtk_accel_group_lock(keys
);
343 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
345 translated
= translate_entries(def
, n_entries
);
346 gtk_item_factory_create_items(item_factory
, n_entries
,
348 free_translated_entries(translated
, n_entries
);
353 /* Prevent the user from setting a short-cut on this item */
354 void menuitem_no_shortcuts(GtkWidget
*item
)
358 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
360 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
361 g_free(menuitem
->accel_path
);
362 menuitem
->accel_path
= NULL
;
366 static void items_sensitive(gboolean state
)
371 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
376 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
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
);
423 /* Used when you menu-click on the Large or Small toolbar tools */
424 void show_style_menu(FilerWindow
*filer_window
,
425 GdkEventButton
*event
,
430 pos
[0] = event
->x_root
;
431 pos
[1] = event
->y_root
;
434 window_with_focus
= filer_window
;
438 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
439 (gpointer
) pos
, event
->button
, event
->time
);
443 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dname
,
444 MenuIconStyle style
, CallbackFn func
,
445 gboolean separator
, gboolean strip_ext
)
447 GList
*widgets
= NULL
;
453 dir
= opendir(dname
);
459 item
= gtk_menu_item_new();
460 widgets
= g_list_append(widgets
, item
);
461 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
464 while ((ent
= readdir(dir
)))
474 /* Ignore hidden files */
475 if (ent
->d_name
[0] == '.')
478 /* Strip off extension, if any */
479 dot
= strchr(ent
->d_name
, '.');
480 if (strip_ext
&& dot
)
481 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
483 leaf
= g_strdup(ent
->d_name
);
485 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
486 ditem
= diritem_new(NULL
);
487 diritem_restat(fname
, ditem
);
489 if (ditem
->image
&& style
!= MIS_NONE
)
493 if (!ditem
->image
->huge_pixmap
)
494 pixmap_make_huge(ditem
->image
);
495 icon
= ditem
->image
->huge_pixmap
;
496 mask
= ditem
->image
->huge_mask
;
499 icon
= ditem
->image
->pixmap
;
500 mask
= ditem
->image
->mask
;
505 if (!ditem
->image
->sm_pixmap
)
506 pixmap_make_small(ditem
->image
);
507 icon
= ditem
->image
->sm_pixmap
;
508 mask
= ditem
->image
->sm_mask
;
512 item
= gtk_menu_item_new();
513 /* TODO: Find a way to allow short-cuts */
514 menuitem_no_shortcuts(item
);
516 hbox
= gtk_hbox_new(FALSE
, 2);
517 gtk_container_add(GTK_CONTAINER(item
), hbox
);
519 img
= gtk_image_new_from_pixmap(icon
, mask
);
520 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
522 label
= gtk_label_new(leaf
);
523 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
524 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
529 item
= gtk_menu_item_new_with_label(leaf
);
533 g_signal_connect_swapped(item
, "activate",
534 G_CALLBACK(func
), fname
);
535 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
536 g_signal_connect_swapped(item
, "destroy",
537 G_CALLBACK(g_free
), fname
);
539 widgets
= g_list_append(widgets
, item
);
548 /* Scan the templates dir and create entries for the New menu */
549 static void update_new_files_menu(MenuIconStyle style
)
551 static GList
*widgets
= NULL
;
553 gchar
*templ_dname
= NULL
;
559 for (next
= widgets
; next
; next
= next
->next
)
560 gtk_widget_destroy((GtkWidget
*) next
->data
);
562 g_list_free(widgets
);
566 templ_dname
= choices_find_path_load("Templates", "");
569 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
570 (CallbackFn
) new_file_type
, TRUE
, TRUE
);
573 gtk_widget_show_all(filer_new_menu
);
576 /* 'item' is the number of the item to appear under the pointer. */
577 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
583 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
584 event
->type
== GDK_BUTTON_RELEASE
))
586 GdkEventButton
*bev
= (GdkEventButton
*) event
;
588 pos
[0] = bev
->x_root
;
589 pos
[1] = bev
->y_root
;
590 button
= bev
->button
;
593 else if (event
&& event
->type
== GDK_KEY_PRESS
)
595 GdkEventKey
*kev
= (GdkEventKey
*) event
;
597 get_pointer_xy(pos
, pos
+ 1);
601 get_pointer_xy(pos
, pos
+ 1);
605 gtk_widget_show_all(menu
);
606 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
607 position_menu
, (gpointer
) pos
, button
, time
);
608 select_nth_item(GTK_MENU_SHELL(menu
), item
);
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
: case MIS_HUGE
:
626 if (mis
== MIS_CURRENT
&& window_with_focus
)
628 switch (window_with_focus
->display_style
)
641 display
= o_display_size
.int_value
;
657 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
659 DirItem
*file_item
= NULL
;
660 GdkModifierType state
= 0;
664 /* Remove previous AppMenu, if any */
667 window_with_focus
= filer_window
;
669 if (event
->type
== GDK_BUTTON_PRESS
)
670 state
= ((GdkEventButton
*) event
)->state
;
671 else if (event
->type
== GDK_KEY_PRESS
)
672 state
= ((GdkEventKey
*) event
)->state
;
674 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
676 filer_window
->temp_item_selected
= TRUE
;
677 collection_select_item(filer_window
->collection
, item
);
681 filer_window
->temp_item_selected
= FALSE
;
684 /* Short-cut to the Send To menu */
685 if (state
& GDK_SHIFT_MASK
)
691 if (filer_window
->collection
->number_selected
== 0)
694 _("You should Shift+Menu click over a file to "
695 "send it somewhere"));
699 paths
= filer_selected_items(filer_window
);
701 show_send_to_menu(paths
, event
); /* (paths eaten) */
707 GtkWidget
*file_label
, *file_menu
;
708 Collection
*collection
= filer_window
->collection
;
712 file_label
= filer_file_item
;
713 file_menu
= filer_file_menu
;
714 gtk_check_menu_item_set_active(
715 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
716 filer_window
->show_thumbs
);
717 gtk_check_menu_item_set_active(
718 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
719 filer_window
->show_hidden
);
720 buffer
= g_string_new(NULL
);
722 switch (collection
->number_selected
)
725 g_string_assign(buffer
, _("Next Click"));
726 items_sensitive(TRUE
);
729 item
= selected_item(filer_window
->collection
);
731 dir_update_item(filer_window
->directory
,
733 items_sensitive(TRUE
);
734 file_item
= selected_item(
735 filer_window
->collection
);
736 g_string_sprintf(buffer
, "%s '%s'",
737 basetype_name(file_item
),
738 file_item
->leafname
);
739 if (!can_set_run_action(file_item
))
740 menu_set_items_shaded(filer_file_menu
,
744 items_sensitive(FALSE
);
745 g_string_sprintf(buffer
, _("%d items"),
746 collection
->number_selected
);
749 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
750 g_string_free(buffer
, TRUE
);
752 menu_show_shift_action(file_shift_item
, file_item
,
753 collection
->number_selected
== 0);
755 appmenu_add(make_path(filer_window
->path
,
756 file_item
->leafname
)->str
,
757 file_item
, filer_file_menu
);
760 update_new_files_menu(get_menu_icon_style());
762 gtk_widget_set_sensitive(filer_new_window
,
763 !o_unique_filer_windows
.int_value
);
765 popup_menu
= (state
& GDK_CONTROL_MASK
)
771 show_popup_menu(popup_menu
, event
,
772 popup_menu
== filer_file_menu
? 5 : 1);
775 static void menu_closed(GtkWidget
*widget
)
777 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
778 return; /* Close panel item chosen? */
782 if (window_with_focus
->temp_item_selected
)
784 collection_clear_selection(window_with_focus
->collection
);
785 window_with_focus
->temp_item_selected
= FALSE
;
789 void target_callback(FilerWindow
*filer_window
,
793 Collection
*collection
= filer_window
->collection
;
795 g_return_if_fail(window_with_focus
!= NULL
);
796 g_return_if_fail(window_with_focus
== filer_window
);
798 /* Don't grab the primary selection */
799 filer_window
->temp_item_selected
= TRUE
;
801 collection_wink_item(collection
, item
);
802 collection_clear_except(collection
, item
);
803 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
805 if (item
< collection
->number_of_items
)
806 collection_unselect_item(collection
, item
);
807 filer_window
->temp_item_selected
= FALSE
;
810 /* Set the text of the 'Shift Open...' menu item.
811 * If icon is NULL, reset the text and also shade it, unless 'next'.
813 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
815 guchar
*shift_action
= NULL
;
819 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
821 if (item
->flags
& ITEM_FLAG_MOUNTED
)
822 shift_action
= N_("Unmount");
824 shift_action
= N_("Mount");
826 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
827 shift_action
= N_("Show Target");
828 else if (item
->base_type
== TYPE_DIRECTORY
)
829 shift_action
= N_("Look Inside");
830 else if (item
->base_type
== TYPE_FILE
)
831 shift_action
= N_("Open As Text");
833 gtk_label_set_text(GTK_LABEL(menu_item
),
834 shift_action
? _(shift_action
)
836 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
841 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
843 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
846 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
848 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
851 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
853 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
856 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
858 g_return_if_fail(window_with_focus
!= NULL
);
860 display_set_sort_fn(window_with_focus
, sort_by_name
);
863 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
865 g_return_if_fail(window_with_focus
!= NULL
);
867 display_set_sort_fn(window_with_focus
, sort_by_type
);
870 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
872 g_return_if_fail(window_with_focus
!= NULL
);
874 display_set_sort_fn(window_with_focus
, sort_by_date
);
877 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
879 g_return_if_fail(window_with_focus
!= NULL
);
881 display_set_sort_fn(window_with_focus
, sort_by_size
);
884 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
889 g_return_if_fail(window_with_focus
!= NULL
);
891 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
894 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
899 g_return_if_fail(window_with_focus
!= NULL
);
901 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
904 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
906 g_return_if_fail(window_with_focus
!= NULL
);
909 filer_update_dir(window_with_focus
, TRUE
);
912 static void delete(FilerWindow
*filer_window
)
915 paths
= filer_selected_items(filer_window
);
916 action_delete(paths
);
917 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
921 static void usage(FilerWindow
*filer_window
)
924 paths
= filer_selected_items(filer_window
);
926 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
930 static void chmod_items(FilerWindow
*filer_window
)
933 paths
= filer_selected_items(filer_window
);
935 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
939 static void find(FilerWindow
*filer_window
)
942 paths
= filer_selected_items(filer_window
);
944 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
948 /* This creates a new savebox widget, and allows the user to pick a new path
950 * Once the new path has been picked, the callback will be called with
951 * both the current and new paths.
952 * NOTE: This function unrefs 'image'!
954 static void savebox_show(const gchar
*action
, const gchar
*path
,
955 MaskedPixmap
*image
, SaveCb callback
)
957 GtkWidget
*savebox
= NULL
;
958 GtkWidget
*check_relative
= NULL
;
960 g_return_if_fail(image
!= NULL
);
962 savebox
= gtk_savebox_new(action
);
964 if (callback
== link_cb
)
966 check_relative
= gtk_check_button_new_with_mnemonic(
967 _("_Relative link"));
968 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
971 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
972 gtk_tooltips_set_tip(tooltips
, check_relative
,
973 _("If on, the symlink will store the path from the "
974 "symlink to the target file. Use this if the symlink "
975 "and the target will be moved together.\n"
976 "If off, the path from the root directory is stored - "
977 "use this if the symlink may move but the target will "
979 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
980 check_relative
, FALSE
, TRUE
, 0);
981 gtk_widget_show(check_relative
);
984 g_signal_connect(savebox
, "save_to_file",
985 G_CALLBACK(save_to_file
), NULL
);
987 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
988 g_strdup(path
), g_free
);
989 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
990 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
992 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
993 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
994 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
995 g_object_unref(image
);
997 gtk_widget_show(savebox
);
1000 static gint
save_to_file(GObject
*savebox
,
1001 const gchar
*pathname
, gpointer data
)
1004 const gchar
*current_path
;
1006 callback
= g_object_get_data(savebox
, "action_callback");
1007 current_path
= g_object_get_data(savebox
, "current_path");
1009 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1010 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1012 return callback(savebox
, current_path
, pathname
)
1013 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1016 static gboolean
copy_cb(GObject
*savebox
,
1017 const gchar
*current
, const gchar
*new)
1019 return action_with_leaf(action_copy
, current
, new);
1022 static gboolean
action_with_leaf(ActionFn action
,
1023 const gchar
*current
, const gchar
*new)
1031 report_error(_("New pathname is not absolute"));
1035 if (new[strlen(new) - 1] == '/')
1037 new_dir
= g_strdup(new);
1044 slash
= strrchr(new, '/');
1045 new_dir
= g_strndup(new, slash
- new);
1049 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1050 action(local_paths
, new_dir
, leaf
, -1);
1051 g_list_free(local_paths
);
1058 /* Open a savebox to act on the selected file.
1059 * Call 'callback' later to perform the operation.
1061 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1062 const gchar
*action
, SaveCb callback
)
1064 g_object_ref(image
);
1065 savebox_show(action
, path
, image
, callback
);
1068 static gboolean
rename_cb(GObject
*savebox
,
1069 const gchar
*current
, const gchar
*new)
1071 return action_with_leaf(action_move
, current
, new);
1074 static gboolean
link_cb(GObject
*savebox
,
1075 const gchar
*initial
, const gchar
*path
)
1077 GtkToggleButton
*check_relative
;
1080 check_relative
= g_object_get_data(savebox
, "check_relative");
1082 if (gtk_toggle_button_get_active(check_relative
))
1086 rpath
= get_relative_path(path
, initial
);
1087 err
= symlink(rpath
, path
);
1092 err
= symlink(initial
, path
);
1096 report_error("symlink: %s", g_strerror(errno
));
1100 dir_check_this(path
);
1105 static void run_action(DirItem
*item
)
1107 if (can_set_run_action(item
))
1108 type_set_handler_dialog(item
->mime_type
);
1111 _("You can only set the run action for a "
1115 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1117 filer_opendir(home_dir
, NULL
);
1120 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1124 path
= g_strconcat(filer_window
->path
,
1125 "/", item
->leafname
, "#", NULL
);
1127 filer_change_to(filer_window
, path
, NULL
);
1131 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1133 g_return_if_fail(window_with_focus
!= NULL
);
1135 window_with_focus
->temp_item_selected
= FALSE
;
1136 collection_select_all(window_with_focus
->collection
);
1139 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1141 g_return_if_fail(window_with_focus
!= NULL
);
1143 window_with_focus
->temp_item_selected
= FALSE
;
1144 collection_clear_selection(window_with_focus
->collection
);
1147 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1149 g_return_if_fail(window_with_focus
!= NULL
);
1151 window_with_focus
->temp_item_selected
= FALSE
;
1152 collection_invert_selection(window_with_focus
->collection
);
1155 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1160 static gboolean
new_directory_cb(GObject
*savebox
,
1161 const gchar
*initial
, const gchar
*path
)
1163 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1165 report_error("mkdir: %s", g_strerror(errno
));
1169 dir_check_this(path
);
1171 if (filer_exists(window_with_focus
))
1174 leaf
= strrchr(path
, '/');
1176 display_set_autoselect(window_with_focus
, leaf
+ 1);
1182 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1184 g_return_if_fail(window_with_focus
!= NULL
);
1186 savebox_show(_("Create"),
1187 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1188 type_to_icon(special_directory
),
1192 static gboolean
new_file_cb(GObject
*savebox
,
1193 const gchar
*initial
, const gchar
*path
)
1197 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1201 report_error(_("Error creating '%s': %s"),
1202 path
, g_strerror(errno
));
1207 report_error(_("Error creating '%s': %s"),
1208 path
, g_strerror(errno
));
1210 dir_check_this(path
);
1212 if (filer_exists(window_with_focus
))
1215 leaf
= strrchr(path
, '/');
1217 display_set_autoselect(window_with_focus
, leaf
+ 1);
1223 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1225 g_return_if_fail(window_with_focus
!= NULL
);
1227 savebox_show(_("Create"),
1228 make_path(window_with_focus
->path
, _("NewFile"))->str
,
1229 type_to_icon(text_plain
),
1233 static gboolean
new_file_type_cb(GObject
*savebox
,
1234 const gchar
*initial
, const gchar
*path
)
1236 const gchar
*oleaf
, *leaf
;
1237 gchar
*templ
, *templ_dname
, *dest
;
1240 /* We can work out the template path from the initial name */
1241 oleaf
= g_basename(initial
);
1242 templ_dname
= choices_find_path_load("Templates", "");
1246 _("Error creating file: could not find the template for %s"),
1251 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1252 g_free(templ_dname
);
1254 dest
= g_dirname(path
);
1255 leaf
= g_basename(path
);
1256 paths
= g_list_append(NULL
, templ
);
1258 action_copy(paths
, dest
, leaf
, -1);
1264 if (filer_exists(window_with_focus
))
1265 display_set_autoselect(window_with_focus
, leaf
);
1270 static void do_send_to(gchar
*templ
)
1272 g_return_if_fail(send_to_paths
!= NULL
);
1274 run_with_files(templ
, send_to_paths
);
1277 static void new_file_type(gchar
*templ
)
1282 g_return_if_fail(window_with_focus
!= NULL
);
1284 leaf
= g_basename(templ
);
1285 type
= type_get_type(templ
);
1287 savebox_show(_("Create"),
1288 make_path(window_with_focus
->path
, leaf
)->str
,
1293 static void customise_send_to(gpointer data
)
1300 dirs
= g_string_new(NULL
);
1302 path
= choices_list_dirs("");
1303 for (i
= 0; i
< path
->len
; i
++)
1305 guchar
*old
= (guchar
*) path
->pdata
[i
];
1307 g_string_append(dirs
, old
);
1308 g_string_append(dirs
, "SendTo\n");
1310 choices_free_list(path
);
1312 save
= choices_find_path_save("", "SendTo", TRUE
);
1317 _("The `Send To' menu provides a quick way to send some files "
1318 "to an application. The applications listed are those in "
1319 "the following directories:\n\n%s\n%s\n"
1320 "The `Send To' menu may be opened by Shift+Menu clicking "
1323 save
? _("I'll show you your SendTo directory now; you should "
1324 "symlink (Ctrl+Shift drag) any applications you want "
1326 : _("Your CHOICESPATH variable setting prevents "
1327 "customisations - sorry."));
1329 g_string_free(dirs
, TRUE
);
1332 filer_opendir(save
, NULL
);
1335 /* Scan the SendTo dir and create and show the Send To menu.
1336 * The 'paths' list and every path in it is claimed, and will be
1337 * freed later -- don't free it yourself!
1339 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1341 GtkWidget
*menu
, *item
;
1345 menu
= gtk_menu_new();
1347 path
= choices_list_dirs("SendTo");
1349 for (i
= 0; i
< path
->len
; i
++)
1351 GList
*widgets
= NULL
;
1352 guchar
*dir
= (guchar
*) path
->pdata
[i
];
1354 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1355 (CallbackFn
) do_send_to
,
1359 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1360 gtk_menu_item_new());
1362 g_list_free(widgets
); /* TODO: Get rid of this */
1365 choices_free_list(path
);
1367 item
= gtk_menu_item_new_with_label(_("Customise"));
1368 g_signal_connect_swapped(item
, "activate",
1369 G_CALLBACK(customise_send_to
), NULL
);
1370 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1374 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1375 g_list_free(send_to_paths
);
1377 send_to_paths
= paths
;
1379 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1382 show_popup_menu(menu
, event
, 0);
1385 static void send_to(FilerWindow
*filer_window
)
1390 paths
= filer_selected_items(filer_window
);
1391 event
= gtk_get_current_event();
1394 show_send_to_menu(paths
, event
);
1396 gdk_event_free(event
);
1399 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1401 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1403 argv
[2] = o_menu_xterm
.value
;
1405 g_return_if_fail(window_with_focus
!= NULL
);
1407 rox_spawn(window_with_focus
->path
, argv
);
1410 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1412 g_return_if_fail(window_with_focus
!= NULL
);
1414 filer_change_to(window_with_focus
, home_dir
, NULL
);
1417 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1419 g_return_if_fail(window_with_focus
!= NULL
);
1421 filer_open_parent(window_with_focus
);
1424 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1426 g_return_if_fail(window_with_focus
!= NULL
);
1428 change_to_parent(window_with_focus
);
1431 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1433 g_return_if_fail(window_with_focus
!= NULL
);
1435 filer_window_autosize(window_with_focus
, TRUE
);
1438 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1440 g_return_if_fail(window_with_focus
!= NULL
);
1442 if (o_unique_filer_windows
.int_value
)
1444 report_error(_("You can't open a second view onto "
1445 "this directory because the `Unique Windows' option "
1446 "is turned on in the Options window."));
1449 filer_opendir(window_with_focus
->path
, window_with_focus
);
1453 static void su_to_user(GtkWidget
*dialog
)
1456 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1460 g_return_if_fail(dialog
!= NULL
);
1462 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1463 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1465 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1467 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1468 argv
[3] = gtk_entry_get_text(user
);
1469 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1473 report_error(_("fork: %s"), g_strerror(errno
));
1478 gtk_widget_destroy(dialog
);
1481 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1483 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1485 g_return_if_fail(window_with_focus
!= NULL
);
1487 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1488 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1489 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1490 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1491 g_strdup(window_with_focus
->path
), g_free
);
1493 vbox
= gtk_vbox_new(FALSE
, 4);
1494 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1495 gtk_box_pack_start(GTK_BOX(vbox
),
1496 gtk_label_new(_("Browse as which user?")),
1499 hbox
= gtk_hbox_new(FALSE
, 4);
1500 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1502 gtk_box_pack_start(GTK_BOX(hbox
),
1503 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1505 entry
= gtk_entry_new();
1506 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1507 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1508 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1509 gtk_widget_grab_focus(entry
);
1510 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1511 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1512 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1514 hbox
= gtk_hbox_new(TRUE
, 0);
1515 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1517 button
= gtk_button_new_with_label(_("OK"));
1518 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1519 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1520 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1521 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1522 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1524 button
= gtk_button_new_with_label(_("Cancel"));
1525 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1526 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1527 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1528 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1529 GTK_OBJECT(dialog
));
1531 gtk_widget_show_all(dialog
);
1535 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1537 g_return_if_fail(window_with_focus
!= NULL
);
1539 gtk_widget_destroy(window_with_focus
->window
);
1542 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1544 MiniType type
= (MiniType
) action
;
1546 g_return_if_fail(window_with_focus
!= NULL
);
1548 /* Item needs to remain selected... */
1549 if (type
== MINI_SHELL
)
1550 window_with_focus
->temp_item_selected
= FALSE
;
1552 minibuffer_show(window_with_focus
, type
);
1555 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1557 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1560 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1561 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1563 GList
*items
, *item
;
1565 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1567 item
= g_list_nth(items
, from
);
1570 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1576 static void save_menus(void)
1580 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1583 gtk_accel_map_save(menurc
);
1588 static void keys_changed(gpointer data
)
1593 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1596 GtkWidget
*item
= NULL
;
1598 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1599 nth
= g_list_nth(items
, n
);
1601 g_return_if_fail(nth
!= NULL
);
1603 item
= (GtkWidget
*) (nth
->data
);
1606 gtk_menu_shell_select_item(shell
, item
);
1609 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1611 Collection
*collection
;
1615 g_return_if_fail(window_with_focus
!= NULL
);
1617 collection
= window_with_focus
->collection
;
1619 if (collection
->number_selected
< 1)
1625 case FILE_COPY_ITEM
:
1626 prompt
= _("Copy ... ?");
1628 case FILE_RENAME_ITEM
:
1629 prompt
= _("Rename ... ?");
1631 case FILE_LINK_ITEM
:
1632 prompt
= _("Symlink ... ?");
1634 case FILE_OPEN_FILE
:
1635 prompt
= _("Shift Open ... ?");
1638 prompt
= _("Help about ... ?");
1640 case FILE_SHOW_FILE_INFO
:
1641 prompt
= _("Examine ... ?");
1643 case FILE_RUN_ACTION
:
1644 prompt
= _("Set run action for ... ?");
1647 prompt
= _("Set icon for ... ?");
1650 prompt
= _("Send ... to ... ?");
1653 prompt
= _("DELETE ... ?");
1656 prompt
= _("Count the size of ... ?");
1658 case FILE_CHMOD_ITEMS
:
1659 prompt
= _("Set permissions on ... ?");
1662 prompt
= _("Search inside ... ?");
1664 case FILE_OPEN_VFS_AVFS
:
1665 prompt
= _("Look inside ... ?");
1668 g_warning("Unknown action!");
1671 filer_target_mode(window_with_focus
, target_callback
,
1672 GINT_TO_POINTER(action
), prompt
);
1679 send_to(window_with_focus
);
1682 delete(window_with_focus
);
1685 usage(window_with_focus
);
1687 case FILE_CHMOD_ITEMS
:
1688 chmod_items(window_with_focus
);
1691 find(window_with_focus
);
1697 /* All the following actions require exactly one file selected */
1699 if (collection
->number_selected
> 1)
1701 report_error(_("You cannot do this to more than "
1702 "one item at a time"));
1706 item
= selected_item(collection
);
1707 g_return_if_fail(item
!= NULL
);
1709 item
= dir_update_item(window_with_focus
->directory
,
1714 report_error(_("Item no longer exists!"));
1718 path
= make_path(window_with_focus
->path
, item
->leafname
)->str
;
1722 case FILE_COPY_ITEM
:
1723 src_dest_action_item(path
, item
->image
,
1724 _("Copy"), copy_cb
);
1726 case FILE_RENAME_ITEM
:
1727 src_dest_action_item(path
, item
->image
,
1728 _("Rename"), rename_cb
);
1730 case FILE_LINK_ITEM
:
1731 src_dest_action_item(path
, item
->image
,
1732 _("Symlink"), link_cb
);
1734 case FILE_OPEN_FILE
:
1735 filer_openitem(window_with_focus
,
1736 selected_item_number(collection
),
1737 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1740 show_item_help(path
, item
);
1742 case FILE_SHOW_FILE_INFO
:
1745 case FILE_RUN_ACTION
:
1749 icon_set_handler_dialog(item
, path
);
1751 case FILE_OPEN_VFS_AVFS
:
1752 open_vfs_avfs(window_with_focus
, item
);
1755 g_warning("Unknown action!");
1760 static void show_key_help(GtkWidget
*button
, gpointer data
)
1762 report_error(_("To set a keyboard short-cut for a menu item:\n\n"
1763 "- Open the menu over a filer window,\n"
1764 "- Move the pointer over the item you want to use,\n"
1765 "- Press the key you want attached to it.\n\n"
1766 "The key will appear next to the menu item and you can just press "
1767 "that key without opening the menu in future."));
1770 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1772 GtkWidget
*button
, *align
;
1774 g_return_val_if_fail(option
== NULL
, NULL
);
1776 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1777 button
= gtk_button_new_with_label(_("Set keyboard shortcuts"));
1778 gtk_container_add(GTK_CONTAINER(align
), button
);
1779 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1781 return g_list_append(NULL
, align
);