4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* menu.c - code for handling the popup menu */
28 #include <sys/param.h>
45 #include "gui_support.h"
48 #include "gtksavebox.h"
50 #include "minibuffer.h"
57 #include "usericons.h"
59 #include "collection.h"
62 #define C_ "<control>"
88 typedef enum menu_icon_style
{
89 MIS_NONE
, MIS_SMALL
, MIS_LARGE
, MIS_HUGE
,
90 MIS_CURRENT
, /* As per current filer window */
94 typedef void (*ActionFn
)(GList
*paths
, char *dest_dir
, char *leaf
, int quiet
);
95 typedef void MenuCallback(GtkWidget
*widget
, gpointer data
);
97 GtkAccelGroup
*filer_keys
;
98 GtkAccelGroup
*pinboard_keys
;
100 GtkWidget
*popup_menu
= NULL
; /* Currently open menu */
102 static gint updating_menu
= 0; /* Non-zero => ignore activations */
103 static GList
*send_to_paths
= NULL
;
105 /* Static prototypes */
107 static void save_menus(void);
108 static void menu_closed(GtkWidget
*widget
);
109 static void items_sensitive(gboolean state
);
110 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
111 gboolean (*callback
)(guchar
*current
, guchar
*new));
112 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
);
113 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new);
114 static gboolean
link_cb(guchar
*initial
, guchar
*path
);
115 static void select_nth_item(GtkMenuShell
*shell
, int n
);
116 static void new_file_type(gchar
*templ
);
117 static void do_send_to(gchar
*templ
);
118 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
);
120 /* Note that for most of these callbacks none of the arguments are used. */
122 /* (action used in these three - DetailsType) */
123 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
);
124 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
);
125 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
);
127 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
);
128 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
);
129 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
);
130 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
);
132 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
);
133 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
);
134 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
);
136 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
);
138 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
);
139 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
);
140 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
);
141 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
);
142 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
);
143 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
);
145 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
);
146 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
);
147 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
);
148 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
);
149 /* static void new_user(gpointer data, guint action, GtkWidget *widget); */
150 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
);
152 /* (action used in this - MiniType) */
153 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
);
154 static void resize(gpointer data
, guint action
, GtkWidget
*widget
);
157 #define MENUS_NAME "menus2"
158 static void keys_changed(gpointer data
);
160 # define MENUS_NAME "menus"
161 static void mark_menus_modified(gboolean mod
);
164 static GtkWidget
*filer_menu
; /* The popup filer menu */
165 static GtkWidget
*filer_file_item
; /* The File '' label */
166 static GtkWidget
*filer_file_menu
; /* The File '' menu */
167 static GtkWidget
*file_shift_item
; /* Shift Open label */
168 GtkWidget
*display_large_menu
; /* Display->Large With... */
169 GtkWidget
*display_small_menu
; /* Display->Small With... */
171 static GtkWidget
*filer_vfs_menu
; /* The Open VFS menu */
173 static GtkWidget
*filer_hidden_menu
; /* The Show Hidden item */
174 static GtkWidget
*filer_thumb_menu
; /* The Show Thumbs item */
175 static GtkWidget
*filer_new_window
; /* The New Window item */
176 static GtkWidget
*filer_new_menu
; /* The New submenu */
178 /* Used for Copy, etc */
179 static GtkWidget
*savebox
= NULL
;
180 static GtkWidget
*check_relative
= NULL
;
181 static guchar
*current_path
= NULL
;
182 static gboolean (*current_savebox_callback
)(guchar
*current
, guchar
*new);
187 static GtkItemFactoryEntry filer_menu_def
[] = {
188 {N_("Display"), NULL
, NULL
, 0, "<Branch>"},
189 {">" N_("Huge Icons"), NULL
, huge_with
, DETAILS_NONE
, NULL
},
190 {">" N_("Large Icons"), NULL
, large_with
, DETAILS_NONE
, NULL
},
191 {">" N_("Small Icons"), NULL
, small_with
, DETAILS_NONE
, NULL
},
192 {">" N_("Huge, With..."), NULL
, NULL
, 0, "<Branch>"},
193 {">>" N_("Summary"), NULL
, huge_with
, DETAILS_SUMMARY
, NULL
},
194 {">>" N_("Sizes"), NULL
, huge_with
, DETAILS_SIZE
, NULL
},
195 {">>" N_("Permissions"), NULL
, huge_with
, DETAILS_PERMISSIONS
, NULL
},
196 {">>" N_("Type"), NULL
, huge_with
, DETAILS_TYPE
, NULL
},
197 {">>" N_("Times"), NULL
, huge_with
, DETAILS_TIMES
, NULL
},
198 {">" N_("Large, With..."), NULL
, NULL
, 0, "<Branch>"},
199 {">>" N_("Summary"), NULL
, large_with
, DETAILS_SUMMARY
, NULL
},
200 {">>" N_("Sizes"), NULL
, large_with
, DETAILS_SIZE
, NULL
},
201 {">>" N_("Permissions"), NULL
, large_with
, DETAILS_PERMISSIONS
, NULL
},
202 {">>" N_("Type"), NULL
, large_with
, DETAILS_TYPE
, NULL
},
203 {">>" N_("Times"), NULL
, large_with
, DETAILS_TIMES
, NULL
},
204 {">" N_("Small, With..."), NULL
, NULL
, 0, "<Branch>"},
205 {">>" N_("Summary"), NULL
, small_with
, DETAILS_SUMMARY
, NULL
},
206 {">>" N_("Sizes"), NULL
, small_with
, DETAILS_SIZE
, NULL
},
207 {">>" N_("Permissions"), NULL
, small_with
, DETAILS_PERMISSIONS
, NULL
},
208 {">>" N_("Type"), NULL
, small_with
, DETAILS_TYPE
, NULL
},
209 {">>" N_("Times"), NULL
, small_with
, DETAILS_TIMES
, NULL
},
210 {">", NULL
, NULL
, 0, "<Separator>"},
211 {">" N_("Sort by Name"), NULL
, sort_name
, 0, NULL
},
212 {">" N_("Sort by Type"), NULL
, sort_type
, 0, NULL
},
213 {">" N_("Sort by Date"), NULL
, sort_date
, 0, NULL
},
214 {">" N_("Sort by Size"), NULL
, sort_size
, 0, NULL
},
215 {">", NULL
, NULL
, 0, "<Separator>"},
216 {">" N_("Show Hidden"), NULL
, hidden
, 0, "<ToggleItem>"},
217 {">" N_("Show Thumbnails"), NULL
, show_thumbs
, 0, "<ToggleItem>"},
218 {">" N_("Refresh"), NULL
, refresh
, 0, NULL
},
219 {N_("File"), NULL
, NULL
, 0, "<Branch>"},
220 {">" N_("Copy..."), NULL
, file_op
, FILE_COPY_ITEM
, NULL
},
221 {">" N_("Rename..."), NULL
, file_op
, FILE_RENAME_ITEM
, NULL
},
222 {">" N_("Link..."), NULL
, file_op
, FILE_LINK_ITEM
, NULL
},
223 {">" N_("Shift Open"), NULL
, file_op
, FILE_OPEN_FILE
, NULL
},
224 {">" N_("Help"), NULL
, file_op
, FILE_HELP
, NULL
},
225 {">" N_("Info"), NULL
, file_op
, FILE_SHOW_FILE_INFO
, NULL
},
226 {">" N_("Set Run Action..."), NULL
, file_op
, FILE_RUN_ACTION
, NULL
},
227 {">" N_("Set Icon..."), NULL
, file_op
, FILE_SET_ICON
, NULL
},
229 {">" N_("Open VFS"), NULL
, NULL
, 0, "<Branch>"},
230 {">>" N_("Unzip"), NULL
, file_op
, FILE_OPEN_VFS_UZIP
, NULL
},
231 {">>" N_("Untar"), NULL
, file_op
, FILE_OPEN_VFS_UTAR
, NULL
},
232 {">>" N_("Deb"), NULL
, file_op
, FILE_OPEN_VFS_DEB
, NULL
},
233 {">>" N_("RPM"), NULL
, file_op
, FILE_OPEN_VFS_RPM
, NULL
},
235 {">" N_("Open AVFS"), NULL
, file_op
, FILE_OPEN_VFS_AVFS
, NULL
},
237 {">", NULL
, NULL
, 0, "<Separator>"},
238 {">" N_("Send To..."), NULL
, file_op
, FILE_SEND_TO
, NULL
},
239 {">" N_("Delete"), NULL
, file_op
, FILE_DELETE
, NULL
},
240 {">" N_("Disk Usage"), NULL
, file_op
, FILE_USAGE
, NULL
},
241 {">" N_("Permissions"), NULL
, file_op
, FILE_CHMOD_ITEMS
, NULL
},
242 {">" N_("Find"), NULL
, file_op
, FILE_FIND
, NULL
},
243 {N_("Select"), NULL
, NULL
, 0, "<Branch>"},
244 {">" N_("Select All"), NULL
, select_all
, 0, NULL
},
245 {">" N_("Clear Selection"), NULL
, clear_selection
, 0, NULL
},
246 {">" N_("Invert Selection"), NULL
, invert_selection
, 0, NULL
},
247 {">" N_("Select If..."), NULL
, mini_buffer
, MINI_SELECT_IF
, NULL
},
248 {N_("Options..."), NULL
, menu_show_options
, 0, NULL
},
249 {N_("New"), NULL
, NULL
, 0, "<Branch>"},
250 {">" N_("Directory"), NULL
, new_directory
, 0, NULL
},
251 {">" N_("Blank file"), NULL
, new_file
, 0, NULL
},
252 {N_("Xterm Here"), NULL
, xterm_here
, 0, NULL
},
253 {N_("Window"), NULL
, NULL
, 0, "<Branch>"},
254 {">" N_("Parent, New Window"), NULL
, open_parent
, 0, NULL
},
255 {">" N_("Parent, Same Window"), NULL
, open_parent_same
, 0, NULL
},
256 {">" N_("New Window"), NULL
, new_window
, 0, NULL
},
257 {">" N_("Home Directory"), NULL
, home_directory
, 0, NULL
},
258 {">" N_("Resize Window"), NULL
, resize
, 0, NULL
},
259 /* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
261 {">" N_("Close Window"), NULL
, close_window
, 0, NULL
},
262 {">", NULL
, NULL
, 0, "<Separator>"},
263 {">" N_("Enter Path..."), "slash", mini_buffer
, MINI_PATH
, NULL
},
264 {">" N_("Shell Command..."), NULL
, mini_buffer
, MINI_SHELL
, NULL
},
265 {">", NULL
, NULL
, 0, "<Separator>"},
266 {">" N_("Show ROX-Filer Help"), "F1", menu_rox_help
, 0, NULL
},
270 #define GET_MENU_ITEM(var, menu) \
271 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
273 #define GET_SMENU_ITEM(var, menu, sub) \
275 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
276 var = gtk_item_factory_get_widget(item_factory, tmp); \
280 #define GET_SSMENU_ITEM(var, menu, sub, subsub) \
282 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
283 var = gtk_item_factory_get_widget(item_factory, tmp); \
294 GtkItemFactory
*item_factory
;
296 filer_keys
= gtk_accel_group_new();
297 item_factory
= menu_create(filer_menu_def
,
298 sizeof(filer_menu_def
) / sizeof(*filer_menu_def
),
299 "<filer>", filer_keys
);
301 GET_MENU_ITEM(filer_menu
, "filer");
302 GET_SMENU_ITEM(filer_file_menu
, "filer", "File");
304 GET_SSMENU_ITEM(filer_vfs_menu
, "filer", "File", "Open VFS");
306 GET_SSMENU_ITEM(filer_hidden_menu
, "filer", "Display", "Show Hidden");
307 GET_SSMENU_ITEM(filer_thumb_menu
, "filer", "Display",
310 GET_SSMENU_ITEM(display_large_menu
, "filer",
311 "Display", "Large, With...");
312 GET_SSMENU_ITEM(display_small_menu
, "filer",
313 "Display", "Small, With...");
315 GET_SMENU_ITEM(filer_new_menu
, "filer", "New");
317 /* File '' label... */
318 items
= gtk_container_children(GTK_CONTAINER(filer_menu
));
319 filer_file_item
= GTK_BIN(g_list_nth(items
, 1)->data
)->child
;
322 /* Shift Open... label */
323 items
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
324 file_shift_item
= GTK_BIN(g_list_nth(items
, 3)->data
)->child
;
327 GET_SSMENU_ITEM(item
, "filer", "Window", "New Window");
328 filer_new_window
= GTK_BIN(item
)->child
;
330 menurc
= choices_find_path_load(MENUS_NAME
, PROJECT
);
334 gtk_accel_map_load(menurc
);
336 gtk_item_factory_parse_rc(menurc
);
337 mark_menus_modified(FALSE
);
342 gtk_signal_connect(GTK_OBJECT(filer_menu
), "unmap_event",
343 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
344 gtk_signal_connect(GTK_OBJECT(filer_file_menu
), "unmap_event",
345 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
347 option_add_string("menu_xterm", "xterm", NULL
);
348 option_add_int("menu_iconsize", MIS_SMALL
, NULL
);
349 option_add_saver(save_menus
);
351 tips
= gtk_tooltips_new();
352 check_relative
= gtk_check_button_new_with_label(_("Relative link"));
353 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative
), TRUE
);
354 GTK_WIDGET_UNSET_FLAGS(check_relative
, GTK_CAN_FOCUS
);
355 gtk_tooltips_set_tip(tips
, check_relative
,
356 _("If on, the symlink will store the path from the "
357 "symlink to the target file. Use this if the symlink "
358 "and the target will be moved together.\n"
359 "If off, the path from the root directory is stored - "
360 "use this if the symlink may move but the target will "
363 savebox
= gtk_savebox_new();
364 gtk_box_pack_start(GTK_BOX(GTK_SAVEBOX(savebox
)->vbox
),
365 check_relative
, FALSE
, TRUE
, 0);
366 gtk_widget_show(check_relative
);
368 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_to_file",
369 GTK_SIGNAL_FUNC(save_to_file
), NULL
);
370 gtk_signal_connect_object(GTK_OBJECT(savebox
), "save_done",
371 GTK_SIGNAL_FUNC(gtk_widget_hide
),
372 GTK_OBJECT(savebox
));
375 g_signal_connect_object(G_OBJECT(filer_keys
), "accel_changed",
376 (GCallback
) keys_changed
, NULL
, 0);
382 /* Name is in the form "<panel>" */
383 GtkItemFactory
*menu_create(GtkItemFactoryEntry
*def
, int n_entries
,
384 guchar
*name
, GtkAccelGroup
*keys
)
386 GtkItemFactory
*item_factory
;
387 GtkItemFactoryEntry
*translated
;
391 keys
= gtk_accel_group_new();
392 gtk_accel_group_lock(keys
);
395 item_factory
= gtk_item_factory_new(GTK_TYPE_MENU
, name
, keys
);
397 translated
= translate_entries(def
, n_entries
);
398 gtk_item_factory_create_items(item_factory
, n_entries
,
400 free_translated_entries(translated
, n_entries
);
405 /* Prevent the user from setting a short-cut on this item */
406 void menuitem_no_shortcuts(GtkWidget
*item
)
410 GtkMenuItem *menuitem = GTK_MENU_ITEM(item);
412 _gtk_widget_set_accel_path(item, NULL, NULL);
413 g_free(menuitem->accel_path);
414 menuitem->accel_path = NULL;
417 gtk_widget_lock_accelerators(item
);
421 static void items_sensitive(gboolean state
)
426 items
= item
= gtk_container_children(GTK_CONTAINER(filer_file_menu
));
429 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
435 items
= item
= gtk_container_children(GTK_CONTAINER(filer_vfs_menu
));
438 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, state
);
445 /* 'data' is an array of three ints:
446 * [ pointer_x, pointer_y, item_under_pointer ]
448 void position_menu(GtkMenu
*menu
, gint
*x
, gint
*y
,
454 int *pos
= (int *) data
;
455 GtkRequisition requisition
;
460 next
= items
= gtk_container_children(GTK_CONTAINER(menu
));
462 while (item
>= 0 && next
)
464 int h
= ((GtkWidget
*) next
->data
)->requisition
.height
;
477 gtk_widget_size_request(GTK_WIDGET(menu
), &requisition
);
479 *x
= pos
[0] - (requisition
.width
* 7 / 8);
480 *y
= pos
[1] - y_shift
;
482 *x
= CLAMP(*x
, 0, screen_width
- requisition
.width
);
483 *y
= CLAMP(*y
, 0, screen_height
- requisition
.height
);
491 /* Used when you menu-click on the Large or Small toolbar tools */
492 void show_style_menu(FilerWindow
*filer_window
,
493 GdkEventButton
*event
,
498 pos
[0] = event
->x_root
;
499 pos
[1] = event
->y_root
;
502 window_with_focus
= filer_window
;
506 gtk_menu_popup(GTK_MENU(popup_menu
), NULL
, NULL
, position_menu
,
507 (gpointer
) pos
, event
->button
, event
->time
);
511 static GList
*menu_from_dir(GtkWidget
*menu
, const gchar
*dname
,
512 MenuIconStyle style
, CallbackFn func
,
513 gboolean separator
, gboolean strip_ext
)
515 GList
*widgets
= NULL
;
521 dir
= opendir(dname
);
527 item
= gtk_menu_item_new();
528 widgets
= g_list_append(widgets
, item
);
529 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
532 while ((ent
= readdir(dir
)))
542 /* Ignore hidden files */
543 if (ent
->d_name
[0] == '.')
546 /* Strip off extension, if any */
547 dot
= strchr(ent
->d_name
, '.');
548 if (strip_ext
&& dot
)
549 leaf
= g_strndup(ent
->d_name
, dot
- ent
->d_name
);
551 leaf
= g_strdup(ent
->d_name
);
553 fname
= g_strconcat(dname
, "/", ent
->d_name
, NULL
);
554 ditem
= diritem_new(NULL
);
555 diritem_restat(fname
, ditem
);
557 if (ditem
->image
&& style
!= MIS_NONE
)
561 if (!ditem
->image
->huge_pixmap
)
562 pixmap_make_huge(ditem
->image
);
563 icon
= ditem
->image
->huge_pixmap
;
564 mask
= ditem
->image
->huge_mask
;
567 icon
= ditem
->image
->pixmap
;
568 mask
= ditem
->image
->mask
;
573 if (!ditem
->image
->sm_pixmap
)
574 pixmap_make_small(ditem
->image
);
575 icon
= ditem
->image
->sm_pixmap
;
576 mask
= ditem
->image
->sm_mask
;
580 item
= gtk_menu_item_new();
581 /* TODO: Find a way to allow short-cuts */
582 menuitem_no_shortcuts(item
);
584 hbox
= gtk_hbox_new(FALSE
, 2);
585 gtk_container_add(GTK_CONTAINER(item
), hbox
);
587 img
= gtk_pixmap_new(icon
, mask
);
588 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 2);
590 label
= gtk_label_new(leaf
);
591 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
592 gtk_box_pack_start(GTK_BOX(hbox
), label
, TRUE
, TRUE
, 2);
597 item
= gtk_menu_item_new_with_label(leaf
);
601 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
602 GTK_SIGNAL_FUNC(func
), (GtkObject
*) fname
);
603 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
604 gtk_signal_connect_object(GTK_OBJECT(item
), "destroy",
605 GTK_SIGNAL_FUNC(g_free
), (GtkObject
*) fname
);
607 widgets
= g_list_append(widgets
, item
);
616 /* Scan the templates dir and create entries for the New menu */
617 static void update_new_files_menu(MenuIconStyle style
)
619 static GList
*widgets
= NULL
;
621 gchar
*templ_dname
= NULL
;
627 for (next
= widgets
; next
; next
= next
->next
)
628 gtk_widget_destroy((GtkWidget
*) next
->data
);
630 g_list_free(widgets
);
634 templ_dname
= choices_find_path_load("Templates", "");
637 widgets
= menu_from_dir(filer_new_menu
, templ_dname
, style
,
638 (CallbackFn
) new_file_type
, TRUE
, TRUE
);
641 gtk_widget_show_all(filer_new_menu
);
644 /* 'item' is the number of the item to appear under the pointer. */
645 void show_popup_menu(GtkWidget
*menu
, GdkEvent
*event
, int item
)
651 if (event
&& (event
->type
== GDK_BUTTON_PRESS
||
652 event
->type
== GDK_BUTTON_RELEASE
))
654 GdkEventButton
*bev
= (GdkEventButton
*) event
;
656 pos
[0] = bev
->x_root
;
657 pos
[1] = bev
->y_root
;
658 button
= bev
->button
;
661 else if (event
&& event
->type
== GDK_KEY_PRESS
)
663 GdkEventKey
*kev
= (GdkEventKey
*) event
;
665 get_pointer_xy(pos
, pos
+ 1);
669 get_pointer_xy(pos
, pos
+ 1);
673 gtk_widget_show_all(menu
);
674 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
675 position_menu
, (gpointer
) pos
, button
, time
);
676 select_nth_item(GTK_MENU_SHELL(menu
), item
);
679 static MenuIconStyle
get_menu_icon_style(void)
684 mis
= option_get_int("menu_iconsize");
688 case MIS_NONE
: case MIS_SMALL
: case MIS_LARGE
: case MIS_HUGE
:
694 if (mis
== MIS_CURRENT
&& window_with_focus
)
696 switch (window_with_focus
->display_style
)
709 display
= option_get_int("display_size");
725 void show_filer_menu(FilerWindow
*filer_window
, GdkEvent
*event
, int item
)
727 DirItem
*file_item
= NULL
;
728 GdkModifierType state
= 0;
732 /* Remove previous AppMenu, if any */
735 window_with_focus
= filer_window
;
737 if (event
->type
== GDK_BUTTON_PRESS
)
738 state
= ((GdkEventButton
*) event
)->state
;
739 else if (event
->type
== GDK_KEY_PRESS
)
740 state
= ((GdkEventKey
*) event
)->state
;
742 if (filer_window
->collection
->number_selected
== 0 && item
>= 0)
744 filer_window
->temp_item_selected
= TRUE
;
745 collection_select_item(filer_window
->collection
, item
);
749 filer_window
->temp_item_selected
= FALSE
;
752 /* Short-cut to the Send To menu */
753 if (state
& GDK_SHIFT_MASK
)
759 if (filer_window
->collection
->number_selected
== 0)
762 _("You should Shift+Menu click over a file to "
763 "send it somewhere"));
767 paths
= filer_selected_items(filer_window
);
769 show_send_to_menu(paths
, event
); /* (paths eaten) */
775 GtkWidget
*file_label
, *file_menu
;
776 Collection
*collection
= filer_window
->collection
;
780 file_label
= filer_file_item
;
781 file_menu
= filer_file_menu
;
782 gtk_check_menu_item_set_active(
783 GTK_CHECK_MENU_ITEM(filer_thumb_menu
),
784 filer_window
->show_thumbs
);
785 gtk_check_menu_item_set_active(
786 GTK_CHECK_MENU_ITEM(filer_hidden_menu
),
787 filer_window
->show_hidden
);
788 buffer
= g_string_new(NULL
);
790 if (collection
->number_selected
== 1)
792 item
= selected_item(filer_window
->collection
);
794 dir_update_item(filer_window
->directory
,
798 switch (collection
->number_selected
)
801 g_string_assign(buffer
, _("Next Click"));
802 items_sensitive(TRUE
);
805 items_sensitive(TRUE
);
806 file_item
= selected_item(
807 filer_window
->collection
);
808 g_string_sprintf(buffer
, "%s '%s'",
809 basetype_name(file_item
),
810 file_item
->leafname
);
811 if (!can_set_run_action(file_item
))
812 menu_set_items_shaded(filer_file_menu
,
816 items_sensitive(FALSE
);
817 g_string_sprintf(buffer
, _("%d items"),
818 collection
->number_selected
);
821 gtk_label_set_text(GTK_LABEL(file_label
), buffer
->str
);
822 g_string_free(buffer
, TRUE
);
824 menu_show_shift_action(file_shift_item
, file_item
,
825 collection
->number_selected
== 0);
827 appmenu_add(make_path(filer_window
->path
,
828 file_item
->leafname
)->str
,
829 file_item
, filer_file_menu
);
832 update_new_files_menu(get_menu_icon_style());
834 gtk_widget_set_sensitive(filer_new_window
, !o_unique_filer_windows
);
836 popup_menu
= (state
& GDK_CONTROL_MASK
)
842 show_popup_menu(popup_menu
, event
,
843 popup_menu
== filer_file_menu
? 5 : 1);
846 static void menu_closed(GtkWidget
*widget
)
848 if (window_with_focus
== NULL
|| widget
!= popup_menu
)
849 return; /* Close panel item chosen? */
853 if (window_with_focus
->temp_item_selected
)
855 collection_clear_selection(window_with_focus
->collection
);
856 window_with_focus
->temp_item_selected
= FALSE
;
860 void target_callback(FilerWindow
*filer_window
,
864 Collection
*collection
= filer_window
->collection
;
866 g_return_if_fail(window_with_focus
!= NULL
);
867 g_return_if_fail(window_with_focus
== filer_window
);
869 /* Don't grab the primary selection */
870 filer_window
->temp_item_selected
= TRUE
;
872 collection_wink_item(collection
, item
);
873 collection_clear_except(collection
, item
);
874 file_op(NULL
, GPOINTER_TO_INT(action
), GTK_WIDGET(collection
));
876 if (item
< collection
->number_of_items
)
877 collection_unselect_item(collection
, item
);
878 filer_window
->temp_item_selected
= FALSE
;
881 /* Set the text of the 'Shift Open...' menu item.
882 * If icon is NULL, reset the text and also shade it, unless 'next'.
884 void menu_show_shift_action(GtkWidget
*menu_item
, DirItem
*item
, gboolean next
)
886 guchar
*shift_action
= NULL
;
890 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
892 if (item
->flags
& ITEM_FLAG_MOUNTED
)
893 shift_action
= N_("Unmount");
895 shift_action
= N_("Mount");
897 else if (item
->flags
& ITEM_FLAG_SYMLINK
)
898 shift_action
= N_("Show Target");
899 else if (item
->base_type
== TYPE_DIRECTORY
)
900 shift_action
= N_("Look Inside");
901 else if (item
->base_type
== TYPE_FILE
)
902 shift_action
= N_("Open As Text");
904 gtk_label_set_text(GTK_LABEL(menu_item
),
905 shift_action
? _(shift_action
)
907 gtk_widget_set_sensitive(menu_item
, shift_action
!= NULL
|| next
);
912 static void huge_with(gpointer data
, guint action
, GtkWidget
*widget
)
914 display_set_layout(window_with_focus
, HUGE_ICONS
, action
);
917 static void large_with(gpointer data
, guint action
, GtkWidget
*widget
)
919 display_set_layout(window_with_focus
, LARGE_ICONS
, action
);
922 static void small_with(gpointer data
, guint action
, GtkWidget
*widget
)
924 display_set_layout(window_with_focus
, SMALL_ICONS
, action
);
927 static void sort_name(gpointer data
, guint action
, GtkWidget
*widget
)
929 g_return_if_fail(window_with_focus
!= NULL
);
931 display_set_sort_fn(window_with_focus
, sort_by_name
);
934 static void sort_type(gpointer data
, guint action
, GtkWidget
*widget
)
936 g_return_if_fail(window_with_focus
!= NULL
);
938 display_set_sort_fn(window_with_focus
, sort_by_type
);
941 static void sort_date(gpointer data
, guint action
, GtkWidget
*widget
)
943 g_return_if_fail(window_with_focus
!= NULL
);
945 display_set_sort_fn(window_with_focus
, sort_by_date
);
948 static void sort_size(gpointer data
, guint action
, GtkWidget
*widget
)
950 g_return_if_fail(window_with_focus
!= NULL
);
952 display_set_sort_fn(window_with_focus
, sort_by_size
);
955 static void hidden(gpointer data
, guint action
, GtkWidget
*widget
)
960 g_return_if_fail(window_with_focus
!= NULL
);
962 display_set_hidden(window_with_focus
, !window_with_focus
->show_hidden
);
965 static void show_thumbs(gpointer data
, guint action
, GtkWidget
*widget
)
970 g_return_if_fail(window_with_focus
!= NULL
);
972 display_set_thumbs(window_with_focus
, !window_with_focus
->show_thumbs
);
975 static void refresh(gpointer data
, guint action
, GtkWidget
*widget
)
977 g_return_if_fail(window_with_focus
!= NULL
);
980 filer_update_dir(window_with_focus
, TRUE
);
983 static void delete(FilerWindow
*filer_window
)
986 paths
= filer_selected_items(filer_window
);
987 action_delete(paths
);
988 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
992 static void usage(FilerWindow
*filer_window
)
995 paths
= filer_selected_items(filer_window
);
997 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
1001 static void chmod_items(FilerWindow
*filer_window
)
1004 paths
= filer_selected_items(filer_window
);
1005 action_chmod(paths
);
1006 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
1010 static void find(FilerWindow
*filer_window
)
1013 paths
= filer_selected_items(filer_window
);
1015 g_list_foreach(paths
, (GFunc
) g_free
, NULL
);
1019 /* This pops up our savebox widget, cancelling any currently open one,
1020 * and allows the user to pick a new path for it.
1021 * Once the new path has been picked, the callback will be called with
1022 * both the current and new paths.
1023 * NOTE: This function unrefs 'image'!
1025 static void savebox_show(guchar
*title
, guchar
*path
, MaskedPixmap
*image
,
1026 gboolean (*callback
)(guchar
*current
, guchar
*new))
1028 g_return_if_fail(image
!= NULL
);
1030 if (GTK_WIDGET_VISIBLE(savebox
))
1031 gtk_widget_hide(savebox
);
1033 if (callback
== link_cb
)
1034 gtk_widget_show(check_relative
);
1036 gtk_widget_hide(check_relative
);
1039 g_free(current_path
);
1040 current_path
= g_strdup(path
);
1041 current_savebox_callback
= callback
;
1043 gtk_window_set_title(GTK_WINDOW(savebox
), title
);
1044 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox
), current_path
);
1045 gtk_savebox_set_icon(GTK_SAVEBOX(savebox
), image
->pixmap
, image
->mask
);
1046 pixmap_unref(image
);
1048 gtk_widget_show(savebox
);
1051 static gint
save_to_file(GtkSavebox
*savebox
, guchar
*pathname
)
1053 g_return_val_if_fail(current_savebox_callback
!= NULL
,
1054 GTK_XDS_SAVE_ERROR
);
1056 return current_savebox_callback(current_path
, pathname
)
1057 ? GTK_XDS_SAVED
: GTK_XDS_SAVE_ERROR
;
1060 static gboolean
copy_cb(guchar
*current
, guchar
*new)
1062 return action_with_leaf(action_copy
, current
, new);
1065 static gboolean
action_with_leaf(ActionFn action
, guchar
*current
, guchar
*new)
1067 char *new_dir
, *leaf
;
1072 report_error(_("New pathname is not absolute"));
1076 if (new[strlen(new) - 1] == '/')
1078 new_dir
= g_strdup(new);
1085 slash
= strrchr(new, '/');
1086 new_dir
= g_strndup(new, slash
- new);
1090 local_paths
= g_list_append(NULL
, current
);
1091 action(local_paths
, new_dir
, leaf
, -1);
1092 g_list_free(local_paths
);
1099 /* Open a savebox to act on the selected file.
1100 * Call 'callback' later to perform the operation.
1102 static void src_dest_action_item(guchar
*path
, MaskedPixmap
*image
,
1104 gboolean (*callback
)(guchar
*, guchar
*))
1107 savebox_show(title
, path
, image
, callback
);
1110 static gboolean
rename_cb(guchar
*current
, guchar
*new)
1112 return action_with_leaf(action_move
, current
, new);
1115 static gboolean
link_cb(guchar
*initial
, guchar
*path
)
1119 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_relative
)))
1123 rpath
= get_relative_path(path
, initial
);
1124 err
= symlink(rpath
, path
);
1129 err
= symlink(initial
, path
);
1133 report_error("symlink: %s", g_strerror(errno
));
1137 dir_check_this(path
);
1142 static void run_action(DirItem
*item
)
1144 if (can_set_run_action(item
))
1145 type_set_handler_dialog(item
->mime_type
);
1148 _("You can only set the run action for a "
1152 void open_home(gpointer data
, guint action
, GtkWidget
*widget
)
1154 filer_opendir(home_dir
, NULL
);
1158 static void real_vfs_open(FilerWindow
*filer_window
, DirItem
*item
, char *fs
)
1162 path
= g_strconcat(filer_window
->path
,
1167 filer_change_to(filer_window
, path
, NULL
);
1171 static void open_vfs_avfs(FilerWindow
*filer_window
, DirItem
*item
)
1175 path
= g_strconcat(filer_window
->path
,
1176 "/", item
->leafname
, "#", NULL
);
1178 filer_change_to(filer_window
, path
, NULL
);
1183 static void select_all(gpointer data
, guint action
, GtkWidget
*widget
)
1185 g_return_if_fail(window_with_focus
!= NULL
);
1187 window_with_focus
->temp_item_selected
= FALSE
;
1188 collection_select_all(window_with_focus
->collection
);
1191 static void clear_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1193 g_return_if_fail(window_with_focus
!= NULL
);
1195 window_with_focus
->temp_item_selected
= FALSE
;
1196 collection_clear_selection(window_with_focus
->collection
);
1199 static void invert_selection(gpointer data
, guint action
, GtkWidget
*widget
)
1201 g_return_if_fail(window_with_focus
!= NULL
);
1203 window_with_focus
->temp_item_selected
= FALSE
;
1204 collection_invert_selection(window_with_focus
->collection
);
1207 void menu_show_options(gpointer data
, guint action
, GtkWidget
*widget
)
1212 static gboolean
new_directory_cb(guchar
*initial
, guchar
*path
)
1214 if (mkdir(path
, S_IRWXU
| S_IRWXG
| S_IRWXO
))
1216 report_error("mkdir: %s", g_strerror(errno
));
1220 dir_check_this(path
);
1222 if (filer_exists(window_with_focus
))
1225 leaf
= strrchr(path
, '/');
1227 display_set_autoselect(window_with_focus
, leaf
+ 1);
1233 static void new_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1235 g_return_if_fail(window_with_focus
!= NULL
);
1237 savebox_show(_("New Directory"),
1238 make_path(window_with_focus
->path
, _("NewDir"))->str
,
1239 type_to_icon(special_directory
),
1243 static gboolean
new_file_cb(guchar
*initial
, guchar
*path
)
1247 fd
= open(path
, O_CREAT
| O_EXCL
, 0666);
1251 report_error(_("Error creating '%s': %s"),
1252 path
, g_strerror(errno
));
1257 report_error(_("Error creating '%s': %s"),
1258 path
, g_strerror(errno
));
1260 dir_check_this(path
);
1262 if (filer_exists(window_with_focus
))
1265 leaf
= strrchr(path
, '/');
1267 display_set_autoselect(window_with_focus
, leaf
+ 1);
1273 static void new_file(gpointer data
, guint action
, GtkWidget
*widget
)
1275 g_return_if_fail(window_with_focus
!= NULL
);
1277 savebox_show(_("New File"),
1278 make_path(window_with_focus
->path
, _("NewFile"))->str
,
1279 type_to_icon(text_plain
),
1283 static gboolean
new_file_type_cb(guchar
*initial
, guchar
*path
)
1285 gchar
*templ
, *templ_dname
, *oleaf
, *dest
, *leaf
;
1288 /* We can work out the template path from the initial name */
1289 oleaf
= g_basename(initial
);
1290 templ_dname
= choices_find_path_load("Templates", "");
1294 _("Error creating file: could not find the template for %s"),
1299 templ
= g_strconcat(templ_dname
, "/", oleaf
, NULL
);
1300 g_free(templ_dname
);
1302 dest
= g_dirname(path
);
1303 leaf
= g_basename(path
);
1304 paths
= g_list_append(NULL
, templ
);
1306 action_copy(paths
, dest
, leaf
, -1);
1312 if (filer_exists(window_with_focus
))
1313 display_set_autoselect(window_with_focus
, leaf
);
1318 static void do_send_to(gchar
*templ
)
1320 g_return_if_fail(send_to_paths
!= NULL
);
1322 run_with_files(templ
, send_to_paths
);
1325 static void new_file_type(gchar
*templ
)
1330 g_return_if_fail(window_with_focus
!= NULL
);
1332 leaf
= g_basename(templ
);
1333 type
= type_get_type(templ
);
1335 savebox_show(_("New File"),
1336 make_path(window_with_focus
->path
, leaf
)->str
,
1341 static void customise_send_to(gpointer data
)
1348 dirs
= g_string_new(NULL
);
1350 path
= choices_list_dirs("");
1351 for (i
= 0; i
< path
->len
; i
++)
1353 guchar
*old
= (guchar
*) path
->pdata
[i
];
1355 g_string_append(dirs
, old
);
1356 g_string_append(dirs
, "SendTo\n");
1358 choices_free_list(path
);
1360 save
= choices_find_path_save("", "SendTo", TRUE
);
1365 _("The `Send To' menu provides a quick way to send some files "
1366 "to an application. The applications listed are those in "
1367 "the following directories:\n\n%s\n%s\n"
1368 "The `Send To' menu may be opened by Shift+Menu clicking "
1371 save
? _("I'll show you your SendTo directory now; you should "
1372 "symlink (Ctrl+Shift drag) any applications you want "
1374 : _("Your CHOICESPATH variable setting prevents "
1375 "customisations - sorry."));
1377 g_string_free(dirs
, TRUE
);
1380 filer_opendir(save
, NULL
);
1383 /* Scan the SendTo dir and create and show the Send To menu.
1384 * The 'paths' list and every path in it is claimed, and will be
1385 * freed later -- don't free it yourself!
1387 static void show_send_to_menu(GList
*paths
, GdkEvent
*event
)
1389 GtkWidget
*menu
, *item
;
1393 menu
= gtk_menu_new();
1395 path
= choices_list_dirs("SendTo");
1397 for (i
= 0; i
< path
->len
; i
++)
1399 GList
*widgets
= NULL
;
1400 guchar
*dir
= (guchar
*) path
->pdata
[i
];
1402 widgets
= menu_from_dir(menu
, dir
, get_menu_icon_style(),
1403 (CallbackFn
) do_send_to
,
1407 gtk_menu_shell_append(GTK_MENU_SHELL(menu
),
1408 gtk_menu_item_new());
1410 g_list_free(widgets
); /* TODO: Get rid of this */
1413 choices_free_list(path
);
1415 item
= gtk_menu_item_new_with_label(_("Customise"));
1416 gtk_signal_connect_object(GTK_OBJECT(item
), "activate",
1417 GTK_SIGNAL_FUNC(customise_send_to
), NULL
);
1418 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1422 g_list_foreach(send_to_paths
, (GFunc
) g_free
, NULL
);
1423 g_list_free(send_to_paths
);
1425 send_to_paths
= paths
;
1427 gtk_signal_connect(GTK_OBJECT(menu
), "unmap_event",
1428 GTK_SIGNAL_FUNC(menu_closed
), NULL
);
1431 show_popup_menu(menu
, event
, 0);
1434 static void send_to(FilerWindow
*filer_window
)
1439 paths
= filer_selected_items(filer_window
);
1440 event
= gtk_get_current_event();
1443 show_send_to_menu(paths
, event
);
1445 gdk_event_free(event
);
1448 static void xterm_here(gpointer data
, guint action
, GtkWidget
*widget
)
1450 char *argv
[] = {"sh", "-c", NULL
, NULL
};
1452 argv
[2] = option_get_static_string("menu_xterm");
1454 g_return_if_fail(window_with_focus
!= NULL
);
1456 rox_spawn(window_with_focus
->path
, argv
);
1459 static void home_directory(gpointer data
, guint action
, GtkWidget
*widget
)
1461 g_return_if_fail(window_with_focus
!= NULL
);
1463 filer_change_to(window_with_focus
, home_dir
, NULL
);
1466 static void open_parent(gpointer data
, guint action
, GtkWidget
*widget
)
1468 g_return_if_fail(window_with_focus
!= NULL
);
1470 filer_open_parent(window_with_focus
);
1473 static void open_parent_same(gpointer data
, guint action
, GtkWidget
*widget
)
1475 g_return_if_fail(window_with_focus
!= NULL
);
1477 change_to_parent(window_with_focus
);
1480 static void resize(gpointer data
, guint action
, GtkWidget
*widget
)
1482 g_return_if_fail(window_with_focus
!= NULL
);
1484 filer_window_autosize(window_with_focus
, TRUE
);
1487 static void new_window(gpointer data
, guint action
, GtkWidget
*widget
)
1489 g_return_if_fail(window_with_focus
!= NULL
);
1491 if (o_unique_filer_windows
)
1493 report_error(_("You can't open a second view onto "
1494 "this directory because the `Unique Windows' option "
1495 "is turned on in the Options window."));
1498 filer_opendir(window_with_focus
->path
, window_with_focus
);
1502 static void su_to_user(GtkWidget
*dialog
)
1505 "xterm", "-e", "su_rox", "USER", "APP_RUN", "DIR", NULL
};
1509 g_return_if_fail(dialog
!= NULL
);
1511 path
= gtk_object_get_data(GTK_OBJECT(dialog
), "dir_path");
1512 user
= gtk_object_get_data(GTK_OBJECT(dialog
), "user_name");
1514 g_return_if_fail(user
!= NULL
&& path
!= NULL
);
1516 argv
[2] = g_strconcat(app_dir
, "/su_rox", NULL
);
1517 argv
[3] = gtk_entry_get_text(user
);
1518 argv
[4] = g_strconcat(app_dir
, "/AppRun", NULL
);
1522 report_error(_("fork: %s"), g_strerror(errno
));
1527 gtk_widget_destroy(dialog
);
1530 static void new_user(gpointer data
, guint action
, GtkWidget
*widget
)
1532 GtkWidget
*dialog
, *vbox
, *hbox
, *entry
, *button
;
1534 g_return_if_fail(window_with_focus
!= NULL
);
1536 dialog
= gtk_window_new(GTK_WINDOW_DIALOG
);
1537 gtk_window_set_title(GTK_WINDOW(dialog
), _("New window, as user..."));
1538 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 4);
1539 gtk_object_set_data_full(GTK_OBJECT(dialog
), "dir_path",
1540 g_strdup(window_with_focus
->path
), g_free
);
1542 vbox
= gtk_vbox_new(FALSE
, 4);
1543 gtk_container_add(GTK_CONTAINER(dialog
), vbox
);
1544 gtk_box_pack_start(GTK_BOX(vbox
),
1545 gtk_label_new(_("Browse as which user?")),
1548 hbox
= gtk_hbox_new(FALSE
, 4);
1549 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1551 gtk_box_pack_start(GTK_BOX(hbox
),
1552 gtk_label_new(_("User:")), FALSE
, TRUE
, 2);
1554 entry
= gtk_entry_new();
1555 gtk_entry_set_text(GTK_ENTRY(entry
), "root");
1556 gtk_editable_select_region(GTK_EDITABLE(entry
), 0, -1);
1557 gtk_box_pack_start(GTK_BOX(hbox
), entry
, TRUE
, TRUE
, 2);
1558 gtk_widget_grab_focus(entry
);
1559 gtk_object_set_data(GTK_OBJECT(dialog
), "user_name", entry
);
1560 gtk_signal_connect_object(GTK_OBJECT(entry
), "activate",
1561 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1563 hbox
= gtk_hbox_new(TRUE
, 0);
1564 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 2);
1566 button
= gtk_button_new_with_label(_("OK"));
1567 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1568 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1569 gtk_window_set_default(GTK_WINDOW(dialog
), button
);
1570 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1571 GTK_SIGNAL_FUNC(su_to_user
), GTK_OBJECT(dialog
));
1573 button
= gtk_button_new_with_label(_("Cancel"));
1574 GTK_WIDGET_SET_FLAGS(button
, GTK_CAN_DEFAULT
);
1575 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
1576 gtk_signal_connect_object(GTK_OBJECT(button
), "clicked",
1577 GTK_SIGNAL_FUNC(gtk_widget_destroy
),
1578 GTK_OBJECT(dialog
));
1580 gtk_widget_show_all(dialog
);
1584 static void close_window(gpointer data
, guint action
, GtkWidget
*widget
)
1586 g_return_if_fail(window_with_focus
!= NULL
);
1588 gtk_widget_destroy(window_with_focus
->window
);
1591 static void mini_buffer(gpointer data
, guint action
, GtkWidget
*widget
)
1593 MiniType type
= (MiniType
) action
;
1595 g_return_if_fail(window_with_focus
!= NULL
);
1597 /* Item needs to remain selected... */
1598 if (type
== MINI_SHELL
)
1599 window_with_focus
->temp_item_selected
= FALSE
;
1601 minibuffer_show(window_with_focus
, type
);
1604 void menu_rox_help(gpointer data
, guint action
, GtkWidget
*widget
)
1606 filer_opendir(make_path(app_dir
, "Help")->str
, NULL
);
1609 /* Set n items from position 'from' in 'menu' to the 'shaded' state */
1610 void menu_set_items_shaded(GtkWidget
*menu
, gboolean shaded
, int from
, int n
)
1612 GList
*items
, *item
;
1614 items
= gtk_container_children(GTK_CONTAINER(menu
));
1616 item
= g_list_nth(items
, from
);
1619 gtk_widget_set_sensitive(GTK_BIN(item
->data
)->child
, !shaded
);
1626 /* This is called for every modified menu entry. We just use it to
1627 * find out if the menu has changed at all.
1629 static void set_mod(gboolean
*mod
, guchar
*str
)
1631 if (str
&& str
[0] == '(')
1636 static void save_menus(void)
1641 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, TRUE
);
1644 gtk_accel_map_save(menurc
);
1648 menurc
= choices_find_path_save(MENUS_NAME
, PROJECT
, FALSE
);
1651 gboolean mod
= FALSE
;
1655 /* Find out if anything changed... */
1656 gtk_item_factory_dump_items(NULL
, TRUE
,
1657 (GtkPrintFunc
) set_mod
, &mod
);
1659 /* Dump out if so... */
1662 menurc
= choices_find_path_save(MENUS_NAME
,
1664 g_return_if_fail(menurc
!= NULL
);
1665 mark_menus_modified(TRUE
);
1666 gtk_item_factory_dump_rc(menurc
, NULL
, TRUE
);
1667 mark_menus_modified(FALSE
);
1675 static void keys_changed(gpointer data
)
1680 static void mark_modified(gpointer hash_key
,
1684 GtkItemFactoryItem
*item
= (GtkItemFactoryItem
*) value
;
1686 item
->modified
= (gboolean
) GPOINTER_TO_INT(user_data
);
1689 /* Set or clear the 'modified' flag in all menu items. Messy... */
1690 static void mark_menus_modified(gboolean mod
)
1692 GtkItemFactoryClass
*class;
1694 class = gtk_type_class(GTK_TYPE_ITEM_FACTORY
);
1696 g_hash_table_foreach(class->item_ht
, mark_modified
,
1697 GINT_TO_POINTER(mod
));
1701 static void select_nth_item(GtkMenuShell
*shell
, int n
)
1704 GtkWidget
*item
= NULL
;
1706 items
= gtk_container_children(GTK_CONTAINER(shell
));
1707 nth
= g_list_nth(items
, n
);
1709 g_return_if_fail(nth
!= NULL
);
1711 item
= (GtkWidget
*) (nth
->data
);
1714 gtk_menu_shell_select_item(shell
, item
);
1717 static void file_op(gpointer data
, FileOp action
, GtkWidget
*widget
)
1719 Collection
*collection
;
1723 g_return_if_fail(window_with_focus
!= NULL
);
1725 collection
= window_with_focus
->collection
;
1727 if (collection
->number_selected
< 1)
1733 case FILE_COPY_ITEM
:
1734 prompt
= _("Copy ... ?");
1736 case FILE_RENAME_ITEM
:
1737 prompt
= _("Rename ... ?");
1739 case FILE_LINK_ITEM
:
1740 prompt
= _("Symlink ... ?");
1742 case FILE_OPEN_FILE
:
1743 prompt
= _("Shift Open ... ?");
1746 prompt
= _("Help about ... ?");
1748 case FILE_SHOW_FILE_INFO
:
1749 prompt
= _("Examine ... ?");
1751 case FILE_RUN_ACTION
:
1752 prompt
= _("Set run action for ... ?");
1755 prompt
= _("Set icon for ... ?");
1758 prompt
= _("Send ... to ... ?");
1761 prompt
= _("DELETE ... ?");
1764 prompt
= _("Count the size of ... ?");
1766 case FILE_CHMOD_ITEMS
:
1767 prompt
= _("Set permissions on ... ?");
1770 prompt
= _("Search inside ... ?");
1773 case FILE_OPEN_VFS_RPM
:
1774 case FILE_OPEN_VFS_UTAR
:
1775 case FILE_OPEN_VFS_UZIP
:
1776 case FILE_OPEN_VFS_DEB
:
1778 case FILE_OPEN_VFS_AVFS
:
1780 prompt
= _("Look inside ... ?");
1783 g_warning("Unknown action!");
1786 filer_target_mode(window_with_focus
, target_callback
,
1787 GINT_TO_POINTER(action
), prompt
);
1794 send_to(window_with_focus
);
1797 delete(window_with_focus
);
1800 usage(window_with_focus
);
1802 case FILE_CHMOD_ITEMS
:
1803 chmod_items(window_with_focus
);
1806 find(window_with_focus
);
1812 /* All the following actions require exactly one file selected */
1814 if (collection
->number_selected
> 1)
1816 report_error(_("You cannot do this to more than "
1817 "one item at a time"));
1821 item
= selected_item(collection
);
1822 g_return_if_fail(item
!= NULL
);
1824 item
= dir_update_item(window_with_focus
->directory
,
1829 report_error(_("Item no longer exists!"));
1833 path
= make_path(window_with_focus
->path
, item
->leafname
)->str
;
1837 case FILE_COPY_ITEM
:
1838 src_dest_action_item(path
, item
->image
,
1839 _("Copy"), copy_cb
);
1841 case FILE_RENAME_ITEM
:
1842 src_dest_action_item(path
, item
->image
,
1843 _("Rename"), rename_cb
);
1845 case FILE_LINK_ITEM
:
1846 src_dest_action_item(path
, item
->image
,
1847 _("Symlink"), link_cb
);
1849 case FILE_OPEN_FILE
:
1850 filer_openitem(window_with_focus
,
1851 selected_item_number(collection
),
1852 OPEN_SAME_WINDOW
| OPEN_SHIFT
);
1855 show_item_help(path
, item
);
1857 case FILE_SHOW_FILE_INFO
:
1860 case FILE_RUN_ACTION
:
1864 icon_set_handler_dialog(item
, path
);
1867 case FILE_OPEN_VFS_RPM
:
1868 real_vfs_open(window_with_focus
, item
, "rpm");
1870 case FILE_OPEN_VFS_UTAR
:
1871 real_vfs_open(window_with_focus
, item
, "utar");
1873 case FILE_OPEN_VFS_UZIP
:
1874 real_vfs_open(window_with_focus
, item
, "uzip");
1876 case FILE_OPEN_VFS_DEB
:
1877 real_vfs_open(window_with_focus
, item
, "deb");
1880 case FILE_OPEN_VFS_AVFS
:
1881 open_vfs_avfs(window_with_focus
, item
);
1884 g_warning("Unknown action!");