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_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
212 {">", NULL
, NULL
, 0, "<Separator>"},
213 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
214 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
215 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
216 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
217 {">", NULL
, NULL
, 0, "<Separator>"},
218 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
219 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
220 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
221 {">" N_("Count"), NULL
, file_op
, FILE_USAGE
, NULL
},
222 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
223 {">", NULL
, NULL
, 0, "<Separator>"},
224 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
225 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
226 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
227 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
228 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
229 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
230 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
231 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
232 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
233 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
234 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
235 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
236 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
237 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
238 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
239 {">" N_("Follow Symbolic Links"), NULL
, follow_symlinks
, 0, NULL
},
240 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
241 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
243 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
244 {">", NULL
, NULL
, 0, "<Separator>"},
245 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
246 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
247 {">" N_("Xterm Here"), NULL
, xterm_here
, FALSE
, NULL
},
248 {">" N_("Switch to xterm"), NULL
, xterm_here
, TRUE
, NULL
},
249 {N_("Help"), NULL
, NULL
, 0, "<Branch>"},
250 {">" N_("About ROX-Filer..."), NULL
, menu_rox_help
, HELP_ABOUT
, NULL
},
251 {">" N_("Show Help Files"), "F1", menu_rox_help
, HELP_DIR
, NULL
},
252 {">" N_("Manual"), NULL
, menu_rox_help
, HELP_MANUAL
, NULL
},
256 #define GET_MENU_ITEM(var, menu) \
257 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
259 #define GET_SMENU_ITEM(var, menu, sub) \
261 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
262 var = gtk_item_factory_get_widget(item_factory, tmp); \
266 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
268 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
269 var = gtk_item_factory_get_widget(item_factory, tmp); \
273 void ensure_filer_menu(void)
278 GtkItemFactory
*item_factory
;
283 filer_keys
= gtk_accel_group_new();
284 item_factory
= menu_create(filer_menu_def
,
285 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
286 "<filer>", filer_keys
);
288 GET_MENU_ITEM(filer_menu
, "filer");
289 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
290 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
291 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
294 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
295 GET_SSMENU_ITEM(item
, "filer", "Window", "Follow Symbolic Links");
296 filer_follow_sym
= GTK_BIN(item
)->child
;
298 /* File '' label... */
299 items
= gtk_container_get_children(GTK_CONTAINER(filer_menu
));
300 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
303 /* Shift Open... label */
304 items
= gtk_container_get_children(GTK_CONTAINER(filer_file_menu
));
305 file_shift_item
= GTK_BIN(g_list_nth(items
, 6)->data
)->child
;
308 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
309 filer_new_window
= GTK_BIN(item
)->child
;
311 g_signal_connect(filer_menu
, "unmap_event",
312 G_CALLBACK(menu_closed
), NULL
);
313 g_signal_connect(filer_file_menu
, "unmap_event",
314 G_CALLBACK(menu_closed
), NULL
);
316 g_signal_connect(filer_keys
, "accel_changed",
317 G_CALLBACK(save_menus
), NULL
);
324 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
327 gtk_accel_map_load(menurc
);
331 option_add_string(&o_menu_xterm
, "menu_xterm", "xterm");
332 option_add_int(&o_menu_iconsize
, "menu_iconsize", MIS_SMALL
);
333 option_add_saver(save_menus
);
335 option_register_widget("menu-set-keys", set_keys_button
);
338 /* Name is in the form "<panel>" */
339 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
340 const gchar
*name
, GtkAccelGroup
*keys
)
342 GtkItemFactory
*item_factory
;
343 GtkItemFactoryEntry
*translated
;
347 keys
= gtk_accel_group_new();
348 gtk_accel_group_lock(keys
);
351 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
353 translated
= translate_entries(def
, n_entries
);
354 gtk_item_factory_create_items(item_factory
, n_entries
,
356 free_translated_entries(translated
, n_entries
);
361 /* Prevent the user from setting a short-cut on this item */
362 static void menuitem_no_shortcuts(GtkWidget
*item
)
366 GtkMenuItem
*menuitem
= GTK_MENU_ITEM(item
);
368 _gtk_widget_set_accel_path(item
, NULL
, NULL
);
369 g_free(menuitem
->accel_path
);
370 menuitem
->accel_path
= NULL
;
374 /* Shade items that only work on single files */
375 static void shade_file_menu_items(gboolean shaded
)
377 menu_set_items_shaded(filer_file_menu
, shaded
, 0, 3);
378 menu_set_items_shaded(filer_file_menu
, shaded
, 5, 3);
379 menu_set_items_shaded(filer_file_menu
, shaded
, 10, 2);
382 /* 'data' is an array of three ints:
383 * [ pointer_x, pointer_y, item_under_pointer ]
385 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
386 gboolean
*push_in
, gpointer data
)
388 int *pos
= (int *) data
;
389 GtkRequisition requisition
;
394 next
= items
= gtk_container_get_children(GTK_CONTAINER(menu
));
396 while (item
>= 0 && next
)
398 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
411 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
413 *x
= pos
[0] - (requisition
.width
* 7 / 8);
414 *y
= pos
[1] - y_shift
;
416 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
417 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
423 /* Used when you menu-click on the Large or Small toolbar tools */
424 void show_style_menu(FilerWindow
*filer_window
,
425 GdkEventButton
*event
,
430 pos
[0] = event
->x_root
;
431 pos
[1] = event
->y_root
;
434 window_with_focus
= filer_window
;
438 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
439 (gpointer
) pos
, event
->button
, event
->time
);
443 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dir_name
,
444 MenuIconStyle style
, CallbackFn func
,
445 gboolean separator
, gboolean strip_ext
,
448 GList
*widgets
= NULL
;
455 dname
= pathdup(dir_name
);
457 dir
= opendir(dname
);
463 item
= gtk_menu_item_new();
464 widgets
= g_list_append(widgets
, item
);
465 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
468 while ((ent
= readdir(dir
)))
476 /* Ignore hidden files */
477 if (ent
->d_name
[0] == '.')
480 /* Strip off extension, if any */
481 dot
= strchr(ent
->d_name
, '.');
482 if (strip_ext
&& dot
)
483 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
485 leaf
= g_strdup(ent
->d_name
);
487 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
488 ditem
= diritem_new("");
489 diritem_restat(fname
, ditem
, NULL
);
491 if (ditem
->image
&& style
!= MIS_NONE
)
497 pixbuf
= ditem
->image
->pixbuf
;
500 if (!ditem
->image
->sm_pixbuf
)
501 pixmap_make_small(ditem
->image
);
502 pixbuf
= ditem
->image
->sm_pixbuf
;
506 item
= gtk_menu_item_new();
507 /* TODO: Find a way to allow short-cuts */
508 menuitem_no_shortcuts(item
);
510 hbox
= gtk_hbox_new(FALSE
, 2);
511 gtk_container_add(GTK_CONTAINER(item
), hbox
);
513 img
= gtk_image_new_from_pixbuf(pixbuf
);
515 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
517 label
= gtk_label_new(leaf
);
518 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
519 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
523 item
= gtk_menu_item_new_with_label(leaf
);
525 /* If it is a directory (but NOT an AppDir) and we are
526 * recursing then set up a sub menu.
528 if (recurse
&& ditem
->base_type
== TYPE_DIRECTORY
&&
529 !(ditem
->flags
& ITEM_FLAG_APPDIR
))
534 sub
= gtk_menu_new();
535 new_widgets
= menu_from_dir(sub
, fname
, style
, func
,
536 separator
, strip_ext
, FALSE
);
537 g_list_free(new_widgets
);
538 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item
), sub
);
541 g_signal_connect_swapped(item
, "activate",
542 G_CALLBACK(func
), fname
);
547 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
548 g_signal_connect_swapped(item
, "destroy",
549 G_CALLBACK(g_free
), fname
);
551 widgets
= g_list_append(widgets
, item
);
561 /* Scan the templates dir and create entries for the New menu */
562 static void update_new_files_menu(MenuIconStyle style
)
564 static GList
*widgets
= NULL
;
566 gchar
*templ_dname
= NULL
;
572 for (next
= widgets
; next
; next
= next
->next
)
573 gtk_widget_destroy((GtkWidget
*) next
->data
);
575 g_list_free(widgets
);
579 templ_dname
= choices_find_path_load("Templates", "");
582 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
583 (CallbackFn
) new_file_type
, TRUE
, TRUE
,
587 gtk_widget_show_all(filer_new_menu
);
590 /* 'item' is the number of the item to appear under the pointer. */
591 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
597 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
598 event
->type
== GDK_BUTTON_RELEASE
))
600 GdkEventButton
*bev
= (GdkEventButton
*) event
;
602 pos
[0] = bev
->x_root
;
603 pos
[1] = bev
->y_root
;
604 button
= bev
->button
;
607 else if (event
&& event
->type
== GDK_KEY_PRESS
)
609 GdkEventKey
*kev
= (GdkEventKey
*) event
;
611 get_pointer_xy(pos
, pos
+ 1);
615 get_pointer_xy(pos
, pos
+ 1);
619 gtk_widget_show_all(menu
);
620 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
621 position_menu
, (gpointer
) pos
, button
, time
);
622 select_nth_item(GTK_MENU_SHELL(menu
), item
);
625 /* Hide the popup menu, if any */
626 void menu_popdown(void)
629 gtk_menu_popdown(GTK_MENU(popup_menu
));
632 static MenuIconStyle
get_menu_icon_style(void)
637 mis
= o_menu_iconsize
.int_value
;
641 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
:
647 if (mis
== MIS_CURRENT
&& window_with_focus
)
649 switch (window_with_focus
->display_style
)
661 display
= o_display_size
.int_value
;
676 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
678 DirItem
*file_item
= NULL
;
679 GdkModifierType state
= 0;
682 n_selected
= view_count_selected(filer_window
->view
);
688 /* Remove previous AppMenu, if any */
691 window_with_focus
= filer_window
;
693 if (event
->type
== GDK_BUTTON_PRESS
)
694 state
= ((GdkEventButton
*) event
)->state
;
695 else if (event
->type
== GDK_KEY_PRESS
)
696 state
= ((GdkEventKey
*) event
)->state
;
698 if (n_selected
== 0 && item
>= 0)
700 filer_window
->temp_item_selected
= TRUE
;
701 collection_select_item(filer_window
->collection
, item
);
702 n_selected
= view_count_selected(filer_window
->view
);
706 filer_window
->temp_item_selected
= FALSE
;
709 /* Short-cut to the Send To menu */
710 if (state
& GDK_SHIFT_MASK
)
719 _("You should Shift+Menu click over a file to "
720 "send it somewhere"));
724 paths
= filer_selected_items(filer_window
);
726 show_send_to_menu(paths
, event
); /* (paths eaten) */
732 GtkWidget
*file_label
, *file_menu
;
736 file_label
= filer_file_item
;
737 file_menu
= filer_file_menu
;
738 gtk_check_menu_item_set_active(
739 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
740 filer_window
->show_thumbs
);
741 gtk_check_menu_item_set_active(
742 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
743 filer_window
->show_hidden
);
744 buffer
= g_string_new(NULL
);
749 g_string_assign(buffer
, _("Next Click"));
750 shade_file_menu_items(FALSE
);
753 item
= filer_selected_item(filer_window
);
755 dir_update_item(filer_window
->directory
,
757 shade_file_menu_items(FALSE
);
758 file_item
= filer_selected_item(filer_window
);
759 g_string_sprintf(buffer
, "%s '%s'",
760 basetype_name(file_item
),
761 file_item
->leafname
);
762 if (!can_set_run_action(file_item
))
763 menu_set_items_shaded(filer_file_menu
,
767 shade_file_menu_items(TRUE
);
768 g_string_sprintf(buffer
, _("%d items"),
772 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
773 g_string_free(buffer
, TRUE
);
775 menu_show_shift_action(file_shift_item
, file_item
,
778 appmenu_add(make_path(filer_window
->sym_path
,
779 file_item
->leafname
)->str
,
780 file_item
, filer_file_menu
);
783 update_new_files_menu(get_menu_icon_style());
785 gtk_widget_set_sensitive(filer_new_window
,
786 !o_unique_filer_windows
.int_value
);
787 gtk_widget_set_sensitive(filer_follow_sym
,
788 strcmp(filer_window
->sym_path
, filer_window
->real_path
) != 0);
790 popup_menu
= (state
& GDK_CONTROL_MASK
)
796 show_popup_menu(popup_menu
, event
,
797 popup_menu
== filer_file_menu
? 5 : 1);
800 static void menu_closed(GtkWidget
*widget
)
802 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
803 return; /* Close panel item chosen? */
807 if (window_with_focus
->temp_item_selected
)
809 view_clear_selection(window_with_focus
->view
);
810 window_with_focus
->temp_item_selected
= FALSE
;
814 static void target_callback(FilerWindow
*filer_window
,
818 Collection
*collection
;
820 g_return_if_fail(filer_window
!= NULL
);
822 collection
= filer_window
->collection
;
824 window_with_focus
= filer_window
;
826 /* Don't grab the primary selection */
827 filer_window
->temp_item_selected
= TRUE
;
829 collection_wink_item(collection
, item
);
830 collection_clear_except(collection
, item
);
831 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
833 if (item
< collection
->number_of_items
)
834 collection_unselect_item(collection
, item
);
835 filer_window
->temp_item_selected
= FALSE
;
838 /* Set the text of the 'Shift Open...' menu item.
839 * If icon is NULL, reset the text and also shade it, unless 'next'.
841 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
843 guchar
*shift_action
= NULL
;
847 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
849 if (item
->flags
& ITEM_FLAG_MOUNTED
)
850 shift_action
= N_("Unmount");
852 shift_action
= N_("Mount");
854 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
855 shift_action
= N_("Show Target");
856 else if (item
->base_type
== TYPE_DIRECTORY
)
857 shift_action
= N_("Look Inside");
858 else if (item
->base_type
== TYPE_FILE
)
859 shift_action
= N_("Open As Text");
861 gtk_label_set_text(GTK_LABEL(menu_item
),
862 shift_action
? _(shift_action
)
864 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
869 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
871 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
874 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
876 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
879 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
881 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
884 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
886 g_return_if_fail(window_with_focus
!= NULL
);
888 display_set_sort_fn(window_with_focus
, sort_by_name
);
891 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
893 g_return_if_fail(window_with_focus
!= NULL
);
895 display_set_sort_fn(window_with_focus
, sort_by_type
);
898 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
900 g_return_if_fail(window_with_focus
!= NULL
);
902 display_set_sort_fn(window_with_focus
, sort_by_date
);
905 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
907 g_return_if_fail(window_with_focus
!= NULL
);
909 display_set_sort_fn(window_with_focus
, sort_by_size
);
912 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
917 g_return_if_fail(window_with_focus
!= NULL
);
919 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
922 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
927 g_return_if_fail(window_with_focus
!= NULL
);
929 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
932 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
934 g_return_if_fail(window_with_focus
!= NULL
);
937 filer_update_dir(window_with_focus
, TRUE
);
940 static void delete(FilerWindow
*filer_window
)
943 paths
= filer_selected_items(filer_window
);
944 action_delete(paths
);
945 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
949 static void usage(FilerWindow
*filer_window
)
952 paths
= filer_selected_items(filer_window
);
954 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
958 static void chmod_items(FilerWindow
*filer_window
)
961 paths
= filer_selected_items(filer_window
);
962 action_chmod(paths
, FALSE
, NULL
);
963 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
967 static void find(FilerWindow
*filer_window
)
970 paths
= filer_selected_items(filer_window
);
972 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
976 /* This creates a new savebox widget, and allows the user to pick a new path
978 * Once the new path has been picked, the callback will be called with
979 * both the current and new paths.
980 * NOTE: This function unrefs 'image'!
982 static void savebox_show(const gchar
*action
, const gchar
*path
,
983 MaskedPixmap
*image
, SaveCb callback
)
985 GtkWidget
*savebox
= NULL
;
986 GtkWidget
*check_relative
= NULL
;
988 g_return_if_fail(image
!= NULL
);
990 savebox
= gtk_savebox_new(action
);
992 if (callback
== link_cb
)
994 check_relative
= gtk_check_button_new_with_mnemonic(
995 _("_Relative link"));
996 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
),
999 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
1000 gtk_tooltips_set_tip(tooltips
, check_relative
,
1001 _("If on, the symlink will store the path from the "
1002 "symlink to the target file. Use this if the symlink "
1003 "and the target will be moved together.\n"
1004 "If off, the path from the root directory is stored - "
1005 "use this if the symlink may move but the target will "
1006 "stay put."), NULL
);
1007 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox
)->vbox
),
1008 check_relative
, FALSE
, TRUE
, 0);
1009 gtk_widget_show(check_relative
);
1012 g_signal_connect(savebox
, "save_to_file",
1013 G_CALLBACK(save_to_file
), NULL
);
1015 g_object_set_data_full(G_OBJECT(savebox
), "current_path",
1016 g_strdup(path
), g_free
);
1017 g_object_set_data(G_OBJECT(savebox
), "action_callback", callback
);
1018 g_object_set_data(G_OBJECT(savebox
), "check_relative", check_relative
);
1020 gtk_window_set_title(GTK_WINDOW(savebox
), action
);
1022 if (g_utf8_validate(path
, -1, NULL
))
1023 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), path
);
1028 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), u8
);
1031 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixbuf
);
1032 g_object_unref(image
);
1034 gtk_widget_show(savebox
);
1037 static gint
save_to_file(GObject
*savebox
,
1038 const gchar
*pathname
, gpointer data
)
1041 const gchar
*current_path
;
1043 callback
= g_object_get_data(savebox
, "action_callback");
1044 current_path
= g_object_get_data(savebox
, "current_path");
1046 g_return_val_if_fail(callback
!= NULL
, GTK_XDS_SAVE_ERROR
);
1047 g_return_val_if_fail(current_path
!= NULL
, GTK_XDS_SAVE_ERROR
);
1049 return callback(savebox
, current_path
, pathname
)
1050 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1053 static gboolean
copy_cb(GObject
*savebox
,
1054 const gchar
*current
, const gchar
*new)
1056 return action_with_leaf(action_copy
, current
, new);
1059 static gboolean
action_with_leaf(ActionFn action
,
1060 const gchar
*current
, const gchar
*new)
1068 report_error(_("New pathname is not absolute"));
1072 if (new[strlen(new) - 1] == '/')
1074 new_dir
= g_strdup(new);
1081 slash
= strrchr(new, '/');
1082 new_dir
= g_strndup(new, slash
- new);
1086 local_paths
= g_list_append(NULL
, (gchar
*) current
);
1087 action(local_paths
, new_dir
, leaf
, -1);
1088 g_list_free(local_paths
);
1095 /* Open a savebox to act on the selected file.
1096 * Call 'callback' later to perform the operation.
1098 static void src_dest_action_item(const gchar
*path
, MaskedPixmap
*image
,
1099 const gchar
*action
, SaveCb callback
)
1101 g_object_ref(image
);
1102 savebox_show(action
, path
, image
, callback
);
1105 static gboolean
rename_cb(GObject
*savebox
,
1106 const gchar
*current
, const gchar
*new)
1108 return action_with_leaf(action_move
, current
, new);
1111 static gboolean
link_cb(GObject
*savebox
,
1112 const gchar
*initial
, const gchar
*path
)
1114 GtkToggleButton
*check_relative
;
1119 check_relative
= g_object_get_data(savebox
, "check_relative");
1121 if (gtk_toggle_button_get_active(check_relative
))
1122 link_path
= get_relative_path(path
, initial
);
1124 link_path
= g_strdup(initial
);
1126 if (mc_lstat(path
, &info
) == 0 && S_ISLNK(info
.st_mode
))
1128 GtkWidget
*box
, *button
;
1131 box
= gtk_message_dialog_new(NULL
, 0, GTK_MESSAGE_QUESTION
,
1133 _("Symlink from '%s' already exists. "
1134 "Replace it with a link to '%s'?"),
1137 gtk_window_set_position(GTK_WINDOW(box
), GTK_WIN_POS_MOUSE
);
1139 button
= button_new_mixed(GTK_STOCK_YES
, _("_Replace"));
1140 gtk_widget_show(button
);
1141 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1142 gtk_dialog_add_action_widget(GTK_DIALOG(box
),
1143 button
, GTK_RESPONSE_OK
);
1144 gtk_dialog_set_default_response(GTK_DIALOG(box
),
1147 ans
= gtk_dialog_run(GTK_DIALOG(box
));
1148 gtk_widget_destroy(box
);
1150 if (ans
!= GTK_RESPONSE_OK
)
1159 err
= symlink(link_path
, path
);
1164 report_error("symlink: %s", g_strerror(errno
));
1168 dir_check_this(path
);
1173 static void run_action(DirItem
*item
)
1175 if (can_set_run_action(item
))
1176 type_set_handler_dialog(item
->mime_type
);
1179 _("You can only set the run action for a "
1183 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1185 filer_opendir(home_dir
, NULL
);
1188 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1192 path
= g_strconcat(filer_window
->sym_path
,
1193 "/", item
->leafname
, "#", NULL
);
1195 filer_change_to(filer_window
, path
, NULL
);
1199 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1201 g_return_if_fail(window_with_focus
!= NULL
);
1203 window_with_focus
->temp_item_selected
= FALSE
;
1204 collection_select_all(window_with_focus
->collection
);
1207 static void clear_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 view_clear_selection(window_with_focus
->view
);
1215 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1217 g_return_if_fail(window_with_focus
!= NULL
);
1219 window_with_focus
->temp_item_selected
= FALSE
;
1220 collection_invert_selection(window_with_focus
->collection
);
1223 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1227 win
= options_show();
1231 number_of_windows
++;
1232 g_signal_connect(win
, "destroy",
1233 G_CALLBACK(one_less_window
), NULL
);
1237 static gboolean
new_directory_cb(GObject
*savebox
,
1238 const gchar
*initial
, const gchar
*path
)
1240 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1242 report_error("mkdir: %s", g_strerror(errno
));
1246 dir_check_this(path
);
1248 if (filer_exists(window_with_focus
))
1251 leaf
= strrchr(path
, '/');
1253 display_set_autoselect(window_with_focus
, leaf
+ 1);
1259 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1261 g_return_if_fail(window_with_focus
!= NULL
);
1263 savebox_show(_("Create"),
1264 make_path(window_with_focus
->sym_path
, _("NewDir"))->str
,
1265 type_to_icon(inode_directory
), new_directory_cb
);
1268 static gboolean
new_file_cb(GObject
*savebox
,
1269 const gchar
*initial
, const gchar
*path
)
1273 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1277 report_error(_("Error creating '%s': %s"),
1278 path
, g_strerror(errno
));
1283 report_error(_("Error creating '%s': %s"),
1284 path
, g_strerror(errno
));
1286 dir_check_this(path
);
1288 if (filer_exists(window_with_focus
))
1291 leaf
= strrchr(path
, '/');
1293 display_set_autoselect(window_with_focus
, leaf
+ 1);
1299 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1301 g_return_if_fail(window_with_focus
!= NULL
);
1303 savebox_show(_("Create"),
1304 make_path(window_with_focus
->sym_path
, _("NewFile"))->str
,
1305 type_to_icon(text_plain
),
1309 static gboolean
new_file_type_cb(GObject
*savebox
,
1310 const gchar
*initial
, const gchar
*path
)
1312 const gchar
*oleaf
, *leaf
;
1313 gchar
*templ
, *templ_dname
, *dest
;
1316 /* We can work out the template path from the initial name */
1317 oleaf
= g_basename(initial
);
1318 templ_dname
= choices_find_path_load("Templates", "");
1322 _("Error creating file: could not find the template for %s"),
1327 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1328 g_free(templ_dname
);
1330 dest
= g_dirname(path
);
1331 leaf
= g_basename(path
);
1332 paths
= g_list_append(NULL
, templ
);
1334 action_copy(paths
, dest
, leaf
, TRUE
);
1340 if (filer_exists(window_with_focus
))
1341 display_set_autoselect(window_with_focus
, leaf
);
1346 static void do_send_to(gchar
*templ
)
1348 g_return_if_fail(send_to_paths
!= NULL
);
1350 run_with_files(templ
, send_to_paths
);
1353 static void new_file_type(gchar
*templ
)
1358 g_return_if_fail(window_with_focus
!= NULL
);
1360 leaf
= g_basename(templ
);
1361 type
= type_get_type(templ
);
1363 savebox_show(_("Create"),
1364 make_path(window_with_focus
->sym_path
, leaf
)->str
,
1369 static void customise_send_to(gpointer data
)
1376 dirs
= g_string_new(NULL
);
1378 path
= choices_list_dirs("");
1379 for (i
= 0; i
< path
->len
; i
++)
1381 guchar
*old
= (guchar
*) path
->pdata
[i
];
1383 g_string_append(dirs
, old
);
1384 g_string_append(dirs
, "SendTo\n");
1386 choices_free_list(path
);
1388 save
= choices_find_path_save("", "SendTo", TRUE
);
1393 _("The `Send To' menu provides a quick way to send some files "
1394 "to an application. The applications listed are those in "
1395 "the following directories:\n\n%s\n%s\n"
1396 "The `Send To' menu may be opened by Shift+Menu clicking "
1399 "You can also create subdirectories called "
1400 "`.text_html', `.text', etc which will only be "
1401 "shown for files of that type. `.group' is shown "
1402 "only when multiple files are selected."),
1404 save
? _("I'll show you your SendTo directory now; you should "
1405 "symlink (Ctrl+Shift drag) any applications you want "
1407 : _("Your CHOICESPATH variable setting prevents "
1408 "customisations - sorry."));
1410 g_string_free(dirs
, TRUE
);
1413 filer_opendir(save
, NULL
);
1416 /* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1419 static void add_sendto(GtkWidget
*menu
, const gchar
*type
, const gchar
*subtype
)
1426 searchdir
= g_strdup_printf("SendTo/.%s_%s", type
, subtype
);
1428 searchdir
= g_strdup_printf("SendTo/.%s", type
);
1430 searchdir
= g_strdup("SendTo");
1432 paths
= choices_list_dirs(searchdir
);
1435 for (i
= 0; i
< paths
->len
; i
++)
1437 GList
*widgets
= NULL
;
1438 guchar
*dir
= (guchar
*) paths
->pdata
[i
];
1440 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1441 (CallbackFn
) do_send_to
,
1442 FALSE
, FALSE
, TRUE
);
1445 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1446 gtk_menu_item_new());
1448 g_list_free(widgets
); /* TODO: Get rid of this */
1451 choices_free_list(paths
);
1454 /* Scan the SendTo dir and create and show the Send To menu.
1455 * The 'paths' list and every path in it is claimed, and will be
1456 * freed later -- don't free it yourself!
1458 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1460 GtkWidget
*menu
, *item
;
1462 menu
= gtk_menu_new();
1464 if (g_list_length(paths
) == 1)
1468 item
= diritem_new("");
1469 diritem_restat(paths
->data
, item
, NULL
);
1472 item
->mime_type
->media_type
,
1473 item
->mime_type
->subtype
);
1475 add_sendto(menu
, item
->mime_type
->media_type
, NULL
);
1480 add_sendto(menu
, "group", NULL
);
1482 add_sendto(menu
, NULL
, NULL
);
1484 item
= gtk_menu_item_new_with_label(_("Customise"));
1485 g_signal_connect_swapped(item
, "activate",
1486 G_CALLBACK(customise_send_to
), NULL
);
1487 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1491 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1492 g_list_free(send_to_paths
);
1494 send_to_paths
= paths
;
1496 g_signal_connect(menu
, "unmap_event", G_CALLBACK(menu_closed
), NULL
);
1499 show_popup_menu(menu
, event
, 0);
1502 static void send_to(FilerWindow
*filer_window
)
1507 paths
= filer_selected_items(filer_window
);
1508 event
= gtk_get_current_event();
1511 show_send_to_menu(paths
, event
);
1513 gdk_event_free(event
);
1516 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1518 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1519 gboolean close
= action
;
1521 argv
[2] = o_menu_xterm
.value
;
1523 g_return_if_fail(window_with_focus
!= NULL
);
1525 if (rox_spawn(window_with_focus
->sym_path
, argv
) && close
)
1526 gtk_widget_destroy(window_with_focus
->window
);
1529 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1531 g_return_if_fail(window_with_focus
!= NULL
);
1533 filer_change_to(window_with_focus
, home_dir
, NULL
);
1536 static void follow_symlinks(gpointer data
, guint action
, GtkWidget
*widget
)
1538 g_return_if_fail(window_with_focus
!= NULL
);
1540 if (strcmp(window_with_focus
->real_path
, window_with_focus
->sym_path
))
1541 filer_change_to(window_with_focus
,
1542 window_with_focus
->real_path
, NULL
);
1544 delayed_error(_("This is already the canonical name "
1545 "for this directory."));
1548 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1550 g_return_if_fail(window_with_focus
!= NULL
);
1552 filer_open_parent(window_with_focus
);
1555 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1557 g_return_if_fail(window_with_focus
!= NULL
);
1559 change_to_parent(window_with_focus
);
1562 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1564 g_return_if_fail(window_with_focus
!= NULL
);
1566 filer_window_autosize(window_with_focus
, TRUE
);
1569 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1571 g_return_if_fail(window_with_focus
!= NULL
);
1573 if (o_unique_filer_windows
.int_value
)
1575 report_error(_("You can't open a second view onto "
1576 "this directory because the `Unique Windows' option "
1577 "is turned on in the Options window."));
1580 filer_opendir(window_with_focus
->sym_path
, window_with_focus
);
1584 static void su_to_user(GtkWidget
*dialog
)
1587 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1591 g_return_if_fail(dialog
!= NULL
);
1593 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1594 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1596 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1598 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1599 argv
[3] = gtk_entry_get_text(user
);
1600 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1604 report_error(_("fork: %s"), g_strerror(errno
));
1609 gtk_widget_destroy(dialog
);
1612 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1614 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1616 g_return_if_fail(window_with_focus
!= NULL
);
1618 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1619 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1620 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1621 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1622 g_strdup(window_with_focus
->path
), g_free
);
1624 vbox
= gtk_vbox_new(FALSE
, 4);
1625 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1626 gtk_box_pack_start(GTK_BOX(vbox
),
1627 gtk_label_new(_("Browse as which user?")),
1630 hbox
= gtk_hbox_new(FALSE
, 4);
1631 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1633 gtk_box_pack_start(GTK_BOX(hbox
),
1634 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1636 entry
= gtk_entry_new();
1637 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1638 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1639 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1640 gtk_widget_grab_focus(entry
);
1641 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1642 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1643 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1645 hbox
= gtk_hbox_new(TRUE
, 0);
1646 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1648 button
= gtk_button_new_with_label(_("OK"));
1649 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1650 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1651 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1652 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1653 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1655 button
= gtk_button_new_with_label(_("Cancel"));
1656 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1657 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1658 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1659 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1660 GTK_OBJECT(dialog
));
1662 gtk_widget_show_all(dialog
);
1666 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1668 g_return_if_fail(window_with_focus
!= NULL
);
1670 gtk_widget_destroy(window_with_focus
->window
);
1673 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1675 MiniType type
= (MiniType
) action
;
1677 g_return_if_fail(window_with_focus
!= NULL
);
1679 /* Item needs to remain selected... */
1680 if (type
== MINI_SHELL
)
1681 window_with_focus
->temp_item_selected
= FALSE
;
1683 minibuffer_show(window_with_focus
, type
);
1686 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1688 if (action
== HELP_ABOUT
)
1689 infobox_new(app_dir
);
1690 else if (action
== HELP_DIR
)
1691 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1692 else if (action
== HELP_MANUAL
)
1694 gchar
*manual
= NULL
;
1698 manual
= g_strconcat(app_dir
, "/Help/Manual-",
1699 current_lang
, ".html", NULL
);
1700 if (access(manual
, F_OK
))
1708 manual
= g_strconcat(app_dir
,
1709 "/Help/Manual.html", NULL
);
1711 run_by_path(manual
);
1716 g_warning("Unknown help action %d\n", action
);
1719 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1720 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1722 GList
*items
, *item
;
1724 items
= gtk_container_get_children(GTK_CONTAINER(menu
));
1726 item
= g_list_nth(items
, from
);
1729 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1735 static void save_menus(void)
1739 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1742 gtk_accel_map_save(menurc
);
1747 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1752 items
= gtk_container_get_children(GTK_CONTAINER(shell
));
1753 item
= g_list_nth_data(items
, n
);
1755 g_return_if_fail(item
!= NULL
);
1759 gtk_menu_shell_select_item(shell
, item
);
1762 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1768 g_return_if_fail(window_with_focus
!= NULL
);
1770 n_selected
= view_count_selected(window_with_focus
->view
);
1778 case FILE_COPY_ITEM
:
1779 prompt
= _("Copy ... ?");
1781 case FILE_RENAME_ITEM
:
1782 prompt
= _("Rename ... ?");
1784 case FILE_LINK_ITEM
:
1785 prompt
= _("Symlink ... ?");
1787 case FILE_OPEN_FILE
:
1788 prompt
= _("Shift Open ... ?");
1791 prompt
= _("Help about ... ?");
1793 case FILE_SHOW_FILE_INFO
:
1794 prompt
= _("Examine ... ?");
1796 case FILE_RUN_ACTION
:
1797 prompt
= _("Set run action for ... ?");
1800 prompt
= _("Set icon for ... ?");
1803 prompt
= _("Send ... to ... ?");
1806 prompt
= _("DELETE ... ?");
1809 prompt
= _("Count the size of ... ?");
1811 case FILE_CHMOD_ITEMS
:
1812 prompt
= _("Set permissions on ... ?");
1815 prompt
= _("Search inside ... ?");
1817 case FILE_OPEN_VFS_AVFS
:
1818 prompt
= _("Look inside ... ?");
1821 g_warning("Unknown action!");
1824 filer_target_mode(window_with_focus
, target_callback
,
1825 GINT_TO_POINTER(action
), prompt
);
1832 send_to(window_with_focus
);
1835 delete(window_with_focus
);
1838 usage(window_with_focus
);
1840 case FILE_CHMOD_ITEMS
:
1841 chmod_items(window_with_focus
);
1844 find(window_with_focus
);
1846 case FILE_SHOW_FILE_INFO
:
1850 items
= filer_selected_items(window_with_focus
);
1851 infobox_show_list(items
);
1852 g_list_foreach(items
, (GFunc
) g_free
, NULL
);
1860 /* All the following actions require exactly one file selected */
1864 report_error(_("You cannot do this to more than "
1865 "one item at a time"));
1869 item
= filer_selected_item(window_with_focus
);
1870 g_return_if_fail(item
!= NULL
);
1872 item
= dir_update_item(window_with_focus
->directory
,
1877 report_error(_("Item no longer exists!"));
1881 path
= make_path(window_with_focus
->sym_path
, item
->leafname
)->str
;
1885 case FILE_COPY_ITEM
:
1886 src_dest_action_item(path
, item
->image
,
1887 _("Copy"), copy_cb
);
1889 case FILE_RENAME_ITEM
:
1890 src_dest_action_item(path
, item
->image
,
1891 _("Rename"), rename_cb
);
1893 case FILE_LINK_ITEM
:
1894 src_dest_action_item(path
, item
->image
,
1895 _("Symlink"), link_cb
);
1897 case FILE_OPEN_FILE
:
1898 filer_openitem(window_with_focus
,
1899 collection_selected_item_number(
1900 window_with_focus
->collection
),
1901 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1904 show_item_help(path
, item
);
1906 case FILE_RUN_ACTION
:
1910 icon_set_handler_dialog(item
, path
);
1912 case FILE_OPEN_VFS_AVFS
:
1913 open_vfs_avfs(window_with_focus
, item
);
1916 g_warning("Unknown action!");
1921 static void show_key_help(GtkWidget
*button
, gpointer data
)
1923 gboolean can_change_accels
;
1925 g_object_get(G_OBJECT(gtk_settings_get_default()),
1926 "gtk-can-change-accels", &can_change_accels
,
1929 if (!can_change_accels
)
1931 info_message(_("User-definable shortcuts are disabled by "
1932 "default in Gtk2, and you have not enabled "
1933 "them. You can turn this feature on by:\n"
1934 "1) using an XSettings manager, such as ROX-Session\n"
1936 "2) adding this line to ~/.gtkrc-2.0:\n"
1937 "\tgtk-can-change-accels = 1"));
1941 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
1942 "- Open the menu over a filer window,\n"
1943 "- Move the pointer over the item you want to use,\n"
1944 "- Press the key you want attached to it.\n\n"
1945 "The key will appear next to the menu item and you can just press "
1946 "that key without opening the menu in future."));
1949 static GList
*set_keys_button(Option
*option
, xmlNode
*node
, guchar
*label
)
1951 GtkWidget
*button
, *align
;
1953 g_return_val_if_fail(option
== NULL
, NULL
);
1955 align
= gtk_alignment_new(0.5, 0.5, 0, 0);
1956 button
= button_new_mixed(GTK_STOCK_DIALOG_INFO
,
1957 _("Set keyboard shortcuts"));
1958 gtk_container_add(GTK_CONTAINER(align
), button
);
1959 g_signal_connect(button
, "clicked", G_CALLBACK(show_key_help
), NULL
);
1961 return g_list_append(NULL
, align
);