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_("Window"), NULL
, NULL
, 0, "<Branch>"},
233 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
234 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
235 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
236 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
237 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
238 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
239 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
241 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
242 {">", NULL
, NULL
, 0, "<Separator>"},
243 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
244 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
245 {">" N_("Xterm Here"), NULL
, xterm_here
, FALSE
, NULL
},
246 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, 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); \
269 void ensure_filer_menu(void)
274 GtkItemFactory
*item_factory
;
279 filer_keys
= gtk_accel_group_new();
280 item_factory
= menu_create(filer_menu_def
,
281 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
282 "<filer>", filer_keys
);
284 GET_MENU_ITEM(filer_menu
, "filer");
285 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
286 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
287 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
290 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
291 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
292 filer_follow_sym
= GTK_BIN(item
)->child
;
294 /* File '' label... */
295 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
296 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
299 /* Shift Open... label */
300 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
301 file_shift_item
= GTK_BIN(g_list_nth(items
, 3)->data
)->child
;
304 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
305 filer_new_window
= GTK_BIN(item
)->child
;
307 g_signal_connect(filer_menu
, "unmap_event",
308 G_CALLBACK(menu_closed
), NULL
);
309 g_signal_connect(filer_file_menu
, "unmap_event",
310 G_CALLBACK(menu_closed
), NULL
);
312 g_signal_connect_object(G_OBJECT(filer_keys
), "accel_changed",
313 (GCallback
) keys_changed
, NULL
, 0);
320 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
323 gtk_accel_map_load(menurc
);
327 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
328 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
329 option_add_saver(save_menus
);
331 option_register_widget("menu-set-keys", set_keys_button
);
334 /* Name is in the form "<panel>" */
335 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
336 const gchar
*name
, GtkAccelGroup
*keys
)
338 GtkItemFactory
*item_factory
;
339 GtkItemFactoryEntry
*translated
;
343 keys
= gtk_accel_group_new();
344 gtk_accel_group_lock(keys
);
347 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
349 translated
= translate_entries(def
, n_entries
);
350 gtk_item_factory_create_items(item_factory
, n_entries
,
352 free_translated_entries(translated
, n_entries
);
357 /* Prevent the user from setting a short-cut on this item */
358 void menuitem_no_shortcuts(GtkWidget
*item
)
362 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
364 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
365 g_free(menuitem
->accel_path
);
366 menuitem
->accel_path
= NULL
;
370 static void shade_file_menu_items(gboolean shaded
)
372 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 5);
373 menu_set_items_shaded(filer_file_menu
, shaded
, 6, 3);
376 /* 'data' is an array of three ints:
377 * [ pointer_x, pointer_y, item_under_pointer ]
379 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
380 gboolean
*push_in
, gpointer data
)
382 int *pos
= (int *) data
;
383 GtkRequisition requisition
;
388 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
390 while (item
>= 0 && next
)
392 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
405 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
407 *x
= pos
[0] - (requisition
.width
* 7 / 8);
408 *y
= pos
[1] - y_shift
;
410 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
411 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
417 /* Used when you menu-click on the Large or Small toolbar tools */
418 void show_style_menu(FilerWindow
*filer_window
,
419 GdkEventButton
*event
,
424 pos
[0] = event
->x_root
;
425 pos
[1] = event
->y_root
;
428 window_with_focus
= filer_window
;
432 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
433 (gpointer
) pos
, event
->button
, event
->time
);
437 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dname
,
438 MenuIconStyle style
, CallbackFn func
,
439 gboolean separator
, gboolean strip_ext
,
442 GList
*widgets
= NULL
;
448 dir
= opendir(dname
);
454 item
= gtk_menu_item_new();
455 widgets
= g_list_append(widgets
, item
);
456 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
459 while ((ent
= readdir(dir
)))
467 /* Ignore hidden files */
468 if (ent
->d_name
[0] == '.')
471 /* Strip off extension, if any */
472 dot
= strchr(ent
->d_name
, '.');
473 if (strip_ext
&& dot
)
474 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
476 leaf
= g_strdup(ent
->d_name
);
478 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
479 ditem
= diritem_new("");
480 diritem_restat(fname
, ditem
, NULL
);
482 if (ditem
->image
&& style
!= MIS_NONE
)
488 pixbuf
= ditem
->image
->pixbuf
;
491 if (!ditem
->image
->sm_pixbuf
)
492 pixmap_make_small(ditem
->image
);
493 pixbuf
= ditem
->image
->sm_pixbuf
;
497 item
= gtk_menu_item_new();
498 /* TODO: Find a way to allow short-cuts */
499 menuitem_no_shortcuts(item
);
501 hbox
= gtk_hbox_new(FALSE
, 2);
502 gtk_container_add(GTK_CONTAINER(item
), hbox
);
504 img
= gtk_image_new_from_pixbuf(pixbuf
);
506 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
508 label
= gtk_label_new(leaf
);
509 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
510 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
514 item
= gtk_menu_item_new_with_label(leaf
);
516 /* If it is a directory (but NOT an AppDir) and we are
517 * recursing then set up a sub menu.
519 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
520 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
525 sub
= gtk_menu_new();
526 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
527 separator
, strip_ext
, FALSE
);
528 g_list_free(new_widgets
);
529 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
532 g_signal_connect_swapped(item
, "activate",
533 G_CALLBACK(func
), fname
);
538 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
539 g_signal_connect_swapped(item
, "destroy",
540 G_CALLBACK(g_free
), fname
);
542 widgets
= g_list_append(widgets
, item
);
551 /* Scan the templates dir and create entries for the New menu */
552 static void update_new_files_menu(MenuIconStyle style
)
554 static GList
*widgets
= NULL
;
556 gchar
*templ_dname
= NULL
;
562 for (next
= widgets
; next
; next
= next
->next
)
563 gtk_widget_destroy((GtkWidget
*) next
->data
);
565 g_list_free(widgets
);
569 templ_dname
= choices_find_path_load("Templates", "");
572 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
573 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
577 gtk_widget_show_all(filer_new_menu
);
580 /* 'item' is the number of the item to appear under the pointer. */
581 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
587 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
588 event
->type
== GDK_BUTTON_RELEASE
))
590 GdkEventButton
*bev
= (GdkEventButton
*) event
;
592 pos
[0] = bev
->x_root
;
593 pos
[1] = bev
->y_root
;
594 button
= bev
->button
;
597 else if (event
&& event
->type
== GDK_KEY_PRESS
)
599 GdkEventKey
*kev
= (GdkEventKey
*) event
;
601 get_pointer_xy(pos
, pos
+ 1);
605 get_pointer_xy(pos
, pos
+ 1);
609 gtk_widget_show_all(menu
);
610 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
611 position_menu
, (gpointer
) pos
, button
, time
);
612 select_nth_item(GTK_MENU_SHELL(menu
), item
);
615 /* Hide the popup menu, if any */
616 void menu_popdown(void)
619 gtk_menu_popdown(GTK_MENU(popup_menu
));
622 static MenuIconStyle
get_menu_icon_style(void)
627 mis
= o_menu_iconsize
.int_value
;
631 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
637 if (mis
== MIS_CURRENT
&& window_with_focus
)
639 switch (window_with_focus
->display_style
)
651 display
= o_display_size
.int_value
;
666 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
668 DirItem
*file_item
= NULL
;
669 GdkModifierType state
= 0;
675 /* Remove previous AppMenu, if any */
678 window_with_focus
= filer_window
;
680 if (event
->type
== GDK_BUTTON_PRESS
)
681 state
= ((GdkEventButton
*) event
)->state
;
682 else if (event
->type
== GDK_KEY_PRESS
)
683 state
= ((GdkEventKey
*) event
)->state
;
685 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
687 filer_window
->temp_item_selected
= TRUE
;
688 collection_select_item(filer_window
->collection
, item
);
692 filer_window
->temp_item_selected
= FALSE
;
695 /* Short-cut to the Send To menu */
696 if (state
& GDK_SHIFT_MASK
)
702 if (filer_window
->collection
->number_selected
== 0)
705 _("You should Shift+Menu click over a file to "
706 "send it somewhere"));
710 paths
= filer_selected_items(filer_window
);
712 show_send_to_menu(paths
, event
); /* (paths eaten) */
718 GtkWidget
*file_label
, *file_menu
;
719 Collection
*collection
= filer_window
->collection
;
723 file_label
= filer_file_item
;
724 file_menu
= filer_file_menu
;
725 gtk_check_menu_item_set_active(
726 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
727 filer_window
->show_thumbs
);
728 gtk_check_menu_item_set_active(
729 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
730 filer_window
->show_hidden
);
731 buffer
= g_string_new(NULL
);
733 switch (collection
->number_selected
)
736 g_string_assign(buffer
, _("Next Click"));
737 shade_file_menu_items(FALSE
);
740 item
= filer_selected_item(filer_window
);
742 dir_update_item(filer_window
->directory
,
744 shade_file_menu_items(FALSE
);
745 file_item
= filer_selected_item(filer_window
);
746 g_string_sprintf(buffer
, "%s '%s'",
747 basetype_name(file_item
),
748 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_sprintf(buffer
, _("%d items"),
756 collection
->number_selected
);
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
,
763 collection
->number_selected
== 0);
765 appmenu_add(make_path(filer_window
->sym_path
,
766 file_item
->leafname
)->str
,
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 collection_clear_selection(window_with_focus
->collection
);
797 window_with_focus
->temp_item_selected
= FALSE
;
801 void target_callback(FilerWindow
*filer_window
,
805 Collection
*collection
= filer_window
->collection
;
807 g_return_if_fail(window_with_focus
!= NULL
);
808 g_return_if_fail(window_with_focus
== filer_window
);
810 /* Don't grab the primary selection */
811 filer_window
->temp_item_selected
= TRUE
;
813 collection_wink_item(collection
, item
);
814 collection_clear_except(collection
, item
);
815 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
817 if (item
< collection
->number_of_items
)
818 collection_unselect_item(collection
, item
);
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_("Mount");
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 huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
855 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
858 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
860 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
863 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
865 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
868 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
870 g_return_if_fail(window_with_focus
!= NULL
);
872 display_set_sort_fn(window_with_focus
, sort_by_name
);
875 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
877 g_return_if_fail(window_with_focus
!= NULL
);
879 display_set_sort_fn(window_with_focus
, sort_by_type
);
882 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
884 g_return_if_fail(window_with_focus
!= NULL
);
886 display_set_sort_fn(window_with_focus
, sort_by_date
);
889 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
891 g_return_if_fail(window_with_focus
!= NULL
);
893 display_set_sort_fn(window_with_focus
, sort_by_size
);
896 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
901 g_return_if_fail(window_with_focus
!= NULL
);
903 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
906 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
911 g_return_if_fail(window_with_focus
!= NULL
);
913 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
916 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
918 g_return_if_fail(window_with_focus
!= NULL
);
921 filer_update_dir(window_with_focus
, TRUE
);
924 static void delete(FilerWindow
*filer_window
)
927 paths
= filer_selected_items(filer_window
);
928 action_delete(paths
);
929 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
933 static void usage(FilerWindow
*filer_window
)
936 paths
= filer_selected_items(filer_window
);
938 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
942 static void chmod_items(FilerWindow
*filer_window
)
945 paths
= filer_selected_items(filer_window
);
947 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
951 static void find(FilerWindow
*filer_window
)
954 paths
= filer_selected_items(filer_window
);
956 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
960 /* This creates a new savebox widget, and allows the user to pick a new path
962 * Once the new path has been picked, the callback will be called with
963 * both the current and new paths.
964 * NOTE: This function unrefs 'image'!
966 static void savebox_show(const gchar
*action
, const gchar
*path
,
967 MaskedPixmap
*image
, SaveCb callback
)
969 GtkWidget
*savebox
= NULL
;
970 GtkWidget
*check_relative
= NULL
;
972 g_return_if_fail(image
!= NULL
);
974 savebox
= gtk_savebox_new(action
);
976 if (callback
== link_cb
)
978 check_relative
= gtk_check_button_new_with_mnemonic(
979 _("_Relative link"));
980 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
983 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
984 gtk_tooltips_set_tip(tooltips
, check_relative
,
985 _("If on, the symlink will store the path from the "
986 "symlink to the target file. Use this if the symlink "
987 "and the target will be moved together.\n"
988 "If off, the path from the root directory is stored - "
989 "use this if the symlink may move but the target will "
991 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
992 check_relative
, FALSE
, TRUE
, 0);
993 gtk_widget_show(check_relative
);
996 g_signal_connect(savebox
, "save_to_file",
997 G_CALLBACK(save_to_file
), NULL
);
999 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1000 g_strdup(path
), g_free
);
1001 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1002 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1004 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1006 if (g_utf8_validate(path
, -1, NULL
))
1007 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1012 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1015 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1016 g_object_unref(image
);
1018 gtk_widget_show(savebox
);
1021 static gint
save_to_file(GObject
*savebox
,
1022 const gchar
*pathname
, gpointer data
)
1025 const gchar
*current_path
;
1027 callback
= g_object_get_data(savebox
, "action_callback");
1028 current_path
= g_object_get_data(savebox
, "current_path");
1030 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1031 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1033 return callback(savebox
, current_path
, pathname
)
1034 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1037 static gboolean
copy_cb(GObject
*savebox
,
1038 const gchar
*current
, const gchar
*new)
1040 return action_with_leaf(action_copy
, current
, new);
1043 static gboolean
action_with_leaf(ActionFn action
,
1044 const gchar
*current
, const gchar
*new)
1052 report_error(_("New pathname is not absolute"));
1056 if (new[strlen(new) - 1] == '/')
1058 new_dir
= g_strdup(new);
1065 slash
= strrchr(new, '/');
1066 new_dir
= g_strndup(new, slash
- new);
1070 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1071 action(local_paths
, new_dir
, leaf
, -1);
1072 g_list_free(local_paths
);
1079 /* Open a savebox to act on the selected file.
1080 * Call 'callback' later to perform the operation.
1082 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1083 const gchar
*action
, SaveCb callback
)
1085 g_object_ref(image
);
1086 savebox_show(action
, path
, image
, callback
);
1089 static gboolean
rename_cb(GObject
*savebox
,
1090 const gchar
*current
, const gchar
*new)
1092 return action_with_leaf(action_move
, current
, new);
1095 static gboolean
link_cb(GObject
*savebox
,
1096 const gchar
*initial
, const gchar
*path
)
1098 GtkToggleButton
*check_relative
;
1103 check_relative
= g_object_get_data(savebox
, "check_relative");
1105 if (gtk_toggle_button_get_active(check_relative
))
1106 link_path
= get_relative_path(path
, initial
);
1108 link_path
= g_strdup(initial
);
1110 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1112 GtkWidget
*box
, *button
;
1115 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1117 _("Symlink from '%s' already exists. "
1118 "Replace it with a link to '%s'?"),
1121 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1123 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1124 gtk_widget_show(button
);
1125 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1126 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1127 button
, GTK_RESPONSE_OK
);
1128 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1131 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1132 gtk_widget_destroy(box
);
1134 if (ans
!= GTK_RESPONSE_OK
)
1143 err
= symlink(link_path
, path
);
1148 report_error("symlink: %s", g_strerror(errno
));
1152 dir_check_this(path
);
1157 static void run_action(DirItem
*item
)
1159 if (can_set_run_action(item
))
1160 type_set_handler_dialog(item
->mime_type
);
1163 _("You can only set the run action for a "
1167 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1169 filer_opendir(home_dir
, NULL
);
1172 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1176 path
= g_strconcat(filer_window
->sym_path
,
1177 "/", item
->leafname
, "#", NULL
);
1179 filer_change_to(filer_window
, path
, NULL
);
1183 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1185 g_return_if_fail(window_with_focus
!= NULL
);
1187 window_with_focus
->temp_item_selected
= FALSE
;
1188 collection_select_all(window_with_focus
->collection
);
1191 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1193 g_return_if_fail(window_with_focus
!= NULL
);
1195 window_with_focus
->temp_item_selected
= FALSE
;
1196 collection_clear_selection(window_with_focus
->collection
);
1199 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1201 g_return_if_fail(window_with_focus
!= NULL
);
1203 window_with_focus
->temp_item_selected
= FALSE
;
1204 collection_invert_selection(window_with_focus
->collection
);
1207 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1211 win
= options_show();
1215 number_of_windows
++;
1216 g_signal_connect(win
, "destroy",
1217 G_CALLBACK(one_less_window
), NULL
);
1221 static gboolean
new_directory_cb(GObject
*savebox
,
1222 const gchar
*initial
, const gchar
*path
)
1224 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1226 report_error("mkdir: %s", g_strerror(errno
));
1230 dir_check_this(path
);
1232 if (filer_exists(window_with_focus
))
1235 leaf
= strrchr(path
, '/');
1237 display_set_autoselect(window_with_focus
, leaf
+ 1);
1243 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1245 g_return_if_fail(window_with_focus
!= NULL
);
1247 savebox_show(_("Create"),
1248 make_path(window_with_focus
->sym_path
, _("NewDir"))->str
,
1249 type_to_icon(inode_directory
), new_directory_cb
);
1252 static gboolean
new_file_cb(GObject
*savebox
,
1253 const gchar
*initial
, const gchar
*path
)
1257 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1261 report_error(_("Error creating '%s': %s"),
1262 path
, g_strerror(errno
));
1267 report_error(_("Error creating '%s': %s"),
1268 path
, g_strerror(errno
));
1270 dir_check_this(path
);
1272 if (filer_exists(window_with_focus
))
1275 leaf
= strrchr(path
, '/');
1277 display_set_autoselect(window_with_focus
, leaf
+ 1);
1283 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1285 g_return_if_fail(window_with_focus
!= NULL
);
1287 savebox_show(_("Create"),
1288 make_path(window_with_focus
->sym_path
, _("NewFile"))->str
,
1289 type_to_icon(text_plain
),
1293 static gboolean
new_file_type_cb(GObject
*savebox
,
1294 const gchar
*initial
, const gchar
*path
)
1296 const gchar
*oleaf
, *leaf
;
1297 gchar
*templ
, *templ_dname
, *dest
;
1300 /* We can work out the template path from the initial name */
1301 oleaf
= g_basename(initial
);
1302 templ_dname
= choices_find_path_load("Templates", "");
1306 _("Error creating file: could not find the template for %s"),
1311 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1312 g_free(templ_dname
);
1314 dest
= g_dirname(path
);
1315 leaf
= g_basename(path
);
1316 paths
= g_list_append(NULL
, templ
);
1318 action_copy(paths
, dest
, leaf
, TRUE
);
1324 if (filer_exists(window_with_focus
))
1325 display_set_autoselect(window_with_focus
, leaf
);
1330 static void do_send_to(gchar
*templ
)
1332 g_return_if_fail(send_to_paths
!= NULL
);
1334 run_with_files(templ
, send_to_paths
);
1337 static void new_file_type(gchar
*templ
)
1342 g_return_if_fail(window_with_focus
!= NULL
);
1344 leaf
= g_basename(templ
);
1345 type
= type_get_type(templ
);
1347 savebox_show(_("Create"),
1348 make_path(window_with_focus
->sym_path
, leaf
)->str
,
1353 static void customise_send_to(gpointer data
)
1360 dirs
= g_string_new(NULL
);
1362 path
= choices_list_dirs("");
1363 for (i
= 0; i
< path
->len
; i
++)
1365 guchar
*old
= (guchar
*) path
->pdata
[i
];
1367 g_string_append(dirs
, old
);
1368 g_string_append(dirs
, "SendTo\n");
1370 choices_free_list(path
);
1372 save
= choices_find_path_save("", "SendTo", TRUE
);
1377 _("The `Send To' menu provides a quick way to send some files "
1378 "to an application. The applications listed are those in "
1379 "the following directories:\n\n%s\n%s\n"
1380 "The `Send To' menu may be opened by Shift+Menu clicking "
1383 "You can also create subdirectories called "
1384 "`.text_html', `.text', etc which will only be "
1385 "shown for files of that type. `.group' is shown "
1386 "only when multiple files are selected."),
1388 save
? _("I'll show you your SendTo directory now; you should "
1389 "symlink (Ctrl+Shift drag) any applications you want "
1391 : _("Your CHOICESPATH variable setting prevents "
1392 "customisations - sorry."));
1394 g_string_free(dirs
, TRUE
);
1397 filer_opendir(save
, NULL
);
1400 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1403 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1410 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1412 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1414 searchdir
= g_strdup("SendTo");
1416 paths
= choices_list_dirs(searchdir
);
1419 for (i
= 0; i
< paths
->len
; i
++)
1421 GList
*widgets
= NULL
;
1422 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1424 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1425 (CallbackFn
) do_send_to
,
1426 FALSE
, FALSE
, TRUE
);
1429 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1430 gtk_menu_item_new());
1432 g_list_free(widgets
); /* TODO: Get rid of this */
1435 choices_free_list(paths
);
1438 /* Scan the SendTo dir and create and show the Send To menu.
1439 * The 'paths' list and every path in it is claimed, and will be
1440 * freed later -- don't free it yourself!
1442 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1444 GtkWidget
*menu
, *item
;
1446 menu
= gtk_menu_new();
1448 if (g_list_length(paths
) == 1)
1452 item
= diritem_new("");
1453 diritem_restat(paths
->data
, item
, NULL
);
1456 item
->mime_type
->media_type
,
1457 item
->mime_type
->subtype
);
1459 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1464 add_sendto(menu
, "group", NULL
);
1466 add_sendto(menu
, NULL
, NULL
);
1468 item
= gtk_menu_item_new_with_label(_("Customise"));
1469 g_signal_connect_swapped(item
, "activate",
1470 G_CALLBACK(customise_send_to
), NULL
);
1471 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1475 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1476 g_list_free(send_to_paths
);
1478 send_to_paths
= paths
;
1480 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1483 show_popup_menu(menu
, event
, 0);
1486 static void send_to(FilerWindow
*filer_window
)
1491 paths
= filer_selected_items(filer_window
);
1492 event
= gtk_get_current_event();
1495 show_send_to_menu(paths
, event
);
1497 gdk_event_free(event
);
1500 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1502 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1503 gboolean close
= action
;
1505 argv
[2] = o_menu_xterm
.value
;
1507 g_return_if_fail(window_with_focus
!= NULL
);
1509 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1510 gtk_widget_destroy(window_with_focus
->window
);
1513 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1515 g_return_if_fail(window_with_focus
!= NULL
);
1517 filer_change_to(window_with_focus
, home_dir
, NULL
);
1520 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1522 g_return_if_fail(window_with_focus
!= NULL
);
1524 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1525 filer_change_to(window_with_focus
,
1526 window_with_focus
->real_path
, NULL
);
1528 delayed_error(_("This is already the canonical name "
1529 "for this directory."));
1532 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1534 g_return_if_fail(window_with_focus
!= NULL
);
1536 filer_open_parent(window_with_focus
);
1539 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1541 g_return_if_fail(window_with_focus
!= NULL
);
1543 change_to_parent(window_with_focus
);
1546 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1548 g_return_if_fail(window_with_focus
!= NULL
);
1550 filer_window_autosize(window_with_focus
, TRUE
);
1553 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1555 g_return_if_fail(window_with_focus
!= NULL
);
1557 if (o_unique_filer_windows
.int_value
)
1559 report_error(_("You can't open a second view onto "
1560 "this directory because the `Unique Windows' option "
1561 "is turned on in the Options window."));
1564 filer_opendir(window_with_focus
->sym_path
, window_with_focus
);
1568 static void su_to_user(GtkWidget
*dialog
)
1571 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1575 g_return_if_fail(dialog
!= NULL
);
1577 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1578 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1580 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1582 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1583 argv
[3] = gtk_entry_get_text(user
);
1584 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1588 report_error(_("fork: %s"), g_strerror(errno
));
1593 gtk_widget_destroy(dialog
);
1596 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1598 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1600 g_return_if_fail(window_with_focus
!= NULL
);
1602 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1603 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1604 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1605 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1606 g_strdup(window_with_focus
->path
), g_free
);
1608 vbox
= gtk_vbox_new(FALSE
, 4);
1609 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1610 gtk_box_pack_start(GTK_BOX(vbox
),
1611 gtk_label_new(_("Browse as which user?")),
1614 hbox
= gtk_hbox_new(FALSE
, 4);
1615 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1617 gtk_box_pack_start(GTK_BOX(hbox
),
1618 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1620 entry
= gtk_entry_new();
1621 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1622 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1623 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1624 gtk_widget_grab_focus(entry
);
1625 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1626 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1627 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1629 hbox
= gtk_hbox_new(TRUE
, 0);
1630 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1632 button
= gtk_button_new_with_label(_("OK"));
1633 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1634 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1635 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1636 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1637 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1639 button
= gtk_button_new_with_label(_("Cancel"));
1640 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1641 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1642 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1643 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1644 GTK_OBJECT(dialog
));
1646 gtk_widget_show_all(dialog
);
1650 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1652 g_return_if_fail(window_with_focus
!= NULL
);
1654 gtk_widget_destroy(window_with_focus
->window
);
1657 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1659 MiniType type
= (MiniType
) action
;
1661 g_return_if_fail(window_with_focus
!= NULL
);
1663 /* Item needs to remain selected... */
1664 if (type
== MINI_SHELL
)
1665 window_with_focus
->temp_item_selected
= FALSE
;
1667 minibuffer_show(window_with_focus
, type
);
1670 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1672 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1675 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1676 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1678 GList
*items
, *item
;
1680 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1682 item
= g_list_nth(items
, from
);
1685 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1691 static void save_menus(void)
1695 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1698 gtk_accel_map_save(menurc
);
1703 static void keys_changed(gpointer data
)
1708 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1713 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1714 item
= g_list_nth_data(items
, n
);
1716 g_return_if_fail(item
!= NULL
);
1720 gtk_menu_shell_select_item(shell
, item
);
1723 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1725 Collection
*collection
;
1729 g_return_if_fail(window_with_focus
!= NULL
);
1731 collection
= window_with_focus
->collection
;
1733 if (collection
->number_selected
< 1)
1739 case FILE_COPY_ITEM
:
1740 prompt
= _("Copy ... ?");
1742 case FILE_RENAME_ITEM
:
1743 prompt
= _("Rename ... ?");
1745 case FILE_LINK_ITEM
:
1746 prompt
= _("Symlink ... ?");
1748 case FILE_OPEN_FILE
:
1749 prompt
= _("Shift Open ... ?");
1752 prompt
= _("Help about ... ?");
1754 case FILE_SHOW_FILE_INFO
:
1755 prompt
= _("Examine ... ?");
1757 case FILE_RUN_ACTION
:
1758 prompt
= _("Set run action for ... ?");
1761 prompt
= _("Set icon for ... ?");
1764 prompt
= _("Send ... to ... ?");
1767 prompt
= _("DELETE ... ?");
1770 prompt
= _("Count the size of ... ?");
1772 case FILE_CHMOD_ITEMS
:
1773 prompt
= _("Set permissions on ... ?");
1776 prompt
= _("Search inside ... ?");
1778 case FILE_OPEN_VFS_AVFS
:
1779 prompt
= _("Look inside ... ?");
1782 g_warning("Unknown action!");
1785 filer_target_mode(window_with_focus
, target_callback
,
1786 GINT_TO_POINTER(action
), prompt
);
1793 send_to(window_with_focus
);
1796 delete(window_with_focus
);
1799 usage(window_with_focus
);
1801 case FILE_CHMOD_ITEMS
:
1802 chmod_items(window_with_focus
);
1805 find(window_with_focus
);
1807 case FILE_SHOW_FILE_INFO
:
1811 items
= filer_selected_items(window_with_focus
);
1812 infobox_show_list(items
);
1813 g_list_foreach(items
, (GFunc
) g_free
, NULL
);
1821 /* All the following actions require exactly one file selected */
1823 if (collection
->number_selected
> 1)
1825 report_error(_("You cannot do this to more than "
1826 "one item at a time"));
1830 item
= filer_selected_item(window_with_focus
);
1831 g_return_if_fail(item
!= NULL
);
1833 item
= dir_update_item(window_with_focus
->directory
,
1838 report_error(_("Item no longer exists!"));
1842 path
= make_path(window_with_focus
->sym_path
, item
->leafname
)->str
;
1846 case FILE_COPY_ITEM
:
1847 src_dest_action_item(path
, item
->image
,
1848 _("Copy"), copy_cb
);
1850 case FILE_RENAME_ITEM
:
1851 src_dest_action_item(path
, item
->image
,
1852 _("Rename"), rename_cb
);
1854 case FILE_LINK_ITEM
:
1855 src_dest_action_item(path
, item
->image
,
1856 _("Symlink"), link_cb
);
1858 case FILE_OPEN_FILE
:
1859 filer_openitem(window_with_focus
,
1860 collection_selected_item_number(collection
),
1861 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1864 show_item_help(path
, item
);
1866 case FILE_RUN_ACTION
:
1870 icon_set_handler_dialog(item
, path
);
1872 case FILE_OPEN_VFS_AVFS
:
1873 open_vfs_avfs(window_with_focus
, item
);
1876 g_warning("Unknown action!");
1881 static void show_key_help(GtkWidget
*button
, gpointer data
)
1883 gboolean can_change_accels
;
1885 g_object_get(G_OBJECT(gtk_settings_get_default()),
1886 "gtk-can-change-accels", &can_change_accels
,
1889 if (!can_change_accels
)
1891 info_message(_("User-definable shortcuts are disabled by "
1892 "default in Gtk2, and you have not enabled "
1893 "them. You can turn this feature on by:\n"
1894 "1) using an XSettings manager, such as ROX-Session\n"
1896 "2) adding this line to ~/.gtkrc-2.0:\n"
1897 "\tgtk-can-change-accels = 1"));
1901 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1902 "- Open the menu over a filer window,\n"
1903 "- Move the pointer over the item you want to use,\n"
1904 "- Press the key you want attached to it.\n\n"
1905 "The key will appear next to the menu item and you can just press "
1906 "that key without opening the menu in future."));
1909 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1911 GtkWidget
*button
, *align
;
1913 g_return_val_if_fail(option
== NULL
, NULL
);
1915 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1916 button
= button_new_mixed(GTK_STOCK_DIALOG_INFO
,
1917 _("Set keyboard shortcuts"));
1918 gtk_container_add(GTK_CONTAINER(align
), button
);
1919 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1921 return g_list_append(NULL
, align
);