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_("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(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
= filer_window
->collection
;
814 g_return_if_fail(filer_window
!= NULL
);
816 window_with_focus
= filer_window
;
818 /* Don't grab the primary selection */
819 filer_window
->temp_item_selected
= TRUE
;
821 collection_wink_item(collection
, item
);
822 collection_clear_except(collection
, item
);
823 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
825 if (item
< collection
->number_of_items
)
826 collection_unselect_item(collection
, item
);
827 filer_window
->temp_item_selected
= FALSE
;
830 /* Set the text of the 'Shift Open...' menu item.
831 * If icon is NULL, reset the text and also shade it, unless 'next'.
833 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
835 guchar
*shift_action
= NULL
;
839 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
841 if (item
->flags
& ITEM_FLAG_MOUNTED
)
842 shift_action
= N_("Unmount");
844 shift_action
= N_("Mount");
846 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
847 shift_action
= N_("Show Target");
848 else if (item
->base_type
== TYPE_DIRECTORY
)
849 shift_action
= N_("Look Inside");
850 else if (item
->base_type
== TYPE_FILE
)
851 shift_action
= N_("Open As Text");
853 gtk_label_set_text(GTK_LABEL(menu_item
),
854 shift_action
? _(shift_action
)
856 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
861 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
863 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
866 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
868 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
871 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
873 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
876 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
878 g_return_if_fail(window_with_focus
!= NULL
);
880 display_set_sort_fn(window_with_focus
, sort_by_name
);
883 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
885 g_return_if_fail(window_with_focus
!= NULL
);
887 display_set_sort_fn(window_with_focus
, sort_by_type
);
890 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
892 g_return_if_fail(window_with_focus
!= NULL
);
894 display_set_sort_fn(window_with_focus
, sort_by_date
);
897 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
899 g_return_if_fail(window_with_focus
!= NULL
);
901 display_set_sort_fn(window_with_focus
, sort_by_size
);
904 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
909 g_return_if_fail(window_with_focus
!= NULL
);
911 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
914 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
919 g_return_if_fail(window_with_focus
!= NULL
);
921 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
924 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
926 g_return_if_fail(window_with_focus
!= NULL
);
929 filer_update_dir(window_with_focus
, TRUE
);
932 static void delete(FilerWindow
*filer_window
)
935 paths
= filer_selected_items(filer_window
);
936 action_delete(paths
);
937 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
941 static void usage(FilerWindow
*filer_window
)
944 paths
= filer_selected_items(filer_window
);
946 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
950 static void chmod_items(FilerWindow
*filer_window
)
953 paths
= filer_selected_items(filer_window
);
955 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
959 static void find(FilerWindow
*filer_window
)
962 paths
= filer_selected_items(filer_window
);
964 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
968 /* This creates a new savebox widget, and allows the user to pick a new path
970 * Once the new path has been picked, the callback will be called with
971 * both the current and new paths.
972 * NOTE: This function unrefs 'image'!
974 static void savebox_show(const gchar
*action
, const gchar
*path
,
975 MaskedPixmap
*image
, SaveCb callback
)
977 GtkWidget
*savebox
= NULL
;
978 GtkWidget
*check_relative
= NULL
;
980 g_return_if_fail(image
!= NULL
);
982 savebox
= gtk_savebox_new(action
);
984 if (callback
== link_cb
)
986 check_relative
= gtk_check_button_new_with_mnemonic(
987 _("_Relative link"));
988 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
991 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
992 gtk_tooltips_set_tip(tooltips
, check_relative
,
993 _("If on, the symlink will store the path from the "
994 "symlink to the target file. Use this if the symlink "
995 "and the target will be moved together.\n"
996 "If off, the path from the root directory is stored - "
997 "use this if the symlink may move but the target will "
999 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1000 check_relative
, FALSE
, TRUE
, 0);
1001 gtk_widget_show(check_relative
);
1004 g_signal_connect(savebox
, "save_to_file",
1005 G_CALLBACK(save_to_file
), NULL
);
1007 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1008 g_strdup(path
), g_free
);
1009 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1010 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1012 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1014 if (g_utf8_validate(path
, -1, NULL
))
1015 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1020 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1023 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1024 g_object_unref(image
);
1026 gtk_widget_show(savebox
);
1029 static gint
save_to_file(GObject
*savebox
,
1030 const gchar
*pathname
, gpointer data
)
1033 const gchar
*current_path
;
1035 callback
= g_object_get_data(savebox
, "action_callback");
1036 current_path
= g_object_get_data(savebox
, "current_path");
1038 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1039 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1041 return callback(savebox
, current_path
, pathname
)
1042 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1045 static gboolean
copy_cb(GObject
*savebox
,
1046 const gchar
*current
, const gchar
*new)
1048 return action_with_leaf(action_copy
, current
, new);
1051 static gboolean
action_with_leaf(ActionFn action
,
1052 const gchar
*current
, const gchar
*new)
1060 report_error(_("New pathname is not absolute"));
1064 if (new[strlen(new) - 1] == '/')
1066 new_dir
= g_strdup(new);
1073 slash
= strrchr(new, '/');
1074 new_dir
= g_strndup(new, slash
- new);
1078 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1079 action(local_paths
, new_dir
, leaf
, -1);
1080 g_list_free(local_paths
);
1087 /* Open a savebox to act on the selected file.
1088 * Call 'callback' later to perform the operation.
1090 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1091 const gchar
*action
, SaveCb callback
)
1093 g_object_ref(image
);
1094 savebox_show(action
, path
, image
, callback
);
1097 static gboolean
rename_cb(GObject
*savebox
,
1098 const gchar
*current
, const gchar
*new)
1100 return action_with_leaf(action_move
, current
, new);
1103 static gboolean
link_cb(GObject
*savebox
,
1104 const gchar
*initial
, const gchar
*path
)
1106 GtkToggleButton
*check_relative
;
1111 check_relative
= g_object_get_data(savebox
, "check_relative");
1113 if (gtk_toggle_button_get_active(check_relative
))
1114 link_path
= get_relative_path(path
, initial
);
1116 link_path
= g_strdup(initial
);
1118 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1120 GtkWidget
*box
, *button
;
1123 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1125 _("Symlink from '%s' already exists. "
1126 "Replace it with a link to '%s'?"),
1129 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1131 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1132 gtk_widget_show(button
);
1133 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1134 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1135 button
, GTK_RESPONSE_OK
);
1136 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1139 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1140 gtk_widget_destroy(box
);
1142 if (ans
!= GTK_RESPONSE_OK
)
1151 err
= symlink(link_path
, path
);
1156 report_error("symlink: %s", g_strerror(errno
));
1160 dir_check_this(path
);
1165 static void run_action(DirItem
*item
)
1167 if (can_set_run_action(item
))
1168 type_set_handler_dialog(item
->mime_type
);
1171 _("You can only set the run action for a "
1175 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1177 filer_opendir(home_dir
, NULL
);
1180 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1184 path
= g_strconcat(filer_window
->sym_path
,
1185 "/", item
->leafname
, "#", NULL
);
1187 filer_change_to(filer_window
, path
, NULL
);
1191 static void select_all(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_select_all(window_with_focus
->collection
);
1199 static void clear_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 view_clear_selection(window_with_focus
->view
);
1207 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1209 g_return_if_fail(window_with_focus
!= NULL
);
1211 window_with_focus
->temp_item_selected
= FALSE
;
1212 collection_invert_selection(window_with_focus
->collection
);
1215 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1219 win
= options_show();
1223 number_of_windows
++;
1224 g_signal_connect(win
, "destroy",
1225 G_CALLBACK(one_less_window
), NULL
);
1229 static gboolean
new_directory_cb(GObject
*savebox
,
1230 const gchar
*initial
, const gchar
*path
)
1232 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1234 report_error("mkdir: %s", g_strerror(errno
));
1238 dir_check_this(path
);
1240 if (filer_exists(window_with_focus
))
1243 leaf
= strrchr(path
, '/');
1245 display_set_autoselect(window_with_focus
, leaf
+ 1);
1251 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1253 g_return_if_fail(window_with_focus
!= NULL
);
1255 savebox_show(_("Create"),
1256 make_path(window_with_focus
->sym_path
, _("NewDir"))->str
,
1257 type_to_icon(inode_directory
), new_directory_cb
);
1260 static gboolean
new_file_cb(GObject
*savebox
,
1261 const gchar
*initial
, const gchar
*path
)
1265 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1269 report_error(_("Error creating '%s': %s"),
1270 path
, g_strerror(errno
));
1275 report_error(_("Error creating '%s': %s"),
1276 path
, g_strerror(errno
));
1278 dir_check_this(path
);
1280 if (filer_exists(window_with_focus
))
1283 leaf
= strrchr(path
, '/');
1285 display_set_autoselect(window_with_focus
, leaf
+ 1);
1291 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1293 g_return_if_fail(window_with_focus
!= NULL
);
1295 savebox_show(_("Create"),
1296 make_path(window_with_focus
->sym_path
, _("NewFile"))->str
,
1297 type_to_icon(text_plain
),
1301 static gboolean
new_file_type_cb(GObject
*savebox
,
1302 const gchar
*initial
, const gchar
*path
)
1304 const gchar
*oleaf
, *leaf
;
1305 gchar
*templ
, *templ_dname
, *dest
;
1308 /* We can work out the template path from the initial name */
1309 oleaf
= g_basename(initial
);
1310 templ_dname
= choices_find_path_load("Templates", "");
1314 _("Error creating file: could not find the template for %s"),
1319 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1320 g_free(templ_dname
);
1322 dest
= g_dirname(path
);
1323 leaf
= g_basename(path
);
1324 paths
= g_list_append(NULL
, templ
);
1326 action_copy(paths
, dest
, leaf
, TRUE
);
1332 if (filer_exists(window_with_focus
))
1333 display_set_autoselect(window_with_focus
, leaf
);
1338 static void do_send_to(gchar
*templ
)
1340 g_return_if_fail(send_to_paths
!= NULL
);
1342 run_with_files(templ
, send_to_paths
);
1345 static void new_file_type(gchar
*templ
)
1350 g_return_if_fail(window_with_focus
!= NULL
);
1352 leaf
= g_basename(templ
);
1353 type
= type_get_type(templ
);
1355 savebox_show(_("Create"),
1356 make_path(window_with_focus
->sym_path
, leaf
)->str
,
1361 static void customise_send_to(gpointer data
)
1368 dirs
= g_string_new(NULL
);
1370 path
= choices_list_dirs("");
1371 for (i
= 0; i
< path
->len
; i
++)
1373 guchar
*old
= (guchar
*) path
->pdata
[i
];
1375 g_string_append(dirs
, old
);
1376 g_string_append(dirs
, "SendTo\n");
1378 choices_free_list(path
);
1380 save
= choices_find_path_save("", "SendTo", TRUE
);
1385 _("The `Send To' menu provides a quick way to send some files "
1386 "to an application. The applications listed are those in "
1387 "the following directories:\n\n%s\n%s\n"
1388 "The `Send To' menu may be opened by Shift+Menu clicking "
1391 "You can also create subdirectories called "
1392 "`.text_html', `.text', etc which will only be "
1393 "shown for files of that type. `.group' is shown "
1394 "only when multiple files are selected."),
1396 save
? _("I'll show you your SendTo directory now; you should "
1397 "symlink (Ctrl+Shift drag) any applications you want "
1399 : _("Your CHOICESPATH variable setting prevents "
1400 "customisations - sorry."));
1402 g_string_free(dirs
, TRUE
);
1405 filer_opendir(save
, NULL
);
1408 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1411 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1418 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1420 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1422 searchdir
= g_strdup("SendTo");
1424 paths
= choices_list_dirs(searchdir
);
1427 for (i
= 0; i
< paths
->len
; i
++)
1429 GList
*widgets
= NULL
;
1430 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1432 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1433 (CallbackFn
) do_send_to
,
1434 FALSE
, FALSE
, TRUE
);
1437 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1438 gtk_menu_item_new());
1440 g_list_free(widgets
); /* TODO: Get rid of this */
1443 choices_free_list(paths
);
1446 /* Scan the SendTo dir and create and show the Send To menu.
1447 * The 'paths' list and every path in it is claimed, and will be
1448 * freed later -- don't free it yourself!
1450 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1452 GtkWidget
*menu
, *item
;
1454 menu
= gtk_menu_new();
1456 if (g_list_length(paths
) == 1)
1460 item
= diritem_new("");
1461 diritem_restat(paths
->data
, item
, NULL
);
1464 item
->mime_type
->media_type
,
1465 item
->mime_type
->subtype
);
1467 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1472 add_sendto(menu
, "group", NULL
);
1474 add_sendto(menu
, NULL
, NULL
);
1476 item
= gtk_menu_item_new_with_label(_("Customise"));
1477 g_signal_connect_swapped(item
, "activate",
1478 G_CALLBACK(customise_send_to
), NULL
);
1479 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1483 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1484 g_list_free(send_to_paths
);
1486 send_to_paths
= paths
;
1488 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1491 show_popup_menu(menu
, event
, 0);
1494 static void send_to(FilerWindow
*filer_window
)
1499 paths
= filer_selected_items(filer_window
);
1500 event
= gtk_get_current_event();
1503 show_send_to_menu(paths
, event
);
1505 gdk_event_free(event
);
1508 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1510 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1511 gboolean close
= action
;
1513 argv
[2] = o_menu_xterm
.value
;
1515 g_return_if_fail(window_with_focus
!= NULL
);
1517 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1518 gtk_widget_destroy(window_with_focus
->window
);
1521 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1523 g_return_if_fail(window_with_focus
!= NULL
);
1525 filer_change_to(window_with_focus
, home_dir
, NULL
);
1528 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1530 g_return_if_fail(window_with_focus
!= NULL
);
1532 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1533 filer_change_to(window_with_focus
,
1534 window_with_focus
->real_path
, NULL
);
1536 delayed_error(_("This is already the canonical name "
1537 "for this directory."));
1540 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1542 g_return_if_fail(window_with_focus
!= NULL
);
1544 filer_open_parent(window_with_focus
);
1547 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1549 g_return_if_fail(window_with_focus
!= NULL
);
1551 change_to_parent(window_with_focus
);
1554 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1556 g_return_if_fail(window_with_focus
!= NULL
);
1558 filer_window_autosize(window_with_focus
, TRUE
);
1561 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1563 g_return_if_fail(window_with_focus
!= NULL
);
1565 if (o_unique_filer_windows
.int_value
)
1567 report_error(_("You can't open a second view onto "
1568 "this directory because the `Unique Windows' option "
1569 "is turned on in the Options window."));
1572 filer_opendir(window_with_focus
->sym_path
, window_with_focus
);
1576 static void su_to_user(GtkWidget
*dialog
)
1579 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1583 g_return_if_fail(dialog
!= NULL
);
1585 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1586 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1588 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1590 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1591 argv
[3] = gtk_entry_get_text(user
);
1592 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1596 report_error(_("fork: %s"), g_strerror(errno
));
1601 gtk_widget_destroy(dialog
);
1604 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1606 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1608 g_return_if_fail(window_with_focus
!= NULL
);
1610 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1611 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1612 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1613 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1614 g_strdup(window_with_focus
->path
), g_free
);
1616 vbox
= gtk_vbox_new(FALSE
, 4);
1617 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1618 gtk_box_pack_start(GTK_BOX(vbox
),
1619 gtk_label_new(_("Browse as which user?")),
1622 hbox
= gtk_hbox_new(FALSE
, 4);
1623 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1625 gtk_box_pack_start(GTK_BOX(hbox
),
1626 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1628 entry
= gtk_entry_new();
1629 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1630 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1631 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1632 gtk_widget_grab_focus(entry
);
1633 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1634 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1635 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1637 hbox
= gtk_hbox_new(TRUE
, 0);
1638 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1640 button
= gtk_button_new_with_label(_("OK"));
1641 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1642 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1643 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1644 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1645 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1647 button
= gtk_button_new_with_label(_("Cancel"));
1648 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1649 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1650 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1651 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1652 GTK_OBJECT(dialog
));
1654 gtk_widget_show_all(dialog
);
1658 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1660 g_return_if_fail(window_with_focus
!= NULL
);
1662 gtk_widget_destroy(window_with_focus
->window
);
1665 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1667 MiniType type
= (MiniType
) action
;
1669 g_return_if_fail(window_with_focus
!= NULL
);
1671 /* Item needs to remain selected... */
1672 if (type
== MINI_SHELL
)
1673 window_with_focus
->temp_item_selected
= FALSE
;
1675 minibuffer_show(window_with_focus
, type
);
1678 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1680 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1683 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1684 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1686 GList
*items
, *item
;
1688 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1690 item
= g_list_nth(items
, from
);
1693 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1699 static void save_menus(void)
1703 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1706 gtk_accel_map_save(menurc
);
1711 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1716 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1717 item
= g_list_nth_data(items
, n
);
1719 g_return_if_fail(item
!= NULL
);
1723 gtk_menu_shell_select_item(shell
, item
);
1726 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1732 g_return_if_fail(window_with_focus
!= NULL
);
1734 n_selected
= view_count_selected(window_with_focus
->view
);
1742 case FILE_COPY_ITEM
:
1743 prompt
= _("Copy ... ?");
1745 case FILE_RENAME_ITEM
:
1746 prompt
= _("Rename ... ?");
1748 case FILE_LINK_ITEM
:
1749 prompt
= _("Symlink ... ?");
1751 case FILE_OPEN_FILE
:
1752 prompt
= _("Shift Open ... ?");
1755 prompt
= _("Help about ... ?");
1757 case FILE_SHOW_FILE_INFO
:
1758 prompt
= _("Examine ... ?");
1760 case FILE_RUN_ACTION
:
1761 prompt
= _("Set run action for ... ?");
1764 prompt
= _("Set icon for ... ?");
1767 prompt
= _("Send ... to ... ?");
1770 prompt
= _("DELETE ... ?");
1773 prompt
= _("Count the size of ... ?");
1775 case FILE_CHMOD_ITEMS
:
1776 prompt
= _("Set permissions on ... ?");
1779 prompt
= _("Search inside ... ?");
1781 case FILE_OPEN_VFS_AVFS
:
1782 prompt
= _("Look inside ... ?");
1785 g_warning("Unknown action!");
1788 filer_target_mode(window_with_focus
, target_callback
,
1789 GINT_TO_POINTER(action
), prompt
);
1796 send_to(window_with_focus
);
1799 delete(window_with_focus
);
1802 usage(window_with_focus
);
1804 case FILE_CHMOD_ITEMS
:
1805 chmod_items(window_with_focus
);
1808 find(window_with_focus
);
1810 case FILE_SHOW_FILE_INFO
:
1814 items
= filer_selected_items(window_with_focus
);
1815 infobox_show_list(items
);
1816 g_list_foreach(items
, (GFunc
) g_free
, NULL
);
1824 /* All the following actions require exactly one file selected */
1828 report_error(_("You cannot do this to more than "
1829 "one item at a time"));
1833 item
= filer_selected_item(window_with_focus
);
1834 g_return_if_fail(item
!= NULL
);
1836 item
= dir_update_item(window_with_focus
->directory
,
1841 report_error(_("Item no longer exists!"));
1845 path
= make_path(window_with_focus
->sym_path
, item
->leafname
)->str
;
1849 case FILE_COPY_ITEM
:
1850 src_dest_action_item(path
, item
->image
,
1851 _("Copy"), copy_cb
);
1853 case FILE_RENAME_ITEM
:
1854 src_dest_action_item(path
, item
->image
,
1855 _("Rename"), rename_cb
);
1857 case FILE_LINK_ITEM
:
1858 src_dest_action_item(path
, item
->image
,
1859 _("Symlink"), link_cb
);
1861 case FILE_OPEN_FILE
:
1862 filer_openitem(window_with_focus
,
1863 collection_selected_item_number(
1864 window_with_focus
->collection
),
1865 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1868 show_item_help(path
, item
);
1870 case FILE_RUN_ACTION
:
1874 icon_set_handler_dialog(item
, path
);
1876 case FILE_OPEN_VFS_AVFS
:
1877 open_vfs_avfs(window_with_focus
, item
);
1880 g_warning("Unknown action!");
1885 static void show_key_help(GtkWidget
*button
, gpointer data
)
1887 gboolean can_change_accels
;
1889 g_object_get(G_OBJECT(gtk_settings_get_default()),
1890 "gtk-can-change-accels", &can_change_accels
,
1893 if (!can_change_accels
)
1895 info_message(_("User-definable shortcuts are disabled by "
1896 "default in Gtk2, and you have not enabled "
1897 "them. You can turn this feature on by:\n"
1898 "1) using an XSettings manager, such as ROX-Session\n"
1900 "2) adding this line to ~/.gtkrc-2.0:\n"
1901 "\tgtk-can-change-accels = 1"));
1905 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1906 "- Open the menu over a filer window,\n"
1907 "- Move the pointer over the item you want to use,\n"
1908 "- Press the key you want attached to it.\n\n"
1909 "The key will appear next to the menu item and you can just press "
1910 "that key without opening the menu in future."));
1913 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1915 GtkWidget
*button
, *align
;
1917 g_return_val_if_fail(option
== NULL
, NULL
);
1919 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1920 button
= button_new_mixed(GTK_STOCK_DIALOG_INFO
,
1921 _("Set keyboard shortcuts"));
1922 gtk_container_add(GTK_CONTAINER(align
), button
);
1923 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1925 return g_list_append(NULL
, align
);