4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2001, 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 menu */
28 #include <sys/param.h>
45 #include "gui_support.h"
48 #include "gtksavebox.h"
50 #include "minibuffer.h"
56 #include "usericons.h"
59 #define C_ "<control>"
61 typedef enum menu_icon_style
{
62 MIS_NONE
, MIS_SMALL
, MIS_LARGE
, MIS_HUGE
,
63 MIS_CURRENT
, /* As per current filer window */
67 typedef void (*ActionFn
)(GList
*paths
, char *dest_dir
, char *leaf
);
68 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
70 GtkAccelGroup
*filer_keys
;
71 GtkAccelGroup
*pinboard_keys
;
73 GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
75 static gint updating_menu
= 0; /* Non-zero => ignore activations */
76 static GList
*send_to_paths
= NULL
;
78 /* Static prototypes */
80 static void save_menus(void);
81 static void menu_closed(GtkWidget
*widget
);
82 static void items_sensitive(gboolean state
);
83 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
84 gboolean (*callback
)(guchar
*current
, guchar
*new));
85 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
);
86 static void mark_menus_modified(gboolean mod
);
87 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new);
88 static gboolean
link_cb(guchar
*initial
, guchar
*path
);
89 static void select_nth_item(GtkMenuShell
*shell
, int n
);
90 static void new_file_type(gchar
*templ
);
91 static void do_send_to(gchar
*templ
);
92 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
94 /* Note that for most of these callbacks none of the arguments are used. */
96 /* (action used in these two - DetailsType) */
97 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
);
98 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
99 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
101 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
102 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
103 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
104 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
106 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
107 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
108 static void create_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
110 static void copy_item(gpointer data
, guint action
, GtkWidget
*widget
);
111 static void rename_item(gpointer data
, guint action
, GtkWidget
*widget
);
112 static void link_item(gpointer data
, guint action
, GtkWidget
*widget
);
113 static void open_file(gpointer data
, guint action
, GtkWidget
*widget
);
114 static void help(gpointer data
, guint action
, GtkWidget
*widget
);
115 static void show_file_info(gpointer data
, guint action
, GtkWidget
*widget
);
116 static void send_to(gpointer data
, guint action
, GtkWidget
*widget
);
117 static void delete(gpointer data
, guint action
, GtkWidget
*widget
);
118 static void usage(gpointer data
, guint action
, GtkWidget
*widget
);
119 static void chmod_items(gpointer data
, guint action
, GtkWidget
*widget
);
120 static void find(gpointer data
, guint action
, GtkWidget
*widget
);
123 static void open_vfs_rpm(gpointer data
, guint action
, GtkWidget
*widget
);
124 static void open_vfs_utar(gpointer data
, guint action
, GtkWidget
*widget
);
125 static void open_vfs_uzip(gpointer data
, guint action
, GtkWidget
*widget
);
126 static void open_vfs_deb(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void open_vfs_avfs(gpointer data
, guint action
, GtkWidget
*widget
);
131 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
135 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
137 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
138 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
140 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
141 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
142 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
);
144 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void set_icon(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
151 static GtkWidget
*filer_menu
; /* The popup filer menu */
152 static GtkWidget
*filer_file_item
; /* The File '' label */
153 static GtkWidget
*filer_file_menu
; /* The File '' menu */
154 static GtkWidget
*file_shift_item
; /* Shift Open label */
155 GtkWidget
*display_large_menu
; /* Display->Large With... */
156 GtkWidget
*display_small_menu
; /* Display->Small With... */
158 static GtkWidget
*filer_vfs_menu
; /* The Open VFS menu */
160 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
161 static GtkWidget
*filer_new_window
; /* The New Window item */
162 static GtkWidget
*filer_new_menu
; /* The New submenu */
164 /* Used for Copy, etc */
165 static GtkWidget
*savebox
= NULL
;
166 static GtkWidget
*check_relative
= NULL
;
167 static guchar
*current_path
= NULL
;
168 static gboolean (*current_savebox_callback
)(guchar
*current
, guchar
*new);
173 static GtkItemFactoryEntry filer_menu_def
[] = {
174 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
175 {">" N_("Huge Icons"), NULL
, huge_with
, DETAILS_NONE
, NULL
},
176 {">" N_("Large Icons"), NULL
, large_with
, DETAILS_NONE
, NULL
},
177 {">" N_("Small Icons"), NULL
, small_with
, DETAILS_NONE
, NULL
},
178 {">" N_("Huge, With..."), NULL
, NULL
, 0, "<Branch>"},
179 {">>" N_("Summary"), NULL
, huge_with
, DETAILS_SUMMARY
, NULL
},
180 {">>" N_("Sizes"), NULL
, huge_with
, DETAILS_SIZE
, NULL
},
181 {">>" N_("Permissions"), NULL
, huge_with
, DETAILS_PERMISSIONS
, NULL
},
182 {">>" N_("Type"), NULL
, huge_with
, DETAILS_TYPE
, NULL
},
183 {">>" N_("Times"), NULL
, huge_with
, DETAILS_TIMES
, NULL
},
184 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
185 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
186 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
187 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
188 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
189 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
190 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
191 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
192 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
193 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
194 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
195 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, NULL
},
196 {">", NULL
, NULL
, 0, "<Separator>"},
197 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
198 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
199 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
200 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
201 {">", NULL
, NULL
, 0, "<Separator>"},
202 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
203 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
204 {">" N_("Create Thumbs"), NULL
, create_thumbs
, 0, NULL
},
205 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
206 {">" N_("Copy..."), NULL
, copy_item
, 0, NULL
},
207 {">" N_("Rename..."), NULL
, rename_item
, 0, NULL
},
208 {">" N_("Link..."), NULL
, link_item
, 0, NULL
},
209 {">" N_("Shift Open"), NULL
, open_file
, 0, NULL
},
210 {">" N_("Help"), NULL
, help
, 0, NULL
},
211 {">" N_("Info"), NULL
, show_file_info
, 0, NULL
},
212 {">" N_("Set Run Action..."), NULL
, run_action
, 0, NULL
},
213 {">" N_("Set Icon..."), NULL
, set_icon
, 0, NULL
},
215 {">" N_("Open VFS"), NULL
, NULL
, 0, "<Branch>"},
216 {">>" N_("Unzip"), NULL
, open_vfs_uzip
, 0, NULL
},
217 {">>" N_("Untar"), NULL
, open_vfs_utar
, 0, NULL
},
218 {">>" N_("Deb"), NULL
, open_vfs_deb
, 0, NULL
},
219 {">>" N_("RPM"), NULL
, open_vfs_rpm
, 0, NULL
},
221 {">" N_("Open AVFS"), NULL
, open_vfs_avfs
, 0, NULL
},
223 {">", NULL
, NULL
, 0, "<Separator>"},
224 {">" N_("Send To..."), NULL
, send_to
, 0, NULL
},
225 {">" N_("Delete"), NULL
, delete, 0, NULL
},
226 {">" N_("Disk Usage"), NULL
, usage
, 0, NULL
},
227 {">" N_("Permissions"), NULL
, chmod_items
, 0, NULL
},
228 {">" N_("Find"), NULL
, find
, 0, NULL
},
229 {N_("Select All"), NULL
, select_all
, 0, NULL
},
230 {N_("Clear Selection"), NULL
, clear_selection
, 0, 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_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
236 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
237 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
238 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
239 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
240 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
241 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
242 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
244 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
245 {">", NULL
, NULL
, 0, "<Separator>"},
246 {">" N_("Enter Path..."), NULL
, enter_path
, 0, NULL
},
247 {">" N_("Shell Command..."), NULL
, shell_command
, 0, NULL
},
248 {">" N_("Select If..."), NULL
, select_if
, 0, NULL
},
249 {">", NULL
, NULL
, 0, "<Separator>"},
250 {">" N_("Show ROX-Filer Help"), NULL
, menu_rox_help
, 0, NULL
},
254 #define GET_MENU_ITEM(var, menu) \
255 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
257 #define GET_SMENU_ITEM(var, menu, sub) \
259 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
260 var = gtk_item_factory_get_widget(item_factory, tmp); \
264 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
266 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
267 var = gtk_item_factory_get_widget(item_factory, tmp); \
271 /* Creates menu <name> from the <name>_menu_def array.
272 * The accel group <name>_keys must also have been created.
273 * All menu items are translated. Sets 'item_factory'.
275 #define MAKE_MENU(name) \
277 GtkItemFactoryEntry *translated; \
280 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, \
281 "<" #name ">", name ## _keys); \
283 n_entries = sizeof(name ## _menu_def) / sizeof(*name ## _menu_def); \
284 translated = translate_entries(name ## _menu_def, n_entries); \
285 gtk_item_factory_create_items(item_factory, n_entries, \
287 free_translated_entries(translated, n_entries); \
297 GtkItemFactory
*item_factory
;
299 filer_keys
= gtk_accel_group_new();
302 GET_MENU_ITEM(filer_menu
, "filer");
303 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
305 GET_SSMENU_ITEM(filer_vfs_menu
, "filer", "File", "Open VFS");
307 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
309 GET_SSMENU_ITEM(display_large_menu
, "filer",
310 "Display", "Large, With...");
311 GET_SSMENU_ITEM(display_small_menu
, "filer",
312 "Display", "Small, With...");
314 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
316 /* File '' label... */
317 items
= gtk_container_children(GTK_CONTAINER(filer_menu
));
318 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
321 /* Shift Open... label */
322 items
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
323 file_shift_item
= GTK_BIN(g_list_nth(items
, 3)->data
)->child
;
326 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
327 filer_new_window
= GTK_BIN(item
)->child
;
329 menurc
= choices_find_path_load("menus", PROJECT
);
332 gtk_item_factory_parse_rc(menurc
);
333 mark_menus_modified(FALSE
);
337 gtk_signal_connect(GTK_OBJECT(filer_menu
), "unmap_event",
338 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
339 gtk_signal_connect(GTK_OBJECT(filer_file_menu
), "unmap_event",
340 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
342 option_add_string("menu_xterm", "xterm", NULL
);
343 option_add_int("menu_iconsize", MIS_SMALL
, NULL
);
344 option_add_saver(save_menus
);
346 tips
= gtk_tooltips_new();
347 check_relative
= gtk_check_button_new_with_label(_("Relative link"));
348 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
), TRUE
);
349 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
350 gtk_tooltips_set_tip(tips
, check_relative
,
351 _("If on, the symlink will store the path from the "
352 "symlink to the target file. Use this if the symlink "
353 "and the target will be moved together.\n"
354 "If off, the path from the root directory is stored - "
355 "use this if the symlink may move but the target will "
358 savebox
= gtk_savebox_new();
359 gtk_box_pack_start(GTK_BOX(GTK_SAVEBOX(savebox
)->vbox
),
360 check_relative
, FALSE
, TRUE
, 0);
361 gtk_widget_show(check_relative
);
363 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_to_file",
364 GTK_SIGNAL_FUNC(save_to_file
), NULL
);
365 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_done",
366 GTK_SIGNAL_FUNC(gtk_widget_hide
),
367 GTK_OBJECT(savebox
));
372 /* Name is in the form "<panel>" */
373 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
376 GtkItemFactory
*item_factory
;
377 GtkItemFactoryEntry
*translated
;
380 keys
= gtk_accel_group_new();
382 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
384 translated
= translate_entries(def
, n_entries
);
385 gtk_item_factory_create_items(item_factory
, n_entries
,
387 free_translated_entries(translated
, n_entries
);
389 gtk_accel_group_lock(keys
);
394 static void items_sensitive(gboolean state
)
399 items
= item
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
402 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
408 items
= item
= gtk_container_children(GTK_CONTAINER(filer_vfs_menu
));
411 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
418 /* 'data' is an array of three ints:
419 * [ pointer_x, pointer_y, item_under_pointer ]
421 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
427 int *pos
= (int *) data
;
428 GtkRequisition requisition
;
433 next
= items
= gtk_container_children(GTK_CONTAINER(menu
));
435 while (item
>= 0 && next
)
437 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
450 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
452 *x
= pos
[0] - (requisition
.width
* 7 / 8);
453 *y
= pos
[1] - y_shift
;
455 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
456 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
464 /* Used when you menu-click on the Large or Small toolbar tools */
465 void show_style_menu(FilerWindow
*filer_window
,
466 GdkEventButton
*event
,
471 pos
[0] = event
->x_root
;
472 pos
[1] = event
->y_root
;
475 window_with_focus
= filer_window
;
479 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
480 (gpointer
) pos
, event
->button
, event
->time
);
484 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dname
,
485 MenuIconStyle style
, CallbackFn func
,
486 gboolean separator
, gboolean strip_ext
)
488 GList
*widgets
= NULL
;
494 dir
= opendir(dname
);
500 item
= gtk_menu_item_new();
501 widgets
= g_list_append(widgets
, item
);
502 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
505 while ((ent
= readdir(dir
)))
515 /* Ignore hidden files */
516 if (ent
->d_name
[0] == '.')
519 /* Strip off extension, if any */
520 dot
= strchr(ent
->d_name
, '.');
521 if (strip_ext
&& dot
)
522 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
524 leaf
= g_strdup(ent
->d_name
);
526 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
527 diritem_stat(fname
, &ditem
, FALSE
);
529 if (ditem
.image
&& style
!= MIS_NONE
)
533 if (!ditem
.image
->huge_pixmap
)
534 pixmap_make_huge(ditem
.image
);
535 icon
= ditem
.image
->huge_pixmap
;
536 mask
= ditem
.image
->huge_mask
;
539 icon
= ditem
.image
->pixmap
;
540 mask
= ditem
.image
->mask
;
545 if (!ditem
.image
->sm_pixmap
)
546 pixmap_make_small(ditem
.image
);
547 icon
= ditem
.image
->sm_pixmap
;
548 mask
= ditem
.image
->sm_mask
;
552 item
= gtk_menu_item_new();
553 /* TODO: Find a way to allow short-cuts */
554 gtk_widget_lock_accelerators(item
);
556 hbox
= gtk_hbox_new(FALSE
, 2);
557 gtk_container_add(GTK_CONTAINER(item
), hbox
);
559 img
= gtk_pixmap_new(icon
, mask
);
560 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
562 label
= gtk_label_new(leaf
);
563 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
564 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
566 diritem_clear(&ditem
);
569 item
= gtk_menu_item_new_with_label(leaf
);
573 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
574 GTK_SIGNAL_FUNC(func
), (GtkObject
*) fname
);
575 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
576 gtk_signal_connect_object(GTK_OBJECT(item
), "destroy",
577 GTK_SIGNAL_FUNC(g_free
), (GtkObject
*) fname
);
579 widgets
= g_list_append(widgets
, item
);
588 /* Scan the templates dir and create entries for the New menu */
589 static void update_new_files_menu(MenuIconStyle style
)
591 static GList
*widgets
= NULL
;
593 gchar
*templ_dname
= NULL
;
599 for (next
= widgets
; next
; next
= next
->next
)
600 gtk_widget_destroy((GtkWidget
*) next
->data
);
602 g_list_free(widgets
);
606 templ_dname
= choices_find_path_load("Templates", "");
609 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
610 (CallbackFn
) new_file_type
, TRUE
, TRUE
);
613 gtk_widget_show_all(filer_new_menu
);
616 /* 'item' is the number of the item to appear under the pointer. */
617 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
623 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
624 event
->type
== GDK_BUTTON_RELEASE
))
626 GdkEventButton
*bev
= (GdkEventButton
*) event
;
628 pos
[0] = bev
->x_root
;
629 pos
[1] = bev
->y_root
;
630 button
= bev
->button
;
633 else if (event
&& event
->type
== GDK_KEY_PRESS
)
635 GdkEventKey
*kev
= (GdkEventKey
*) event
;
637 get_pointer_xy(pos
, pos
+ 1);
641 get_pointer_xy(pos
, pos
+ 1);
645 gtk_widget_show_all(menu
);
646 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
647 position_menu
, (gpointer
) pos
, button
, time
);
648 select_nth_item(GTK_MENU_SHELL(menu
), item
);
651 static MenuIconStyle
get_menu_icon_style(void)
656 mis
= option_get_int("menu_iconsize");
660 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
: case MIS_HUGE
:
666 if (mis
== MIS_CURRENT
&& window_with_focus
)
668 switch (window_with_focus
->display_style
)
681 display
= option_get_int("display_size");
697 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
699 DirItem
*file_item
= NULL
;
700 GdkModifierType state
= 0;
704 /* Remove previous AppMenu, if any */
707 window_with_focus
= filer_window
;
709 if (event
->type
== GDK_BUTTON_PRESS
)
710 state
= ((GdkEventButton
*) event
)->state
;
711 else if (event
->type
== GDK_KEY_PRESS
)
712 state
= ((GdkEventKey
*) event
)->state
;
714 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
716 collection_select_item(filer_window
->collection
, item
);
717 filer_window
->temp_item_selected
= TRUE
;
721 filer_window
->temp_item_selected
= FALSE
;
724 /* Short-cut to the Send To menu */
725 if (state
& GDK_SHIFT_MASK
)
729 if (filer_window
->collection
->number_selected
== 0)
732 _("You should Shift+Menu click over a file to "
733 "send it somewhere"));
737 paths
= filer_selected_items(filer_window
);
741 show_send_to_menu(paths
, event
); /* (paths eaten) */
747 GtkWidget
*file_label
, *file_menu
;
748 Collection
*collection
= filer_window
->collection
;
751 file_label
= filer_file_item
;
752 file_menu
= filer_file_menu
;
753 gtk_check_menu_item_set_active(
754 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
755 filer_window
->show_hidden
);
756 buffer
= g_string_new(NULL
);
757 switch (collection
->number_selected
)
760 g_string_assign(buffer
, _("Next Click"));
761 items_sensitive(TRUE
);
764 items_sensitive(TRUE
);
765 file_item
= selected_item(
766 filer_window
->collection
);
767 g_string_sprintf(buffer
, "%s '%s'",
768 basetype_name(file_item
),
769 file_item
->leafname
);
770 if (!can_set_run_action(file_item
))
771 menu_set_items_shaded(filer_file_menu
,
775 items_sensitive(FALSE
);
776 g_string_sprintf(buffer
, _("%d items"),
777 collection
->number_selected
);
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
,
784 collection
->number_selected
== 0);
786 appmenu_add(make_path(filer_window
->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
, !o_unique_filer_windows
);
795 popup_menu
= (state
& GDK_CONTROL_MASK
)
801 show_popup_menu(popup_menu
, event
,
802 popup_menu
== filer_file_menu
? 5 : 1);
805 static void menu_closed(GtkWidget
*widget
)
807 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
808 return; /* Close panel item chosen? */
812 if (window_with_focus
->temp_item_selected
)
814 collection_clear_selection(window_with_focus
->collection
);
815 window_with_focus
->temp_item_selected
= FALSE
;
819 void target_callback(FilerWindow
*filer_window
,
823 Collection
*collection
= filer_window
->collection
;
825 g_return_if_fail(window_with_focus
!= NULL
);
826 g_return_if_fail(window_with_focus
== filer_window
);
827 g_return_if_fail(real_fn
!= NULL
);
829 collection_wink_item(collection
, item
);
830 collection_clear_selection(collection
);
831 collection_select_item(collection
, item
);
832 ((GtkItemFactoryCallback1
) real_fn
)(NULL
, 0, GTK_WIDGET(collection
));
834 /* TODO: Opening a Savebox grabs the selection; don't lose it again! */
835 if (item
< collection
->number_of_items
)
836 collection_unselect_item(collection
, item
);
839 /* Set the text of the 'Shift Open...' menu item.
840 * If icon is NULL, reset the text and also shade it, unless 'next'.
842 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
844 guchar
*shift_action
= NULL
;
848 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
850 if (item
->flags
& ITEM_FLAG_MOUNTED
)
851 shift_action
= N_("Unmount");
853 shift_action
= N_("Mount");
855 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
856 shift_action
= N_("Show Target");
857 else if (item
->base_type
== TYPE_DIRECTORY
)
858 shift_action
= N_("Look Inside");
859 else if (item
->base_type
== TYPE_FILE
)
860 shift_action
= N_("Open As Text");
862 gtk_label_set_text(GTK_LABEL(menu_item
),
863 shift_action
? _(shift_action
)
865 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
870 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
872 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
875 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
877 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
880 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
882 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
885 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
887 g_return_if_fail(window_with_focus
!= NULL
);
889 display_set_sort_fn(window_with_focus
, sort_by_name
);
892 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
894 g_return_if_fail(window_with_focus
!= NULL
);
896 display_set_sort_fn(window_with_focus
, sort_by_type
);
899 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
901 g_return_if_fail(window_with_focus
!= NULL
);
903 display_set_sort_fn(window_with_focus
, sort_by_date
);
906 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
908 g_return_if_fail(window_with_focus
!= NULL
);
910 display_set_sort_fn(window_with_focus
, sort_by_size
);
913 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
918 g_return_if_fail(window_with_focus
!= NULL
);
920 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
923 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
925 g_return_if_fail(window_with_focus
!= NULL
);
928 filer_update_dir(window_with_focus
, TRUE
);
931 static void create_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
933 g_return_if_fail(window_with_focus
!= NULL
);
935 dir_rescan_with_thumbs(window_with_focus
->directory
,
936 window_with_focus
->path
);
939 static void delete(gpointer data
, guint action
, GtkWidget
*widget
)
941 g_return_if_fail(window_with_focus
!= NULL
);
943 if (window_with_focus
->collection
->number_selected
== 0)
944 filer_target_mode(window_with_focus
,
945 target_callback
, delete,
948 action_delete(window_with_focus
);
951 static void usage(gpointer data
, guint action
, GtkWidget
*widget
)
953 g_return_if_fail(window_with_focus
!= NULL
);
955 if (window_with_focus
->collection
->number_selected
== 0)
956 filer_target_mode(window_with_focus
,
957 target_callback
, usage
,
958 _("Count the size of ... ?"));
960 action_usage(window_with_focus
);
963 static void chmod_items(gpointer data
, guint action
, GtkWidget
*widget
)
965 g_return_if_fail(window_with_focus
!= NULL
);
967 if (window_with_focus
->collection
->number_selected
== 0)
968 filer_target_mode(window_with_focus
,
969 target_callback
, chmod_items
,
970 _("Set permissions on ... ?"));
972 action_chmod(window_with_focus
);
975 static void find(gpointer data
, guint action
, GtkWidget
*widget
)
977 g_return_if_fail(window_with_focus
!= NULL
);
979 if (window_with_focus
->collection
->number_selected
== 0)
980 filer_target_mode(window_with_focus
,
981 target_callback
, find
,
982 _("Search inside ... ?"));
984 action_find(window_with_focus
);
987 /* This pops up our savebox widget, cancelling any currently open one,
988 * and allows the user to pick a new path for it.
989 * Once the new path has been picked, the callback will be called with
990 * both the current and new paths.
991 * NOTE: This function unrefs 'image'!
993 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
994 gboolean (*callback
)(guchar
*current
, guchar
*new))
996 if (GTK_WIDGET_VISIBLE(savebox
))
997 gtk_widget_hide(savebox
);
999 if (callback
== link_cb
)
1000 gtk_widget_show(check_relative
);
1002 gtk_widget_hide(check_relative
);
1005 g_free(current_path
);
1006 current_path
= g_strdup(path
);
1007 current_savebox_callback
= callback
;
1009 gtk_window_set_title(GTK_WINDOW(savebox
), title
);
1010 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), current_path
);
1011 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
1012 pixmap_unref(image
);
1014 gtk_widget_grab_focus(GTK_SAVEBOX(savebox
)->entry
);
1015 gtk_widget_show(savebox
);
1018 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
)
1020 g_return_val_if_fail(current_savebox_callback
!= NULL
,
1021 GTK_XDS_SAVE_ERROR
);
1023 return current_savebox_callback(current_path
, pathname
)
1024 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1027 static gboolean
copy_cb(guchar
*current
, guchar
*new)
1029 return action_with_leaf(action_copy
, current
, new);
1032 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new)
1034 char *new_dir
, *leaf
;
1039 report_rox_error(_("New pathname is not absolute"));
1043 if (new[strlen(new) - 1] == '/')
1045 new_dir
= g_strdup(new);
1052 slash
= strrchr(new, '/');
1053 new_dir
= g_strndup(new, slash
- new);
1057 local_paths
= g_list_append(NULL
, current
);
1058 action(local_paths
, new_dir
, leaf
);
1059 g_list_free(local_paths
);
1066 #define SHOW_SAVEBOX(title, callback) \
1070 item = selected_item(collection); \
1071 path = make_path(window_with_focus->path, item->leafname)->str; \
1072 pixmap_ref(item->image); \
1073 savebox_show(title, path, item->image, callback); \
1076 static void copy_item(gpointer data
, guint action
, GtkWidget
*widget
)
1078 Collection
*collection
;
1080 g_return_if_fail(window_with_focus
!= NULL
);
1082 collection
= window_with_focus
->collection
;
1083 if (collection
->number_selected
> 1)
1085 report_rox_error(_("You cannot do this to more than "
1086 "one item at a time"));
1089 else if (collection
->number_selected
!= 1)
1090 filer_target_mode(window_with_focus
,
1091 target_callback
, copy_item
,
1094 SHOW_SAVEBOX(_("Copy"), copy_cb
);
1097 static gboolean
rename_cb(guchar
*current
, guchar
*new)
1099 return action_with_leaf(action_move
, current
, new);
1102 static void rename_item(gpointer data
, guint action
, GtkWidget
*widget
)
1104 Collection
*collection
;
1106 g_return_if_fail(window_with_focus
!= NULL
);
1108 collection
= window_with_focus
->collection
;
1109 if (collection
->number_selected
> 1)
1111 report_rox_error(_("You cannot do this to more than "
1112 "one item at a time"));
1115 else if (collection
->number_selected
!= 1)
1116 filer_target_mode(window_with_focus
,
1117 target_callback
, rename_item
,
1120 SHOW_SAVEBOX(_("Rename"), rename_cb
);
1123 static gboolean
link_cb(guchar
*initial
, guchar
*path
)
1127 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_relative
)))
1131 rpath
= get_relative_path(path
, initial
);
1132 err
= symlink(rpath
, path
);
1137 err
= symlink(initial
, path
);
1141 report_rox_error("symlink: %s", g_strerror(errno
));
1147 static void link_item(gpointer data
, guint action
, GtkWidget
*widget
)
1149 Collection
*collection
;
1151 g_return_if_fail(window_with_focus
!= NULL
);
1153 collection
= window_with_focus
->collection
;
1154 if (collection
->number_selected
> 1)
1156 report_rox_error(_("You cannot do this to more than "
1157 "one item at a time"));
1160 else if (collection
->number_selected
!= 1)
1161 filer_target_mode(window_with_focus
,
1162 target_callback
, link_item
,
1163 _("Symlink ... ?"));
1165 SHOW_SAVEBOX(_("Symlink"), link_cb
);
1168 static void open_file(gpointer data
, guint action
, GtkWidget
*widget
)
1170 Collection
*collection
;
1172 g_return_if_fail(window_with_focus
!= NULL
);
1174 collection
= window_with_focus
->collection
;
1175 if (collection
->number_selected
> 1)
1177 report_rox_error(_("You cannot do this to more than "
1178 "one item at a time"));
1181 else if (collection
->number_selected
!= 1)
1182 filer_target_mode(window_with_focus
,
1183 target_callback
, open_file
,
1184 _("Shift Open ... ?"));
1186 filer_openitem(window_with_focus
,
1187 selected_item_number(collection
),
1188 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1191 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
)
1193 Collection
*collection
;
1195 g_return_if_fail(window_with_focus
!= NULL
);
1197 collection
= window_with_focus
->collection
;
1198 if (collection
->number_selected
> 1)
1200 report_rox_error(_("You cannot do this to more than "
1201 "one item at a time"));
1204 else if (collection
->number_selected
!= 1)
1205 filer_target_mode(window_with_focus
,
1206 target_callback
, run_action
,
1207 _("Set run action for ... ?"));
1212 item
= selected_item(collection
);
1213 g_return_if_fail(item
!= NULL
);
1215 if (can_set_run_action(item
))
1216 type_set_handler_dialog(item
->mime_type
);
1219 _("You can only set the run action for a "
1224 static void set_icon(gpointer data
, guint action
, GtkWidget
*widget
)
1226 Collection
*collection
;
1228 g_return_if_fail(window_with_focus
!= NULL
);
1230 collection
= window_with_focus
->collection
;
1231 if (collection
->number_selected
> 1)
1233 report_rox_error(_("You cannot do this to more than "
1234 "one item at a time"));
1237 else if (collection
->number_selected
!= 1)
1238 filer_target_mode(window_with_focus
,
1239 target_callback
, set_icon
,
1240 _("Set icon for ... ?"));
1246 item
= selected_item(collection
);
1247 g_return_if_fail(item
!= NULL
);
1249 path
= make_path(window_with_focus
->path
, item
->leafname
)->str
;
1251 icon_set_handler_dialog(item
, path
);
1255 static void show_file_info(gpointer unused
, guint action
, GtkWidget
*widget
)
1258 Collection
*collection
;
1260 g_return_if_fail(window_with_focus
!= NULL
);
1262 collection
= window_with_focus
->collection
;
1263 if (collection
->number_selected
> 1)
1265 report_rox_error(_("You cannot do this to more than "
1266 "one item at a time"));
1269 else if (collection
->number_selected
!= 1)
1271 filer_target_mode(window_with_focus
,
1272 target_callback
, show_file_info
,
1273 _("Examine ... ?"));
1277 file
= selected_item(collection
);
1278 infobox_new(make_path(window_with_focus
->path
, file
->leafname
)->str
);
1281 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1283 filer_opendir(home_dir
, NULL
);
1286 static void help(gpointer data
, guint action
, GtkWidget
*widget
)
1288 Collection
*collection
;
1291 g_return_if_fail(window_with_focus
!= NULL
);
1293 collection
= window_with_focus
->collection
;
1294 if (collection
->number_selected
> 1)
1296 report_rox_error(_("You cannot do this to more than "
1297 "one item at a time"));
1300 else if (collection
->number_selected
!= 1)
1302 filer_target_mode(window_with_focus
, target_callback
, help
,
1303 _("Help about ... ?"));
1306 item
= selected_item(collection
);
1308 show_item_help(make_path(window_with_focus
->path
, item
->leafname
)->str
,
1313 #define OPEN_VFS(fs) \
1314 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1316 Collection *collection; \
1318 g_return_if_fail(window_with_focus != NULL); \
1320 collection = window_with_focus->collection; \
1321 if (collection->number_selected < 1) \
1322 filer_target_mode(window_with_focus, target_callback, \
1324 _("Look inside ... ?")); \
1326 real_vfs_open(#fs); \
1329 static void real_vfs_open(char *fs
)
1334 if (window_with_focus
->collection
->number_selected
!= 1)
1336 report_rox_error(_("You must select a single file "
1337 "to open as a Virtual File System"));
1341 item
= selected_item(window_with_focus
->collection
);
1343 path
= g_strconcat(window_with_focus
->path
,
1348 filer_change_to(window_with_focus
, path
, NULL
);
1357 static void open_vfs_avfs(gpointer data
, guint action
, GtkWidget
*widget
)
1361 Collection
*collection
;
1363 g_return_if_fail(window_with_focus
!= NULL
);
1365 collection
= window_with_focus
->collection
;
1366 if (collection
->number_selected
< 1)
1368 filer_target_mode(window_with_focus
, target_callback
,
1370 _("Look inside ... ?"));
1373 else if (collection
->number_selected
!= 1)
1375 report_rox_error(_("You must select a single file "
1376 "to open as a Virtual File System"));
1380 item
= selected_item(collection
);
1382 path
= g_strconcat(window_with_focus
->path
,
1383 "/", item
->leafname
, "#", NULL
);
1385 filer_change_to(window_with_focus
, path
, NULL
);
1390 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1392 g_return_if_fail(window_with_focus
!= NULL
);
1394 collection_select_all(window_with_focus
->collection
);
1395 window_with_focus
->temp_item_selected
= FALSE
;
1398 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1400 g_return_if_fail(window_with_focus
!= NULL
);
1402 collection_clear_selection(window_with_focus
->collection
);
1403 window_with_focus
->temp_item_selected
= FALSE
;
1406 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1411 static gboolean
new_directory_cb(guchar
*initial
, guchar
*path
)
1413 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1415 report_rox_error("mkdir: %s", g_strerror(errno
));
1419 dir_check_this(path
);
1421 if (filer_exists(window_with_focus
))
1424 leaf
= strrchr(path
, '/');
1426 display_set_autoselect(window_with_focus
, leaf
+ 1);
1432 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1434 g_return_if_fail(window_with_focus
!= NULL
);
1436 savebox_show(_("New Directory"),
1437 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1438 type_to_icon(&special_directory
),
1442 static gboolean
new_file_cb(guchar
*initial
, guchar
*path
)
1446 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1450 report_rox_error(_("Error creating '%s': %s"),
1451 path
, g_strerror(errno
));
1456 report_rox_error(_("Error creating '%s': %s"),
1457 path
, g_strerror(errno
));
1459 dir_check_this(path
);
1461 if (filer_exists(window_with_focus
))
1464 leaf
= strrchr(path
, '/');
1466 display_set_autoselect(window_with_focus
, leaf
+ 1);
1472 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1474 g_return_if_fail(window_with_focus
!= NULL
);
1476 savebox_show(_("New File"),
1477 make_path(window_with_focus
->path
, _("NewFile"))->str
,
1478 type_to_icon(&text_plain
),
1482 static gboolean
new_file_type_cb(guchar
*initial
, guchar
*path
)
1484 gchar
*templ
, *templ_dname
, *oleaf
, *dest
, *leaf
;
1487 /* We can work out the template path from the initial name */
1488 oleaf
= g_basename(initial
);
1489 templ_dname
= choices_find_path_load("Templates", "");
1493 _("Error creating file: could not find the template for %s"),
1498 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1499 g_free(templ_dname
);
1501 dest
= g_dirname(path
);
1502 leaf
= g_basename(path
);
1503 paths
= g_list_append(NULL
, templ
);
1505 action_copy(paths
, dest
, leaf
);
1511 if (filer_exists(window_with_focus
))
1512 display_set_autoselect(window_with_focus
, leaf
);
1517 static void do_send_to(gchar
*templ
)
1519 g_return_if_fail(send_to_paths
!= NULL
);
1521 run_with_files(templ
, send_to_paths
);
1524 static void new_file_type(gchar
*templ
)
1529 g_return_if_fail(window_with_focus
!= NULL
);
1531 leaf
= g_basename(templ
);
1532 type
= type_get_type(templ
);
1534 savebox_show(_("New File"),
1535 make_path(window_with_focus
->path
, leaf
)->str
,
1540 static void customise_send_to(gpointer data
)
1547 dirs
= g_string_new(NULL
);
1549 path
= choices_list_dirs("");
1550 for (i
= 0; i
< path
->len
; i
++)
1552 guchar
*old
= (guchar
*) path
->pdata
[i
];
1554 g_string_append(dirs
, old
);
1555 g_string_append(dirs
, "SendTo\n");
1557 choices_free_list(path
);
1559 save
= choices_find_path_save("", "SendTo", TRUE
);
1564 _("The `Send To' menu provides a quick way to send some files "
1565 "to an application. The applications listed are those in "
1566 "the following directories:\n\n%s\n%s\n"
1567 "The `Send To' menu may be opened by Shift+Menu clicking "
1570 save
? _("I'll show you your SendTo directory now; you should "
1571 "symlink (Ctrl+Shift drag) any applications you want "
1573 : _("Your CHOICESPATH variable setting prevents "
1574 "customisations - sorry."));
1576 g_string_free(dirs
, TRUE
);
1579 filer_opendir(save
, NULL
);
1582 /* Scan the SendTo dir and create and show the Send To menu.
1583 * The 'paths' list and every path in it is claimed, and will be
1584 * freed later -- don't free it yourself!
1586 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1588 GtkWidget
*menu
, *item
;
1592 menu
= gtk_menu_new();
1594 path
= choices_list_dirs("SendTo");
1596 for (i
= 0; i
< path
->len
; i
++)
1598 GList
*widgets
= NULL
;
1599 guchar
*dir
= (guchar
*) path
->pdata
[i
];
1601 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1602 (CallbackFn
) do_send_to
,
1606 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1607 gtk_menu_item_new());
1609 g_list_free(widgets
); /* TODO: Get rid of this */
1612 choices_free_list(path
);
1614 item
= gtk_menu_item_new_with_label(_("Customise"));
1615 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
1616 GTK_SIGNAL_FUNC(customise_send_to
), NULL
);
1617 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1621 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1622 g_list_free(send_to_paths
);
1624 send_to_paths
= paths
;
1626 gtk_signal_connect(GTK_OBJECT(menu
), "unmap_event",
1627 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
1630 show_popup_menu(menu
, event
, 0);
1633 static void send_to(gpointer data
, guint action
, GtkWidget
*widget
)
1635 Collection
*collection
;
1637 g_return_if_fail(window_with_focus
!= NULL
);
1639 collection
= window_with_focus
->collection
;
1641 if (collection
->number_selected
< 1)
1642 filer_target_mode(window_with_focus
, target_callback
,
1643 send_to
, _("Send ... to ... ?"));
1649 paths
= filer_selected_items(window_with_focus
);
1650 event
= gtk_get_current_event();
1653 show_send_to_menu(paths
, event
);
1655 gdk_event_free(event
);
1659 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1661 char *argv
[] = {"sh", "-c", NULL
, NULL
};
1663 argv
[2] = option_get_static_string("menu_xterm");
1665 g_return_if_fail(window_with_focus
!= NULL
);
1667 if (!spawn_full(argv
, window_with_focus
->path
))
1668 report_rox_error(_("Failed to fork() child process"));
1671 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1673 g_return_if_fail(window_with_focus
!= NULL
);
1675 filer_change_to(window_with_focus
, home_dir
, NULL
);
1678 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1680 g_return_if_fail(window_with_focus
!= NULL
);
1682 filer_open_parent(window_with_focus
);
1685 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1687 g_return_if_fail(window_with_focus
!= NULL
);
1689 change_to_parent(window_with_focus
);
1692 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1694 g_return_if_fail(window_with_focus
!= NULL
);
1696 filer_window_autosize(window_with_focus
, TRUE
);
1699 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1701 g_return_if_fail(window_with_focus
!= NULL
);
1703 if (o_unique_filer_windows
)
1705 report_rox_error(_("You can't open a second view onto "
1706 "this directory because the `Unique Windows' option "
1707 "is turned on in the Options window."));
1710 filer_opendir(window_with_focus
->path
, window_with_focus
);
1714 static void su_to_user(GtkWidget
*dialog
)
1717 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1721 g_return_if_fail(dialog
!= NULL
);
1723 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1724 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1726 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1728 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1729 argv
[3] = gtk_entry_get_text(user
);
1730 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1734 report_rox_error(_("fork: %s"), g_strerror(errno
));
1739 gtk_widget_destroy(dialog
);
1742 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1744 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1746 g_return_if_fail(window_with_focus
!= NULL
);
1748 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1749 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1750 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1751 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1752 g_strdup(window_with_focus
->path
), g_free
);
1754 vbox
= gtk_vbox_new(FALSE
, 4);
1755 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1756 gtk_box_pack_start(GTK_BOX(vbox
),
1757 gtk_label_new(_("Browse as which user?")),
1760 hbox
= gtk_hbox_new(FALSE
, 4);
1761 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1763 gtk_box_pack_start(GTK_BOX(hbox
),
1764 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1766 entry
= gtk_entry_new();
1767 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1768 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1769 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1770 gtk_widget_grab_focus(entry
);
1771 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1772 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1773 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1775 hbox
= gtk_hbox_new(TRUE
, 0);
1776 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1778 button
= gtk_button_new_with_label(_("OK"));
1779 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1780 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1781 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1782 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1783 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1785 button
= gtk_button_new_with_label(_("Cancel"));
1786 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1787 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1788 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1789 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1790 GTK_OBJECT(dialog
));
1792 gtk_widget_show_all(dialog
);
1796 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1798 g_return_if_fail(window_with_focus
!= NULL
);
1800 gtk_widget_destroy(window_with_focus
->window
);
1803 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
)
1805 g_return_if_fail(window_with_focus
!= NULL
);
1807 minibuffer_show(window_with_focus
, MINI_PATH
);
1810 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
)
1812 g_return_if_fail(window_with_focus
!= NULL
);
1814 minibuffer_show(window_with_focus
, MINI_SHELL
);
1817 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
)
1819 g_return_if_fail(window_with_focus
!= NULL
);
1821 minibuffer_show(window_with_focus
, MINI_SELECT_IF
);
1824 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1826 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1829 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1830 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1832 GList
*items
, *item
;
1834 items
= gtk_container_children(GTK_CONTAINER(menu
));
1836 item
= g_list_nth(items
, from
);
1839 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1845 /* This is called for every modified menu entry. We just use it to
1846 * find out if the menu has changed at all.
1848 static void set_mod(gboolean
*mod
, guchar
*str
)
1850 if (str
&& str
[0] == '(')
1854 static void save_menus(void)
1858 menurc
= choices_find_path_save("menus", PROJECT
, FALSE
);
1861 gboolean mod
= FALSE
;
1865 /* Find out if anything changed... */
1866 gtk_item_factory_dump_items(NULL
, TRUE
,
1867 (GtkPrintFunc
) set_mod
, &mod
);
1869 /* Dump out if so... */
1872 menurc
= choices_find_path_save("menus", PROJECT
, TRUE
);
1873 g_return_if_fail(menurc
!= NULL
);
1874 mark_menus_modified(TRUE
);
1875 gtk_item_factory_dump_rc(menurc
, NULL
, TRUE
);
1876 mark_menus_modified(FALSE
);
1882 static void mark_modified(gpointer hash_key
,
1886 GtkItemFactoryItem
*item
= (GtkItemFactoryItem
*) value
;
1888 item
->modified
= (gboolean
) GPOINTER_TO_INT(user_data
);
1891 /* Set or clear the 'modified' flag in all menu items. Messy... */
1892 static void mark_menus_modified(gboolean mod
)
1894 GtkItemFactoryClass
*class;
1896 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY
);
1898 g_hash_table_foreach(class->item_ht
, mark_modified
,
1899 GINT_TO_POINTER(mod
));
1902 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1905 GtkWidget
*item
= NULL
;
1907 items
= gtk_container_children(GTK_CONTAINER(shell
));
1908 nth
= g_list_nth(items
, n
);
1910 g_return_if_fail(nth
!= NULL
);
1912 item
= (GtkWidget
*) (nth
->data
);
1915 gtk_menu_shell_select_item(shell
, item
);