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)
731 report_error(PROJECT
,
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
));
833 if (item
< collection
->number_of_items
)
834 collection_unselect_item(collection
, item
);
837 /* Set the text of the 'Shift Open...' menu item.
838 * If icon is NULL, reset the text and also shade it, unless 'next'.
840 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
842 guchar
*shift_action
= NULL
;
846 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
848 if (item
->flags
& ITEM_FLAG_MOUNTED
)
849 shift_action
= N_("Unmount");
851 shift_action
= N_("Mount");
853 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
854 shift_action
= N_("Show Target");
855 else if (item
->base_type
== TYPE_DIRECTORY
)
856 shift_action
= N_("Look Inside");
857 else if (item
->base_type
== TYPE_FILE
)
858 shift_action
= N_("Open As Text");
860 gtk_label_set_text(GTK_LABEL(menu_item
),
861 shift_action
? _(shift_action
)
863 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
868 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
870 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
873 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
875 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
878 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
880 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
883 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
885 g_return_if_fail(window_with_focus
!= NULL
);
887 display_set_sort_fn(window_with_focus
, sort_by_name
);
890 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
892 g_return_if_fail(window_with_focus
!= NULL
);
894 display_set_sort_fn(window_with_focus
, sort_by_type
);
897 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
899 g_return_if_fail(window_with_focus
!= NULL
);
901 display_set_sort_fn(window_with_focus
, sort_by_date
);
904 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
906 g_return_if_fail(window_with_focus
!= NULL
);
908 display_set_sort_fn(window_with_focus
, sort_by_size
);
911 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
916 g_return_if_fail(window_with_focus
!= NULL
);
918 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
921 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
923 g_return_if_fail(window_with_focus
!= NULL
);
926 filer_update_dir(window_with_focus
, TRUE
);
929 static void create_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
931 g_return_if_fail(window_with_focus
!= NULL
);
933 dir_rescan_with_thumbs(window_with_focus
->directory
,
934 window_with_focus
->path
);
937 static void delete(gpointer data
, guint action
, GtkWidget
*widget
)
939 g_return_if_fail(window_with_focus
!= NULL
);
941 if (window_with_focus
->collection
->number_selected
== 0)
942 filer_target_mode(window_with_focus
,
943 target_callback
, delete,
946 action_delete(window_with_focus
);
949 static void usage(gpointer data
, guint action
, GtkWidget
*widget
)
951 g_return_if_fail(window_with_focus
!= NULL
);
953 if (window_with_focus
->collection
->number_selected
== 0)
954 filer_target_mode(window_with_focus
,
955 target_callback
, usage
,
956 _("Count the size of ... ?"));
958 action_usage(window_with_focus
);
961 static void chmod_items(gpointer data
, guint action
, GtkWidget
*widget
)
963 g_return_if_fail(window_with_focus
!= NULL
);
965 if (window_with_focus
->collection
->number_selected
== 0)
966 filer_target_mode(window_with_focus
,
967 target_callback
, chmod_items
,
968 _("Set permissions on ... ?"));
970 action_chmod(window_with_focus
);
973 static void find(gpointer data
, guint action
, GtkWidget
*widget
)
975 g_return_if_fail(window_with_focus
!= NULL
);
977 if (window_with_focus
->collection
->number_selected
== 0)
978 filer_target_mode(window_with_focus
,
979 target_callback
, find
,
980 _("Search inside ... ?"));
982 action_find(window_with_focus
);
985 /* This pops up our savebox widget, cancelling any currently open one,
986 * and allows the user to pick a new path for it.
987 * Once the new path has been picked, the callback will be called with
988 * both the current and new paths.
989 * NOTE: This function unrefs 'image'!
991 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
992 gboolean (*callback
)(guchar
*current
, guchar
*new))
994 if (GTK_WIDGET_VISIBLE(savebox
))
995 gtk_widget_hide(savebox
);
997 if (callback
== link_cb
)
998 gtk_widget_show(check_relative
);
1000 gtk_widget_hide(check_relative
);
1003 g_free(current_path
);
1004 current_path
= g_strdup(path
);
1005 current_savebox_callback
= callback
;
1007 gtk_window_set_title(GTK_WINDOW(savebox
), title
);
1008 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), current_path
);
1009 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
1010 pixmap_unref(image
);
1012 gtk_widget_grab_focus(GTK_SAVEBOX(savebox
)->entry
);
1013 gtk_widget_show(savebox
);
1016 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
)
1018 g_return_val_if_fail(current_savebox_callback
!= NULL
,
1019 GTK_XDS_SAVE_ERROR
);
1021 return current_savebox_callback(current_path
, pathname
)
1022 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1025 static gboolean
copy_cb(guchar
*current
, guchar
*new)
1027 return action_with_leaf(action_copy
, current
, new);
1030 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new)
1032 char *new_dir
, *leaf
;
1037 report_error(PROJECT
, _("New pathname is not absolute"));
1041 if (new[strlen(new) - 1] == '/')
1043 new_dir
= g_strdup(new);
1050 slash
= strrchr(new, '/');
1051 new_dir
= g_strndup(new, slash
- new);
1055 local_paths
= g_list_append(NULL
, current
);
1056 action(local_paths
, new_dir
, leaf
);
1057 g_list_free(local_paths
);
1064 #define SHOW_SAVEBOX(title, callback) \
1068 item = selected_item(collection); \
1069 path = make_path(window_with_focus->path, item->leafname)->str; \
1070 pixmap_ref(item->image); \
1071 savebox_show(title, path, item->image, callback); \
1074 static void copy_item(gpointer data
, guint action
, GtkWidget
*widget
)
1076 Collection
*collection
;
1078 g_return_if_fail(window_with_focus
!= NULL
);
1080 collection
= window_with_focus
->collection
;
1081 if (collection
->number_selected
> 1)
1083 report_error(PROJECT
, _("You cannot do this to more than "
1084 "one item at a time"));
1087 else if (collection
->number_selected
!= 1)
1088 filer_target_mode(window_with_focus
,
1089 target_callback
, copy_item
,
1092 SHOW_SAVEBOX(_("Copy"), copy_cb
);
1095 static gboolean
rename_cb(guchar
*current
, guchar
*new)
1097 return action_with_leaf(action_move
, current
, new);
1100 static void rename_item(gpointer data
, guint action
, GtkWidget
*widget
)
1102 Collection
*collection
;
1104 g_return_if_fail(window_with_focus
!= NULL
);
1106 collection
= window_with_focus
->collection
;
1107 if (collection
->number_selected
> 1)
1109 report_error(PROJECT
, _("You cannot do this to more than "
1110 "one item at a time"));
1113 else if (collection
->number_selected
!= 1)
1114 filer_target_mode(window_with_focus
,
1115 target_callback
, rename_item
,
1118 SHOW_SAVEBOX(_("Rename"), rename_cb
);
1121 static gboolean
link_cb(guchar
*initial
, guchar
*path
)
1125 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_relative
)))
1129 rpath
= get_relative_path(path
, initial
);
1130 err
= symlink(rpath
, path
);
1135 err
= symlink(initial
, path
);
1139 report_error("ROX-Filer: symlink()", g_strerror(errno
));
1145 static void link_item(gpointer data
, guint action
, GtkWidget
*widget
)
1147 Collection
*collection
;
1149 g_return_if_fail(window_with_focus
!= NULL
);
1151 collection
= window_with_focus
->collection
;
1152 if (collection
->number_selected
> 1)
1154 report_error(PROJECT
, _("You cannot do this to more than "
1155 "one item at a time"));
1158 else if (collection
->number_selected
!= 1)
1159 filer_target_mode(window_with_focus
,
1160 target_callback
, link_item
,
1161 _("Symlink ... ?"));
1163 SHOW_SAVEBOX(_("Symlink"), link_cb
);
1166 static void open_file(gpointer data
, guint action
, GtkWidget
*widget
)
1168 Collection
*collection
;
1170 g_return_if_fail(window_with_focus
!= NULL
);
1172 collection
= window_with_focus
->collection
;
1173 if (collection
->number_selected
> 1)
1175 report_error(PROJECT
, _("You cannot do this to more than "
1176 "one item at a time"));
1179 else if (collection
->number_selected
!= 1)
1180 filer_target_mode(window_with_focus
,
1181 target_callback
, open_file
,
1182 _("Shift Open ... ?"));
1184 filer_openitem(window_with_focus
,
1185 selected_item_number(collection
),
1186 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1189 static void run_action(gpointer data
, guint action
, GtkWidget
*widget
)
1191 Collection
*collection
;
1193 g_return_if_fail(window_with_focus
!= NULL
);
1195 collection
= window_with_focus
->collection
;
1196 if (collection
->number_selected
> 1)
1198 report_error(PROJECT
, _("You cannot do this to more than "
1199 "one item at a time"));
1202 else if (collection
->number_selected
!= 1)
1203 filer_target_mode(window_with_focus
,
1204 target_callback
, run_action
,
1205 _("Set run action for ... ?"));
1210 item
= selected_item(collection
);
1211 g_return_if_fail(item
!= NULL
);
1213 if (can_set_run_action(item
))
1214 type_set_handler_dialog(item
->mime_type
);
1216 report_error(PROJECT
,
1217 _("You can only set the run action for a "
1222 static void set_icon(gpointer data
, guint action
, GtkWidget
*widget
)
1224 Collection
*collection
;
1226 g_return_if_fail(window_with_focus
!= NULL
);
1228 collection
= window_with_focus
->collection
;
1229 if (collection
->number_selected
> 1)
1231 report_error(PROJECT
, _("You cannot do this to more than "
1232 "one item at a time"));
1235 else if (collection
->number_selected
!= 1)
1236 filer_target_mode(window_with_focus
,
1237 target_callback
, set_icon
,
1238 _("Set icon for ... ?"));
1244 item
= selected_item(collection
);
1245 g_return_if_fail(item
!= NULL
);
1247 path
= make_path(window_with_focus
->path
, item
->leafname
)->str
;
1249 icon_set_handler_dialog(item
, path
);
1253 static void show_file_info(gpointer unused
, guint action
, GtkWidget
*widget
)
1256 Collection
*collection
;
1258 g_return_if_fail(window_with_focus
!= NULL
);
1260 collection
= window_with_focus
->collection
;
1261 if (collection
->number_selected
> 1)
1263 report_error(PROJECT
, _("You cannot do this to more than "
1264 "one item at a time"));
1267 else if (collection
->number_selected
!= 1)
1269 filer_target_mode(window_with_focus
,
1270 target_callback
, show_file_info
,
1271 _("Examine ... ?"));
1275 file
= selected_item(collection
);
1276 infobox_new(make_path(window_with_focus
->path
, file
->leafname
)->str
);
1279 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1281 filer_opendir(home_dir
);
1284 static void help(gpointer data
, guint action
, GtkWidget
*widget
)
1286 Collection
*collection
;
1289 g_return_if_fail(window_with_focus
!= NULL
);
1291 collection
= window_with_focus
->collection
;
1292 if (collection
->number_selected
> 1)
1294 report_error(PROJECT
, _("You cannot do this to more than "
1295 "one item at a time"));
1298 else if (collection
->number_selected
!= 1)
1300 filer_target_mode(window_with_focus
, target_callback
, help
,
1301 _("Help about ... ?"));
1304 item
= selected_item(collection
);
1306 show_item_help(make_path(window_with_focus
->path
, item
->leafname
)->str
,
1311 #define OPEN_VFS(fs) \
1312 static void open_vfs_ ## fs (gpointer data, guint action, GtkWidget *widget) \
1314 Collection *collection; \
1316 g_return_if_fail(window_with_focus != NULL); \
1318 collection = window_with_focus->collection; \
1319 if (collection->number_selected < 1) \
1320 filer_target_mode(window_with_focus, target_callback, \
1322 _("Look inside ... ?")); \
1324 real_vfs_open(#fs); \
1327 static void real_vfs_open(char *fs
)
1332 if (window_with_focus
->collection
->number_selected
!= 1)
1334 report_error(PROJECT
, _("You must select a single file "
1335 "to open as a Virtual File System"));
1339 item
= selected_item(window_with_focus
->collection
);
1341 path
= g_strconcat(window_with_focus
->path
,
1346 filer_change_to(window_with_focus
, path
, NULL
);
1355 static void open_vfs_avfs(gpointer data
, guint action
, GtkWidget
*widget
)
1359 Collection
*collection
;
1361 g_return_if_fail(window_with_focus
!= NULL
);
1363 collection
= window_with_focus
->collection
;
1364 if (collection
->number_selected
< 1)
1366 filer_target_mode(window_with_focus
, target_callback
,
1368 _("Look inside ... ?"));
1371 else if (collection
->number_selected
!= 1)
1373 report_error(PROJECT
, _("You must select a single file "
1374 "to open as a Virtual File System"));
1378 item
= selected_item(collection
);
1380 path
= g_strconcat(window_with_focus
->path
,
1381 "/", item
->leafname
, "#", NULL
);
1383 filer_change_to(window_with_focus
, path
, NULL
);
1388 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1390 g_return_if_fail(window_with_focus
!= NULL
);
1392 collection_select_all(window_with_focus
->collection
);
1393 window_with_focus
->temp_item_selected
= FALSE
;
1396 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1398 g_return_if_fail(window_with_focus
!= NULL
);
1400 collection_clear_selection(window_with_focus
->collection
);
1401 window_with_focus
->temp_item_selected
= FALSE
;
1404 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1409 static gboolean
new_directory_cb(guchar
*initial
, guchar
*path
)
1411 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1413 report_error("mkdir", g_strerror(errno
));
1417 dir_check_this(path
);
1419 if (filer_exists(window_with_focus
))
1422 leaf
= strrchr(path
, '/');
1424 display_set_autoselect(window_with_focus
, leaf
+ 1);
1430 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1432 g_return_if_fail(window_with_focus
!= NULL
);
1434 savebox_show(_("New Directory"),
1435 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1436 type_to_icon(&special_directory
),
1440 static gboolean
new_file_cb(guchar
*initial
, guchar
*path
)
1444 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1448 report_error(_("Error creating file"), g_strerror(errno
));
1453 report_error(_("Error creating file"), g_strerror(errno
));
1455 dir_check_this(path
);
1457 if (filer_exists(window_with_focus
))
1460 leaf
= strrchr(path
, '/');
1462 display_set_autoselect(window_with_focus
, leaf
+ 1);
1468 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1470 g_return_if_fail(window_with_focus
!= NULL
);
1472 savebox_show(_("New File"),
1473 make_path(window_with_focus
->path
, _("NewFile"))->str
,
1474 type_to_icon(&text_plain
),
1478 static gboolean
new_file_type_cb(guchar
*initial
, guchar
*path
)
1480 gchar
*templ
, *templ_dname
, *oleaf
, *dest
, *leaf
;
1483 /* We can work out the template path from the initial name */
1484 oleaf
= g_basename(initial
);
1485 templ_dname
= choices_find_path_load("Templates", "");
1490 mess
= g_strconcat(_("Could not find the template for "),
1492 report_error(_("Error creating file"), mess
);
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
);
1563 msg
= g_strdup_printf(
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
);
1578 report_error(PROJECT
, msg
);
1581 filer_opendir(save
);
1586 /* Scan the SendTo dir and create and show the Send To menu.
1587 * The 'paths' list and every path in it is claimed, and will be
1588 * freed later -- don't free it yourself!
1590 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1592 GtkWidget
*menu
, *item
;
1596 menu
= gtk_menu_new();
1598 path
= choices_list_dirs("SendTo");
1600 for (i
= 0; i
< path
->len
; i
++)
1602 GList
*widgets
= NULL
;
1603 guchar
*dir
= (guchar
*) path
->pdata
[i
];
1605 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1606 (CallbackFn
) do_send_to
,
1610 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1611 gtk_menu_item_new());
1613 g_list_free(widgets
); /* TODO: Get rid of this */
1616 choices_free_list(path
);
1618 item
= gtk_menu_item_new_with_label(_("Customise"));
1619 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
1620 GTK_SIGNAL_FUNC(customise_send_to
), NULL
);
1621 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1625 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1626 g_list_free(send_to_paths
);
1628 send_to_paths
= paths
;
1630 gtk_signal_connect(GTK_OBJECT(menu
), "unmap_event",
1631 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
1634 show_popup_menu(menu
, event
, 0);
1637 static void send_to(gpointer data
, guint action
, GtkWidget
*widget
)
1639 Collection
*collection
;
1641 g_return_if_fail(window_with_focus
!= NULL
);
1643 collection
= window_with_focus
->collection
;
1645 if (collection
->number_selected
< 1)
1646 filer_target_mode(window_with_focus
, target_callback
,
1647 send_to
, _("Send ... to ... ?"));
1653 paths
= filer_selected_items(window_with_focus
);
1654 event
= gtk_get_current_event();
1657 show_send_to_menu(paths
, event
);
1659 gdk_event_free(event
);
1663 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1665 char *argv
[] = {"sh", "-c", NULL
, NULL
};
1667 argv
[2] = option_get_static_string("menu_xterm");
1669 g_return_if_fail(window_with_focus
!= NULL
);
1671 if (!spawn_full(argv
, window_with_focus
->path
))
1672 report_error(PROJECT
, _("Failed to fork() child process"));
1675 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1677 g_return_if_fail(window_with_focus
!= NULL
);
1679 filer_change_to(window_with_focus
, home_dir
, NULL
);
1682 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1684 g_return_if_fail(window_with_focus
!= NULL
);
1686 filer_open_parent(window_with_focus
);
1689 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1691 g_return_if_fail(window_with_focus
!= NULL
);
1693 change_to_parent(window_with_focus
);
1696 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1698 g_return_if_fail(window_with_focus
!= NULL
);
1700 filer_window_autosize(window_with_focus
, TRUE
);
1703 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1705 g_return_if_fail(window_with_focus
!= NULL
);
1707 if (o_unique_filer_windows
)
1709 report_error(PROJECT
, _("You can't open a second view onto "
1710 "this directory because the `Unique Windows' option "
1711 "is turned on in the Options window."));
1714 filer_opendir(window_with_focus
->path
);
1718 static void su_to_user(GtkWidget
*dialog
)
1721 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1725 g_return_if_fail(dialog
!= NULL
);
1727 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1728 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1730 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1732 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1733 argv
[3] = gtk_entry_get_text(user
);
1734 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1738 report_error(_("fork() failed"), g_strerror(errno
));
1743 gtk_widget_destroy(dialog
);
1746 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1748 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1750 g_return_if_fail(window_with_focus
!= NULL
);
1752 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1753 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1754 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1755 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1756 g_strdup(window_with_focus
->path
), g_free
);
1758 vbox
= gtk_vbox_new(FALSE
, 4);
1759 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1760 gtk_box_pack_start(GTK_BOX(vbox
),
1761 gtk_label_new(_("Browse as which user?")),
1764 hbox
= gtk_hbox_new(FALSE
, 4);
1765 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1767 gtk_box_pack_start(GTK_BOX(hbox
),
1768 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1770 entry
= gtk_entry_new();
1771 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1772 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1773 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1774 gtk_widget_grab_focus(entry
);
1775 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1776 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1777 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1779 hbox
= gtk_hbox_new(TRUE
, 0);
1780 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1782 button
= gtk_button_new_with_label(_("OK"));
1783 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1784 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1785 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1786 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1787 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1789 button
= gtk_button_new_with_label(_("Cancel"));
1790 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1791 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1792 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1793 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1794 GTK_OBJECT(dialog
));
1796 gtk_widget_show_all(dialog
);
1800 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1802 g_return_if_fail(window_with_focus
!= NULL
);
1804 gtk_widget_destroy(window_with_focus
->window
);
1807 static void enter_path(gpointer data
, guint action
, GtkWidget
*widget
)
1809 g_return_if_fail(window_with_focus
!= NULL
);
1811 minibuffer_show(window_with_focus
, MINI_PATH
);
1814 static void shell_command(gpointer data
, guint action
, GtkWidget
*widget
)
1816 g_return_if_fail(window_with_focus
!= NULL
);
1818 minibuffer_show(window_with_focus
, MINI_SHELL
);
1821 static void select_if(gpointer data
, guint action
, GtkWidget
*widget
)
1823 g_return_if_fail(window_with_focus
!= NULL
);
1825 minibuffer_show(window_with_focus
, MINI_SELECT_IF
);
1828 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1830 filer_opendir(make_path(app_dir
, "Help")->str
);
1833 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1834 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1836 GList
*items
, *item
;
1838 items
= gtk_container_children(GTK_CONTAINER(menu
));
1840 item
= g_list_nth(items
, from
);
1843 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1849 /* This is called for every modified menu entry. We just use it to
1850 * find out if the menu has changed at all.
1852 static void set_mod(gboolean
*mod
, guchar
*str
)
1854 if (str
&& str
[0] == '(')
1858 static void save_menus(void)
1862 menurc
= choices_find_path_save("menus", PROJECT
, FALSE
);
1865 gboolean mod
= FALSE
;
1869 /* Find out if anything changed... */
1870 gtk_item_factory_dump_items(NULL
, TRUE
,
1871 (GtkPrintFunc
) set_mod
, &mod
);
1873 /* Dump out if so... */
1876 menurc
= choices_find_path_save("menus", PROJECT
, TRUE
);
1877 g_return_if_fail(menurc
!= NULL
);
1878 mark_menus_modified(TRUE
);
1879 gtk_item_factory_dump_rc(menurc
, NULL
, TRUE
);
1880 mark_menus_modified(FALSE
);
1886 static void mark_modified(gpointer hash_key
,
1890 GtkItemFactoryItem
*item
= (GtkItemFactoryItem
*) value
;
1892 item
->modified
= (gboolean
) GPOINTER_TO_INT(user_data
);
1895 /* Set or clear the 'modified' flag in all menu items. Messy... */
1896 static void mark_menus_modified(gboolean mod
)
1898 GtkItemFactoryClass
*class;
1900 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY
);
1902 g_hash_table_foreach(class->item_ht
, mark_modified
,
1903 GINT_TO_POINTER(mod
));
1906 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1909 GtkWidget
*item
= NULL
;
1911 items
= gtk_container_children(GTK_CONTAINER(shell
));
1912 nth
= g_list_nth(items
, n
);
1914 g_return_if_fail(nth
!= NULL
);
1916 item
= (GtkWidget
*) (nth
->data
);
1919 gtk_menu_shell_select_item(shell
, item
);