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 "view_iface.h"
61 #include "collection.h"
81 typedef enum menu_icon_style
{
82 MIS_NONE
, MIS_SMALL
, MIS_LARGE
,
84 MIS_CURRENT
, /* As per current filer window */
88 typedef void (*ActionFn
)(GList
*paths
,
89 const char *dest_dir
, const char *leaf
, int quiet
);
90 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
92 typedef gboolean (*SaveCb
)(GObject
*savebox
,
93 const gchar
*current
, const gchar
*new);
95 GtkAccelGroup
*filer_keys
= NULL
;
97 static GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
99 static gint updating_menu
= 0; /* Non-zero => ignore activations */
100 static GList
*send_to_paths
= NULL
;
102 static Option o_menu_iconsize
, o_menu_xterm
;
104 /* Static prototypes */
106 static void save_menus(void);
107 static void menu_closed(GtkWidget
*widget
);
108 static void shade_file_menu_items(gboolean shaded
);
109 static void savebox_show(const gchar
*action
, const gchar
*path
,
110 MaskedPixmap
*image
, SaveCb callback
);
111 static gint
save_to_file(GObject
*savebox
,
112 const gchar
*pathname
, gpointer data
);
113 static gboolean
action_with_leaf(ActionFn action
,
114 const gchar
*current
, const gchar
*new);
115 static gboolean
link_cb(GObject
*savebox
,
116 const gchar
*initial
, const gchar
*path
);
117 static void select_nth_item(GtkMenuShell
*shell
, int n
);
118 static void new_file_type(gchar
*templ
);
119 static void do_send_to(gchar
*templ
);
120 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
121 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
);
123 /* Note that for most of these callbacks none of the arguments are used. */
125 /* (action used in these three - DetailsType) */
126 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
141 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
149 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
150 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
151 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
152 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
153 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
154 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
156 /* (action used in this - MiniType) */
157 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
158 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
160 #define MENUS_NAME "menus2"
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_("About ROX-Filer..."), "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(filer_keys
, "accel_changed",
313 G_CALLBACK(save_menus
), NULL
);
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 static 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
*dir_name
,
438 MenuIconStyle style
, CallbackFn func
,
439 gboolean separator
, gboolean strip_ext
,
442 GList
*widgets
= NULL
;
449 dname
= pathdup(dir_name
);
451 dir
= opendir(dname
);
457 item
= gtk_menu_item_new();
458 widgets
= g_list_append(widgets
, item
);
459 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
462 while ((ent
= readdir(dir
)))
470 /* Ignore hidden files */
471 if (ent
->d_name
[0] == '.')
474 /* Strip off extension, if any */
475 dot
= strchr(ent
->d_name
, '.');
476 if (strip_ext
&& dot
)
477 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
479 leaf
= g_strdup(ent
->d_name
);
481 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
482 ditem
= diritem_new("");
483 diritem_restat(fname
, ditem
, NULL
);
485 if (ditem
->image
&& style
!= MIS_NONE
)
491 pixbuf
= ditem
->image
->pixbuf
;
494 if (!ditem
->image
->sm_pixbuf
)
495 pixmap_make_small(ditem
->image
);
496 pixbuf
= ditem
->image
->sm_pixbuf
;
500 item
= gtk_menu_item_new();
501 /* TODO: Find a way to allow short-cuts */
502 menuitem_no_shortcuts(item
);
504 hbox
= gtk_hbox_new(FALSE
, 2);
505 gtk_container_add(GTK_CONTAINER(item
), hbox
);
507 img
= gtk_image_new_from_pixbuf(pixbuf
);
509 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
511 label
= gtk_label_new(leaf
);
512 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
513 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
517 item
= gtk_menu_item_new_with_label(leaf
);
519 /* If it is a directory (but NOT an AppDir) and we are
520 * recursing then set up a sub menu.
522 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
523 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
528 sub
= gtk_menu_new();
529 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
530 separator
, strip_ext
, FALSE
);
531 g_list_free(new_widgets
);
532 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
535 g_signal_connect_swapped(item
, "activate",
536 G_CALLBACK(func
), fname
);
541 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
542 g_signal_connect_swapped(item
, "destroy",
543 G_CALLBACK(g_free
), fname
);
545 widgets
= g_list_append(widgets
, item
);
555 /* Scan the templates dir and create entries for the New menu */
556 static void update_new_files_menu(MenuIconStyle style
)
558 static GList
*widgets
= NULL
;
560 gchar
*templ_dname
= NULL
;
566 for (next
= widgets
; next
; next
= next
->next
)
567 gtk_widget_destroy((GtkWidget
*) next
->data
);
569 g_list_free(widgets
);
573 templ_dname
= choices_find_path_load("Templates", "");
576 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
577 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
581 gtk_widget_show_all(filer_new_menu
);
584 /* 'item' is the number of the item to appear under the pointer. */
585 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
591 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
592 event
->type
== GDK_BUTTON_RELEASE
))
594 GdkEventButton
*bev
= (GdkEventButton
*) event
;
596 pos
[0] = bev
->x_root
;
597 pos
[1] = bev
->y_root
;
598 button
= bev
->button
;
601 else if (event
&& event
->type
== GDK_KEY_PRESS
)
603 GdkEventKey
*kev
= (GdkEventKey
*) event
;
605 get_pointer_xy(pos
, pos
+ 1);
609 get_pointer_xy(pos
, pos
+ 1);
613 gtk_widget_show_all(menu
);
614 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
615 position_menu
, (gpointer
) pos
, button
, time
);
616 select_nth_item(GTK_MENU_SHELL(menu
), item
);
619 /* Hide the popup menu, if any */
620 void menu_popdown(void)
623 gtk_menu_popdown(GTK_MENU(popup_menu
));
626 static MenuIconStyle
get_menu_icon_style(void)
631 mis
= o_menu_iconsize
.int_value
;
635 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
641 if (mis
== MIS_CURRENT
&& window_with_focus
)
643 switch (window_with_focus
->display_style
)
655 display
= o_display_size
.int_value
;
670 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
672 DirItem
*file_item
= NULL
;
673 GdkModifierType state
= 0;
676 n_selected
= view_count_selected(filer_window
->view
);
682 /* Remove previous AppMenu, if any */
685 window_with_focus
= filer_window
;
687 if (event
->type
== GDK_BUTTON_PRESS
)
688 state
= ((GdkEventButton
*) event
)->state
;
689 else if (event
->type
== GDK_KEY_PRESS
)
690 state
= ((GdkEventKey
*) event
)->state
;
692 if (n_selected
== 0 && item
>= 0)
694 filer_window
->temp_item_selected
= TRUE
;
695 collection_select_item(filer_window
->collection
, item
);
696 n_selected
= view_count_selected(filer_window
->view
);
700 filer_window
->temp_item_selected
= FALSE
;
703 /* Short-cut to the Send To menu */
704 if (state
& GDK_SHIFT_MASK
)
713 _("You should Shift+Menu click over a file to "
714 "send it somewhere"));
718 paths
= filer_selected_items(filer_window
);
720 show_send_to_menu(paths
, event
); /* (paths eaten) */
726 GtkWidget
*file_label
, *file_menu
;
730 file_label
= filer_file_item
;
731 file_menu
= filer_file_menu
;
732 gtk_check_menu_item_set_active(
733 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
734 filer_window
->show_thumbs
);
735 gtk_check_menu_item_set_active(
736 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
737 filer_window
->show_hidden
);
738 buffer
= g_string_new(NULL
);
743 g_string_assign(buffer
, _("Next Click"));
744 shade_file_menu_items(FALSE
);
747 item
= filer_selected_item(filer_window
);
749 dir_update_item(filer_window
->directory
,
751 shade_file_menu_items(FALSE
);
752 file_item
= filer_selected_item(filer_window
);
753 g_string_sprintf(buffer
, "%s '%s'",
754 basetype_name(file_item
),
755 file_item
->leafname
);
756 if (!can_set_run_action(file_item
))
757 menu_set_items_shaded(filer_file_menu
,
761 shade_file_menu_items(TRUE
);
762 g_string_sprintf(buffer
, _("%d items"),
766 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
767 g_string_free(buffer
, TRUE
);
769 menu_show_shift_action(file_shift_item
, file_item
,
772 appmenu_add(make_path(filer_window
->sym_path
,
773 file_item
->leafname
)->str
,
774 file_item
, filer_file_menu
);
777 update_new_files_menu(get_menu_icon_style());
779 gtk_widget_set_sensitive(filer_new_window
,
780 !o_unique_filer_windows
.int_value
);
781 gtk_widget_set_sensitive(filer_follow_sym
,
782 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
784 popup_menu
= (state
& GDK_CONTROL_MASK
)
790 show_popup_menu(popup_menu
, event
,
791 popup_menu
== filer_file_menu
? 5 : 1);
794 static void menu_closed(GtkWidget
*widget
)
796 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
797 return; /* Close panel item chosen? */
801 if (window_with_focus
->temp_item_selected
)
803 view_clear_selection(window_with_focus
->view
);
804 window_with_focus
->temp_item_selected
= FALSE
;
808 static void target_callback(FilerWindow
*filer_window
,
812 Collection
*collection
;
814 g_return_if_fail(filer_window
!= NULL
);
816 collection
= filer_window
->collection
;
818 window_with_focus
= filer_window
;
820 /* Don't grab the primary selection */
821 filer_window
->temp_item_selected
= TRUE
;
823 collection_wink_item(collection
, item
);
824 collection_clear_except(collection
, item
);
825 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
827 if (item
< collection
->number_of_items
)
828 collection_unselect_item(collection
, item
);
829 filer_window
->temp_item_selected
= FALSE
;
832 /* Set the text of the 'Shift Open...' menu item.
833 * If icon is NULL, reset the text and also shade it, unless 'next'.
835 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
837 guchar
*shift_action
= NULL
;
841 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
843 if (item
->flags
& ITEM_FLAG_MOUNTED
)
844 shift_action
= N_("Unmount");
846 shift_action
= N_("Mount");
848 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
849 shift_action
= N_("Show Target");
850 else if (item
->base_type
== TYPE_DIRECTORY
)
851 shift_action
= N_("Look Inside");
852 else if (item
->base_type
== TYPE_FILE
)
853 shift_action
= N_("Open As Text");
855 gtk_label_set_text(GTK_LABEL(menu_item
),
856 shift_action
? _(shift_action
)
858 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
863 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
865 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
868 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
870 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
873 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
875 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
878 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
880 g_return_if_fail(window_with_focus
!= NULL
);
882 display_set_sort_fn(window_with_focus
, sort_by_name
);
885 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
887 g_return_if_fail(window_with_focus
!= NULL
);
889 display_set_sort_fn(window_with_focus
, sort_by_type
);
892 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
894 g_return_if_fail(window_with_focus
!= NULL
);
896 display_set_sort_fn(window_with_focus
, sort_by_date
);
899 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
901 g_return_if_fail(window_with_focus
!= NULL
);
903 display_set_sort_fn(window_with_focus
, sort_by_size
);
906 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
911 g_return_if_fail(window_with_focus
!= NULL
);
913 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
916 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
921 g_return_if_fail(window_with_focus
!= NULL
);
923 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
926 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
928 g_return_if_fail(window_with_focus
!= NULL
);
931 filer_update_dir(window_with_focus
, TRUE
);
934 static void delete(FilerWindow
*filer_window
)
937 paths
= filer_selected_items(filer_window
);
938 action_delete(paths
);
939 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
943 static void usage(FilerWindow
*filer_window
)
946 paths
= filer_selected_items(filer_window
);
948 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
952 static void chmod_items(FilerWindow
*filer_window
)
955 paths
= filer_selected_items(filer_window
);
956 action_chmod(paths
, FALSE
, NULL
);
957 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
961 static void find(FilerWindow
*filer_window
)
964 paths
= filer_selected_items(filer_window
);
966 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
970 /* This creates a new savebox widget, and allows the user to pick a new path
972 * Once the new path has been picked, the callback will be called with
973 * both the current and new paths.
974 * NOTE: This function unrefs 'image'!
976 static void savebox_show(const gchar
*action
, const gchar
*path
,
977 MaskedPixmap
*image
, SaveCb callback
)
979 GtkWidget
*savebox
= NULL
;
980 GtkWidget
*check_relative
= NULL
;
982 g_return_if_fail(image
!= NULL
);
984 savebox
= gtk_savebox_new(action
);
986 if (callback
== link_cb
)
988 check_relative
= gtk_check_button_new_with_mnemonic(
989 _("_Relative link"));
990 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
993 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
994 gtk_tooltips_set_tip(tooltips
, check_relative
,
995 _("If on, the symlink will store the path from the "
996 "symlink to the target file. Use this if the symlink "
997 "and the target will be moved together.\n"
998 "If off, the path from the root directory is stored - "
999 "use this if the symlink may move but the target will "
1000 "stay put."), NULL
);
1001 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1002 check_relative
, FALSE
, TRUE
, 0);
1003 gtk_widget_show(check_relative
);
1006 g_signal_connect(savebox
, "save_to_file",
1007 G_CALLBACK(save_to_file
), NULL
);
1009 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1010 g_strdup(path
), g_free
);
1011 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1012 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1014 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1016 if (g_utf8_validate(path
, -1, NULL
))
1017 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1022 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1025 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1026 g_object_unref(image
);
1028 gtk_widget_show(savebox
);
1031 static gint
save_to_file(GObject
*savebox
,
1032 const gchar
*pathname
, gpointer data
)
1035 const gchar
*current_path
;
1037 callback
= g_object_get_data(savebox
, "action_callback");
1038 current_path
= g_object_get_data(savebox
, "current_path");
1040 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1041 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1043 return callback(savebox
, current_path
, pathname
)
1044 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1047 static gboolean
copy_cb(GObject
*savebox
,
1048 const gchar
*current
, const gchar
*new)
1050 return action_with_leaf(action_copy
, current
, new);
1053 static gboolean
action_with_leaf(ActionFn action
,
1054 const gchar
*current
, const gchar
*new)
1062 report_error(_("New pathname is not absolute"));
1066 if (new[strlen(new) - 1] == '/')
1068 new_dir
= g_strdup(new);
1075 slash
= strrchr(new, '/');
1076 new_dir
= g_strndup(new, slash
- new);
1080 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1081 action(local_paths
, new_dir
, leaf
, -1);
1082 g_list_free(local_paths
);
1089 /* Open a savebox to act on the selected file.
1090 * Call 'callback' later to perform the operation.
1092 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1093 const gchar
*action
, SaveCb callback
)
1095 g_object_ref(image
);
1096 savebox_show(action
, path
, image
, callback
);
1099 static gboolean
rename_cb(GObject
*savebox
,
1100 const gchar
*current
, const gchar
*new)
1102 return action_with_leaf(action_move
, current
, new);
1105 static gboolean
link_cb(GObject
*savebox
,
1106 const gchar
*initial
, const gchar
*path
)
1108 GtkToggleButton
*check_relative
;
1113 check_relative
= g_object_get_data(savebox
, "check_relative");
1115 if (gtk_toggle_button_get_active(check_relative
))
1116 link_path
= get_relative_path(path
, initial
);
1118 link_path
= g_strdup(initial
);
1120 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1122 GtkWidget
*box
, *button
;
1125 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1127 _("Symlink from '%s' already exists. "
1128 "Replace it with a link to '%s'?"),
1131 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1133 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1134 gtk_widget_show(button
);
1135 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1136 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1137 button
, GTK_RESPONSE_OK
);
1138 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1141 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1142 gtk_widget_destroy(box
);
1144 if (ans
!= GTK_RESPONSE_OK
)
1153 err
= symlink(link_path
, path
);
1158 report_error("symlink: %s", g_strerror(errno
));
1162 dir_check_this(path
);
1167 static void run_action(DirItem
*item
)
1169 if (can_set_run_action(item
))
1170 type_set_handler_dialog(item
->mime_type
);
1173 _("You can only set the run action for a "
1177 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1179 filer_opendir(home_dir
, NULL
);
1182 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1186 path
= g_strconcat(filer_window
->sym_path
,
1187 "/", item
->leafname
, "#", NULL
);
1189 filer_change_to(filer_window
, path
, NULL
);
1193 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1195 g_return_if_fail(window_with_focus
!= NULL
);
1197 window_with_focus
->temp_item_selected
= FALSE
;
1198 collection_select_all(window_with_focus
->collection
);
1201 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1203 g_return_if_fail(window_with_focus
!= NULL
);
1205 window_with_focus
->temp_item_selected
= FALSE
;
1206 view_clear_selection(window_with_focus
->view
);
1209 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1211 g_return_if_fail(window_with_focus
!= NULL
);
1213 window_with_focus
->temp_item_selected
= FALSE
;
1214 collection_invert_selection(window_with_focus
->collection
);
1217 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1221 win
= options_show();
1225 number_of_windows
++;
1226 g_signal_connect(win
, "destroy",
1227 G_CALLBACK(one_less_window
), NULL
);
1231 static gboolean
new_directory_cb(GObject
*savebox
,
1232 const gchar
*initial
, const gchar
*path
)
1234 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1236 report_error("mkdir: %s", g_strerror(errno
));
1240 dir_check_this(path
);
1242 if (filer_exists(window_with_focus
))
1245 leaf
= strrchr(path
, '/');
1247 display_set_autoselect(window_with_focus
, leaf
+ 1);
1253 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1255 g_return_if_fail(window_with_focus
!= NULL
);
1257 savebox_show(_("Create"),
1258 make_path(window_with_focus
->sym_path
, _("NewDir"))->str
,
1259 type_to_icon(inode_directory
), new_directory_cb
);
1262 static gboolean
new_file_cb(GObject
*savebox
,
1263 const gchar
*initial
, const gchar
*path
)
1267 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1271 report_error(_("Error creating '%s': %s"),
1272 path
, g_strerror(errno
));
1277 report_error(_("Error creating '%s': %s"),
1278 path
, g_strerror(errno
));
1280 dir_check_this(path
);
1282 if (filer_exists(window_with_focus
))
1285 leaf
= strrchr(path
, '/');
1287 display_set_autoselect(window_with_focus
, leaf
+ 1);
1293 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1295 g_return_if_fail(window_with_focus
!= NULL
);
1297 savebox_show(_("Create"),
1298 make_path(window_with_focus
->sym_path
, _("NewFile"))->str
,
1299 type_to_icon(text_plain
),
1303 static gboolean
new_file_type_cb(GObject
*savebox
,
1304 const gchar
*initial
, const gchar
*path
)
1306 const gchar
*oleaf
, *leaf
;
1307 gchar
*templ
, *templ_dname
, *dest
;
1310 /* We can work out the template path from the initial name */
1311 oleaf
= g_basename(initial
);
1312 templ_dname
= choices_find_path_load("Templates", "");
1316 _("Error creating file: could not find the template for %s"),
1321 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1322 g_free(templ_dname
);
1324 dest
= g_dirname(path
);
1325 leaf
= g_basename(path
);
1326 paths
= g_list_append(NULL
, templ
);
1328 action_copy(paths
, dest
, leaf
, TRUE
);
1334 if (filer_exists(window_with_focus
))
1335 display_set_autoselect(window_with_focus
, leaf
);
1340 static void do_send_to(gchar
*templ
)
1342 g_return_if_fail(send_to_paths
!= NULL
);
1344 run_with_files(templ
, send_to_paths
);
1347 static void new_file_type(gchar
*templ
)
1352 g_return_if_fail(window_with_focus
!= NULL
);
1354 leaf
= g_basename(templ
);
1355 type
= type_get_type(templ
);
1357 savebox_show(_("Create"),
1358 make_path(window_with_focus
->sym_path
, leaf
)->str
,
1363 static void customise_send_to(gpointer data
)
1370 dirs
= g_string_new(NULL
);
1372 path
= choices_list_dirs("");
1373 for (i
= 0; i
< path
->len
; i
++)
1375 guchar
*old
= (guchar
*) path
->pdata
[i
];
1377 g_string_append(dirs
, old
);
1378 g_string_append(dirs
, "SendTo\n");
1380 choices_free_list(path
);
1382 save
= choices_find_path_save("", "SendTo", TRUE
);
1387 _("The `Send To' menu provides a quick way to send some files "
1388 "to an application. The applications listed are those in "
1389 "the following directories:\n\n%s\n%s\n"
1390 "The `Send To' menu may be opened by Shift+Menu clicking "
1393 "You can also create subdirectories called "
1394 "`.text_html', `.text', etc which will only be "
1395 "shown for files of that type. `.group' is shown "
1396 "only when multiple files are selected."),
1398 save
? _("I'll show you your SendTo directory now; you should "
1399 "symlink (Ctrl+Shift drag) any applications you want "
1401 : _("Your CHOICESPATH variable setting prevents "
1402 "customisations - sorry."));
1404 g_string_free(dirs
, TRUE
);
1407 filer_opendir(save
, NULL
);
1410 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1413 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1420 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1422 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1424 searchdir
= g_strdup("SendTo");
1426 paths
= choices_list_dirs(searchdir
);
1429 for (i
= 0; i
< paths
->len
; i
++)
1431 GList
*widgets
= NULL
;
1432 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1434 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1435 (CallbackFn
) do_send_to
,
1436 FALSE
, FALSE
, TRUE
);
1439 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1440 gtk_menu_item_new());
1442 g_list_free(widgets
); /* TODO: Get rid of this */
1445 choices_free_list(paths
);
1448 /* Scan the SendTo dir and create and show the Send To menu.
1449 * The 'paths' list and every path in it is claimed, and will be
1450 * freed later -- don't free it yourself!
1452 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1454 GtkWidget
*menu
, *item
;
1456 menu
= gtk_menu_new();
1458 if (g_list_length(paths
) == 1)
1462 item
= diritem_new("");
1463 diritem_restat(paths
->data
, item
, NULL
);
1466 item
->mime_type
->media_type
,
1467 item
->mime_type
->subtype
);
1469 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1474 add_sendto(menu
, "group", NULL
);
1476 add_sendto(menu
, NULL
, NULL
);
1478 item
= gtk_menu_item_new_with_label(_("Customise"));
1479 g_signal_connect_swapped(item
, "activate",
1480 G_CALLBACK(customise_send_to
), NULL
);
1481 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1485 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1486 g_list_free(send_to_paths
);
1488 send_to_paths
= paths
;
1490 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1493 show_popup_menu(menu
, event
, 0);
1496 static void send_to(FilerWindow
*filer_window
)
1501 paths
= filer_selected_items(filer_window
);
1502 event
= gtk_get_current_event();
1505 show_send_to_menu(paths
, event
);
1507 gdk_event_free(event
);
1510 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1512 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1513 gboolean close
= action
;
1515 argv
[2] = o_menu_xterm
.value
;
1517 g_return_if_fail(window_with_focus
!= NULL
);
1519 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1520 gtk_widget_destroy(window_with_focus
->window
);
1523 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1525 g_return_if_fail(window_with_focus
!= NULL
);
1527 filer_change_to(window_with_focus
, home_dir
, NULL
);
1530 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1532 g_return_if_fail(window_with_focus
!= NULL
);
1534 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1535 filer_change_to(window_with_focus
,
1536 window_with_focus
->real_path
, NULL
);
1538 delayed_error(_("This is already the canonical name "
1539 "for this directory."));
1542 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1544 g_return_if_fail(window_with_focus
!= NULL
);
1546 filer_open_parent(window_with_focus
);
1549 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1551 g_return_if_fail(window_with_focus
!= NULL
);
1553 change_to_parent(window_with_focus
);
1556 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1558 g_return_if_fail(window_with_focus
!= NULL
);
1560 filer_window_autosize(window_with_focus
, TRUE
);
1563 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1565 g_return_if_fail(window_with_focus
!= NULL
);
1567 if (o_unique_filer_windows
.int_value
)
1569 report_error(_("You can't open a second view onto "
1570 "this directory because the `Unique Windows' option "
1571 "is turned on in the Options window."));
1574 filer_opendir(window_with_focus
->sym_path
, window_with_focus
);
1578 static void su_to_user(GtkWidget
*dialog
)
1581 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1585 g_return_if_fail(dialog
!= NULL
);
1587 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1588 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1590 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1592 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1593 argv
[3] = gtk_entry_get_text(user
);
1594 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1598 report_error(_("fork: %s"), g_strerror(errno
));
1603 gtk_widget_destroy(dialog
);
1606 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1608 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1610 g_return_if_fail(window_with_focus
!= NULL
);
1612 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1613 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1614 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1615 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1616 g_strdup(window_with_focus
->path
), g_free
);
1618 vbox
= gtk_vbox_new(FALSE
, 4);
1619 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1620 gtk_box_pack_start(GTK_BOX(vbox
),
1621 gtk_label_new(_("Browse as which user?")),
1624 hbox
= gtk_hbox_new(FALSE
, 4);
1625 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1627 gtk_box_pack_start(GTK_BOX(hbox
),
1628 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1630 entry
= gtk_entry_new();
1631 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1632 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1633 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1634 gtk_widget_grab_focus(entry
);
1635 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1636 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1637 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1639 hbox
= gtk_hbox_new(TRUE
, 0);
1640 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1642 button
= gtk_button_new_with_label(_("OK"));
1643 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1644 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1645 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1646 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1647 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1649 button
= gtk_button_new_with_label(_("Cancel"));
1650 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1651 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1652 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1653 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1654 GTK_OBJECT(dialog
));
1656 gtk_widget_show_all(dialog
);
1660 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1662 g_return_if_fail(window_with_focus
!= NULL
);
1664 gtk_widget_destroy(window_with_focus
->window
);
1667 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1669 MiniType type
= (MiniType
) action
;
1671 g_return_if_fail(window_with_focus
!= NULL
);
1673 /* Item needs to remain selected... */
1674 if (type
== MINI_SHELL
)
1675 window_with_focus
->temp_item_selected
= FALSE
;
1677 minibuffer_show(window_with_focus
, type
);
1680 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1682 infobox_new(app_dir
);
1685 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1686 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1688 GList
*items
, *item
;
1690 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1692 item
= g_list_nth(items
, from
);
1695 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1701 static void save_menus(void)
1705 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1708 gtk_accel_map_save(menurc
);
1713 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1718 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1719 item
= g_list_nth_data(items
, n
);
1721 g_return_if_fail(item
!= NULL
);
1725 gtk_menu_shell_select_item(shell
, item
);
1728 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1734 g_return_if_fail(window_with_focus
!= NULL
);
1736 n_selected
= view_count_selected(window_with_focus
->view
);
1744 case FILE_COPY_ITEM
:
1745 prompt
= _("Copy ... ?");
1747 case FILE_RENAME_ITEM
:
1748 prompt
= _("Rename ... ?");
1750 case FILE_LINK_ITEM
:
1751 prompt
= _("Symlink ... ?");
1753 case FILE_OPEN_FILE
:
1754 prompt
= _("Shift Open ... ?");
1757 prompt
= _("Help about ... ?");
1759 case FILE_SHOW_FILE_INFO
:
1760 prompt
= _("Examine ... ?");
1762 case FILE_RUN_ACTION
:
1763 prompt
= _("Set run action for ... ?");
1766 prompt
= _("Set icon for ... ?");
1769 prompt
= _("Send ... to ... ?");
1772 prompt
= _("DELETE ... ?");
1775 prompt
= _("Count the size of ... ?");
1777 case FILE_CHMOD_ITEMS
:
1778 prompt
= _("Set permissions on ... ?");
1781 prompt
= _("Search inside ... ?");
1783 case FILE_OPEN_VFS_AVFS
:
1784 prompt
= _("Look inside ... ?");
1787 g_warning("Unknown action!");
1790 filer_target_mode(window_with_focus
, target_callback
,
1791 GINT_TO_POINTER(action
), prompt
);
1798 send_to(window_with_focus
);
1801 delete(window_with_focus
);
1804 usage(window_with_focus
);
1806 case FILE_CHMOD_ITEMS
:
1807 chmod_items(window_with_focus
);
1810 find(window_with_focus
);
1812 case FILE_SHOW_FILE_INFO
:
1816 items
= filer_selected_items(window_with_focus
);
1817 infobox_show_list(items
);
1818 g_list_foreach(items
, (GFunc
) g_free
, NULL
);
1826 /* All the following actions require exactly one file selected */
1830 report_error(_("You cannot do this to more than "
1831 "one item at a time"));
1835 item
= filer_selected_item(window_with_focus
);
1836 g_return_if_fail(item
!= NULL
);
1838 item
= dir_update_item(window_with_focus
->directory
,
1843 report_error(_("Item no longer exists!"));
1847 path
= make_path(window_with_focus
->sym_path
, item
->leafname
)->str
;
1851 case FILE_COPY_ITEM
:
1852 src_dest_action_item(path
, item
->image
,
1853 _("Copy"), copy_cb
);
1855 case FILE_RENAME_ITEM
:
1856 src_dest_action_item(path
, item
->image
,
1857 _("Rename"), rename_cb
);
1859 case FILE_LINK_ITEM
:
1860 src_dest_action_item(path
, item
->image
,
1861 _("Symlink"), link_cb
);
1863 case FILE_OPEN_FILE
:
1864 filer_openitem(window_with_focus
,
1865 collection_selected_item_number(
1866 window_with_focus
->collection
),
1867 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1870 show_item_help(path
, item
);
1872 case FILE_RUN_ACTION
:
1876 icon_set_handler_dialog(item
, path
);
1878 case FILE_OPEN_VFS_AVFS
:
1879 open_vfs_avfs(window_with_focus
, item
);
1882 g_warning("Unknown action!");
1887 static void show_key_help(GtkWidget
*button
, gpointer data
)
1889 gboolean can_change_accels
;
1891 g_object_get(G_OBJECT(gtk_settings_get_default()),
1892 "gtk-can-change-accels", &can_change_accels
,
1895 if (!can_change_accels
)
1897 info_message(_("User-definable shortcuts are disabled by "
1898 "default in Gtk2, and you have not enabled "
1899 "them. You can turn this feature on by:\n"
1900 "1) using an XSettings manager, such as ROX-Session\n"
1902 "2) adding this line to ~/.gtkrc-2.0:\n"
1903 "\tgtk-can-change-accels = 1"));
1907 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1908 "- Open the menu over a filer window,\n"
1909 "- Move the pointer over the item you want to use,\n"
1910 "- Press the key you want attached to it.\n\n"
1911 "The key will appear next to the menu item and you can just press "
1912 "that key without opening the menu in future."));
1915 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1917 GtkWidget
*button
, *align
;
1919 g_return_val_if_fail(option
== NULL
, NULL
);
1921 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1922 button
= button_new_mixed(GTK_STOCK_DIALOG_INFO
,
1923 _("Set keyboard shortcuts"));
1924 gtk_container_add(GTK_CONTAINER(align
), button
);
1925 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1927 return g_list_append(NULL
, align
);