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 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 "collection.h"
80 typedef enum menu_icon_style
{
81 MIS_NONE
, MIS_SMALL
, MIS_LARGE
,
83 MIS_CURRENT
, /* As per current filer window */
87 typedef void (*ActionFn
)(GList
*paths
,
88 const char *dest_dir
, const char *leaf
, int quiet
);
89 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
91 typedef gboolean (*SaveCb
)(GObject
*savebox
,
92 const gchar
*current
, const gchar
*new);
94 GtkAccelGroup
*filer_keys
= NULL
;
96 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
98 static gint updating_menu
= 0; /* Non-zero => ignore activations */
99 static GList
*send_to_paths
= NULL
;
101 static Option o_menu_iconsize
, o_menu_xterm
;
103 /* Static prototypes */
105 static void save_menus(void);
106 static void menu_closed(GtkWidget
*widget
);
107 static void shade_file_menu_items(gboolean shaded
);
108 static void savebox_show(const gchar
*action
, const gchar
*path
,
109 MaskedPixmap
*image
, SaveCb callback
);
110 static gint
save_to_file(GObject
*savebox
,
111 const gchar
*pathname
, gpointer data
);
112 static gboolean
action_with_leaf(ActionFn action
,
113 const gchar
*current
, const gchar
*new);
114 static gboolean
link_cb(GObject
*savebox
,
115 const gchar
*initial
, const gchar
*path
);
116 static void select_nth_item(GtkMenuShell
*shell
, int n
);
117 static void new_file_type(gchar
*templ
);
118 static void do_send_to(gchar
*templ
);
119 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
120 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
122 /* Note that for most of these callbacks none of the arguments are used. */
124 /* (action used in these three - DetailsType) */
125 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
);
126 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
140 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
151 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
152 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
153 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
155 /* (action used in this - MiniType) */
156 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
157 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
159 #define MENUS_NAME "menus2"
160 static void keys_changed(gpointer data
);
162 static GtkWidget
*filer_menu
; /* The popup filer menu */
163 static GtkWidget
*filer_file_item
; /* The File '' label */
164 static GtkWidget
*filer_file_menu
; /* The File '' menu */
165 static GtkWidget
*file_shift_item
; /* Shift Open label */
166 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
167 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
168 static GtkWidget
*filer_new_window
; /* The New Window item */
169 static GtkWidget
*filer_new_menu
; /* The New submenu */
170 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
175 static GtkItemFactoryEntry filer_menu_def
[] = {
176 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
177 {">" N_("Huge Icons"), NULL
, huge_with
, DETAILS_NONE
, NULL
},
178 {">" N_("Large Icons"), NULL
, large_with
, DETAILS_NONE
, NULL
},
179 {">" N_("Small Icons"), NULL
, small_with
, DETAILS_NONE
, NULL
},
180 {">" N_("Huge, With..."), NULL
, NULL
, 0, "<Branch>"},
181 {">>" N_("Summary"), NULL
, huge_with
, DETAILS_SUMMARY
, NULL
},
182 {">>" N_("Sizes"), NULL
, huge_with
, DETAILS_SIZE
, NULL
},
183 {">>" N_("Permissions"), NULL
, huge_with
, DETAILS_PERMISSIONS
, NULL
},
184 {">>" N_("Type"), NULL
, huge_with
, DETAILS_TYPE
, NULL
},
185 {">>" N_("Times"), NULL
, huge_with
, DETAILS_TIMES
, NULL
},
186 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
187 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
188 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
189 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
190 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
191 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
192 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
193 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
194 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
195 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
196 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
197 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, NULL
},
198 {">", NULL
, NULL
, 0, "<Separator>"},
199 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
200 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
201 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
202 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
203 {">", NULL
, NULL
, 0, "<Separator>"},
204 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
205 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
206 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
207 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
208 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, NULL
},
209 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
210 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
211 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
212 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
213 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
214 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
215 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
216 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
217 {">", NULL
, NULL
, 0, "<Separator>"},
218 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
219 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
220 {">" N_("Disk Usage"), NULL
, file_op
, FILE_USAGE
, NULL
},
221 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
222 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
223 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
224 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
225 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
226 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
227 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
228 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
229 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
230 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
231 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
232 {N_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
233 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
234 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
235 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
236 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
237 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
238 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
239 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
240 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
242 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
243 {">", NULL
, NULL
, 0, "<Separator>"},
244 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
245 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
246 {">", NULL
, NULL
, 0, "<Separator>"},
247 {">" N_("Show ROX-Filer Help"), "F1", menu_rox_help
, 0, NULL
},
251 #define GET_MENU_ITEM(var, menu) \
252 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
254 #define GET_SMENU_ITEM(var, menu, sub) \
256 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
257 var = gtk_item_factory_get_widget(item_factory, tmp); \
261 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
263 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
264 var = gtk_item_factory_get_widget(item_factory, tmp); \
268 void ensure_filer_menu(void)
273 GtkItemFactory
*item_factory
;
278 filer_keys
= gtk_accel_group_new();
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_thumb_menu
, "filer", "Display",
289 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
290 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
291 filer_follow_sym
= GTK_BIN(item
)->child
;
293 /* File '' label... */
294 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
295 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
298 /* Shift Open... label */
299 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
300 file_shift_item
= GTK_BIN(g_list_nth(items
, 3)->data
)->child
;
303 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
304 filer_new_window
= GTK_BIN(item
)->child
;
306 g_signal_connect(filer_menu
, "unmap_event",
307 G_CALLBACK(menu_closed
), NULL
);
308 g_signal_connect(filer_file_menu
, "unmap_event",
309 G_CALLBACK(menu_closed
), NULL
);
311 g_signal_connect_object(G_OBJECT(filer_keys
), "accel_changed",
312 (GCallback
) keys_changed
, NULL
, 0);
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
);
333 /* Name is in the form "<panel>" */
334 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
335 const gchar
*name
, GtkAccelGroup
*keys
)
337 GtkItemFactory
*item_factory
;
338 GtkItemFactoryEntry
*translated
;
342 keys
= gtk_accel_group_new();
343 gtk_accel_group_lock(keys
);
346 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
348 translated
= translate_entries(def
, n_entries
);
349 gtk_item_factory_create_items(item_factory
, n_entries
,
351 free_translated_entries(translated
, n_entries
);
356 /* Prevent the user from setting a short-cut on this item */
357 void menuitem_no_shortcuts(GtkWidget
*item
)
361 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
363 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
364 g_free(menuitem
->accel_path
);
365 menuitem
->accel_path
= NULL
;
369 static void shade_file_menu_items(gboolean shaded
)
371 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 5);
372 menu_set_items_shaded(filer_file_menu
, shaded
, 6, 3);
375 /* 'data' is an array of three ints:
376 * [ pointer_x, pointer_y, item_under_pointer ]
378 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
379 gboolean
*push_in
, gpointer data
)
381 int *pos
= (int *) data
;
382 GtkRequisition requisition
;
387 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
389 while (item
>= 0 && next
)
391 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
404 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
406 *x
= pos
[0] - (requisition
.width
* 7 / 8);
407 *y
= pos
[1] - y_shift
;
409 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
410 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
416 /* Used when you menu-click on the Large or Small toolbar tools */
417 void show_style_menu(FilerWindow
*filer_window
,
418 GdkEventButton
*event
,
423 pos
[0] = event
->x_root
;
424 pos
[1] = event
->y_root
;
427 window_with_focus
= filer_window
;
431 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
432 (gpointer
) pos
, event
->button
, event
->time
);
436 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dname
,
437 MenuIconStyle style
, CallbackFn func
,
438 gboolean separator
, gboolean strip_ext
,
441 GList
*widgets
= NULL
;
447 dir
= opendir(dname
);
453 item
= gtk_menu_item_new();
454 widgets
= g_list_append(widgets
, item
);
455 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
458 while ((ent
= readdir(dir
)))
466 /* Ignore hidden files */
467 if (ent
->d_name
[0] == '.')
470 /* Strip off extension, if any */
471 dot
= strchr(ent
->d_name
, '.');
472 if (strip_ext
&& dot
)
473 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
475 leaf
= g_strdup(ent
->d_name
);
477 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
478 ditem
= diritem_new("");
479 diritem_restat(fname
, ditem
, NULL
);
481 if (ditem
->image
&& style
!= MIS_NONE
)
487 pixbuf
= ditem
->image
->pixbuf
;
490 if (!ditem
->image
->sm_pixbuf
)
491 pixmap_make_small(ditem
->image
);
492 pixbuf
= ditem
->image
->sm_pixbuf
;
496 item
= gtk_menu_item_new();
497 /* TODO: Find a way to allow short-cuts */
498 menuitem_no_shortcuts(item
);
500 hbox
= gtk_hbox_new(FALSE
, 2);
501 gtk_container_add(GTK_CONTAINER(item
), hbox
);
503 img
= gtk_image_new_from_pixbuf(pixbuf
);
505 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
507 label
= gtk_label_new(leaf
);
508 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
509 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
513 item
= gtk_menu_item_new_with_label(leaf
);
515 /* If it is a directory (but NOT an AppDir) and we are
516 * recursing then set up a sub menu.
518 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
519 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
524 sub
= gtk_menu_new();
525 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
526 separator
, strip_ext
, FALSE
);
527 g_list_free(new_widgets
);
528 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
531 g_signal_connect_swapped(item
, "activate",
532 G_CALLBACK(func
), fname
);
537 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
538 g_signal_connect_swapped(item
, "destroy",
539 G_CALLBACK(g_free
), fname
);
541 widgets
= g_list_append(widgets
, item
);
550 /* Scan the templates dir and create entries for the New menu */
551 static void update_new_files_menu(MenuIconStyle style
)
553 static GList
*widgets
= NULL
;
555 gchar
*templ_dname
= NULL
;
561 for (next
= widgets
; next
; next
= next
->next
)
562 gtk_widget_destroy((GtkWidget
*) next
->data
);
564 g_list_free(widgets
);
568 templ_dname
= choices_find_path_load("Templates", "");
571 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
572 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
576 gtk_widget_show_all(filer_new_menu
);
579 /* 'item' is the number of the item to appear under the pointer. */
580 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
586 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
587 event
->type
== GDK_BUTTON_RELEASE
))
589 GdkEventButton
*bev
= (GdkEventButton
*) event
;
591 pos
[0] = bev
->x_root
;
592 pos
[1] = bev
->y_root
;
593 button
= bev
->button
;
596 else if (event
&& event
->type
== GDK_KEY_PRESS
)
598 GdkEventKey
*kev
= (GdkEventKey
*) event
;
600 get_pointer_xy(pos
, pos
+ 1);
604 get_pointer_xy(pos
, pos
+ 1);
608 gtk_widget_show_all(menu
);
609 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
610 position_menu
, (gpointer
) pos
, button
, time
);
611 select_nth_item(GTK_MENU_SHELL(menu
), item
);
614 /* Hide the popup menu, if any */
615 void menu_popdown(void)
618 gtk_menu_popdown(GTK_MENU(popup_menu
));
621 static MenuIconStyle
get_menu_icon_style(void)
626 mis
= o_menu_iconsize
.int_value
;
630 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
636 if (mis
== MIS_CURRENT
&& window_with_focus
)
638 switch (window_with_focus
->display_style
)
650 display
= o_display_size
.int_value
;
665 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
667 DirItem
*file_item
= NULL
;
668 GdkModifierType state
= 0;
674 /* Remove previous AppMenu, if any */
677 window_with_focus
= filer_window
;
679 if (event
->type
== GDK_BUTTON_PRESS
)
680 state
= ((GdkEventButton
*) event
)->state
;
681 else if (event
->type
== GDK_KEY_PRESS
)
682 state
= ((GdkEventKey
*) event
)->state
;
684 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
686 filer_window
->temp_item_selected
= TRUE
;
687 collection_select_item(filer_window
->collection
, item
);
691 filer_window
->temp_item_selected
= FALSE
;
694 /* Short-cut to the Send To menu */
695 if (state
& GDK_SHIFT_MASK
)
701 if (filer_window
->collection
->number_selected
== 0)
704 _("You should Shift+Menu click over a file to "
705 "send it somewhere"));
709 paths
= filer_selected_items(filer_window
);
711 show_send_to_menu(paths
, event
); /* (paths eaten) */
717 GtkWidget
*file_label
, *file_menu
;
718 Collection
*collection
= filer_window
->collection
;
722 file_label
= filer_file_item
;
723 file_menu
= filer_file_menu
;
724 gtk_check_menu_item_set_active(
725 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
726 filer_window
->show_thumbs
);
727 gtk_check_menu_item_set_active(
728 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
729 filer_window
->show_hidden
);
730 buffer
= g_string_new(NULL
);
732 switch (collection
->number_selected
)
735 g_string_assign(buffer
, _("Next Click"));
736 shade_file_menu_items(FALSE
);
739 item
= filer_selected_item(filer_window
);
741 dir_update_item(filer_window
->directory
,
743 shade_file_menu_items(FALSE
);
744 file_item
= filer_selected_item(filer_window
);
745 g_string_sprintf(buffer
, "%s '%s'",
746 basetype_name(file_item
),
747 file_item
->leafname
);
748 if (!can_set_run_action(file_item
))
749 menu_set_items_shaded(filer_file_menu
,
753 shade_file_menu_items(TRUE
);
754 g_string_sprintf(buffer
, _("%d items"),
755 collection
->number_selected
);
758 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
759 g_string_free(buffer
, TRUE
);
761 menu_show_shift_action(file_shift_item
, file_item
,
762 collection
->number_selected
== 0);
764 appmenu_add(make_path(filer_window
->sym_path
,
765 file_item
->leafname
)->str
,
766 file_item
, filer_file_menu
);
769 update_new_files_menu(get_menu_icon_style());
771 gtk_widget_set_sensitive(filer_new_window
,
772 !o_unique_filer_windows
.int_value
);
773 gtk_widget_set_sensitive(filer_follow_sym
,
774 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
776 popup_menu
= (state
& GDK_CONTROL_MASK
)
782 show_popup_menu(popup_menu
, event
,
783 popup_menu
== filer_file_menu
? 5 : 1);
786 static void menu_closed(GtkWidget
*widget
)
788 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
789 return; /* Close panel item chosen? */
793 if (window_with_focus
->temp_item_selected
)
795 collection_clear_selection(window_with_focus
->collection
);
796 window_with_focus
->temp_item_selected
= FALSE
;
800 void target_callback(FilerWindow
*filer_window
,
804 Collection
*collection
= filer_window
->collection
;
806 g_return_if_fail(window_with_focus
!= NULL
);
807 g_return_if_fail(window_with_focus
== filer_window
);
809 /* Don't grab the primary selection */
810 filer_window
->temp_item_selected
= TRUE
;
812 collection_wink_item(collection
, item
);
813 collection_clear_except(collection
, item
);
814 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
816 if (item
< collection
->number_of_items
)
817 collection_unselect_item(collection
, item
);
818 filer_window
->temp_item_selected
= FALSE
;
821 /* Set the text of the 'Shift Open...' menu item.
822 * If icon is NULL, reset the text and also shade it, unless 'next'.
824 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
826 guchar
*shift_action
= NULL
;
830 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
832 if (item
->flags
& ITEM_FLAG_MOUNTED
)
833 shift_action
= N_("Unmount");
835 shift_action
= N_("Mount");
837 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
838 shift_action
= N_("Show Target");
839 else if (item
->base_type
== TYPE_DIRECTORY
)
840 shift_action
= N_("Look Inside");
841 else if (item
->base_type
== TYPE_FILE
)
842 shift_action
= N_("Open As Text");
844 gtk_label_set_text(GTK_LABEL(menu_item
),
845 shift_action
? _(shift_action
)
847 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
852 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
854 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
857 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
859 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
862 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
864 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
867 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
869 g_return_if_fail(window_with_focus
!= NULL
);
871 display_set_sort_fn(window_with_focus
, sort_by_name
);
874 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
876 g_return_if_fail(window_with_focus
!= NULL
);
878 display_set_sort_fn(window_with_focus
, sort_by_type
);
881 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
883 g_return_if_fail(window_with_focus
!= NULL
);
885 display_set_sort_fn(window_with_focus
, sort_by_date
);
888 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
890 g_return_if_fail(window_with_focus
!= NULL
);
892 display_set_sort_fn(window_with_focus
, sort_by_size
);
895 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
900 g_return_if_fail(window_with_focus
!= NULL
);
902 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
905 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
910 g_return_if_fail(window_with_focus
!= NULL
);
912 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
915 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
917 g_return_if_fail(window_with_focus
!= NULL
);
920 filer_update_dir(window_with_focus
, TRUE
);
923 static void delete(FilerWindow
*filer_window
)
926 paths
= filer_selected_items(filer_window
);
927 action_delete(paths
);
928 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
932 static void usage(FilerWindow
*filer_window
)
935 paths
= filer_selected_items(filer_window
);
937 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
941 static void chmod_items(FilerWindow
*filer_window
)
944 paths
= filer_selected_items(filer_window
);
946 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
950 static void find(FilerWindow
*filer_window
)
953 paths
= filer_selected_items(filer_window
);
955 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
959 /* This creates a new savebox widget, and allows the user to pick a new path
961 * Once the new path has been picked, the callback will be called with
962 * both the current and new paths.
963 * NOTE: This function unrefs 'image'!
965 static void savebox_show(const gchar
*action
, const gchar
*path
,
966 MaskedPixmap
*image
, SaveCb callback
)
968 GtkWidget
*savebox
= NULL
;
969 GtkWidget
*check_relative
= NULL
;
971 g_return_if_fail(image
!= NULL
);
973 savebox
= gtk_savebox_new(action
);
975 if (callback
== link_cb
)
977 check_relative
= gtk_check_button_new_with_mnemonic(
978 _("_Relative link"));
979 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
982 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
983 gtk_tooltips_set_tip(tooltips
, check_relative
,
984 _("If on, the symlink will store the path from the "
985 "symlink to the target file. Use this if the symlink "
986 "and the target will be moved together.\n"
987 "If off, the path from the root directory is stored - "
988 "use this if the symlink may move but the target will "
990 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
991 check_relative
, FALSE
, TRUE
, 0);
992 gtk_widget_show(check_relative
);
995 g_signal_connect(savebox
, "save_to_file",
996 G_CALLBACK(save_to_file
), NULL
);
998 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
999 g_strdup(path
), g_free
);
1000 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1001 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1003 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1005 if (g_utf8_validate(path
, -1, NULL
))
1006 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1011 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1014 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1015 g_object_unref(image
);
1017 gtk_widget_show(savebox
);
1020 static gint
save_to_file(GObject
*savebox
,
1021 const gchar
*pathname
, gpointer data
)
1024 const gchar
*current_path
;
1026 callback
= g_object_get_data(savebox
, "action_callback");
1027 current_path
= g_object_get_data(savebox
, "current_path");
1029 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1030 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1032 return callback(savebox
, current_path
, pathname
)
1033 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1036 static gboolean
copy_cb(GObject
*savebox
,
1037 const gchar
*current
, const gchar
*new)
1039 return action_with_leaf(action_copy
, current
, new);
1042 static gboolean
action_with_leaf(ActionFn action
,
1043 const gchar
*current
, const gchar
*new)
1051 report_error(_("New pathname is not absolute"));
1055 if (new[strlen(new) - 1] == '/')
1057 new_dir
= g_strdup(new);
1064 slash
= strrchr(new, '/');
1065 new_dir
= g_strndup(new, slash
- new);
1069 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1070 action(local_paths
, new_dir
, leaf
, -1);
1071 g_list_free(local_paths
);
1078 /* Open a savebox to act on the selected file.
1079 * Call 'callback' later to perform the operation.
1081 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1082 const gchar
*action
, SaveCb callback
)
1084 g_object_ref(image
);
1085 savebox_show(action
, path
, image
, callback
);
1088 static gboolean
rename_cb(GObject
*savebox
,
1089 const gchar
*current
, const gchar
*new)
1091 return action_with_leaf(action_move
, current
, new);
1094 static gboolean
link_cb(GObject
*savebox
,
1095 const gchar
*initial
, const gchar
*path
)
1097 GtkToggleButton
*check_relative
;
1102 check_relative
= g_object_get_data(savebox
, "check_relative");
1104 if (gtk_toggle_button_get_active(check_relative
))
1105 link_path
= get_relative_path(path
, initial
);
1107 link_path
= g_strdup(initial
);
1109 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1111 GtkWidget
*box
, *button
;
1114 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1116 _("Symlink from '%s' already exists. "
1117 "Replace it with a link to '%s'?"),
1120 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1122 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1123 gtk_widget_show(button
);
1124 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1125 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1126 button
, GTK_RESPONSE_OK
);
1127 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1130 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1131 gtk_widget_destroy(box
);
1133 if (ans
!= GTK_RESPONSE_OK
)
1142 err
= symlink(link_path
, path
);
1147 report_error("symlink: %s", g_strerror(errno
));
1151 dir_check_this(path
);
1156 static void run_action(DirItem
*item
)
1158 if (can_set_run_action(item
))
1159 type_set_handler_dialog(item
->mime_type
);
1162 _("You can only set the run action for a "
1166 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1168 filer_opendir(home_dir
, NULL
);
1171 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1175 path
= g_strconcat(filer_window
->sym_path
,
1176 "/", item
->leafname
, "#", NULL
);
1178 filer_change_to(filer_window
, path
, NULL
);
1182 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1184 g_return_if_fail(window_with_focus
!= NULL
);
1186 window_with_focus
->temp_item_selected
= FALSE
;
1187 collection_select_all(window_with_focus
->collection
);
1190 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1192 g_return_if_fail(window_with_focus
!= NULL
);
1194 window_with_focus
->temp_item_selected
= FALSE
;
1195 collection_clear_selection(window_with_focus
->collection
);
1198 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1200 g_return_if_fail(window_with_focus
!= NULL
);
1202 window_with_focus
->temp_item_selected
= FALSE
;
1203 collection_invert_selection(window_with_focus
->collection
);
1206 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1210 win
= options_show();
1214 number_of_windows
++;
1215 g_signal_connect(win
, "destroy",
1216 G_CALLBACK(one_less_window
), NULL
);
1220 static gboolean
new_directory_cb(GObject
*savebox
,
1221 const gchar
*initial
, const gchar
*path
)
1223 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1225 report_error("mkdir: %s", g_strerror(errno
));
1229 dir_check_this(path
);
1231 if (filer_exists(window_with_focus
))
1234 leaf
= strrchr(path
, '/');
1236 display_set_autoselect(window_with_focus
, leaf
+ 1);
1242 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1244 g_return_if_fail(window_with_focus
!= NULL
);
1246 savebox_show(_("Create"),
1247 make_path(window_with_focus
->sym_path
, _("NewDir"))->str
,
1248 type_to_icon(inode_directory
), new_directory_cb
);
1251 static gboolean
new_file_cb(GObject
*savebox
,
1252 const gchar
*initial
, const gchar
*path
)
1256 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1260 report_error(_("Error creating '%s': %s"),
1261 path
, g_strerror(errno
));
1266 report_error(_("Error creating '%s': %s"),
1267 path
, g_strerror(errno
));
1269 dir_check_this(path
);
1271 if (filer_exists(window_with_focus
))
1274 leaf
= strrchr(path
, '/');
1276 display_set_autoselect(window_with_focus
, leaf
+ 1);
1282 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1284 g_return_if_fail(window_with_focus
!= NULL
);
1286 savebox_show(_("Create"),
1287 make_path(window_with_focus
->sym_path
, _("NewFile"))->str
,
1288 type_to_icon(text_plain
),
1292 static gboolean
new_file_type_cb(GObject
*savebox
,
1293 const gchar
*initial
, const gchar
*path
)
1295 const gchar
*oleaf
, *leaf
;
1296 gchar
*templ
, *templ_dname
, *dest
;
1299 /* We can work out the template path from the initial name */
1300 oleaf
= g_basename(initial
);
1301 templ_dname
= choices_find_path_load("Templates", "");
1305 _("Error creating file: could not find the template for %s"),
1310 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1311 g_free(templ_dname
);
1313 dest
= g_dirname(path
);
1314 leaf
= g_basename(path
);
1315 paths
= g_list_append(NULL
, templ
);
1317 action_copy(paths
, dest
, leaf
, TRUE
);
1323 if (filer_exists(window_with_focus
))
1324 display_set_autoselect(window_with_focus
, leaf
);
1329 static void do_send_to(gchar
*templ
)
1331 g_return_if_fail(send_to_paths
!= NULL
);
1333 run_with_files(templ
, send_to_paths
);
1336 static void new_file_type(gchar
*templ
)
1341 g_return_if_fail(window_with_focus
!= NULL
);
1343 leaf
= g_basename(templ
);
1344 type
= type_get_type(templ
);
1346 savebox_show(_("Create"),
1347 make_path(window_with_focus
->sym_path
, leaf
)->str
,
1352 static void customise_send_to(gpointer data
)
1359 dirs
= g_string_new(NULL
);
1361 path
= choices_list_dirs("");
1362 for (i
= 0; i
< path
->len
; i
++)
1364 guchar
*old
= (guchar
*) path
->pdata
[i
];
1366 g_string_append(dirs
, old
);
1367 g_string_append(dirs
, "SendTo\n");
1369 choices_free_list(path
);
1371 save
= choices_find_path_save("", "SendTo", TRUE
);
1376 _("The `Send To' menu provides a quick way to send some files "
1377 "to an application. The applications listed are those in "
1378 "the following directories:\n\n%s\n%s\n"
1379 "The `Send To' menu may be opened by Shift+Menu clicking "
1382 "You can also create subdirectories called "
1383 "`.text_html', `.text', etc which will only be "
1384 "shown for files of that type. `.group' is shown "
1385 "only when multiple files are selected."),
1387 save
? _("I'll show you your SendTo directory now; you should "
1388 "symlink (Ctrl+Shift drag) any applications you want "
1390 : _("Your CHOICESPATH variable setting prevents "
1391 "customisations - sorry."));
1393 g_string_free(dirs
, TRUE
);
1396 filer_opendir(save
, NULL
);
1399 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1402 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1409 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1411 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1413 searchdir
= g_strdup("SendTo");
1415 paths
= choices_list_dirs(searchdir
);
1418 for (i
= 0; i
< paths
->len
; i
++)
1420 GList
*widgets
= NULL
;
1421 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1423 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1424 (CallbackFn
) do_send_to
,
1425 FALSE
, FALSE
, TRUE
);
1428 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1429 gtk_menu_item_new());
1431 g_list_free(widgets
); /* TODO: Get rid of this */
1434 choices_free_list(paths
);
1437 /* Scan the SendTo dir and create and show the Send To menu.
1438 * The 'paths' list and every path in it is claimed, and will be
1439 * freed later -- don't free it yourself!
1441 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1443 GtkWidget
*menu
, *item
;
1445 menu
= gtk_menu_new();
1447 if (g_list_length(paths
) == 1)
1451 item
= diritem_new("");
1452 diritem_restat(paths
->data
, item
, NULL
);
1455 item
->mime_type
->media_type
,
1456 item
->mime_type
->subtype
);
1458 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1463 add_sendto(menu
, "group", NULL
);
1465 add_sendto(menu
, NULL
, NULL
);
1467 item
= gtk_menu_item_new_with_label(_("Customise"));
1468 g_signal_connect_swapped(item
, "activate",
1469 G_CALLBACK(customise_send_to
), NULL
);
1470 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1474 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1475 g_list_free(send_to_paths
);
1477 send_to_paths
= paths
;
1479 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1482 show_popup_menu(menu
, event
, 0);
1485 static void send_to(FilerWindow
*filer_window
)
1490 paths
= filer_selected_items(filer_window
);
1491 event
= gtk_get_current_event();
1494 show_send_to_menu(paths
, event
);
1496 gdk_event_free(event
);
1499 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1501 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1503 argv
[2] = o_menu_xterm
.value
;
1505 g_return_if_fail(window_with_focus
!= NULL
);
1507 rox_spawn(window_with_focus
->sym_path
, argv
);
1510 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1512 g_return_if_fail(window_with_focus
!= NULL
);
1514 filer_change_to(window_with_focus
, home_dir
, NULL
);
1517 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1519 g_return_if_fail(window_with_focus
!= NULL
);
1521 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1522 filer_change_to(window_with_focus
,
1523 window_with_focus
->real_path
, NULL
);
1525 delayed_error(_("This is already the canonical name "
1526 "for this directory."));
1529 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1531 g_return_if_fail(window_with_focus
!= NULL
);
1533 filer_open_parent(window_with_focus
);
1536 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1538 g_return_if_fail(window_with_focus
!= NULL
);
1540 change_to_parent(window_with_focus
);
1543 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1545 g_return_if_fail(window_with_focus
!= NULL
);
1547 filer_window_autosize(window_with_focus
, TRUE
);
1550 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1552 g_return_if_fail(window_with_focus
!= NULL
);
1554 if (o_unique_filer_windows
.int_value
)
1556 report_error(_("You can't open a second view onto "
1557 "this directory because the `Unique Windows' option "
1558 "is turned on in the Options window."));
1561 filer_opendir(window_with_focus
->sym_path
, window_with_focus
);
1565 static void su_to_user(GtkWidget
*dialog
)
1568 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1572 g_return_if_fail(dialog
!= NULL
);
1574 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1575 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1577 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1579 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1580 argv
[3] = gtk_entry_get_text(user
);
1581 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1585 report_error(_("fork: %s"), g_strerror(errno
));
1590 gtk_widget_destroy(dialog
);
1593 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1595 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1597 g_return_if_fail(window_with_focus
!= NULL
);
1599 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1600 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1601 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1602 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1603 g_strdup(window_with_focus
->path
), g_free
);
1605 vbox
= gtk_vbox_new(FALSE
, 4);
1606 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1607 gtk_box_pack_start(GTK_BOX(vbox
),
1608 gtk_label_new(_("Browse as which user?")),
1611 hbox
= gtk_hbox_new(FALSE
, 4);
1612 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1614 gtk_box_pack_start(GTK_BOX(hbox
),
1615 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1617 entry
= gtk_entry_new();
1618 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1619 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1620 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1621 gtk_widget_grab_focus(entry
);
1622 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1623 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1624 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1626 hbox
= gtk_hbox_new(TRUE
, 0);
1627 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1629 button
= gtk_button_new_with_label(_("OK"));
1630 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1631 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1632 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1633 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1634 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1636 button
= gtk_button_new_with_label(_("Cancel"));
1637 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1638 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1639 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1640 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1641 GTK_OBJECT(dialog
));
1643 gtk_widget_show_all(dialog
);
1647 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1649 g_return_if_fail(window_with_focus
!= NULL
);
1651 gtk_widget_destroy(window_with_focus
->window
);
1654 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1656 MiniType type
= (MiniType
) action
;
1658 g_return_if_fail(window_with_focus
!= NULL
);
1660 /* Item needs to remain selected... */
1661 if (type
== MINI_SHELL
)
1662 window_with_focus
->temp_item_selected
= FALSE
;
1664 minibuffer_show(window_with_focus
, type
);
1667 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1669 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1672 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1673 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1675 GList
*items
, *item
;
1677 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1679 item
= g_list_nth(items
, from
);
1682 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1688 static void save_menus(void)
1692 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1695 gtk_accel_map_save(menurc
);
1700 static void keys_changed(gpointer data
)
1705 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1710 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1711 item
= g_list_nth_data(items
, n
);
1713 g_return_if_fail(item
!= NULL
);
1717 gtk_menu_shell_select_item(shell
, item
);
1720 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1722 Collection
*collection
;
1726 g_return_if_fail(window_with_focus
!= NULL
);
1728 collection
= window_with_focus
->collection
;
1730 if (collection
->number_selected
< 1)
1736 case FILE_COPY_ITEM
:
1737 prompt
= _("Copy ... ?");
1739 case FILE_RENAME_ITEM
:
1740 prompt
= _("Rename ... ?");
1742 case FILE_LINK_ITEM
:
1743 prompt
= _("Symlink ... ?");
1745 case FILE_OPEN_FILE
:
1746 prompt
= _("Shift Open ... ?");
1749 prompt
= _("Help about ... ?");
1751 case FILE_SHOW_FILE_INFO
:
1752 prompt
= _("Examine ... ?");
1754 case FILE_RUN_ACTION
:
1755 prompt
= _("Set run action for ... ?");
1758 prompt
= _("Set icon for ... ?");
1761 prompt
= _("Send ... to ... ?");
1764 prompt
= _("DELETE ... ?");
1767 prompt
= _("Count the size of ... ?");
1769 case FILE_CHMOD_ITEMS
:
1770 prompt
= _("Set permissions on ... ?");
1773 prompt
= _("Search inside ... ?");
1775 case FILE_OPEN_VFS_AVFS
:
1776 prompt
= _("Look inside ... ?");
1779 g_warning("Unknown action!");
1782 filer_target_mode(window_with_focus
, target_callback
,
1783 GINT_TO_POINTER(action
), prompt
);
1790 send_to(window_with_focus
);
1793 delete(window_with_focus
);
1796 usage(window_with_focus
);
1798 case FILE_CHMOD_ITEMS
:
1799 chmod_items(window_with_focus
);
1802 find(window_with_focus
);
1804 case FILE_SHOW_FILE_INFO
:
1808 items
= filer_selected_items(window_with_focus
);
1809 infobox_show_list(items
);
1810 g_list_foreach(items
, (GFunc
) g_free
, NULL
);
1818 /* All the following actions require exactly one file selected */
1820 if (collection
->number_selected
> 1)
1822 report_error(_("You cannot do this to more than "
1823 "one item at a time"));
1827 item
= filer_selected_item(window_with_focus
);
1828 g_return_if_fail(item
!= NULL
);
1830 item
= dir_update_item(window_with_focus
->directory
,
1835 report_error(_("Item no longer exists!"));
1839 path
= make_path(window_with_focus
->sym_path
, item
->leafname
)->str
;
1843 case FILE_COPY_ITEM
:
1844 src_dest_action_item(path
, item
->image
,
1845 _("Copy"), copy_cb
);
1847 case FILE_RENAME_ITEM
:
1848 src_dest_action_item(path
, item
->image
,
1849 _("Rename"), rename_cb
);
1851 case FILE_LINK_ITEM
:
1852 src_dest_action_item(path
, item
->image
,
1853 _("Symlink"), link_cb
);
1855 case FILE_OPEN_FILE
:
1856 filer_openitem(window_with_focus
,
1857 collection_selected_item_number(collection
),
1858 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1861 show_item_help(path
, item
);
1863 case FILE_RUN_ACTION
:
1867 icon_set_handler_dialog(item
, path
);
1869 case FILE_OPEN_VFS_AVFS
:
1870 open_vfs_avfs(window_with_focus
, item
);
1873 g_warning("Unknown action!");
1878 static void show_key_help(GtkWidget
*button
, gpointer data
)
1880 gboolean can_change_accels
;
1882 g_object_get(G_OBJECT(gtk_settings_get_default()),
1883 "gtk-can-change-accels", &can_change_accels
,
1886 if (!can_change_accels
)
1888 info_message(_("User-definable shortcuts are disabled by "
1889 "default in Gtk2, and you have not enabled "
1890 "them. You can turn this feature on by:\n"
1891 "1) using an XSettings manager, such as ROX-Session\n"
1893 "2) adding this line to ~/.gtkrc-2.0:\n"
1894 "\tgtk-can-change-accels = 1"));
1898 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1899 "- Open the menu over a filer window,\n"
1900 "- Move the pointer over the item you want to use,\n"
1901 "- Press the key you want attached to it.\n\n"
1902 "The key will appear next to the menu item and you can just press "
1903 "that key without opening the menu in future."));
1906 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1908 GtkWidget
*button
, *align
;
1910 g_return_val_if_fail(option
== NULL
, NULL
);
1912 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1913 button
= button_new_mixed(GTK_STOCK_DIALOG_INFO
,
1914 _("Set keyboard shortcuts"));
1915 gtk_container_add(GTK_CONTAINER(align
), button
);
1916 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1918 return g_list_append(NULL
, align
);