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"
62 #include "bookmarks.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 show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
);
152 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
153 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
154 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
155 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
);
157 /* (action used in this - MiniType) */
158 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
159 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
161 #define MENUS_NAME "menus2"
163 static GtkWidget
*filer_menu
; /* The popup filer menu */
164 static GtkWidget
*filer_file_item
; /* The File '' label */
165 static GtkWidget
*filer_file_menu
; /* The File '' menu */
166 static GtkWidget
*file_shift_item
; /* Shift Open label */
167 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
168 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
169 static GtkWidget
*filer_new_window
; /* The New Window item */
170 static GtkWidget
*filer_new_menu
; /* The New submenu */
171 static GtkWidget
*filer_follow_sym
; /* Follow symbolic links item */
176 static GtkItemFactoryEntry filer_menu_def
[] = {
177 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
178 {">" N_("Huge Icons"), NULL
, huge_with
, DETAILS_NONE
, NULL
},
179 {">" N_("Large Icons"), NULL
, large_with
, DETAILS_NONE
, NULL
},
180 {">" N_("Small Icons"), NULL
, small_with
, DETAILS_NONE
, NULL
},
181 {">" N_("Huge, With..."), NULL
, NULL
, 0, "<Branch>"},
182 {">>" N_("Summary"), NULL
, huge_with
, DETAILS_SUMMARY
, NULL
},
183 {">>" N_("Sizes"), NULL
, huge_with
, DETAILS_SIZE
, NULL
},
184 {">>" N_("Permissions"), NULL
, huge_with
, DETAILS_PERMISSIONS
, NULL
},
185 {">>" N_("Type"), NULL
, huge_with
, DETAILS_TYPE
, NULL
},
186 {">>" N_("Times"), NULL
, huge_with
, DETAILS_TIMES
, NULL
},
187 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
188 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
189 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
190 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
191 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
192 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
193 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
194 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
195 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
196 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
197 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
198 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, NULL
},
199 {">", NULL
, NULL
, 0, "<Separator>"},
200 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
201 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
202 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
203 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
204 {">", NULL
, NULL
, 0, "<Separator>"},
205 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
206 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
207 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
208 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
209 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, NULL
},
210 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
211 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
212 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
213 {">", NULL
, NULL
, 0, "<Separator>"},
214 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
215 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
216 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
217 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
218 {">", NULL
, NULL
, 0, "<Separator>"},
219 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
220 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
221 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
222 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
223 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
224 {">", NULL
, NULL
, 0, "<Separator>"},
225 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
226 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
227 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
228 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
229 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
230 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
231 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
232 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
233 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
234 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
235 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
236 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
237 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
238 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
239 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
240 {">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks
, 0, NULL
},
241 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
242 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
243 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
245 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
246 {">", NULL
, NULL
, 0, "<Separator>"},
247 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
248 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
249 {">" N_("Xterm Here"), NULL
, xterm_here
, FALSE
, NULL
},
250 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, NULL
},
251 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
252 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
253 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, NULL
},
254 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
258 #define GET_MENU_ITEM(var, menu) \
259 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
261 #define GET_SMENU_ITEM(var, menu, sub) \
263 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
264 var = gtk_item_factory_get_widget(item_factory, tmp); \
268 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
270 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
271 var = gtk_item_factory_get_widget(item_factory, tmp); \
275 void ensure_filer_menu(void)
280 GtkItemFactory
*item_factory
;
285 filer_keys
= gtk_accel_group_new();
286 item_factory
= menu_create(filer_menu_def
,
287 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
288 "<filer>", filer_keys
);
290 GET_MENU_ITEM(filer_menu
, "filer");
291 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
292 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
293 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
296 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
297 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
298 filer_follow_sym
= GTK_BIN(item
)->child
;
300 /* File '' label... */
301 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
302 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
305 /* Shift Open... label */
306 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
307 file_shift_item
= GTK_BIN(g_list_nth(items
, 6)->data
)->child
;
310 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
311 filer_new_window
= GTK_BIN(item
)->child
;
313 g_signal_connect(filer_menu
, "unmap_event",
314 G_CALLBACK(menu_closed
), NULL
);
315 g_signal_connect(filer_file_menu
, "unmap_event",
316 G_CALLBACK(menu_closed
), NULL
);
318 g_signal_connect(filer_keys
, "accel_changed",
319 G_CALLBACK(save_menus
), NULL
);
326 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
329 gtk_accel_map_load(menurc
);
333 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
334 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
335 option_add_saver(save_menus
);
337 option_register_widget("menu-set-keys", set_keys_button
);
340 /* Name is in the form "<panel>" */
341 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
342 const gchar
*name
, GtkAccelGroup
*keys
)
344 GtkItemFactory
*item_factory
;
345 GtkItemFactoryEntry
*translated
;
349 keys
= gtk_accel_group_new();
350 gtk_accel_group_lock(keys
);
353 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
355 translated
= translate_entries(def
, n_entries
);
356 gtk_item_factory_create_items(item_factory
, n_entries
,
358 free_translated_entries(translated
, n_entries
);
363 /* Prevent the user from setting a short-cut on this item */
364 static void menuitem_no_shortcuts(GtkWidget
*item
)
368 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
370 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
371 null_g_free(&menuitem
->accel_path
);
375 /* Shade items that only work on single files */
376 static void shade_file_menu_items(gboolean shaded
)
378 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 3);
379 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 3);
380 menu_set_items_shaded(filer_file_menu
, shaded
, 10, 2);
383 /* 'data' is an array of three ints:
384 * [ pointer_x, pointer_y, item_under_pointer ]
386 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
387 gboolean
*push_in
, gpointer data
)
389 int *pos
= (int *) data
;
390 GtkRequisition requisition
;
395 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
397 while (item
>= 0 && next
)
399 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
412 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
414 *x
= pos
[0] - (requisition
.width
* 7 / 8);
415 *y
= pos
[1] - y_shift
;
417 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
418 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
424 /* Used when you menu-click on the Large or Small toolbar tools */
425 void show_style_menu(FilerWindow
*filer_window
,
426 GdkEventButton
*event
,
431 pos
[0] = event
->x_root
;
432 pos
[1] = event
->y_root
;
435 window_with_focus
= filer_window
;
439 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
440 (gpointer
) pos
, event
->button
, event
->time
);
444 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
445 MenuIconStyle style
, CallbackFn func
,
446 gboolean separator
, gboolean strip_ext
,
449 GList
*widgets
= NULL
;
456 dname
= pathdup(dir_name
);
458 dir
= opendir(dname
);
464 item
= gtk_menu_item_new();
465 widgets
= g_list_append(widgets
, item
);
466 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
469 while ((ent
= readdir(dir
)))
477 /* Ignore hidden files */
478 if (ent
->d_name
[0] == '.')
481 /* Strip off extension, if any */
482 dot
= strchr(ent
->d_name
, '.');
483 if (strip_ext
&& dot
)
484 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
486 leaf
= g_strdup(ent
->d_name
);
488 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
489 ditem
= diritem_new("");
490 diritem_restat(fname
, ditem
, NULL
);
492 if (ditem
->image
&& style
!= MIS_NONE
)
498 pixbuf
= ditem
->image
->pixbuf
;
501 if (!ditem
->image
->sm_pixbuf
)
502 pixmap_make_small(ditem
->image
);
503 pixbuf
= ditem
->image
->sm_pixbuf
;
507 item
= gtk_menu_item_new();
508 /* TODO: Find a way to allow short-cuts */
509 menuitem_no_shortcuts(item
);
511 hbox
= gtk_hbox_new(FALSE
, 2);
512 gtk_container_add(GTK_CONTAINER(item
), hbox
);
514 img
= gtk_image_new_from_pixbuf(pixbuf
);
516 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
518 label
= gtk_label_new(leaf
);
519 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
520 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
524 item
= gtk_menu_item_new_with_label(leaf
);
526 /* If it is a directory (but NOT an AppDir) and we are
527 * recursing then set up a sub menu.
529 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
530 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
535 sub
= gtk_menu_new();
536 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
537 separator
, strip_ext
, FALSE
);
538 g_list_free(new_widgets
);
539 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
542 g_signal_connect_swapped(item
, "activate",
543 G_CALLBACK(func
), fname
);
548 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
549 g_signal_connect_swapped(item
, "destroy",
550 G_CALLBACK(g_free
), fname
);
552 widgets
= g_list_append(widgets
, item
);
562 /* Scan the templates dir and create entries for the New menu */
563 static void update_new_files_menu(MenuIconStyle style
)
565 static GList
*widgets
= NULL
;
567 gchar
*templ_dname
= NULL
;
573 for (next
= widgets
; next
; next
= next
->next
)
574 gtk_widget_destroy((GtkWidget
*) next
->data
);
576 g_list_free(widgets
);
580 templ_dname
= choices_find_path_load("Templates", "");
583 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
584 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
588 gtk_widget_show_all(filer_new_menu
);
591 /* 'item' is the number of the item to appear under the pointer. */
592 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
598 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
599 event
->type
== GDK_BUTTON_RELEASE
))
601 GdkEventButton
*bev
= (GdkEventButton
*) event
;
603 pos
[0] = bev
->x_root
;
604 pos
[1] = bev
->y_root
;
605 button
= bev
->button
;
608 else if (event
&& event
->type
== GDK_KEY_PRESS
)
610 GdkEventKey
*kev
= (GdkEventKey
*) event
;
612 get_pointer_xy(pos
, pos
+ 1);
616 get_pointer_xy(pos
, pos
+ 1);
620 gtk_widget_show_all(menu
);
621 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
622 position_menu
, (gpointer
) pos
, button
, time
);
623 select_nth_item(GTK_MENU_SHELL(menu
), item
);
626 /* Hide the popup menu, if any */
627 void menu_popdown(void)
630 gtk_menu_popdown(GTK_MENU(popup_menu
));
633 static MenuIconStyle
get_menu_icon_style(void)
638 mis
= o_menu_iconsize
.int_value
;
642 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
648 if (mis
== MIS_CURRENT
&& window_with_focus
)
650 switch (window_with_focus
->display_style
)
662 display
= o_display_size
.int_value
;
677 /* iter->peek() is the clicked item, or NULL if none */
678 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, ViewIter
*iter
)
680 DirItem
*file_item
= NULL
;
681 GdkModifierType state
= 0;
684 n_selected
= view_count_selected(filer_window
->view
);
690 /* Remove previous AppMenu, if any */
693 window_with_focus
= filer_window
;
696 event
= gtk_get_current_event();
698 if (event
->type
== GDK_BUTTON_PRESS
)
699 state
= ((GdkEventButton
*) event
)->state
;
700 else if (event
->type
== GDK_KEY_PRESS
)
701 state
= ((GdkEventKey
*) event
)->state
;
703 if (n_selected
== 0 && iter
&& iter
->peek(iter
) != NULL
)
705 filer_window
->temp_item_selected
= TRUE
;
706 view_set_selected(filer_window
->view
, iter
, TRUE
);
707 n_selected
= view_count_selected(filer_window
->view
);
711 filer_window
->temp_item_selected
= FALSE
;
714 /* Short-cut to the Send To menu */
715 if (state
& GDK_SHIFT_MASK
)
724 _("You should Shift+Menu click over a file to "
725 "send it somewhere"));
729 paths
= filer_selected_items(filer_window
);
731 show_send_to_menu(paths
, event
); /* (paths eaten) */
737 GtkWidget
*file_label
, *file_menu
;
741 file_label
= filer_file_item
;
742 file_menu
= filer_file_menu
;
743 gtk_check_menu_item_set_active(
744 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
745 filer_window
->show_thumbs
);
746 gtk_check_menu_item_set_active(
747 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
748 filer_window
->show_hidden
);
749 buffer
= g_string_new(NULL
);
754 g_string_assign(buffer
, _("Next Click"));
755 shade_file_menu_items(FALSE
);
758 item
= filer_selected_item(filer_window
);
760 dir_update_item(filer_window
->directory
,
762 shade_file_menu_items(FALSE
);
763 file_item
= filer_selected_item(filer_window
);
764 g_string_printf(buffer
, "%s '%s'",
765 basetype_name(file_item
),
766 g_utf8_validate(file_item
->leafname
,
768 ? file_item
->leafname
770 if (!can_set_run_action(file_item
))
771 menu_set_items_shaded(filer_file_menu
,
775 shade_file_menu_items(TRUE
);
776 g_string_printf(buffer
, _("%d items"),
780 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
781 g_string_free(buffer
, TRUE
);
783 menu_show_shift_action(file_shift_item
, file_item
,
786 appmenu_add(make_path(filer_window
->sym_path
,
787 file_item
->leafname
)->str
,
788 file_item
, filer_file_menu
);
791 update_new_files_menu(get_menu_icon_style());
793 gtk_widget_set_sensitive(filer_new_window
,
794 !o_unique_filer_windows
.int_value
);
795 gtk_widget_set_sensitive(filer_follow_sym
,
796 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
798 popup_menu
= (state
& GDK_CONTROL_MASK
)
804 show_popup_menu(popup_menu
, event
,
805 popup_menu
== filer_file_menu
? 5 : 1);
808 static void menu_closed(GtkWidget
*widget
)
810 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
811 return; /* Close panel item chosen? */
815 if (window_with_focus
->temp_item_selected
)
817 view_clear_selection(window_with_focus
->view
);
818 window_with_focus
->temp_item_selected
= FALSE
;
822 static void target_callback(FilerWindow
*filer_window
,
826 g_return_if_fail(filer_window
!= NULL
);
828 window_with_focus
= filer_window
;
830 /* Don't grab the primary selection */
831 filer_window
->temp_item_selected
= TRUE
;
833 view_wink_item(filer_window
->view
, iter
);
834 view_select_only(filer_window
->view
, iter
);
835 file_op(NULL
, GPOINTER_TO_INT(action
), NULL
);
837 view_clear_selection(filer_window
->view
);
838 filer_window
->temp_item_selected
= FALSE
;
841 /* Set the text of the 'Shift Open...' menu item.
842 * If icon is NULL, reset the text and also shade it, unless 'next'.
844 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
846 guchar
*shift_action
= NULL
;
850 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
852 if (item
->flags
& ITEM_FLAG_MOUNTED
)
853 shift_action
= N_("Unmount");
855 shift_action
= N_("Open unmounted");
857 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
858 shift_action
= N_("Show Target");
859 else if (item
->base_type
== TYPE_DIRECTORY
)
860 shift_action
= N_("Look Inside");
861 else if (item
->base_type
== TYPE_FILE
)
862 shift_action
= N_("Open As Text");
864 gtk_label_set_text(GTK_LABEL(menu_item
),
865 shift_action
? _(shift_action
)
867 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
872 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
874 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
877 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
879 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
882 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
884 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
887 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
889 g_return_if_fail(window_with_focus
!= NULL
);
891 display_set_sort_fn(window_with_focus
, sort_by_name
);
894 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
896 g_return_if_fail(window_with_focus
!= NULL
);
898 display_set_sort_fn(window_with_focus
, sort_by_type
);
901 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
903 g_return_if_fail(window_with_focus
!= NULL
);
905 display_set_sort_fn(window_with_focus
, sort_by_date
);
908 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
910 g_return_if_fail(window_with_focus
!= NULL
);
912 display_set_sort_fn(window_with_focus
, sort_by_size
);
915 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
920 g_return_if_fail(window_with_focus
!= NULL
);
922 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
925 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
930 g_return_if_fail(window_with_focus
!= NULL
);
932 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
935 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
937 g_return_if_fail(window_with_focus
!= NULL
);
940 filer_update_dir(window_with_focus
, TRUE
);
943 static void delete(FilerWindow
*filer_window
)
946 paths
= filer_selected_items(filer_window
);
947 action_delete(paths
);
948 destroy_glist(&paths
);
951 static void usage(FilerWindow
*filer_window
)
954 paths
= filer_selected_items(filer_window
);
956 destroy_glist(&paths
);
959 static void chmod_items(FilerWindow
*filer_window
)
962 paths
= filer_selected_items(filer_window
);
963 action_chmod(paths
, FALSE
, NULL
);
964 destroy_glist(&paths
);
967 static void find(FilerWindow
*filer_window
)
970 paths
= filer_selected_items(filer_window
);
972 destroy_glist(&paths
);
975 /* This creates a new savebox widget, and allows the user to pick a new path
977 * Once the new path has been picked, the callback will be called with
978 * both the current and new paths.
979 * NOTE: This function unrefs 'image'!
981 static void savebox_show(const gchar
*action
, const gchar
*path
,
982 MaskedPixmap
*image
, SaveCb callback
)
984 GtkWidget
*savebox
= NULL
;
985 GtkWidget
*check_relative
= NULL
;
987 g_return_if_fail(image
!= NULL
);
989 savebox
= gtk_savebox_new(action
);
991 if (callback
== link_cb
)
993 check_relative
= gtk_check_button_new_with_mnemonic(
994 _("_Relative link"));
995 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
998 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
999 gtk_tooltips_set_tip(tooltips
, check_relative
,
1000 _("If on, the symlink will store the path from the "
1001 "symlink to the target file. Use this if the symlink "
1002 "and the target will be moved together.\n"
1003 "If off, the path from the root directory is stored - "
1004 "use this if the symlink may move but the target will "
1005 "stay put."), NULL
);
1006 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1007 check_relative
, FALSE
, TRUE
, 0);
1008 gtk_widget_show(check_relative
);
1011 g_signal_connect(savebox
, "save_to_file",
1012 G_CALLBACK(save_to_file
), NULL
);
1014 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1015 g_strdup(path
), g_free
);
1016 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1017 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1019 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1021 if (g_utf8_validate(path
, -1, NULL
))
1022 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1027 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1030 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1031 g_object_unref(image
);
1033 gtk_widget_show(savebox
);
1036 static gint
save_to_file(GObject
*savebox
,
1037 const gchar
*pathname
, gpointer data
)
1040 const gchar
*current_path
;
1042 callback
= g_object_get_data(savebox
, "action_callback");
1043 current_path
= g_object_get_data(savebox
, "current_path");
1045 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1046 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1048 return callback(savebox
, current_path
, pathname
)
1049 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1052 static gboolean
copy_cb(GObject
*savebox
,
1053 const gchar
*current
, const gchar
*new)
1055 return action_with_leaf(action_copy
, current
, new);
1058 static gboolean
action_with_leaf(ActionFn action
,
1059 const gchar
*current
, const gchar
*new)
1067 report_error(_("New pathname is not absolute"));
1071 if (new[strlen(new) - 1] == '/')
1073 new_dir
= g_strdup(new);
1080 slash
= strrchr(new, '/');
1081 new_dir
= g_strndup(new, slash
- new);
1085 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1086 action(local_paths
, new_dir
, leaf
, -1);
1087 g_list_free(local_paths
);
1094 /* Open a savebox to act on the selected file.
1095 * Call 'callback' later to perform the operation.
1097 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1098 const gchar
*action
, SaveCb callback
)
1100 g_object_ref(image
);
1101 savebox_show(action
, path
, image
, callback
);
1104 static gboolean
rename_cb(GObject
*savebox
,
1105 const gchar
*current
, const gchar
*new)
1107 return action_with_leaf(action_move
, current
, new);
1110 static gboolean
link_cb(GObject
*savebox
,
1111 const gchar
*initial
, const gchar
*path
)
1113 GtkToggleButton
*check_relative
;
1118 check_relative
= g_object_get_data(savebox
, "check_relative");
1120 if (gtk_toggle_button_get_active(check_relative
))
1121 link_path
= get_relative_path(path
, initial
);
1123 link_path
= g_strdup(initial
);
1125 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1127 GtkWidget
*box
, *button
;
1130 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1132 _("Symlink from '%s' already exists. "
1133 "Replace it with a link to '%s'?"),
1136 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1138 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1139 gtk_widget_show(button
);
1140 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1141 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1142 button
, GTK_RESPONSE_OK
);
1143 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1146 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1147 gtk_widget_destroy(box
);
1149 if (ans
!= GTK_RESPONSE_OK
)
1158 err
= symlink(link_path
, path
);
1163 report_error("symlink: %s", g_strerror(errno
));
1167 dir_check_this(path
);
1172 static void run_action(DirItem
*item
)
1174 if (can_set_run_action(item
))
1175 type_set_handler_dialog(item
->mime_type
);
1178 _("You can only set the run action for a "
1182 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1184 filer_opendir(home_dir
, NULL
, NULL
);
1187 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1191 path
= g_strconcat(filer_window
->sym_path
,
1192 "/", item
->leafname
, "#", NULL
);
1194 filer_change_to(filer_window
, path
, NULL
);
1198 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1200 g_return_if_fail(window_with_focus
!= NULL
);
1202 window_with_focus
->temp_item_selected
= FALSE
;
1203 view_select_all(window_with_focus
->view
);
1206 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1208 g_return_if_fail(window_with_focus
!= NULL
);
1210 window_with_focus
->temp_item_selected
= FALSE
;
1211 view_clear_selection(window_with_focus
->view
);
1214 static gboolean
invert_cb(ViewIter
*iter
, gpointer data
)
1216 return !view_get_selected((ViewIface
*) data
, iter
);
1219 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1221 g_return_if_fail(window_with_focus
!= NULL
);
1223 window_with_focus
->temp_item_selected
= FALSE
;
1225 view_select_if(window_with_focus
->view
, invert_cb
,
1226 window_with_focus
->view
);
1229 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1233 win
= options_show();
1237 number_of_windows
++;
1238 g_signal_connect(win
, "destroy",
1239 G_CALLBACK(one_less_window
), NULL
);
1243 static gboolean
new_directory_cb(GObject
*savebox
,
1244 const gchar
*initial
, const gchar
*path
)
1246 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1248 report_error("mkdir: %s", g_strerror(errno
));
1252 dir_check_this(path
);
1254 if (filer_exists(window_with_focus
))
1257 leaf
= strrchr(path
, '/');
1259 display_set_autoselect(window_with_focus
, leaf
+ 1);
1265 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1267 g_return_if_fail(window_with_focus
!= NULL
);
1269 savebox_show(_("Create"),
1270 make_path(window_with_focus
->sym_path
, _("NewDir"))->str
,
1271 type_to_icon(inode_directory
), new_directory_cb
);
1274 static gboolean
new_file_cb(GObject
*savebox
,
1275 const gchar
*initial
, const gchar
*path
)
1279 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1283 report_error(_("Error creating '%s': %s"),
1284 path
, g_strerror(errno
));
1289 report_error(_("Error creating '%s': %s"),
1290 path
, g_strerror(errno
));
1292 dir_check_this(path
);
1294 if (filer_exists(window_with_focus
))
1297 leaf
= strrchr(path
, '/');
1299 display_set_autoselect(window_with_focus
, leaf
+ 1);
1305 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1307 g_return_if_fail(window_with_focus
!= NULL
);
1309 savebox_show(_("Create"),
1310 make_path(window_with_focus
->sym_path
, _("NewFile"))->str
,
1311 type_to_icon(text_plain
),
1315 static gboolean
new_file_type_cb(GObject
*savebox
,
1316 const gchar
*initial
, const gchar
*path
)
1318 const gchar
*oleaf
, *leaf
;
1319 gchar
*templ
, *templ_dname
, *dest
;
1322 /* We can work out the template path from the initial name */
1323 oleaf
= g_basename(initial
);
1324 templ_dname
= choices_find_path_load("Templates", "");
1328 _("Error creating file: could not find the template for %s"),
1333 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1334 g_free(templ_dname
);
1336 dest
= g_path_get_dirname(path
);
1337 leaf
= g_basename(path
);
1338 paths
= g_list_append(NULL
, templ
);
1340 action_copy(paths
, dest
, leaf
, TRUE
);
1346 if (filer_exists(window_with_focus
))
1347 display_set_autoselect(window_with_focus
, leaf
);
1352 static void do_send_to(gchar
*templ
)
1354 g_return_if_fail(send_to_paths
!= NULL
);
1356 run_with_files(templ
, send_to_paths
);
1359 static void new_file_type(gchar
*templ
)
1364 g_return_if_fail(window_with_focus
!= NULL
);
1366 leaf
= g_basename(templ
);
1367 type
= type_get_type(templ
);
1369 savebox_show(_("Create"),
1370 make_path(window_with_focus
->sym_path
, leaf
)->str
,
1375 static void customise_send_to(gpointer data
)
1382 dirs
= g_string_new(NULL
);
1384 path
= choices_list_dirs("");
1385 for (i
= 0; i
< path
->len
; i
++)
1387 guchar
*old
= (guchar
*) path
->pdata
[i
];
1389 g_string_append(dirs
, old
);
1390 g_string_append(dirs
, "SendTo\n");
1392 choices_free_list(path
);
1394 save
= choices_find_path_save("", "SendTo", TRUE
);
1399 _("The `Send To' menu provides a quick way to send some files "
1400 "to an application. The applications listed are those in "
1401 "the following directories:\n\n%s\n%s\n"
1402 "The `Send To' menu may be opened by Shift+Menu clicking "
1405 "You can also create subdirectories called "
1406 "`.text_html', `.text', etc which will only be "
1407 "shown for files of that type. `.group' is shown "
1408 "only when multiple files are selected."),
1410 save
? _("I'll show you your SendTo directory now; you should "
1411 "symlink (Ctrl+Shift drag) any applications you want "
1413 : _("Your CHOICESPATH variable setting prevents "
1414 "customisations - sorry."));
1416 g_string_free(dirs
, TRUE
);
1419 filer_opendir(save
, NULL
, NULL
);
1422 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1425 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1432 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1434 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1436 searchdir
= g_strdup("SendTo");
1438 paths
= choices_list_dirs(searchdir
);
1441 for (i
= 0; i
< paths
->len
; i
++)
1443 GList
*widgets
= NULL
;
1444 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1446 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1447 (CallbackFn
) do_send_to
,
1448 FALSE
, FALSE
, TRUE
);
1451 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1452 gtk_menu_item_new());
1454 g_list_free(widgets
); /* TODO: Get rid of this */
1457 choices_free_list(paths
);
1460 /* Scan the SendTo dir and create and show the Send To menu.
1461 * The 'paths' list and every path in it is claimed, and will be
1462 * freed later -- don't free it yourself!
1464 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1466 GtkWidget
*menu
, *item
;
1468 menu
= gtk_menu_new();
1470 if (g_list_length(paths
) == 1)
1474 item
= diritem_new("");
1475 diritem_restat(paths
->data
, item
, NULL
);
1478 item
->mime_type
->media_type
,
1479 item
->mime_type
->subtype
);
1481 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1486 add_sendto(menu
, "group", NULL
);
1488 add_sendto(menu
, NULL
, NULL
);
1490 item
= gtk_menu_item_new_with_label(_("Customise"));
1491 g_signal_connect_swapped(item
, "activate",
1492 G_CALLBACK(customise_send_to
), NULL
);
1493 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1496 destroy_glist(&send_to_paths
);
1498 send_to_paths
= paths
;
1500 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1503 show_popup_menu(menu
, event
, 0);
1506 static void send_to(FilerWindow
*filer_window
)
1511 paths
= filer_selected_items(filer_window
);
1512 event
= gtk_get_current_event();
1515 show_send_to_menu(paths
, event
);
1517 gdk_event_free(event
);
1520 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1522 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1523 gboolean close
= action
;
1525 argv
[2] = o_menu_xterm
.value
;
1527 g_return_if_fail(window_with_focus
!= NULL
);
1529 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1530 gtk_widget_destroy(window_with_focus
->window
);
1533 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1535 g_return_if_fail(window_with_focus
!= NULL
);
1537 filer_change_to(window_with_focus
, home_dir
, NULL
);
1540 static void show_bookmarks(gpointer data
, guint action
, GtkWidget
*widget
)
1542 g_return_if_fail(window_with_focus
!= NULL
);
1544 bookmarks_show_menu(window_with_focus
);
1547 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1549 g_return_if_fail(window_with_focus
!= NULL
);
1551 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1552 filer_change_to(window_with_focus
,
1553 window_with_focus
->real_path
, NULL
);
1555 delayed_error(_("This is already the canonical name "
1556 "for this directory."));
1559 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1561 g_return_if_fail(window_with_focus
!= NULL
);
1563 filer_open_parent(window_with_focus
);
1566 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1568 g_return_if_fail(window_with_focus
!= NULL
);
1570 change_to_parent(window_with_focus
);
1573 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1575 g_return_if_fail(window_with_focus
!= NULL
);
1577 filer_window_autosize(window_with_focus
);
1580 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1582 g_return_if_fail(window_with_focus
!= NULL
);
1584 if (o_unique_filer_windows
.int_value
)
1586 report_error(_("You can't open a second view onto "
1587 "this directory because the `Unique Windows' option "
1588 "is turned on in the Options window."));
1591 filer_opendir(window_with_focus
->sym_path
, window_with_focus
, NULL
);
1595 static void su_to_user(GtkWidget
*dialog
)
1598 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1602 g_return_if_fail(dialog
!= NULL
);
1604 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1605 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1607 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1609 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1610 argv
[3] = gtk_entry_get_text(user
);
1611 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1615 report_error(_("fork: %s"), g_strerror(errno
));
1620 gtk_widget_destroy(dialog
);
1623 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1625 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1627 g_return_if_fail(window_with_focus
!= NULL
);
1629 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1630 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1631 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1632 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1633 g_strdup(window_with_focus
->path
), g_free
);
1635 vbox
= gtk_vbox_new(FALSE
, 4);
1636 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1637 gtk_box_pack_start(GTK_BOX(vbox
),
1638 gtk_label_new(_("Browse as which user?")),
1641 hbox
= gtk_hbox_new(FALSE
, 4);
1642 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1644 gtk_box_pack_start(GTK_BOX(hbox
),
1645 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1647 entry
= gtk_entry_new();
1648 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1649 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1650 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1651 gtk_widget_grab_focus(entry
);
1652 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1653 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1654 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1656 hbox
= gtk_hbox_new(TRUE
, 0);
1657 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1659 button
= gtk_button_new_with_label(_("OK"));
1660 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1661 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1662 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1663 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1664 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1666 button
= gtk_button_new_with_label(_("Cancel"));
1667 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1668 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1669 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1670 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1671 GTK_OBJECT(dialog
));
1673 gtk_widget_show_all(dialog
);
1677 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1679 g_return_if_fail(window_with_focus
!= NULL
);
1681 gtk_widget_destroy(window_with_focus
->window
);
1684 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1686 MiniType type
= (MiniType
) action
;
1688 g_return_if_fail(window_with_focus
!= NULL
);
1690 /* Item needs to remain selected... */
1691 if (type
== MINI_SHELL
)
1692 window_with_focus
->temp_item_selected
= FALSE
;
1694 minibuffer_show(window_with_focus
, type
);
1697 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1699 if (action
== HELP_ABOUT
)
1700 infobox_new(app_dir
);
1701 else if (action
== HELP_DIR
)
1702 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
, NULL
);
1703 else if (action
== HELP_MANUAL
)
1705 gchar
*manual
= NULL
;
1709 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1710 current_lang
, ".html", NULL
);
1711 if (access(manual
, F_OK
))
1712 null_g_free(&manual
);
1716 manual
= g_strconcat(app_dir
,
1717 "/Help/Manual.html", NULL
);
1719 run_by_path(manual
);
1724 g_warning("Unknown help action %d\n", action
);
1727 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1728 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1730 GList
*items
, *item
;
1732 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1734 item
= g_list_nth(items
, from
);
1737 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1743 static void save_menus(void)
1747 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1750 gtk_accel_map_save(menurc
);
1755 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1760 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1761 item
= g_list_nth_data(items
, n
);
1763 g_return_if_fail(item
!= NULL
);
1767 gtk_menu_shell_select_item(shell
, item
);
1770 static void file_op(gpointer data
, FileOp action
, GtkWidget
*unused
)
1777 g_return_if_fail(window_with_focus
!= NULL
);
1779 n_selected
= view_count_selected(window_with_focus
->view
);
1787 case FILE_COPY_ITEM
:
1788 prompt
= _("Copy ... ?");
1790 case FILE_RENAME_ITEM
:
1791 prompt
= _("Rename ... ?");
1793 case FILE_LINK_ITEM
:
1794 prompt
= _("Symlink ... ?");
1796 case FILE_OPEN_FILE
:
1797 prompt
= _("Shift Open ... ?");
1800 prompt
= _("Help about ... ?");
1802 case FILE_SHOW_FILE_INFO
:
1803 prompt
= _("Examine ... ?");
1805 case FILE_RUN_ACTION
:
1806 prompt
= _("Set run action for ... ?");
1809 prompt
= _("Set icon for ... ?");
1812 prompt
= _("Send ... to ... ?");
1815 prompt
= _("DELETE ... ?");
1818 prompt
= _("Count the size of ... ?");
1820 case FILE_CHMOD_ITEMS
:
1821 prompt
= _("Set permissions on ... ?");
1824 prompt
= _("Search inside ... ?");
1826 case FILE_OPEN_VFS_AVFS
:
1827 prompt
= _("Look inside ... ?");
1830 g_warning("Unknown action!");
1833 filer_target_mode(window_with_focus
, target_callback
,
1834 GINT_TO_POINTER(action
), prompt
);
1841 send_to(window_with_focus
);
1844 delete(window_with_focus
);
1847 usage(window_with_focus
);
1849 case FILE_CHMOD_ITEMS
:
1850 chmod_items(window_with_focus
);
1853 find(window_with_focus
);
1855 case FILE_SHOW_FILE_INFO
:
1859 items
= filer_selected_items(window_with_focus
);
1860 infobox_show_list(items
);
1861 destroy_glist(&items
);
1868 /* All the following actions require exactly one file selected */
1872 report_error(_("You cannot do this to more than "
1873 "one item at a time"));
1877 view_get_iter(window_with_focus
->view
, &iter
, VIEW_ITER_SELECTED
);
1879 item
= iter
.next(&iter
);
1880 g_return_if_fail(item
!= NULL
);
1881 /* iter may be passed to filer_openitem... */
1884 item
= dir_update_item(window_with_focus
->directory
,
1889 report_error(_("Item no longer exists!"));
1893 path
= make_path(window_with_focus
->sym_path
, item
->leafname
)->str
;
1897 case FILE_COPY_ITEM
:
1898 src_dest_action_item(path
, item
->image
,
1899 _("Copy"), copy_cb
);
1901 case FILE_RENAME_ITEM
:
1902 src_dest_action_item(path
, item
->image
,
1903 _("Rename"), rename_cb
);
1905 case FILE_LINK_ITEM
:
1906 src_dest_action_item(path
, item
->image
,
1907 _("Symlink"), link_cb
);
1909 case FILE_OPEN_FILE
:
1910 filer_openitem(window_with_focus
, &iter
,
1911 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1914 show_item_help(path
, item
);
1916 case FILE_RUN_ACTION
:
1920 icon_set_handler_dialog(item
, path
);
1922 case FILE_OPEN_VFS_AVFS
:
1923 open_vfs_avfs(window_with_focus
, item
);
1926 g_warning("Unknown action!");
1931 static void show_key_help(GtkWidget
*button
, gpointer data
)
1933 gboolean can_change_accels
;
1935 g_object_get(G_OBJECT(gtk_settings_get_default()),
1936 "gtk-can-change-accels", &can_change_accels
,
1939 if (!can_change_accels
)
1941 info_message(_("User-definable shortcuts are disabled by "
1942 "default in Gtk2, and you have not enabled "
1943 "them. You can turn this feature on by:\n"
1944 "1) using an XSettings manager, such as ROX-Session\n"
1946 "2) adding this line to ~/.gtkrc-2.0:\n"
1947 "\tgtk-can-change-accels = 1"));
1951 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1952 "- Open the menu over a filer window,\n"
1953 "- Move the pointer over the item you want to use,\n"
1954 "- Press the key you want attached to it.\n\n"
1955 "The key will appear next to the menu item and you can just press "
1956 "that key without opening the menu in future."));
1959 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1961 GtkWidget
*button
, *align
;
1963 g_return_val_if_fail(option
== NULL
, NULL
);
1965 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1966 button
= button_new_mixed(GTK_STOCK_DIALOG_INFO
,
1967 _("Set keyboard shortcuts"));
1968 gtk_container_add(GTK_CONTAINER(align
), button
);
1969 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1971 return g_list_append(NULL
, align
);