Bugfix: unselect item when menu is closed
[rox-filer.git] / ROX-Filer / src / menu.c
Commit [+]AuthorDateLineData
477a62a2 Thomas Leonard1999-11-24 11:05:20 +00001/*
ab588714 Thomas Leonard1999-06-17 15:07:06 +00002 * ROX-Filer, filer for the ROX desktop project
ca691736 Thomas Leonard2006-03-25 11:55:13 +00003 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
e5df6718
TL
Thomas Leonard1999-11-14 13:09:17 +00004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
ab588714
TL
Thomas Leonard1999-06-17 15:07:06 +000018 */
19
d2c0a26d Thomas Leonard2002-04-03 19:27:07 +000020/* menu.c - code for handling the popup menus */
ab588714 Thomas Leonard1999-06-17 15:07:06 +000021
9b47a3cd
TL
Thomas Leonard2007-09-30 17:37:20 +010022#ifndef GTK_STOCK_INFO
23# define GTK_STOCK_INFO "gtk-info"
24#endif
25
46f44e58 Thomas Leonard2001-08-07 12:36:41 +000026#include "config.h"
453ec2d2 Thomas Leonard2002-03-12 11:03:39 +000027
f94990cd Thomas Leonard1999-08-04 12:53:48 +000028#include <stdio.h>
cfaed676 Thomas Leonard1999-08-11 15:39:05 +000029#include <stdlib.h>
d92f28f2 Thomas Leonard1999-07-21 09:52:34 +000030#include <sys/wait.h>
08ff7a0c Thomas Leonard2000-03-18 13:21:53 +000031#include <sys/param.h>
f94990cd Thomas Leonard1999-08-04 12:53:48 +000032#include <fcntl.h>
f94990cd Thomas Leonard1999-08-04 12:53:48 +000033#include <errno.h>
cfaed676 Thomas Leonard1999-08-11 15:39:05 +000034#include <string.h>
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +000035#include <dirent.h>
d92f28f2 Thomas Leonard1999-07-21 09:52:34 +000036
ab588714
TL
Thomas Leonard1999-06-17 15:07:06 +000037#include <gtk/gtk.h>
38
2658eef1
TL
Thomas Leonard2000-07-28 21:11:07 +000039#include "global.h"
40
b2b6a9ee Thomas Leonard2000-07-17 17:16:43 +000041#include "menu.h"
214bd481 Thomas Leonard2000-01-07 14:35:58 +000042#include "run.h"
496c7467 Thomas Leonard1999-08-05 20:29:17 +000043#include "action.h"
ab588714 Thomas Leonard1999-06-17 15:07:06 +000044#include "filer.h"
2658eef1 Thomas Leonard2000-07-28 21:11:07 +000045#include "pixmaps.h"
85c09878 Thomas Leonard1999-07-30 13:07:21 +000046#include "type.h"
ab588714 Thomas Leonard1999-06-17 15:07:06 +000047#include "support.h"
0b01e447 Thomas Leonard1999-07-20 13:06:47 +000048#include "gui_support.h"
a1ff9747
TL
Thomas Leonard1999-07-23 15:17:02 +000049#include "options.h"
50#include "choices.h"
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +000051#include "gtksavebox.h"
3979e2f3 Thomas Leonard1999-11-03 09:25:29 +000052#include "mount.h"
4b6288b4 Thomas Leonard2000-01-22 13:09:30 +000053#include "minibuffer.h"
ba72a534 Thomas Leonard2000-04-16 21:02:01 +000054#include "i18n.h"
99ec9896 Thomas Leonard2000-07-21 17:28:47 +000055#include "main.h"
2658eef1
TL
Thomas Leonard2000-07-28 21:11:07 +000056#include "pinboard.h"
57#include "dir.h"
e69a9b4e Thomas Leonard2001-12-10 22:42:02 +000058#include "diritem.h"
ec72fb2f Thomas Leonard2001-01-27 15:23:45 +000059#include "appmenu.h"
76e0c317 Thomas Leonard2001-02-07 17:59:14 +000060#include "usericons.h"
f9c962df Thomas Leonard2001-04-27 15:49:34 +000061#include "infobox.h"
5777df6b Thomas Leonard2002-06-11 14:47:07 +000062#include "view_iface.h"
e69a9b4e Thomas Leonard2001-12-10 22:42:02 +000063#include "display.h"
ad60a44a Thomas Leonard2002-12-01 19:19:30 +000064#include "bookmarks.h"
2195aa82 Thomas Leonard2004-04-13 09:04:07 +000065#include "panel.h"
a7cc76f5 Thomas Leonard2005-01-09 13:08:37 +000066#include "bulk_rename.h"
881abaaf Stephen Watson2004-11-25 20:06:37 +000067#include "xtypes.h"
d72a0fb1 Thomas Leonard2007-09-16 11:47:34 +010068#include "log.h"
ab588714 Thomas Leonard1999-06-17 15:07:06 +000069
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +000070typedef enum {
71 FILE_COPY_ITEM,
72 FILE_RENAME_ITEM,
73 FILE_LINK_ITEM,
74 FILE_OPEN_FILE,
05cbc244 Thomas Leonard2003-11-17 10:32:22 +000075 FILE_PROPERTIES,
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +000076 FILE_RUN_ACTION,
77 FILE_SET_ICON,
78 FILE_SEND_TO,
79 FILE_DELETE,
80 FILE_USAGE,
81 FILE_CHMOD_ITEMS,
82 FILE_FIND,
68b718ac Stephen Watson2003-12-02 19:21:24 +000083 FILE_SET_TYPE,
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +000084} FileOp;
85
2d91f96f
TL
Thomas Leonard2002-03-08 16:08:31 +000086typedef void (*ActionFn)(GList *paths,
87 const char *dest_dir, const char *leaf, int quiet);
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +000088typedef void MenuCallback(GtkWidget *widget, gpointer data);
92d41b2b Thomas Leonard2000-07-30 17:27:45 +000089
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +000090typedef gboolean (*SaveCb)(GObject *savebox,
91 const gchar *current, const gchar *new);
92
d2c0a26d Thomas Leonard2002-04-03 19:27:07 +000093GtkAccelGroup *filer_keys = NULL;
59a554b7 Thomas Leonard2002-12-26 18:02:26 +000094static gboolean filer_keys_need_init = TRUE;
ab588714 Thomas Leonard1999-06-17 15:07:06 +000095
d2c0a26d Thomas Leonard2002-04-03 19:27:07 +000096static GtkWidget *popup_menu = NULL; /* Currently open menu */
51a60b03 Thomas Leonard2000-01-09 18:51:38 +000097
a799932f Thomas Leonard2000-02-13 12:51:57 +000098static gint updating_menu = 0; /* Non-zero => ignore activations */
dce3d041 Thomas Leonard2001-08-22 11:58:38 +000099static GList *send_to_paths = NULL;
a799932f Thomas Leonard2000-02-13 12:51:57 +0000100
e6d077a6 Thomas Leonard2004-03-16 10:48:52 +0000101static Option o_menu_iconsize, o_menu_xterm, o_menu_quick;
89a24bf0 Thomas Leonard2002-02-20 17:48:27 +0000102
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000103/* Static prototypes */
0e6e5c9a Thomas Leonard2000-01-11 13:34:32 +0000104
b2b6a9ee Thomas Leonard2000-07-17 17:16:43 +0000105static void save_menus(void);
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000106static void menu_closed(GtkWidget *widget);
30c262f5 Thomas Leonard2002-06-01 14:39:52 +0000107static void shade_file_menu_items(gboolean shaded);
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +0000108static void savebox_show(const gchar *action, const gchar *path,
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +0000109 MaskedPixmap *image, SaveCb callback,
110 GdkDragAction dnd_action);
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +0000111static gint save_to_file(GObject *savebox,
112 const gchar *pathname, gpointer data);
2d91f96f
TL
Thomas Leonard2002-03-08 16:08:31 +0000113static gboolean action_with_leaf(ActionFn action,
114 const gchar *current, const gchar *new);
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +0000115static gboolean link_cb(GObject *savebox,
116 const gchar *initial, const gchar *path);
b5f57111 Thomas Leonard2001-04-29 14:09:39 +0000117static void select_nth_item(GtkMenuShell *shell, int n);
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000118static void new_file_type(gchar *templ);
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000119static void do_send_to(gchar *templ);
120static void show_send_to_menu(GList *paths, GdkEvent *event);
f7646571 Thomas Leonard2002-03-08 12:37:38 +0000121static GList *set_keys_button(Option *option, xmlNode *node, guchar *label);
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000122
9ed4a936 Thomas Leonard2000-06-16 18:41:07 +0000123/* Note that for most of these callbacks none of the arguments are used. */
45d7baf6 Thomas Leonard1999-12-19 15:50:02 +0000124
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000125static void view_type(gpointer data, guint action, GtkWidget *widget);
126
63a9b2b0 Thomas Leonard2001-11-14 12:00:19 +0000127/* (action used in these three - DetailsType) */
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000128static void change_size(gpointer data, guint action, GtkWidget *widget);
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000129static void change_size_auto(gpointer data, guint action, GtkWidget *widget);
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000130static void set_with(gpointer data, guint action, GtkWidget *widget);
deebe52f Thomas Leonard2000-06-15 12:04:45 +0000131
7f0bfceb
TL
Thomas Leonard2002-12-27 12:19:54 +0000132static void set_sort(gpointer data, guint action, GtkWidget *widget);
133static void reverse_sort(gpointer data, guint action, GtkWidget *widget);
2385cf7b Thomas Leonard1999-12-26 10:42:48 +0000134
0bccc573 Stephen Watson2006-08-13 16:33:52 +0000135static void filter_directories(gpointer data, guint action, GtkWidget *widget);
205db6de Thomas Leonard1999-08-05 16:16:47 +0000136static void hidden(gpointer data, guint action, GtkWidget *widget);
f2c63f66 Thomas Leonard2001-12-20 14:08:57 +0000137static void show_thumbs(gpointer data, guint action, GtkWidget *widget);
6fd9c5fa Thomas Leonard1999-06-23 09:04:06 +0000138static void refresh(gpointer data, guint action, GtkWidget *widget);
8bb51514 Stephen Watson2004-04-04 10:20:43 +0000139static void save_settings(gpointer data, guint action, GtkWidget *widget);
e2dd1c7c Thomas Leonard1999-08-03 11:28:52 +0000140
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +0000141static void file_op(gpointer data, FileOp action, GtkWidget *widget);
24932e8f Thomas Leonard2000-03-17 13:22:33 +0000142
85c09878
TL
Thomas Leonard1999-07-30 13:07:21 +0000143static void select_all(gpointer data, guint action, GtkWidget *widget);
144static void clear_selection(gpointer data, guint action, GtkWidget *widget);
3082fab2 Thomas Leonard2001-12-02 16:34:08 +0000145static void invert_selection(gpointer data, guint action, GtkWidget *widget);
a841079f Thomas Leonard1999-07-28 15:11:09 +0000146static void new_directory(gpointer data, guint action, GtkWidget *widget);
f31d6615 Thomas Leonard2001-02-20 13:32:14 +0000147static void new_file(gpointer data, guint action, GtkWidget *widget);
62490356 Thomas Leonard2005-03-12 21:08:59 +0000148static void customise_new(gpointer data);
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +0000149static void xterm_here(gpointer data, guint action, GtkWidget *widget);
e5df6718
TL
Thomas Leonard1999-11-14 13:09:17 +0000150
151static void open_parent_same(gpointer data, guint action, GtkWidget *widget);
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000152static void open_parent(gpointer data, guint action, GtkWidget *widget);
bbe66c4b Thomas Leonard2001-03-14 15:45:30 +0000153static void home_directory(gpointer data, guint action, GtkWidget *widget);
ad60a44a Thomas Leonard2002-12-01 19:19:30 +0000154static void show_bookmarks(gpointer data, guint action, GtkWidget *widget);
572c7202 Thomas Leonard2007-08-19 12:39:02 +0100155static void show_log(gpointer data, guint action, GtkWidget *widget);
e5df6718 Thomas Leonard1999-11-14 13:09:17 +0000156static void new_window(gpointer data, guint action, GtkWidget *widget);
35769530 Thomas Leonard2000-09-07 14:58:49 +0000157/* static void new_user(gpointer data, guint action, GtkWidget *widget); */
e5df6718 Thomas Leonard1999-11-14 13:09:17 +0000158static void close_window(gpointer data, guint action, GtkWidget *widget);
38be87fc Thomas Leonard2002-05-17 15:05:53 +0000159static void follow_symlinks(gpointer data, guint action, GtkWidget *widget);
63a9b2b0
TL
Thomas Leonard2001-11-14 12:00:19 +0000160
161/* (action used in this - MiniType) */
162static void mini_buffer(gpointer data, guint action, GtkWidget *widget);
b69128bf Thomas Leonard2000-12-28 19:20:14 +0000163static void resize(gpointer data, guint action, GtkWidget *widget);
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +0000164
5b509326 Thomas Leonard2001-11-24 17:42:42 +0000165#define MENUS_NAME "menus2"
96ad1936 Thomas Leonard1999-08-16 13:25:07 +0000166
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000167static GtkWidget *filer_menu; /* The popup filer menu */
88910f54
TL
Thomas Leonard1999-08-02 11:40:07 +0000168static GtkWidget *filer_file_item; /* The File '' label */
169static GtkWidget *filer_file_menu; /* The File '' menu */
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000170static GtkWidget *file_shift_item; /* Shift Open label */
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000171static GtkWidget *filer_auto_size_menu; /* The Automatic item */
4762eaa1 Thomas Leonard1999-12-07 12:37:27 +0000172static GtkWidget *filer_hidden_menu; /* The Show Hidden item */
b4d8b5b5 Stephen Watson2006-08-14 20:50:27 +0000173static GtkWidget *filer_filter_dirs_menu;/* The Filter Dirs item */
7f0bfceb Thomas Leonard2002-12-27 12:19:54 +0000174static GtkWidget *filer_reverse_menu; /* The Reversed item */
f2c63f66 Thomas Leonard2001-12-20 14:08:57 +0000175static GtkWidget *filer_thumb_menu; /* The Show Thumbs item */
8de9a519 Thomas Leonard2000-03-12 19:13:13 +0000176static GtkWidget *filer_new_window; /* The New Window item */
c35de8cf Thomas Leonard2001-07-10 14:59:26 +0000177static GtkWidget *filer_new_menu; /* The New submenu */
38be87fc Thomas Leonard2002-05-17 15:05:53 +0000178static GtkWidget *filer_follow_sym; /* Follow symbolic links item */
881abaaf Stephen Watson2004-11-25 20:06:37 +0000179static GtkWidget *filer_set_type; /* Set type item */
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000180
b10b33db
TL
Thomas Leonard2000-04-17 12:13:35 +0000181#undef N_
182#define N_(x) x
183
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000184static GtkItemFactoryEntry filer_menu_def[] = {
35769530 Thomas Leonard2000-09-07 14:58:49 +0000185{N_("Display"), NULL, NULL, 0, "<Branch>"},
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000186{">" N_("Icons View"), NULL, view_type, VIEW_TYPE_COLLECTION, NULL},
187{">" N_("Icons, With..."), NULL, NULL, 0, "<Branch>"},
188{">>" N_("Sizes"), NULL, set_with, DETAILS_SIZE, NULL},
189{">>" N_("Permissions"), NULL, set_with, DETAILS_PERMISSIONS, NULL},
6d33da3c Thomas Leonard2003-01-13 12:38:10 +0000190{">>" N_("Types"), NULL, set_with, DETAILS_TYPE, NULL},
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000191{">>" N_("Times"), NULL, set_with, DETAILS_TIMES, NULL},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000192{">" N_("List View"), NULL, view_type, VIEW_TYPE_DETAILS, "<StockItem>", ROX_STOCK_SHOW_DETAILS},
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000193{">", NULL, NULL, 0, "<Separator>"},
0be8e45b
TL
Thomas Leonard2004-04-21 14:29:32 +0000194{">" N_("Bigger Icons"), "equal", change_size, 1, "<StockItem>", GTK_STOCK_ZOOM_IN},
195{">" N_("Smaller Icons"), "minus", change_size, -1, "<StockItem>", GTK_STOCK_ZOOM_OUT},
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000196{">" N_("Automatic"), NULL, change_size_auto, 0, "<ToggleItem>"},
35769530 Thomas Leonard2000-09-07 14:58:49 +0000197{">", NULL, NULL, 0, "<Separator>"},
7f0bfceb
TL
Thomas Leonard2002-12-27 12:19:54 +0000198{">" N_("Sort by Name"), NULL, set_sort, SORT_NAME, NULL},
199{">" N_("Sort by Type"), NULL, set_sort, SORT_TYPE, NULL},
200{">" N_("Sort by Date"), NULL, set_sort, SORT_DATE, NULL},
201{">" N_("Sort by Size"), NULL, set_sort, SORT_SIZE, NULL},
202{">" N_("Sort by Owner"), NULL, set_sort, SORT_OWNER, NULL},
203{">" N_("Sort by Group"), NULL, set_sort, SORT_GROUP, NULL},
204{">" N_("Reversed"), NULL, reverse_sort, 0, "<ToggleItem>"},
35769530 Thomas Leonard2000-09-07 14:58:49 +0000205{">", NULL, NULL, 0, "<Separator>"},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000206{">" N_("Show Hidden"), "<Ctrl>H", hidden, 0, "<ToggleItem>"},
6000d103 Thomas Leonard2004-04-30 16:36:41 +0000207{">" N_("Filter Files..."), NULL, mini_buffer, MINI_FILTER, NULL},
0bccc573 Stephen Watson2006-08-13 16:33:52 +0000208{">" N_("Filter Directories With Files"), NULL, filter_directories, 0, "<ToggleItem>"},
f2c63f66 Thomas Leonard2001-12-20 14:08:57 +0000209{">" N_("Show Thumbnails"), NULL, show_thumbs, 0, "<ToggleItem>"},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000210{">" N_("Refresh"), NULL, refresh, 0, "<StockItem>", GTK_STOCK_REFRESH},
50fb7592 Stephen Watson2006-06-15 19:20:10 +0000211{">" N_("Save Current Display Settings..."), NULL, save_settings, 0, NULL},
35769530 Thomas Leonard2000-09-07 14:58:49 +0000212{N_("File"), NULL, NULL, 0, "<Branch>"},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000213{">" N_("Copy..."), "<Ctrl>C", file_op, FILE_COPY_ITEM, "<StockItem>", GTK_STOCK_COPY},
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +0000214{">" N_("Rename..."), NULL, file_op, FILE_RENAME_ITEM, NULL},
215{">" N_("Link..."), NULL, file_op, FILE_LINK_ITEM, NULL},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000216{">" N_("Delete"), "<Ctrl>X", file_op, FILE_DELETE, "<StockItem>", GTK_STOCK_DELETE},
31875600 Thomas Leonard2002-07-19 15:57:49 +0000217{">", NULL, NULL, 0, "<Separator>"},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000218{">" N_("Shift Open"), NULL, file_op, FILE_OPEN_FILE},
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +0000219{">" N_("Send To..."), NULL, file_op, FILE_SEND_TO, NULL},
31875600 Thomas Leonard2002-07-19 15:57:49 +0000220{">", NULL, NULL, 0, "<Separator>"},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000221{">" N_("Set Run Action..."), "asterisk", file_op, FILE_RUN_ACTION, "<StockItem>", GTK_STOCK_EXECUTE},
31875600 Thomas Leonard2002-07-19 15:57:49 +0000222{">" N_("Set Icon..."), NULL, file_op, FILE_SET_ICON, NULL},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000223{">" N_("Properties"), "<Ctrl>P", file_op, FILE_PROPERTIES, "<StockItem>", GTK_STOCK_PROPERTIES},
31875600 Thomas Leonard2002-07-19 15:57:49 +0000224{">" N_("Count"), NULL, file_op, FILE_USAGE, NULL},
c1615d51 Thomas Leonard2004-01-21 20:03:16 +0000225{">" N_("Set Type..."), NULL, file_op, FILE_SET_TYPE, NULL},
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +0000226{">" N_("Permissions"), NULL, file_op, FILE_CHMOD_ITEMS, NULL},
31875600 Thomas Leonard2002-07-19 15:57:49 +0000227{">", NULL, NULL, 0, "<Separator>"},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000228{">" N_("Find"), "<Ctrl>F", file_op, FILE_FIND, "<StockItem>", GTK_STOCK_FIND},
c9191cce Thomas Leonard2001-11-29 14:39:11 +0000229{N_("Select"), NULL, NULL, 0, "<Branch>"},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000230{">" N_("Select All"), "<Ctrl>A", select_all, 0, NULL},
c9191cce Thomas Leonard2001-11-29 14:39:11 +0000231{">" N_("Clear Selection"), NULL, clear_selection, 0, NULL},
3082fab2 Thomas Leonard2001-12-02 16:34:08 +0000232{">" N_("Invert Selection"), NULL, invert_selection, 0, NULL},
37bd3f19 Thomas Leonard2004-03-07 15:45:20 +0000233{">" N_("Select by Name..."), "period", mini_buffer, MINI_SELECT_BY_NAME, NULL},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000234{">" N_("Select If..."), "<Shift>question", mini_buffer, MINI_SELECT_IF, NULL},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000235{N_("Options..."), NULL, menu_show_options, 0, "<StockItem>", GTK_STOCK_PREFERENCES},
c35de8cf
TL
Thomas Leonard2001-07-10 14:59:26 +0000236{N_("New"), NULL, NULL, 0, "<Branch>"},
237{">" N_("Directory"), NULL, new_directory, 0, NULL},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000238{">" N_("Blank file"), NULL, new_file, 0, "<StockItem>", GTK_STOCK_NEW},
62490356 Thomas Leonard2005-03-12 21:08:59 +0000239{">" N_("Customise Menu..."), NULL, customise_new, 0, NULL},
35769530 Thomas Leonard2000-09-07 14:58:49 +0000240{N_("Window"), NULL, NULL, 0, "<Branch>"},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000241{">" N_("Parent, New Window"), NULL, open_parent, 0, "<StockItem>", GTK_STOCK_GO_UP},
35769530
TL
Thomas Leonard2000-09-07 14:58:49 +0000242{">" N_("Parent, Same Window"), NULL, open_parent_same, 0, NULL},
243{">" N_("New Window"), NULL, new_window, 0, NULL},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000244{">" N_("Home Directory"), "<Ctrl>Home", home_directory, 0, "<StockItem>", GTK_STOCK_HOME},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000245{">" N_("Show Bookmarks"), "<Ctrl>B", show_bookmarks, 0, "<StockItem>", ROX_STOCK_BOOKMARKS},
572c7202 Thomas Leonard2007-08-19 12:39:02 +0100246{">" N_("Show Log"), NULL, show_log, 0, "<StockItem>", GTK_STOCK_INFO},
38be87fc Thomas Leonard2002-05-17 15:05:53 +0000247{">" N_("Follow Symbolic Links"), NULL, follow_symlinks, 0, NULL},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000248{">" N_("Resize Window"), "<Ctrl>E", resize, 0, NULL},
35769530
TL
Thomas Leonard2000-09-07 14:58:49 +0000249/* {">" N_("New, As User..."), NULL, new_user, 0, NULL}, */
250
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000251{">" N_("Close Window"), "<Ctrl>Q", close_window, 0, "<StockItem>", GTK_STOCK_CLOSE},
35769530 Thomas Leonard2000-09-07 14:58:49 +0000252{">", NULL, NULL, 0, "<Separator>"},
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +0000253{">" N_("Enter Path..."), "slash", mini_buffer, MINI_PATH, NULL},
0be8e45b Thomas Leonard2004-04-21 14:29:32 +0000254{">" N_("Shell Command..."), "<Shift>exclam", mini_buffer, MINI_SHELL, NULL},
cdbab0bd
TL
Thomas Leonard2005-08-14 16:09:24 +0000255{">" N_("Terminal Here"), "grave", xterm_here, FALSE, NULL},
256{">" N_("Switch to Terminal"), NULL, xterm_here, TRUE, NULL},
67134d89
TL
Thomas Leonard2002-07-12 12:47:38 +0000257{N_("Help"), NULL, NULL, 0, "<Branch>"},
258{">" N_("About ROX-Filer..."), NULL, menu_rox_help, HELP_ABOUT, NULL},
061a9e72 Thomas Leonard2003-03-03 16:22:37 +0000259{">" N_("Show Help Files"), "F1", menu_rox_help, HELP_DIR, "<StockItem>", GTK_STOCK_HELP},
4db98e05 Thomas Leonard2002-07-12 12:55:09 +0000260{">" N_("Manual"), NULL, menu_rox_help, HELP_MANUAL, NULL},
ab588714
TL
Thomas Leonard1999-06-17 15:07:06 +0000261};
262
b2b6a9ee Thomas Leonard2000-07-17 17:16:43 +0000263
b10b33db
TL
Thomas Leonard2000-04-17 12:13:35 +0000264#define GET_MENU_ITEM(var, menu) \
265 var = gtk_item_factory_get_widget(item_factory, "<" menu ">");
266
267#define GET_SMENU_ITEM(var, menu, sub) \
268 do { \
269 tmp = g_strdup_printf("<" menu ">/%s", _(sub)); \
270 var = gtk_item_factory_get_widget(item_factory, tmp); \
271 g_free(tmp); \
272 } while (0)
273
274#define GET_SSMENU_ITEM(var, menu, sub, subsub) \
ba72a534 Thomas Leonard2000-04-16 21:02:01 +0000275 do { \
b10b33db
TL
Thomas Leonard2000-04-17 12:13:35 +0000276 tmp = g_strdup_printf("<" menu ">/%s/%s", _(sub), _(subsub)); \
277 var = gtk_item_factory_get_widget(item_factory, tmp); \
ba72a534
TL
Thomas Leonard2000-04-16 21:02:01 +0000278 g_free(tmp); \
279 } while (0)
280
59a554b7
TL
Thomas Leonard2002-12-26 18:02:26 +0000281/* Returns TRUE if the keys were installed (first call only) */
282gboolean ensure_filer_menu(void)
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000283{
85c09878 Thomas Leonard1999-07-30 13:07:21 +0000284 GList *items;
ba72a534
TL
Thomas Leonard2000-04-16 21:02:01 +0000285 guchar *tmp;
286 GtkWidget *item;
e73bc442 Thomas Leonard2000-08-16 17:31:24 +0000287 GtkItemFactory *item_factory;
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000288
59a554b7
TL
Thomas Leonard2002-12-26 18:02:26 +0000289 if (!filer_keys_need_init)
290 return FALSE;
291 filer_keys_need_init = FALSE;
d2c0a26d Thomas Leonard2002-04-03 19:27:07 +0000292
e59eeee4
TL
Thomas Leonard2001-11-26 13:53:11 +0000293 item_factory = menu_create(filer_menu_def,
294 sizeof(filer_menu_def) / sizeof(*filer_menu_def),
295 "<filer>", filer_keys);
ba72a534 Thomas Leonard2000-04-16 21:02:01 +0000296
b10b33db
TL
Thomas Leonard2000-04-17 12:13:35 +0000297 GET_MENU_ITEM(filer_menu, "filer");
298 GET_SMENU_ITEM(filer_file_menu, "filer", "File");
b10b33db Thomas Leonard2000-04-17 12:13:35 +0000299 GET_SSMENU_ITEM(filer_hidden_menu, "filer", "Display", "Show Hidden");
b4d8b5b5 Stephen Watson2006-08-14 20:50:27 +0000300 GET_SSMENU_ITEM(filer_filter_dirs_menu, "filer", "Display", "Filter Directories With Files");
7f0bfceb Thomas Leonard2002-12-27 12:19:54 +0000301 GET_SSMENU_ITEM(filer_reverse_menu, "filer", "Display", "Reversed");
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000302 GET_SSMENU_ITEM(filer_auto_size_menu, "filer", "Display", "Automatic");
f2c63f66
TL
Thomas Leonard2001-12-20 14:08:57 +0000303 GET_SSMENU_ITEM(filer_thumb_menu, "filer", "Display",
304 "Show Thumbnails");
881abaaf
SW
Stephen Watson2004-11-25 20:06:37 +0000305 GET_SSMENU_ITEM(item, "filer", "File", "Set Type...");
306 filer_set_type = GTK_BIN(item)->child;
ba72a534 Thomas Leonard2000-04-16 21:02:01 +0000307
c35de8cf Thomas Leonard2001-07-10 14:59:26 +0000308 GET_SMENU_ITEM(filer_new_menu, "filer", "New");
38be87fc
TL
Thomas Leonard2002-05-17 15:05:53 +0000309 GET_SSMENU_ITEM(item, "filer", "Window", "Follow Symbolic Links");
310 filer_follow_sym = GTK_BIN(item)->child;
12f4243e Thomas Leonard2000-09-07 17:53:49 +0000311
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000312 /* File '' label... */
86b6456e Thomas Leonard2002-03-13 16:44:30 +0000313 items = gtk_container_get_children(GTK_CONTAINER(filer_menu));
85c09878
TL
Thomas Leonard1999-07-30 13:07:21 +0000314 filer_file_item = GTK_BIN(g_list_nth(items, 1)->data)->child;
315 g_list_free(items);
ba72a534 Thomas Leonard2000-04-16 21:02:01 +0000316
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000317 /* Shift Open... label */
86b6456e Thomas Leonard2002-03-13 16:44:30 +0000318 items = gtk_container_get_children(GTK_CONTAINER(filer_file_menu));
c09cfcee Thomas Leonard2003-08-20 12:49:38 +0000319 file_shift_item = GTK_BIN(g_list_nth(items, 5)->data)->child;
dfbd74cb
TL
Thomas Leonard2000-09-08 18:10:43 +0000320 g_list_free(items);
321
b10b33db Thomas Leonard2000-04-17 12:13:35 +0000322 GET_SSMENU_ITEM(item, "filer", "Window", "New Window");
ba72a534 Thomas Leonard2000-04-16 21:02:01 +0000323 filer_new_window = GTK_BIN(item)->child;
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +0000324
c2232d50 Thomas Leonard2010-04-07 15:44:57 +0100325 g_signal_connect(filer_menu, "selection-done",
d2c0a26d Thomas Leonard2002-04-03 19:27:07 +0000326 G_CALLBACK(menu_closed), NULL);
c2232d50 Thomas Leonard2010-04-07 15:44:57 +0100327 g_signal_connect(filer_file_menu, "selection-done",
d2c0a26d
TL
Thomas Leonard2002-04-03 19:27:07 +0000328 G_CALLBACK(menu_closed), NULL);
329
fd1a670f
TL
Thomas Leonard2002-06-25 13:24:53 +0000330 g_signal_connect(filer_keys, "accel_changed",
331 G_CALLBACK(save_menus), NULL);
59a554b7
TL
Thomas Leonard2002-12-26 18:02:26 +0000332
333 return TRUE;
d2c0a26d
TL
Thomas Leonard2002-04-03 19:27:07 +0000334}
335
336void menu_init(void)
337{
338 char *menurc;
339
6967aa47 Stephen Watson2005-04-25 18:02:14 +0000340 menurc = choices_find_xdg_path_load(MENUS_NAME, PROJECT, SITE);
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +0000341 if (menurc)
2658eef1 Thomas Leonard2000-07-28 21:11:07 +0000342 {
5b509326 Thomas Leonard2001-11-24 17:42:42 +0000343 gtk_accel_map_load(menurc);
cedd70be Thomas Leonard2000-12-20 13:06:51 +0000344 g_free(menurc);
2658eef1 Thomas Leonard2000-07-28 21:11:07 +0000345 }
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000346
ad4a5534
TL
Thomas Leonard2002-02-20 18:15:43 +0000347 option_add_string(&o_menu_xterm, "menu_xterm", "xterm");
348 option_add_int(&o_menu_iconsize, "menu_iconsize", MIS_SMALL);
e6d077a6 Thomas Leonard2004-03-16 10:48:52 +0000349 option_add_int(&o_menu_quick, "menu_quick", FALSE);
a86d3171 Thomas Leonard2001-02-03 14:09:53 +0000350 option_add_saver(save_menus);
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +0000351
f7646571 Thomas Leonard2002-03-08 12:37:38 +0000352 option_register_widget("menu-set-keys", set_keys_button);
59a554b7
TL
Thomas Leonard2002-12-26 18:02:26 +0000353
354 filer_keys = gtk_accel_group_new();
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +0000355}
e73bc442
TL
Thomas Leonard2000-08-16 17:31:24 +0000356
357/* Name is in the form "<panel>" */
616d6c1e Thomas Leonard2001-05-28 17:48:06 +0000358GtkItemFactory *menu_create(GtkItemFactoryEntry *def, int n_entries,
2d91f96f Thomas Leonard2002-03-08 16:08:31 +0000359 const gchar *name, GtkAccelGroup *keys)
e73bc442
TL
Thomas Leonard2000-08-16 17:31:24 +0000360{
361 GtkItemFactory *item_factory;
362 GtkItemFactoryEntry *translated;
e73bc442 Thomas Leonard2000-08-16 17:31:24 +0000363
e59eeee4
TL
Thomas Leonard2001-11-26 13:53:11 +0000364 if (!keys)
365 {
366 keys = gtk_accel_group_new();
367 gtk_accel_group_lock(keys);
368 }
e73bc442
TL
Thomas Leonard2000-08-16 17:31:24 +0000369
370 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, name, keys);
371
372 translated = translate_entries(def, n_entries);
373 gtk_item_factory_create_items(item_factory, n_entries,
374 translated, NULL);
375 free_translated_entries(translated, n_entries);
376
616d6c1e Thomas Leonard2001-05-28 17:48:06 +0000377 return item_factory;
e73bc442 Thomas Leonard2000-08-16 17:31:24 +0000378}
5b509326
TL
Thomas Leonard2001-11-24 17:42:42 +0000379
380/* Prevent the user from setting a short-cut on this item */
fd1a670f Thomas Leonard2002-06-25 13:24:53 +0000381static void menuitem_no_shortcuts(GtkWidget *item)
5b509326 Thomas Leonard2001-11-24 17:42:42 +0000382{
e4ef82bd
TL
Thomas Leonard2002-03-08 18:06:04 +0000383 /* XXX */
384#if 0
5b509326
TL
Thomas Leonard2001-11-24 17:42:42 +0000385 GtkMenuItem *menuitem = GTK_MENU_ITEM(item);
386
387 _gtk_widget_set_accel_path(item, NULL, NULL);
256ca8aa Thomas Leonard2002-10-17 12:58:10 +0000388 null_g_free(&menuitem->accel_path);
5b509326
TL
Thomas Leonard2001-11-24 17:42:42 +0000389#endif
390}
88910f54 Thomas Leonard1999-08-02 11:40:07 +0000391
31875600 Thomas Leonard2002-07-19 15:57:49 +0000392/* Shade items that only work on single files */
30c262f5
TL
Thomas Leonard2002-06-01 14:39:52 +0000393static void shade_file_menu_items(gboolean shaded)
394{
a7cc76f5
TL
Thomas Leonard2005-01-09 13:08:37 +0000395 menu_set_items_shaded(filer_file_menu, shaded, 0, 1);
396 menu_set_items_shaded(filer_file_menu, shaded, 2, 1);
4fba9c41
TL
Thomas Leonard2005-11-29 20:24:49 +0000397 menu_set_items_shaded(filer_file_menu, shaded, 5, 1);
398 menu_set_items_shaded(filer_file_menu, shaded, 8, 2);
88910f54
TL
Thomas Leonard1999-08-02 11:40:07 +0000399}
400
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000401/* 'data' is an array of three ints:
402 * [ pointer_x, pointer_y, item_under_pointer ]
403 */
0a115802 Thomas Leonard2001-06-28 16:00:48 +0000404void position_menu(GtkMenu *menu, gint *x, gint *y,
e4ef82bd Thomas Leonard2002-03-08 18:06:04 +0000405 gboolean *push_in, gpointer data)
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000406{
1b34c9e0 Thomas Leonard1999-07-22 17:19:36 +0000407 int *pos = (int *) data;
1b34c9e0 Thomas Leonard1999-07-22 17:19:36 +0000408 GtkRequisition requisition;
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000409 GList *items, *next;
410 int y_shift = 0;
411 int item = pos[2];
412
86b6456e Thomas Leonard2002-03-13 16:44:30 +0000413 next = items = gtk_container_get_children(GTK_CONTAINER(menu));
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000414
7314c995 Thomas Leonard2001-08-23 13:34:05 +0000415 while (item >= 0 && next)
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000416 {
417 int h = ((GtkWidget *) next->data)->requisition.height;
418
419 if (item > 0)
420 y_shift += h;
421 else
422 y_shift += h / 2;
423
424 next = next->next;
425 item--;
426 }
427
428 g_list_free(items);
1b34c9e0 Thomas Leonard1999-07-22 17:19:36 +0000429
1b34c9e0
TL
Thomas Leonard1999-07-22 17:19:36 +0000430 gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
431
20f2247f Thomas Leonard2001-06-20 16:21:18 +0000432 *x = pos[0] - (requisition.width * 7 / 8);
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000433 *y = pos[1] - y_shift;
1b34c9e0 Thomas Leonard1999-07-22 17:19:36 +0000434
a55cd9d2
TL
Thomas Leonard1999-08-21 16:03:08 +0000435 *x = CLAMP(*x, 0, screen_width - requisition.width);
436 *y = CLAMP(*y, 0, screen_height - requisition.height);
0a115802 Thomas Leonard2001-06-28 16:00:48 +0000437
0a115802 Thomas Leonard2001-06-28 16:00:48 +0000438 *push_in = FALSE;
ab588714
TL
Thomas Leonard1999-06-17 15:07:06 +0000439}
440
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000441GtkWidget *make_send_to_item(DirItem *ditem, const char *label,
442 MenuIconStyle style)
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000443{
1ed7fcf8 Thomas Leonard2003-09-28 14:44:03 +0000444 GtkWidget *item;
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000445
dff573ef Thomas Leonard2004-09-21 16:44:34 +0000446 if (style != MIS_NONE && di_image(ditem))
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000447 {
1ed7fcf8 Thomas Leonard2003-09-28 14:44:03 +0000448 GdkPixbuf *pixbuf;
dff573ef
TL
Thomas Leonard2004-09-21 16:44:34 +0000449 MaskedPixmap *image;
450
451 image = di_image(ditem);
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000452
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000453 switch (style)
454 {
455 case MIS_LARGE:
dff573ef Thomas Leonard2004-09-21 16:44:34 +0000456 pixbuf = image->pixbuf;
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000457 break;
458 default:
dff573ef
TL
Thomas Leonard2004-09-21 16:44:34 +0000459 if (!image->sm_pixbuf)
460 pixmap_make_small(image);
461 pixbuf = image->sm_pixbuf;
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000462 break;
463 }
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000464
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000465 item = gtk_image_menu_item_new_with_label(label);
466 /* TODO: Find a way to allow short-cuts */
467 menuitem_no_shortcuts(item);
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000468
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000469 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
470 gtk_image_new_from_pixbuf(pixbuf));
1494db5a Thomas Leonard2003-09-29 09:45:04 +0000471 gtk_widget_show_all(item);
1ed7fcf8
TL
Thomas Leonard2003-09-28 14:44:03 +0000472 }
473 else
474 item = gtk_menu_item_new_with_label(label);
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000475
1ed7fcf8 Thomas Leonard2003-09-28 14:44:03 +0000476 return item;
48825b4f
TL
Thomas Leonard2003-06-29 13:55:36 +0000477}
478
b166d210 Thomas Leonard2002-06-12 11:45:22 +0000479static GList *menu_from_dir(GtkWidget *menu, const gchar *dir_name,
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000480 MenuIconStyle style, CallbackFn func,
6f795b01
TL
Thomas Leonard2002-04-08 14:30:58 +0000481 gboolean separator, gboolean strip_ext,
482 gboolean recurse)
ccb93f45
TL
Thomas Leonard2001-08-10 11:16:00 +0000483{
484 GList *widgets = NULL;
e69a9b4e Thomas Leonard2001-12-10 22:42:02 +0000485 DirItem *ditem;
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000486 int i;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000487 GtkWidget *item;
b166d210 Thomas Leonard2002-06-12 11:45:22 +0000488 char *dname = NULL;
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000489 GPtrArray *names;
b166d210
TL
Thomas Leonard2002-06-12 11:45:22 +0000490
491 dname = pathdup(dir_name);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000492
48825b4f
TL
Thomas Leonard2003-06-29 13:55:36 +0000493 names = list_dir(dname);
494 if (!names)
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +0000495 goto out;
496
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000497 for (i = 0; i < names->len; i++)
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000498 {
48825b4f
TL
Thomas Leonard2003-06-29 13:55:36 +0000499 char *leaf = names->pdata[i];
500 gchar *fname;
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000501
62490356
TL
Thomas Leonard2005-03-12 21:08:59 +0000502 if (separator)
503 {
504 item = gtk_menu_item_new();
505 widgets = g_list_append(widgets, item);
506 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
507 separator = FALSE;
508 }
509
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000510 fname = g_strconcat(dname, "/", leaf, NULL);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +0000511
512 /* Strip off extension, if any */
48825b4f
TL
Thomas Leonard2003-06-29 13:55:36 +0000513 if (strip_ext)
514 {
515 char *dot;
516 dot = strchr(leaf, '.');
517 if (dot)
518 *dot = '\0';
519 }
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000520
0abf1bfe
TL
Thomas Leonard2002-04-05 16:32:37 +0000521 ditem = diritem_new("");
522 diritem_restat(fname, ditem, NULL);
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000523
1ed7fcf8 Thomas Leonard2003-09-28 14:44:03 +0000524 item = make_send_to_item(ditem, leaf, style);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000525
48825b4f
TL
Thomas Leonard2003-06-29 13:55:36 +0000526 g_free(leaf);
527
6f795b01
TL
Thomas Leonard2002-04-08 14:30:58 +0000528 /* If it is a directory (but NOT an AppDir) and we are
529 * recursing then set up a sub menu.
530 */
531 if (recurse && ditem->base_type == TYPE_DIRECTORY &&
532 !(ditem->flags & ITEM_FLAG_APPDIR))
533 {
534 GtkWidget *sub;
535 GList *new_widgets;
536
537 sub = gtk_menu_new();
538 new_widgets = menu_from_dir(sub, fname, style, func,
1ca35563 Thomas Leonard2005-03-12 16:21:02 +0000539 separator, strip_ext, TRUE);
6f795b01
TL
Thomas Leonard2002-04-08 14:30:58 +0000540 g_list_free(new_widgets);
541 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), sub);
542 }
543 else
544 g_signal_connect_swapped(item, "activate",
545 G_CALLBACK(func), fname);
546
547 diritem_free(ditem);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000548
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000549 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
86b6456e
TL
Thomas Leonard2002-03-13 16:44:30 +0000550 g_signal_connect_swapped(item, "destroy",
551 G_CALLBACK(g_free), fname);
c35de8cf
TL
Thomas Leonard2001-07-10 14:59:26 +0000552
553 widgets = g_list_append(widgets, item);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +0000554 }
555
48825b4f Thomas Leonard2003-06-29 13:55:36 +0000556 g_ptr_array_free(names, TRUE);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000557out:
b166d210 Thomas Leonard2002-06-12 11:45:22 +0000558 g_free(dname);
ccb93f45
TL
Thomas Leonard2001-08-10 11:16:00 +0000559
560 return widgets;
561}
562
563/* Scan the templates dir and create entries for the New menu */
564static void update_new_files_menu(MenuIconStyle style)
565{
566 static GList *widgets = NULL;
567
568 gchar *templ_dname = NULL;
569
570 if (widgets)
571 {
572 GList *next;
573
574 for (next = widgets; next; next = next->next)
575 gtk_widget_destroy((GtkWidget *) next->data);
576
577 g_list_free(widgets);
578 widgets = NULL;
579 }
580
6967aa47 Stephen Watson2005-04-25 18:02:14 +0000581 templ_dname = choices_find_xdg_path_load("Templates", "", SITE);
ccb93f45
TL
Thomas Leonard2001-08-10 11:16:00 +0000582 if (templ_dname)
583 {
584 widgets = menu_from_dir(filer_new_menu, templ_dname, style,
6f795b01
TL
Thomas Leonard2002-04-08 14:30:58 +0000585 (CallbackFn) new_file_type, TRUE, TRUE,
586 FALSE);
ccb93f45
TL
Thomas Leonard2001-08-10 11:16:00 +0000587 g_free(templ_dname);
588 }
c35de8cf Thomas Leonard2001-07-10 14:59:26 +0000589 gtk_widget_show_all(filer_new_menu);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +0000590}
591
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000592/* 'item' is the number of the item to appear under the pointer. */
9cfe16fe Thomas Leonard2001-09-09 13:41:02 +0000593void show_popup_menu(GtkWidget *menu, GdkEvent *event, int item)
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000594{
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000595 int pos[3];
9cfe16fe Thomas Leonard2001-09-09 13:41:02 +0000596 int button = 0;
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000597 guint32 time = 0;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000598
9cfe16fe
TL
Thomas Leonard2001-09-09 13:41:02 +0000599 if (event && (event->type == GDK_BUTTON_PRESS ||
600 event->type == GDK_BUTTON_RELEASE))
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000601 {
602 GdkEventButton *bev = (GdkEventButton *) event;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000603
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000604 pos[0] = bev->x_root;
605 pos[1] = bev->y_root;
606 button = bev->button;
607 time = bev->time;
608 }
9cfe16fe Thomas Leonard2001-09-09 13:41:02 +0000609 else if (event && event->type == GDK_KEY_PRESS)
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000610 {
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000611 GdkEventKey *kev = (GdkEventKey *) event;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000612
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000613 get_pointer_xy(pos, pos + 1);
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000614 time = kev->time;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000615 }
9cfe16fe
TL
Thomas Leonard2001-09-09 13:41:02 +0000616 else
617 get_pointer_xy(pos, pos + 1);
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000618
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000619 pos[2] = item;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +0000620
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000621 gtk_widget_show_all(menu);
622 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
623 position_menu, (gpointer) pos, button, time);
624 select_nth_item(GTK_MENU_SHELL(menu), item);
ccb93f45
TL
Thomas Leonard2001-08-10 11:16:00 +0000625}
626
d2c0a26d
TL
Thomas Leonard2002-04-03 19:27:07 +0000627/* Hide the popup menu, if any */
628void menu_popdown(void)
629{
630 if (popup_menu)
631 gtk_menu_popdown(GTK_MENU(popup_menu));
632}
633
07e4b22c
TL
Thomas Leonard2001-09-09 14:13:29 +0000634static MenuIconStyle get_menu_icon_style(void)
635{
636 MenuIconStyle mis;
637 int display;
638
89a24bf0 Thomas Leonard2002-02-20 17:48:27 +0000639 mis = o_menu_iconsize.int_value;
07e4b22c
TL
Thomas Leonard2001-09-09 14:13:29 +0000640
641 switch (mis)
642 {
9b2e302f Thomas Leonard2002-04-28 15:59:59 +0000643 case MIS_NONE: case MIS_SMALL: case MIS_LARGE:
07e4b22c Thomas Leonard2001-09-09 14:13:29 +0000644 return mis;
63ff7eb9
TL
Thomas Leonard2001-09-09 15:23:17 +0000645 default:
646 break;
07e4b22c
TL
Thomas Leonard2001-09-09 14:13:29 +0000647 }
648
649 if (mis == MIS_CURRENT && window_with_focus)
650 {
651 switch (window_with_focus->display_style)
652 {
653 case HUGE_ICONS:
07e4b22c
TL
Thomas Leonard2001-09-09 14:13:29 +0000654 case LARGE_ICONS:
655 return MIS_LARGE;
656 case SMALL_ICONS:
657 return MIS_SMALL;
658 default:
659 break;
660 }
661 }
662
89a24bf0 Thomas Leonard2002-02-20 17:48:27 +0000663 display = o_display_size.int_value;
07e4b22c
TL
Thomas Leonard2001-09-09 14:13:29 +0000664 switch (display)
665 {
666 case HUGE_ICONS:
07e4b22c
TL
Thomas Leonard2001-09-09 14:13:29 +0000667 case LARGE_ICONS:
668 return MIS_LARGE;
669 case SMALL_ICONS:
670 return MIS_SMALL;
671 default:
672 break;
673 }
674
675 return MIS_SMALL;
676}
677
f671e2e4
TL
Thomas Leonard2002-08-11 14:26:39 +0000678/* iter->peek() is the clicked item, or NULL if none */
679void show_filer_menu(FilerWindow *filer_window, GdkEvent *event, ViewIter *iter)
ab588714 Thomas Leonard1999-06-17 15:07:06 +0000680{
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000681 DirItem *file_item = NULL;
b5f57111 Thomas Leonard2001-04-29 14:09:39 +0000682 GdkModifierType state = 0;
5777df6b Thomas Leonard2002-06-11 14:47:07 +0000683 int n_selected;
cc49379d Stephen Watson2003-12-20 13:58:22 +0000684 int n_added = 0;
5777df6b Thomas Leonard2002-06-11 14:47:07 +0000685
3220e1a5
TL
Thomas Leonard2005-08-01 07:10:20 +0000686 g_return_if_fail(event != NULL);
687
3b6cef86 Thomas Leonard2002-06-20 15:42:08 +0000688 n_selected = view_count_selected(filer_window->view);
a799932f Thomas Leonard2000-02-13 12:51:57 +0000689
d2c0a26d
TL
Thomas Leonard2002-04-03 19:27:07 +0000690 ensure_filer_menu();
691
a799932f Thomas Leonard2000-02-13 12:51:57 +0000692 updating_menu++;
ec72fb2f
TL
Thomas Leonard2001-01-27 15:23:45 +0000693
694 /* Remove previous AppMenu, if any */
b6d6984f Thomas Leonard2001-03-08 21:28:47 +0000695 appmenu_remove();
ec72fb2f Thomas Leonard2001-01-27 15:23:45 +0000696
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000697 window_with_focus = filer_window;
b5f57111
TL
Thomas Leonard2001-04-29 14:09:39 +0000698
699 if (event->type == GDK_BUTTON_PRESS)
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000700 state = ((GdkEventButton *) event)->state;
701 else if (event->type == GDK_KEY_PRESS)
702 state = ((GdkEventKey *) event)->state;
1b34c9e0 Thomas Leonard1999-07-22 17:19:36 +0000703
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +0000704 if (n_selected == 0 && iter && iter->peek(iter) != NULL)
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000705 {
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000706 filer_window->temp_item_selected = TRUE;
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +0000707 view_set_selected(filer_window->view, iter, TRUE);
3b6cef86 Thomas Leonard2002-06-20 15:42:08 +0000708 n_selected = view_count_selected(filer_window->view);
24482e66
TL
Thomas Leonard1999-07-24 16:41:54 +0000709 }
710 else
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000711 {
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000712 filer_window->temp_item_selected = FALSE;
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000713 }
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000714
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000715 /* Short-cut to the Send To menu */
716 if (state & GDK_SHIFT_MASK)
717 {
718 GList *paths;
719
084b2c5f
TL
Thomas Leonard2001-12-29 14:58:52 +0000720 updating_menu--;
721
5777df6b Thomas Leonard2002-06-11 14:47:07 +0000722 if (n_selected == 0)
5f30ff41 Thomas Leonard2001-08-22 12:05:59 +0000723 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +0000724 report_error(
5f30ff41
TL
Thomas Leonard2001-08-22 12:05:59 +0000725 _("You should Shift+Menu click over a file to "
726 "send it somewhere"));
727 return;
728 }
729
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000730 paths = filer_selected_items(filer_window);
731
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +0000732 show_send_to_menu(paths, event); /* (paths eaten) */
733
734 return;
735 }
736
88910f54 Thomas Leonard1999-08-02 11:40:07 +0000737 {
77ccdb1d Thomas Leonard2000-03-18 16:50:51 +0000738 GtkWidget *file_label, *file_menu;
77ccdb1d Thomas Leonard2000-03-18 16:50:51 +0000739 GString *buffer;
42a9b56e Thomas Leonard2001-12-13 17:29:38 +0000740 DirItem *item;
77ccdb1d Thomas Leonard2000-03-18 16:50:51 +0000741
dc1fe3ab Thomas Leonard1999-08-01 09:32:19 +0000742 file_label = filer_file_item;
88910f54 Thomas Leonard1999-08-02 11:40:07 +0000743 file_menu = filer_file_menu;
a799932f Thomas Leonard2000-02-13 12:51:57 +0000744 gtk_check_menu_item_set_active(
f2c63f66
TL
Thomas Leonard2001-12-20 14:08:57 +0000745 GTK_CHECK_MENU_ITEM(filer_thumb_menu),
746 filer_window->show_thumbs);
747 gtk_check_menu_item_set_active(
a799932f
TL
Thomas Leonard2000-02-13 12:51:57 +0000748 GTK_CHECK_MENU_ITEM(filer_hidden_menu),
749 filer_window->show_hidden);
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000750 gtk_check_menu_item_set_active(
b4d8b5b5
SW
Stephen Watson2006-08-14 20:50:27 +0000751 GTK_CHECK_MENU_ITEM(filer_filter_dirs_menu),
752 filer_window->filter_directories);
753 gtk_check_menu_item_set_active(
7f0bfceb
TL
Thomas Leonard2002-12-27 12:19:54 +0000754 GTK_CHECK_MENU_ITEM(filer_reverse_menu),
755 filer_window->sort_order != GTK_SORT_ASCENDING);
756 gtk_check_menu_item_set_active(
66d33128
TL
Thomas Leonard2002-12-24 13:30:17 +0000757 GTK_CHECK_MENU_ITEM(filer_auto_size_menu),
758 filer_window->display_style_wanted == AUTO_SIZE_ICONS);
77ccdb1d Thomas Leonard2000-03-18 16:50:51 +0000759 buffer = g_string_new(NULL);
42a9b56e Thomas Leonard2001-12-13 17:29:38 +0000760
5777df6b Thomas Leonard2002-06-11 14:47:07 +0000761 switch (n_selected)
77ccdb1d
TL
Thomas Leonard2000-03-18 16:50:51 +0000762 {
763 case 0:
45312373 Thomas Leonard2000-04-18 11:21:45 +0000764 g_string_assign(buffer, _("Next Click"));
30c262f5 Thomas Leonard2002-06-01 14:39:52 +0000765 shade_file_menu_items(FALSE);
77ccdb1d
TL
Thomas Leonard2000-03-18 16:50:51 +0000766 break;
767 case 1:
30c262f5 Thomas Leonard2002-06-01 14:39:52 +0000768 item = filer_selected_item(filer_window);
dff573ef Thomas Leonard2004-09-21 16:44:34 +0000769 if (item->base_type == TYPE_UNKNOWN)
7195c792
TL
Thomas Leonard2002-02-19 13:39:35 +0000770 dir_update_item(filer_window->directory,
771 item->leafname);
30c262f5
TL
Thomas Leonard2002-06-01 14:39:52 +0000772 shade_file_menu_items(FALSE);
773 file_item = filer_selected_item(filer_window);
f21478c4 Stephen Watson2003-08-02 13:09:11 +0000774 g_string_printf(buffer, _("%s '%s'"),
a56ccd98
TL
Thomas Leonard2002-10-18 13:32:20 +0000775 basetype_name(file_item),
776 g_utf8_validate(file_item->leafname,
777 -1, NULL)
778 ? file_item->leafname
779 : _("(bad utf-8)"));
b7262c9a
TL
Thomas Leonard2000-09-06 21:15:09 +0000780 if (!can_set_run_action(file_item))
781 menu_set_items_shaded(filer_file_menu,
4fba9c41 Thomas Leonard2005-11-29 20:24:49 +0000782 TRUE, 8, 1);
77ccdb1d
TL
Thomas Leonard2000-03-18 16:50:51 +0000783 break;
784 default:
30c262f5 Thomas Leonard2002-06-01 14:39:52 +0000785 shade_file_menu_items(TRUE);
2997763d Thomas Leonard2002-10-26 15:17:06 +0000786 g_string_printf(buffer, _("%d items"),
5777df6b Thomas Leonard2002-06-11 14:47:07 +0000787 n_selected);
77ccdb1d
TL
Thomas Leonard2000-03-18 16:50:51 +0000788 break;
789 }
790 gtk_label_set_text(GTK_LABEL(file_label), buffer->str);
791 g_string_free(buffer, TRUE);
dfbd74cb Thomas Leonard2000-09-08 18:10:43 +0000792
616d6c1e Thomas Leonard2001-05-28 17:48:06 +0000793 menu_show_shift_action(file_shift_item, file_item,
5777df6b Thomas Leonard2002-06-11 14:47:07 +0000794 n_selected == 0);
616d6c1e Thomas Leonard2001-05-28 17:48:06 +0000795 if (file_item)
7bb44fe1
TL
Thomas Leonard2004-01-06 12:56:16 +0000796 n_added = appmenu_add(make_path(filer_window->sym_path,
797 file_item->leafname),
798 file_item, filer_file_menu);
88910f54 Thomas Leonard1999-08-02 11:40:07 +0000799 }
dc1fe3ab Thomas Leonard1999-08-01 09:32:19 +0000800
07e4b22c Thomas Leonard2001-09-09 14:13:29 +0000801 update_new_files_menu(get_menu_icon_style());
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +0000802
89a24bf0
TL
Thomas Leonard2002-02-20 17:48:27 +0000803 gtk_widget_set_sensitive(filer_new_window,
804 !o_unique_filer_windows.int_value);
38be87fc
TL
Thomas Leonard2002-05-17 15:05:53 +0000805 gtk_widget_set_sensitive(filer_follow_sym,
806 strcmp(filer_window->sym_path, filer_window->real_path) != 0);
881abaaf Stephen Watson2004-11-25 20:06:37 +0000807 gtk_widget_set_sensitive(filer_set_type,
5efcc881 Stephen Watson2005-08-13 13:49:54 +0000808 xattr_supported(filer_window->real_path));
8de9a519 Thomas Leonard2000-03-12 19:13:13 +0000809
e6d077a6
TL
Thomas Leonard2004-03-16 10:48:52 +0000810 if (n_selected && o_menu_quick.int_value)
811 popup_menu = (state & GDK_CONTROL_MASK)
812 ? filer_menu
813 : filer_file_menu;
814 else
815 popup_menu = (state & GDK_CONTROL_MASK)
816 ? filer_file_menu
817 : filer_menu;
51a60b03 Thomas Leonard2000-01-09 18:51:38 +0000818
a799932f
TL
Thomas Leonard2000-02-13 12:51:57 +0000819 updating_menu--;
820
dce3d041 Thomas Leonard2001-08-22 11:58:38 +0000821 show_popup_menu(popup_menu, event,
e6d077a6 Thomas Leonard2004-03-16 10:48:52 +0000822 popup_menu == filer_file_menu ? n_added : 1);
ab588714
TL
Thomas Leonard1999-06-17 15:07:06 +0000823}
824
24482e66
TL
Thomas Leonard1999-07-24 16:41:54 +0000825static void menu_closed(GtkWidget *widget)
826{
51a60b03 Thomas Leonard2000-01-09 18:51:38 +0000827 if (window_with_focus == NULL || widget != popup_menu)
3d80cf00 Thomas Leonard1999-07-26 13:28:13 +0000828 return; /* Close panel item chosen? */
24482e66 Thomas Leonard1999-07-24 16:41:54 +0000829
d971b902
TL
Thomas Leonard2000-07-23 14:01:05 +0000830 popup_menu = NULL;
831
24482e66
TL
Thomas Leonard1999-07-24 16:41:54 +0000832 if (window_with_focus->temp_item_selected)
833 {
3b6cef86 Thomas Leonard2002-06-20 15:42:08 +0000834 view_clear_selection(window_with_focus->view);
24482e66
TL
Thomas Leonard1999-07-24 16:41:54 +0000835 window_with_focus->temp_item_selected = FALSE;
836 }
df316a01
TL
Thomas Leonard2003-08-22 10:46:09 +0000837
838 appmenu_remove();
24482e66
TL
Thomas Leonard1999-07-24 16:41:54 +0000839}
840
fd1a670f Thomas Leonard2002-06-25 13:24:53 +0000841static void target_callback(FilerWindow *filer_window,
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +0000842 ViewIter *iter,
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +0000843 gpointer action)
0e6e5c9a Thomas Leonard2000-01-11 13:34:32 +0000844{
893bafca
TL
Thomas Leonard2002-06-20 15:52:54 +0000845 g_return_if_fail(filer_window != NULL);
846
847 window_with_focus = filer_window;
0e6e5c9a Thomas Leonard2000-01-11 13:34:32 +0000848
fdfbec0d
TL
Thomas Leonard2001-12-13 17:03:24 +0000849 /* Don't grab the primary selection */
850 filer_window->temp_item_selected = TRUE;
851
f671e2e4
TL
Thomas Leonard2002-08-11 14:26:39 +0000852 view_wink_item(filer_window->view, iter);
853 view_select_only(filer_window->view, iter);
854 file_op(NULL, GPOINTER_TO_INT(action), NULL);
37a84ca7 Thomas Leonard2001-10-01 10:44:14 +0000855
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +0000856 view_clear_selection(filer_window->view);
fdfbec0d Thomas Leonard2001-12-13 17:03:24 +0000857 filer_window->temp_item_selected = FALSE;
0e6e5c9a
TL
Thomas Leonard2000-01-11 13:34:32 +0000858}
859
616d6c1e
TL
Thomas Leonard2001-05-28 17:48:06 +0000860/* Set the text of the 'Shift Open...' menu item.
861 * If icon is NULL, reset the text and also shade it, unless 'next'.
862 */
863void menu_show_shift_action(GtkWidget *menu_item, DirItem *item, gboolean next)
864{
865 guchar *shift_action = NULL;
866
867 if (item)
868 {
869 if (item->flags & ITEM_FLAG_MOUNT_POINT)
870 {
871 if (item->flags & ITEM_FLAG_MOUNTED)
872 shift_action = N_("Unmount");
873 else
cfbf7533 Thomas Leonard2002-12-03 12:30:47 +0000874 shift_action = N_("Open unmounted");
616d6c1e
TL
Thomas Leonard2001-05-28 17:48:06 +0000875 }
876 else if (item->flags & ITEM_FLAG_SYMLINK)
877 shift_action = N_("Show Target");
878 else if (item->base_type == TYPE_DIRECTORY)
879 shift_action = N_("Look Inside");
880 else if (item->base_type == TYPE_FILE)
881 shift_action = N_("Open As Text");
882 }
883 gtk_label_set_text(GTK_LABEL(menu_item),
884 shift_action ? _(shift_action)
885 : _("Shift Open"));
886 gtk_widget_set_sensitive(menu_item, shift_action != NULL || next);
887}
888
6fd9c5fa
TL
Thomas Leonard1999-06-23 09:04:06 +0000889/* Actions */
890
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000891static void view_type(gpointer data, guint action, GtkWidget *widget)
933f91a2 Thomas Leonard2001-04-02 12:58:09 +0000892{
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000893 ViewType view_type = (ViewType) action;
894
895 g_return_if_fail(window_with_focus != NULL);
896
897 if (view_type == VIEW_TYPE_COLLECTION)
898 display_set_layout(window_with_focus,
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000899 window_with_focus->display_style_wanted,
59a554b7 Thomas Leonard2002-12-26 18:02:26 +0000900 DETAILS_NONE, FALSE);
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000901
902 filer_set_view_type(window_with_focus, (ViewType) action);
933f91a2
TL
Thomas Leonard2001-04-02 12:58:09 +0000903}
904
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000905static void change_size(gpointer data, guint action, GtkWidget *widget)
deebe52f Thomas Leonard2000-06-15 12:04:45 +0000906{
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000907 g_return_if_fail(window_with_focus != NULL);
908
66d33128
TL
Thomas Leonard2002-12-24 13:30:17 +0000909 display_change_size(window_with_focus, action == 1);
910}
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000911
66d33128
TL
Thomas Leonard2002-12-24 13:30:17 +0000912static void change_size_auto(gpointer data, guint action, GtkWidget *widget)
913{
914 g_return_if_fail(window_with_focus != NULL);
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000915
66d33128
TL
Thomas Leonard2002-12-24 13:30:17 +0000916 if (updating_menu)
917 return;
918
919 if (window_with_focus->display_style_wanted == AUTO_SIZE_ICONS)
920 display_set_layout(window_with_focus,
921 window_with_focus->display_style,
59a554b7 Thomas Leonard2002-12-26 18:02:26 +0000922 window_with_focus->details_type, FALSE);
66d33128
TL
Thomas Leonard2002-12-24 13:30:17 +0000923 else
924 display_set_layout(window_with_focus, AUTO_SIZE_ICONS,
59a554b7 Thomas Leonard2002-12-26 18:02:26 +0000925 window_with_focus->details_type, FALSE);
fcce571d Thomas Leonard2000-07-25 18:29:19 +0000926}
deebe52f Thomas Leonard2000-06-15 12:04:45 +0000927
9b32010f Thomas Leonard2002-12-22 18:48:20 +0000928static void set_with(gpointer data, guint action, GtkWidget *widget)
fcce571d Thomas Leonard2000-07-25 18:29:19 +0000929{
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000930 DisplayStyle size;
931
932 g_return_if_fail(window_with_focus != NULL);
933
66d33128 Thomas Leonard2002-12-24 13:30:17 +0000934 size = window_with_focus->display_style_wanted;
9b32010f
TL
Thomas Leonard2002-12-22 18:48:20 +0000935
936 filer_set_view_type(window_with_focus, VIEW_TYPE_COLLECTION);
59a554b7 Thomas Leonard2002-12-26 18:02:26 +0000937 display_set_layout(window_with_focus, size, action, FALSE);
deebe52f
TL
Thomas Leonard2000-06-15 12:04:45 +0000938}
939
7f0bfceb Thomas Leonard2002-12-27 12:19:54 +0000940static void set_sort(gpointer data, guint action, GtkWidget *widget)
2385cf7b Thomas Leonard1999-12-26 10:42:48 +0000941{
7f0bfceb
TL
Thomas Leonard2002-12-27 12:19:54 +0000942 if (updating_menu)
943 return;
2385cf7b Thomas Leonard1999-12-26 10:42:48 +0000944
2385cf7b
TL
Thomas Leonard1999-12-26 10:42:48 +0000945 g_return_if_fail(window_with_focus != NULL);
946
7f0bfceb Thomas Leonard2002-12-27 12:19:54 +0000947 display_set_sort_type(window_with_focus, action, GTK_SORT_ASCENDING);
2385cf7b
TL
Thomas Leonard1999-12-26 10:42:48 +0000948}
949
7f0bfceb Thomas Leonard2002-12-27 12:19:54 +0000950static void reverse_sort(gpointer data, guint action, GtkWidget *widget)
2385cf7b Thomas Leonard1999-12-26 10:42:48 +0000951{
7f0bfceb Thomas Leonard2002-12-27 12:19:54 +0000952 GtkSortType order;
2385cf7b Thomas Leonard1999-12-26 10:42:48 +0000953
7f0bfceb
TL
Thomas Leonard2002-12-27 12:19:54 +0000954 if (updating_menu)
955 return;
956
2385cf7b
TL
Thomas Leonard1999-12-26 10:42:48 +0000957 g_return_if_fail(window_with_focus != NULL);
958
7f0bfceb
TL
Thomas Leonard2002-12-27 12:19:54 +0000959 order = window_with_focus->sort_order;
960 if (order == GTK_SORT_ASCENDING)
961 order = GTK_SORT_DESCENDING;
962 else
963 order = GTK_SORT_ASCENDING;
964
965 display_set_sort_type(window_with_focus, window_with_focus->sort_type,
966 order);
2385cf7b
TL
Thomas Leonard1999-12-26 10:42:48 +0000967}
968
205db6de
TL
Thomas Leonard1999-08-05 16:16:47 +0000969static void hidden(gpointer data, guint action, GtkWidget *widget)
970{
a799932f
TL
Thomas Leonard2000-02-13 12:51:57 +0000971 if (updating_menu)
972 return;
973
205db6de
TL
Thomas Leonard1999-08-05 16:16:47 +0000974 g_return_if_fail(window_with_focus != NULL);
975
af6b42d1
SW
Stephen Watson2004-03-01 23:08:05 +0000976 display_set_hidden(window_with_focus,
977 !window_with_focus->show_hidden);
978}
979
0bccc573
SW
Stephen Watson2006-08-13 16:33:52 +0000980static void filter_directories(gpointer data, guint action, GtkWidget *widget)
981{
982 if (updating_menu)
983 return;
984
985 g_return_if_fail(window_with_focus != NULL);
986
987 display_set_filter_directories(window_with_focus,
988 !window_with_focus->filter_directories);
989}
990
f2c63f66 Thomas Leonard2001-12-20 14:08:57 +0000991static void show_thumbs(gpointer data, guint action, GtkWidget *widget)
6fd9c5fa Thomas Leonard1999-06-23 09:04:06 +0000992{
f2c63f66
TL
Thomas Leonard2001-12-20 14:08:57 +0000993 if (updating_menu)
994 return;
995
6fd9c5fa
TL
Thomas Leonard1999-06-23 09:04:06 +0000996 g_return_if_fail(window_with_focus != NULL);
997
f2c63f66 Thomas Leonard2001-12-20 14:08:57 +0000998 display_set_thumbs(window_with_focus, !window_with_focus->show_thumbs);
6fd9c5fa
TL
Thomas Leonard1999-06-23 09:04:06 +0000999}
1000
f2c63f66 Thomas Leonard2001-12-20 14:08:57 +00001001static void refresh(gpointer data, guint action, GtkWidget *widget)
ea4efd30
TL
Thomas Leonard2000-12-20 18:21:53 +00001002{
1003 g_return_if_fail(window_with_focus != NULL);
1004
559c3031 Thomas Leonard2003-07-28 15:29:37 +00001005 filer_refresh(window_with_focus);
ea4efd30
TL
Thomas Leonard2000-12-20 18:21:53 +00001006}
1007
8bb51514
SW
Stephen Watson2004-04-04 10:20:43 +00001008static void save_settings(gpointer data, guint action, GtkWidget *widget)
1009{
1010 g_return_if_fail(window_with_focus != NULL);
1011
1012 filer_save_settings(window_with_focus);
1013}
1014
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001015static void delete(FilerWindow *filer_window)
0b01e447 Thomas Leonard1999-07-20 13:06:47 +00001016{
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001017 GList *paths;
1018 paths = filer_selected_items(filer_window);
1019 action_delete(paths);
256ca8aa Thomas Leonard2002-10-17 12:58:10 +00001020 destroy_glist(&paths);
496c7467
TL
Thomas Leonard1999-08-05 20:29:17 +00001021}
1022
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001023static void usage(FilerWindow *filer_window)
0ba13389 Thomas Leonard1999-12-01 10:38:01 +00001024{
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001025 GList *paths;
1026 paths = filer_selected_items(filer_window);
1027 action_usage(paths);
256ca8aa Thomas Leonard2002-10-17 12:58:10 +00001028 destroy_glist(&paths);
0ba13389
TL
Thomas Leonard1999-12-01 10:38:01 +00001029}
1030
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001031static void chmod_items(FilerWindow *filer_window)
68f91e74 Thomas Leonard2000-03-12 18:45:50 +00001032{
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001033 GList *paths;
1034 paths = filer_selected_items(filer_window);
0b408fb2 Thomas Leonard2002-07-02 19:25:45 +00001035 action_chmod(paths, FALSE, NULL);
256ca8aa Thomas Leonard2002-10-17 12:58:10 +00001036 destroy_glist(&paths);
68f91e74
TL
Thomas Leonard2000-03-12 18:45:50 +00001037}
1038
68b718ac
SW
Stephen Watson2003-12-02 19:21:24 +00001039static void set_type_items(FilerWindow *filer_window)
1040{
881abaaf
SW
Stephen Watson2004-11-25 20:06:37 +00001041 GList *paths, *p;
1042 int npass=0, nfail=0;
1043
68b718ac Stephen Watson2003-12-02 19:21:24 +00001044 paths = filer_selected_items(filer_window);
881abaaf Stephen Watson2004-11-25 20:06:37 +00001045 for(p=paths; p; p=g_list_next(p)) {
5efcc881 Stephen Watson2005-08-13 13:49:54 +00001046 if(xattr_supported((const char *) p->data))
881abaaf
SW
Stephen Watson2004-11-25 20:06:37 +00001047 npass++;
1048 else
1049 nfail++;
1050 }
1051 if(npass==0)
a7cc76f5
TL
Thomas Leonard2005-01-09 13:08:37 +00001052 report_error(_("Extended attributes, used to store types, are not supported for this "
1053 "file or files.\n"
1054 "This may be due to lack of support from the filesystem or the C library, "
1055 "or it may simply be that the filesystem needs to be mounted with "
1056 "the right mount option ('user_xattr' on Linux)."));
881abaaf
SW
Stephen Watson2004-11-25 20:06:37 +00001057 else if(nfail>0)
1058 report_error(_("Setting type not supported for some of these files"));
1059 if(npass>0)
1060 action_settype(paths, FALSE, NULL);
68b718ac
SW
Stephen Watson2003-12-02 19:21:24 +00001061 destroy_glist(&paths);
1062}
1063
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001064static void find(FilerWindow *filer_window)
41efd0ea Thomas Leonard2000-03-31 22:51:43 +00001065{
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001066 GList *paths;
1067 paths = filer_selected_items(filer_window);
1068 action_find(paths);
256ca8aa Thomas Leonard2002-10-17 12:58:10 +00001069 destroy_glist(&paths);
41efd0ea
TL
Thomas Leonard2000-03-31 22:51:43 +00001070}
1071
4690e561
BJ
Bernard Jungen2008-06-04 21:04:54 +01001072static gboolean last_symlink_check_relative = TRUE;
1073
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001074/* This creates a new savebox widget, and allows the user to pick a new path
1075 * for the file.
4914c5f8
TL
Thomas Leonard2000-03-18 22:20:47 +00001076 * Once the new path has been picked, the callback will be called with
1077 * both the current and new paths.
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001078 * NOTE: This function unrefs 'image'!
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001079 */
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001080static void savebox_show(const gchar *action, const gchar *path,
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +00001081 MaskedPixmap *image, SaveCb callback,
1082 GdkDragAction dnd_action)
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001083{
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001084 GtkWidget *savebox = NULL;
1085 GtkWidget *check_relative = NULL;
1086
8d1e6a6e
TL
Thomas Leonard2001-12-11 16:03:33 +00001087 g_return_if_fail(image != NULL);
1088
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001089 savebox = gtk_savebox_new(action);
56d8304c Thomas Leonard2003-02-23 14:20:42 +00001090 gtk_savebox_set_action(GTK_SAVEBOX(savebox), dnd_action);
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001091
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001092 if (callback == link_cb)
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001093 {
1094 check_relative = gtk_check_button_new_with_mnemonic(
1095 _("_Relative link"));
1096 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_relative),
4690e561 Bernard Jungen2008-06-04 21:04:54 +01001097 last_symlink_check_relative);
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001098
1099 GTK_WIDGET_UNSET_FLAGS(check_relative, GTK_CAN_FOCUS);
1100 gtk_tooltips_set_tip(tooltips, check_relative,
1101 _("If on, the symlink will store the path from the "
1102 "symlink to the target file. Use this if the symlink "
1103 "and the target will be moved together.\n"
1104 "If off, the path from the root directory is stored - "
1105 "use this if the symlink may move but the target will "
1106 "stay put."), NULL);
1107 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(savebox)->vbox),
1108 check_relative, FALSE, TRUE, 0);
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001109 gtk_widget_show(check_relative);
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001110 }
1111
86b6456e
TL
Thomas Leonard2002-03-13 16:44:30 +00001112 g_signal_connect(savebox, "save_to_file",
1113 G_CALLBACK(save_to_file), NULL);
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001114
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001115 g_object_set_data_full(G_OBJECT(savebox), "current_path",
1116 g_strdup(path), g_free);
1117 g_object_set_data(G_OBJECT(savebox), "action_callback", callback);
1118 g_object_set_data(G_OBJECT(savebox), "check_relative", check_relative);
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001119
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001120 gtk_window_set_title(GTK_WINDOW(savebox), action);
b5e1d42d
TL
Thomas Leonard2002-03-21 18:19:06 +00001121
1122 if (g_utf8_validate(path, -1, NULL))
1123 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox), path);
1124 else
1125 {
3273bd20
TL
Thomas Leonard2003-06-30 10:51:06 +00001126 gchar *u8, *dir;
1127 dir = g_path_get_dirname(path);
1128 u8 = to_utf8(g_basename(path));
1129 gtk_savebox_set_pathname(GTK_SAVEBOX(savebox),
1130 make_path(dir, u8));
b5e1d42d Thomas Leonard2002-03-21 18:19:06 +00001131 g_free(u8);
3273bd20 Thomas Leonard2003-06-30 10:51:06 +00001132 g_free(dir);
b5e1d42d Thomas Leonard2002-03-21 18:19:06 +00001133 }
b4db88de Thomas Leonard2002-05-02 14:46:08 +00001134 gtk_savebox_set_icon(GTK_SAVEBOX(savebox), image->pixbuf);
cac37380 Thomas Leonard2002-03-17 18:04:07 +00001135 g_object_unref(image);
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001136
4914c5f8
TL
Thomas Leonard2000-03-18 22:20:47 +00001137 gtk_widget_show(savebox);
1138}
1139
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001140static gint save_to_file(GObject *savebox,
1141 const gchar *pathname, gpointer data)
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001142{
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001143 SaveCb callback;
1144 const gchar *current_path;
1145
1146 callback = g_object_get_data(savebox, "action_callback");
1147 current_path = g_object_get_data(savebox, "current_path");
1148
1149 g_return_val_if_fail(callback != NULL, GTK_XDS_SAVE_ERROR);
1150 g_return_val_if_fail(current_path != NULL, GTK_XDS_SAVE_ERROR);
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001151
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001152 return callback(savebox, current_path, pathname)
4914c5f8
TL
Thomas Leonard2000-03-18 22:20:47 +00001153 ? GTK_XDS_SAVED : GTK_XDS_SAVE_ERROR;
1154}
1155
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001156static gboolean copy_cb(GObject *savebox,
1157 const gchar *current, const gchar *new)
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001158{
92d41b2b
TL
Thomas Leonard2000-07-30 17:27:45 +00001159 return action_with_leaf(action_copy, current, new);
1160}
1161
2d91f96f
TL
Thomas Leonard2002-03-08 16:08:31 +00001162static gboolean action_with_leaf(ActionFn action,
1163 const gchar *current, const gchar *new)
92d41b2b Thomas Leonard2000-07-30 17:27:45 +00001164{
2d91f96f
TL
Thomas Leonard2002-03-08 16:08:31 +00001165 const char *leaf;
1166 char *new_dir;
1167 GList *local_paths;
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001168
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001169 if (new[0] != '/')
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001170 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001171 report_error(_("New pathname is not absolute"));
cfaed676
TL
Thomas Leonard1999-08-11 15:39:05 +00001172 return FALSE;
1173 }
1174
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001175 if (new[strlen(new) - 1] == '/')
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001176 {
4914c5f8 Thomas Leonard2000-03-18 22:20:47 +00001177 new_dir = g_strdup(new);
08ff7a0c Thomas Leonard2000-03-18 13:21:53 +00001178 leaf = NULL;
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001179 }
08ff7a0c Thomas Leonard2000-03-18 13:21:53 +00001180 else
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001181 {
2d91f96f Thomas Leonard2002-03-08 16:08:31 +00001182 const gchar *slash;
08ff7a0c Thomas Leonard2000-03-18 13:21:53 +00001183
4914c5f8
TL
Thomas Leonard2000-03-18 22:20:47 +00001184 slash = strrchr(new, '/');
1185 new_dir = g_strndup(new, slash - new);
08ff7a0c Thomas Leonard2000-03-18 13:21:53 +00001186 leaf = slash + 1;
cfaed676
TL
Thomas Leonard1999-08-11 15:39:05 +00001187 }
1188
2d91f96f Thomas Leonard2002-03-08 16:08:31 +00001189 local_paths = g_list_append(NULL, (gchar *) current);
a652d31e Thomas Leonard2001-11-30 16:56:28 +00001190 action(local_paths, new_dir, leaf, -1);
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001191 g_list_free(local_paths);
08ff7a0c
TL
Thomas Leonard2000-03-18 13:21:53 +00001192
1193 g_free(new_dir);
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001194
08ff7a0c Thomas Leonard2000-03-18 13:21:53 +00001195 return TRUE;
cfaed676
TL
Thomas Leonard1999-08-11 15:39:05 +00001196}
1197
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001198/* Open a savebox to act on the selected file.
1199 * Call 'callback' later to perform the operation.
63a9b2b0 Thomas Leonard2001-11-14 12:00:19 +00001200 */
2d91f96f Thomas Leonard2002-03-08 16:08:31 +00001201static void src_dest_action_item(const gchar *path, MaskedPixmap *image,
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +00001202 const gchar *action, SaveCb callback,
1203 GdkDragAction dnd_action)
cfaed676 Thomas Leonard1999-08-11 15:39:05 +00001204{
cac37380 Thomas Leonard2002-03-17 18:04:07 +00001205 g_object_ref(image);
56d8304c Thomas Leonard2003-02-23 14:20:42 +00001206 savebox_show(action, path, image, callback, dnd_action);
cfaed676
TL
Thomas Leonard1999-08-11 15:39:05 +00001207}
1208
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001209static gboolean rename_cb(GObject *savebox,
1210 const gchar *current, const gchar *new)
f94990cd Thomas Leonard1999-08-04 12:53:48 +00001211{
92d41b2b Thomas Leonard2000-07-30 17:27:45 +00001212 return action_with_leaf(action_move, current, new);
f94990cd
TL
Thomas Leonard1999-08-04 12:53:48 +00001213}
1214
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001215static gboolean link_cb(GObject *savebox,
1216 const gchar *initial, const gchar *path)
ec042fc6 Thomas Leonard1999-08-13 11:18:11 +00001217{
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001218 GtkToggleButton *check_relative;
b7accdb4 Thomas Leonard2002-05-03 15:40:25 +00001219 struct stat info;
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001220 int err;
b7accdb4 Thomas Leonard2002-05-03 15:40:25 +00001221 gchar *link_path;
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001222
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001223 check_relative = g_object_get_data(savebox, "check_relative");
1224
4690e561
BJ
Bernard Jungen2008-06-04 21:04:54 +01001225 last_symlink_check_relative = gtk_toggle_button_get_active(check_relative);
1226
1227 if (last_symlink_check_relative)
b7accdb4
TL
Thomas Leonard2002-05-03 15:40:25 +00001228 link_path = get_relative_path(path, initial);
1229 else
1230 link_path = g_strdup(initial);
1231
1232 if (mc_lstat(path, &info) == 0 && S_ISLNK(info.st_mode))
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001233 {
b7accdb4
TL
Thomas Leonard2002-05-03 15:40:25 +00001234 GtkWidget *box, *button;
1235 gint ans;
1236
1237 box = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION,
1238 GTK_BUTTONS_CANCEL,
1239 _("Symlink from '%s' already exists. "
1240 "Replace it with a link to '%s'?"),
1241 path, link_path);
1242
1243 gtk_window_set_position(GTK_WINDOW(box), GTK_WIN_POS_MOUSE);
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001244
b7accdb4
TL
Thomas Leonard2002-05-03 15:40:25 +00001245 button = button_new_mixed(GTK_STOCK_YES, _("_Replace"));
1246 gtk_widget_show(button);
1247 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1248 gtk_dialog_add_action_widget(GTK_DIALOG(box),
1249 button, GTK_RESPONSE_OK);
1250 gtk_dialog_set_default_response(GTK_DIALOG(box),
1251 GTK_RESPONSE_OK);
1252
1253 ans = gtk_dialog_run(GTK_DIALOG(box));
1254 gtk_widget_destroy(box);
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001255
b7accdb4
TL
Thomas Leonard2002-05-03 15:40:25 +00001256 if (ans != GTK_RESPONSE_OK)
1257 {
1258 g_free(link_path);
1259 return FALSE;
1260 }
1261
1262 unlink(path);
1a0564ce Thomas Leonard2001-04-11 12:10:25 +00001263 }
b7accdb4
TL
Thomas Leonard2002-05-03 15:40:25 +00001264
1265 err = symlink(link_path, path);
1266 g_free(link_path);
1a0564ce
TL
Thomas Leonard2001-04-11 12:10:25 +00001267
1268 if (err)
ec042fc6 Thomas Leonard1999-08-13 11:18:11 +00001269 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001270 report_error("symlink: %s", g_strerror(errno));
ec042fc6
TL
Thomas Leonard1999-08-13 11:18:11 +00001271 return FALSE;
1272 }
5b5b1ff3
TL
Thomas Leonard2002-01-21 12:11:09 +00001273
1274 dir_check_this(path);
1275
ec042fc6
TL
Thomas Leonard1999-08-13 11:18:11 +00001276 return TRUE;
1277}
1278
42a9b56e Thomas Leonard2001-12-13 17:29:38 +00001279static void run_action(DirItem *item)
214bd481 Thomas Leonard2000-01-07 14:35:58 +00001280{
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001281 if (can_set_run_action(item))
1282 type_set_handler_dialog(item->mime_type);
b7262c9a Thomas Leonard2000-09-06 21:15:09 +00001283 else
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001284 report_error(
1285 _("You can only set the run action for a "
1286 "regular file"));
b7262c9a
TL
Thomas Leonard2000-09-06 21:15:09 +00001287}
1288
2b2163f0
TL
Thomas Leonard2000-08-30 18:38:57 +00001289void open_home(gpointer data, guint action, GtkWidget *widget)
1290{
a1896c55 Thomas Leonard2002-08-30 14:29:27 +00001291 filer_opendir(home_dir, NULL, NULL);
2b2163f0
TL
Thomas Leonard2000-08-30 18:38:57 +00001292}
1293
85c09878
TL
Thomas Leonard1999-07-30 13:07:21 +00001294static void select_all(gpointer data, guint action, GtkWidget *widget)
1295{
1296 g_return_if_fail(window_with_focus != NULL);
1297
d092d8e9 Thomas Leonard1999-08-06 15:11:37 +00001298 window_with_focus->temp_item_selected = FALSE;
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +00001299 view_select_all(window_with_focus->view);
85c09878
TL
Thomas Leonard1999-07-30 13:07:21 +00001300}
1301
1302static void clear_selection(gpointer data, guint action, GtkWidget *widget)
1303{
1304 g_return_if_fail(window_with_focus != NULL);
1305
d092d8e9 Thomas Leonard1999-08-06 15:11:37 +00001306 window_with_focus->temp_item_selected = FALSE;
3b6cef86 Thomas Leonard2002-06-20 15:42:08 +00001307 view_clear_selection(window_with_focus->view);
3082fab2
TL
Thomas Leonard2001-12-02 16:34:08 +00001308}
1309
f671e2e4
TL
Thomas Leonard2002-08-11 14:26:39 +00001310static gboolean invert_cb(ViewIter *iter, gpointer data)
1311{
1312 return !view_get_selected((ViewIface *) data, iter);
1313}
1314
3082fab2
TL
Thomas Leonard2001-12-02 16:34:08 +00001315static void invert_selection(gpointer data, guint action, GtkWidget *widget)
1316{
1317 g_return_if_fail(window_with_focus != NULL);
1318
3082fab2 Thomas Leonard2001-12-02 16:34:08 +00001319 window_with_focus->temp_item_selected = FALSE;
f671e2e4
TL
Thomas Leonard2002-08-11 14:26:39 +00001320
1321 view_select_if(window_with_focus->view, invert_cb,
1322 window_with_focus->view);
85c09878
TL
Thomas Leonard1999-07-30 13:07:21 +00001323}
1324
e73bc442 Thomas Leonard2000-08-16 17:31:24 +00001325void menu_show_options(gpointer data, guint action, GtkWidget *widget)
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +00001326{
c5e51eea
TL
Thomas Leonard2002-04-25 16:40:59 +00001327 GtkWidget *win;
1328
1329 win = options_show();
1330
1331 if (win)
1332 {
1333 number_of_windows++;
1334 g_signal_connect(win, "destroy",
30c262f5 Thomas Leonard2002-06-01 14:39:52 +00001335 G_CALLBACK(one_less_window), NULL);
c5e51eea Thomas Leonard2002-04-25 16:40:59 +00001336 }
a841079f
TL
Thomas Leonard1999-07-28 15:11:09 +00001337}
1338
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001339static gboolean new_directory_cb(GObject *savebox,
1340 const gchar *initial, const gchar *path)
f94990cd
TL
Thomas Leonard1999-08-04 12:53:48 +00001341{
1342 if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO))
1343 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001344 report_error("mkdir: %s", g_strerror(errno));
f94990cd
TL
Thomas Leonard1999-08-04 12:53:48 +00001345 return FALSE;
1346 }
db0961c9
TL
Thomas Leonard2000-07-19 17:47:15 +00001347
1348 dir_check_this(path);
8ae0d54d
TL
Thomas Leonard2001-04-05 20:54:36 +00001349
1350 if (filer_exists(window_with_focus))
1351 {
1352 guchar *leaf;
1353 leaf = strrchr(path, '/');
1354 if (leaf)
1355 display_set_autoselect(window_with_focus, leaf + 1);
1356 }
1357
f94990cd
TL
Thomas Leonard1999-08-04 12:53:48 +00001358 return TRUE;
1359}
1360
a841079f
TL
Thomas Leonard1999-07-28 15:11:09 +00001361static void new_directory(gpointer data, guint action, GtkWidget *widget)
1362{
1363 g_return_if_fail(window_with_focus != NULL);
1364
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001365 savebox_show(_("Create"),
5971abb0 Thomas Leonard2002-12-10 12:26:53 +00001366 make_path(window_with_focus->sym_path, _("NewDir")),
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +00001367 type_to_icon(inode_directory), new_directory_cb,
1368 GDK_ACTION_COPY);
a1ff9747
TL
Thomas Leonard1999-07-23 15:17:02 +00001369}
1370
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001371static gboolean new_file_cb(GObject *savebox,
1372 const gchar *initial, const gchar *path)
f31d6615
TL
Thomas Leonard2001-02-20 13:32:14 +00001373{
1374 int fd;
1375
1376 fd = open(path, O_CREAT | O_EXCL, 0666);
1377
1378 if (fd == -1)
1379 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001380 report_error(_("Error creating '%s': %s"),
76954893 Thomas Leonard2001-11-06 14:08:03 +00001381 path, g_strerror(errno));
f31d6615
TL
Thomas Leonard2001-02-20 13:32:14 +00001382 return FALSE;
1383 }
1384
1385 if (close(fd))
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001386 report_error(_("Error creating '%s': %s"),
76954893 Thomas Leonard2001-11-06 14:08:03 +00001387 path, g_strerror(errno));
f31d6615
TL
Thomas Leonard2001-02-20 13:32:14 +00001388
1389 dir_check_this(path);
1390
8ae0d54d
TL
Thomas Leonard2001-04-05 20:54:36 +00001391 if (filer_exists(window_with_focus))
1392 {
1393 guchar *leaf;
1394 leaf = strrchr(path, '/');
1395 if (leaf)
1396 display_set_autoselect(window_with_focus, leaf + 1);
1397 }
1398
f31d6615
TL
Thomas Leonard2001-02-20 13:32:14 +00001399 return TRUE;
1400}
1401
1402static void new_file(gpointer data, guint action, GtkWidget *widget)
1403{
1404 g_return_if_fail(window_with_focus != NULL);
1405
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001406 savebox_show(_("Create"),
5971abb0 Thomas Leonard2002-12-10 12:26:53 +00001407 make_path(window_with_focus->sym_path, _("NewFile")),
b2bca2a1 Thomas Leonard2002-04-25 15:40:47 +00001408 type_to_icon(text_plain),
56d8304c Thomas Leonard2003-02-23 14:20:42 +00001409 new_file_cb, GDK_ACTION_COPY);
f31d6615
TL
Thomas Leonard2001-02-20 13:32:14 +00001410}
1411
ab7d6488
TL
Thomas Leonard2002-03-09 14:43:17 +00001412static gboolean new_file_type_cb(GObject *savebox,
1413 const gchar *initial, const gchar *path)
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001414{
2d91f96f Thomas Leonard2002-03-08 16:08:31 +00001415 const gchar *oleaf, *leaf;
437a288e Bernard Jungen2008-06-04 21:05:56 +01001416 gchar *templ, *rtempl, *templ_dname, *dest;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001417 GList *paths;
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +00001418
1419 /* We can work out the template path from the initial name */
1420 oleaf = g_basename(initial);
6967aa47 Stephen Watson2005-04-25 18:02:14 +00001421 templ_dname = choices_find_xdg_path_load("Templates", "", SITE);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +00001422 if (!templ_dname)
1423 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001424 report_error(
76954893
TL
Thomas Leonard2001-11-06 14:08:03 +00001425 _("Error creating file: could not find the template for %s"),
1426 oleaf);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +00001427 return FALSE;
1428 }
1429
1430 templ = g_strconcat(templ_dname, "/", oleaf, NULL);
1431 g_free(templ_dname);
437a288e
BJ
Bernard Jungen2008-06-04 21:05:56 +01001432 rtempl = pathdup(templ);
1433 g_free(templ);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001434
2997763d Thomas Leonard2002-10-26 15:17:06 +00001435 dest = g_path_get_dirname(path);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001436 leaf = g_basename(path);
437a288e Bernard Jungen2008-06-04 21:05:56 +01001437 paths = g_list_append(NULL, rtempl);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001438
c8392551 Thomas Leonard2002-04-17 11:00:27 +00001439 action_copy(paths, dest, leaf, TRUE);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001440
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001441 g_list_free(paths);
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001442 g_free(dest);
437a288e Bernard Jungen2008-06-04 21:05:56 +01001443 g_free(rtempl);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +00001444
1445 if (filer_exists(window_with_focus))
1446 display_set_autoselect(window_with_focus, leaf);
1447
1448 return TRUE;
1449}
1450
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +00001451static void do_send_to(gchar *templ)
1452{
1453 g_return_if_fail(send_to_paths != NULL);
1454
1455 run_with_files(templ, send_to_paths);
1456}
1457
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001458static void new_file_type(gchar *templ)
8fbeea5d Thomas Leonard2001-06-21 10:44:48 +00001459{
e4ef82bd Thomas Leonard2002-03-08 18:06:04 +00001460 const gchar *leaf;
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +00001461 MIME_type *type;
1462
1463 g_return_if_fail(window_with_focus != NULL);
1464
1465 leaf = g_basename(templ);
1466 type = type_get_type(templ);
1467
ab7d6488 Thomas Leonard2002-03-09 14:43:17 +00001468 savebox_show(_("Create"),
5971abb0 Thomas Leonard2002-12-10 12:26:53 +00001469 make_path(window_with_focus->sym_path, leaf),
b2bca2a1 Thomas Leonard2002-04-25 15:40:47 +00001470 type_to_icon(type),
56d8304c Thomas Leonard2003-02-23 14:20:42 +00001471 new_file_type_cb, GDK_ACTION_COPY);
8fbeea5d
TL
Thomas Leonard2001-06-21 10:44:48 +00001472}
1473
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001474static void customise_send_to(gpointer data)
1475{
1476 GPtrArray *path;
76954893 Thomas Leonard2001-11-06 14:08:03 +00001477 guchar *save;
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001478 GString *dirs;
1479 int i;
1480
1481 dirs = g_string_new(NULL);
1482
032e2a45 Stephen Watson2005-04-25 20:04:18 +00001483 path = choices_list_xdg_dirs("", SITE);
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001484 for (i = 0; i < path->len; i++)
1485 {
1486 guchar *old = (guchar *) path->pdata[i];
1487
1488 g_string_append(dirs, old);
032e2a45 Stephen Watson2005-04-25 20:04:18 +00001489 g_string_append(dirs, "/SendTo\n");
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001490 }
1491 choices_free_list(path);
1492
6967aa47 Stephen Watson2005-04-25 18:02:14 +00001493 save = choices_find_xdg_path_save("", "SendTo", SITE, TRUE);
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001494 if (save)
1495 mkdir(save, 0777);
1496
308dbc5a Thomas Leonard2002-03-20 11:59:41 +00001497 info_message(
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001498 _("The `Send To' menu provides a quick way to send some files "
1499 "to an application. The applications listed are those in "
1500 "the following directories:\n\n%s\n%s\n"
1501 "The `Send To' menu may be opened by Shift+Menu clicking "
02385b9d
TL
Thomas Leonard2002-05-12 13:30:45 +00001502 "over a file.\n\n"
1503 "Advanced use:\n"
1504 "You can also create subdirectories called "
1505 "`.text_html', `.text', etc which will only be "
1506 "shown for files of that type. `.group' is shown "
1507 "only when multiple files are selected."),
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001508 dirs->str,
1509 save ? _("I'll show you your SendTo directory now; you should "
1510 "symlink (Ctrl+Shift drag) any applications you want "
1511 "into it.")
6827a12d
TL
Thomas Leonard2001-08-24 11:29:13 +00001512 : _("Your CHOICESPATH variable setting prevents "
1513 "customisations - sorry."));
62490356
TL
Thomas Leonard2005-03-12 21:08:59 +00001514
1515 g_string_free(dirs, TRUE);
1516
1517 if (save)
1518 filer_opendir(save, NULL, NULL);
1519}
1520
1521static void customise_new(gpointer data)
1522{
1523 GPtrArray *path;
1524 guchar *save;
1525 GString *dirs;
1526 int i;
1527
1528 dirs = g_string_new(NULL);
1529
032e2a45 Stephen Watson2005-04-25 20:04:18 +00001530 path = choices_list_xdg_dirs("", SITE);
62490356
TL
Thomas Leonard2005-03-12 21:08:59 +00001531 for (i = 0; i < path->len; i++)
1532 {
1533 guchar *old = (guchar *) path->pdata[i];
1534
1535 g_string_append(dirs, old);
032e2a45 Stephen Watson2005-04-25 20:04:18 +00001536 g_string_append(dirs, "/Templates\n");
62490356
TL
Thomas Leonard2005-03-12 21:08:59 +00001537 }
1538 choices_free_list(path);
1539
6967aa47 Stephen Watson2005-04-25 18:02:14 +00001540 save = choices_find_xdg_path_save("", "Templates", SITE, TRUE);
62490356
TL
Thomas Leonard2005-03-12 21:08:59 +00001541 if (save)
1542 mkdir(save, 0777);
1543
1544 info_message(
1545 _("Any files placed in your Templates directories will "
1546 "appear on the `New' menu. Choosing one of them will make "
1547 "a copy of it as the new file.\n\n"
1548 "The following directories contain templates:\n\n%s\n%s\n"),
1549 dirs->str,
1550 save ? _("I'll show you your Templates directory now; you "
1551 "should place any template files you want inside it.")
1552 : _("Your CHOICESPATH variable setting prevents "
1553 "customisations - sorry."));
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001554
1555 g_string_free(dirs, TRUE);
1556
dc9020e8 Thomas Leonard2001-08-23 14:09:30 +00001557 if (save)
a1896c55 Thomas Leonard2002-08-30 14:29:27 +00001558 filer_opendir(save, NULL, NULL);
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001559}
1560
02385b9d
TL
Thomas Leonard2002-05-12 13:30:45 +00001561/* Add everything in the directory <Choices>/SendTo/[.type[_subtype]]
1562 * to the menu.
dce3d041 Thomas Leonard2001-08-22 11:58:38 +00001563 */
02385b9d Thomas Leonard2002-05-12 13:30:45 +00001564static void add_sendto(GtkWidget *menu, const gchar *type, const gchar *subtype)
dce3d041 Thomas Leonard2001-08-22 11:58:38 +00001565{
02385b9d
TL
Thomas Leonard2002-05-12 13:30:45 +00001566 gchar *searchdir;
1567 GPtrArray *paths;
1568 int i;
1569
1570 if (subtype)
1571 searchdir = g_strdup_printf("SendTo/.%s_%s", type, subtype);
1572 else if (type)
1573 searchdir = g_strdup_printf("SendTo/.%s", type);
1574 else
1575 searchdir = g_strdup("SendTo");
dce3d041 Thomas Leonard2001-08-22 11:58:38 +00001576
032e2a45 Stephen Watson2005-04-25 20:04:18 +00001577 paths = choices_list_xdg_dirs(searchdir, SITE);
02385b9d Thomas Leonard2002-05-12 13:30:45 +00001578 g_free(searchdir);
8b822640 Thomas Leonard2001-08-27 14:52:37 +00001579
02385b9d Thomas Leonard2002-05-12 13:30:45 +00001580 for (i = 0; i < paths->len; i++)
dce3d041 Thomas Leonard2001-08-22 11:58:38 +00001581 {
8b822640 Thomas Leonard2001-08-27 14:52:37 +00001582 GList *widgets = NULL;
02385b9d Thomas Leonard2002-05-12 13:30:45 +00001583 guchar *dir = (guchar *) paths->pdata[i];
8b822640 Thomas Leonard2001-08-27 14:52:37 +00001584
07e4b22c Thomas Leonard2001-09-09 14:13:29 +00001585 widgets = menu_from_dir(menu, dir, get_menu_icon_style(),
02385b9d
TL
Thomas Leonard2002-05-12 13:30:45 +00001586 (CallbackFn) do_send_to,
1587 FALSE, FALSE, TRUE);
dce3d041 Thomas Leonard2001-08-22 11:58:38 +00001588
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001589 if (widgets)
1590 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
1591 gtk_menu_item_new());
1592
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +00001593 g_list_free(widgets); /* TODO: Get rid of this */
1594 }
1595
02385b9d
TL
Thomas Leonard2002-05-12 13:30:45 +00001596 choices_free_list(paths);
1597}
1598
1599/* Scan the SendTo dir and create and show the Send To menu.
1600 * The 'paths' list and every path in it is claimed, and will be
1601 * freed later -- don't free it yourself!
1602 */
1603static void show_send_to_menu(GList *paths, GdkEvent *event)
1604{
1605 GtkWidget *menu, *item;
1606
1607 menu = gtk_menu_new();
1608
1609 if (g_list_length(paths) == 1)
1610 {
1611 DirItem *item;
1612
1613 item = diritem_new("");
1614 diritem_restat(paths->data, item, NULL);
1615
1616 add_sendto(menu,
1617 item->mime_type->media_type,
1618 item->mime_type->subtype);
1619
1620 add_sendto(menu, item->mime_type->media_type, NULL);
1621
1622 diritem_free(item);
1623 }
1624 else
2bebb2f7
SW
Stephen Watson2004-05-29 14:04:36 +00001625 {
1626 GList *rover;
1627 gboolean same=TRUE, same_media=TRUE;
1628 MIME_type *type=NULL;
1629 DirItem *item;
1630
1631 item = diritem_new("");
1632 for(rover=paths; rover; rover=g_list_next(rover))
1633 {
1634 diritem_restat(rover->data, item, NULL);
1635 if(!type)
1636 type=item->mime_type;
1637 else
1638 {
1639 if(type!=item->mime_type)
1640 {
1641 same=FALSE;
1642 if(strcmp(type->media_type,
1643 item->mime_type->media_type)!=0)
1644 {
1645 same_media=FALSE;
1646 break;
1647 }
1648 }
1649 }
1650 }
1651 diritem_free(item);
1652
1653 if(type)
1654 {
1655 if(same)
1656 add_sendto(menu, type->media_type,
1657 type->subtype);
1658 if(same_media)
1659 add_sendto(menu, type->media_type, NULL);
1660 }
1661
02385b9d Thomas Leonard2002-05-12 13:30:45 +00001662 add_sendto(menu, "group", NULL);
2bebb2f7 Stephen Watson2004-05-29 14:04:36 +00001663 }
02385b9d
TL
Thomas Leonard2002-05-12 13:30:45 +00001664
1665 add_sendto(menu, NULL, NULL);
8b822640 Thomas Leonard2001-08-27 14:52:37 +00001666
dc9020e8 Thomas Leonard2001-08-23 14:09:30 +00001667 item = gtk_menu_item_new_with_label(_("Customise"));
86b6456e
TL
Thomas Leonard2002-03-13 16:44:30 +00001668 g_signal_connect_swapped(item, "activate",
1669 G_CALLBACK(customise_send_to), NULL);
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001670 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1671
dce3d041 Thomas Leonard2001-08-22 11:58:38 +00001672 if (send_to_paths)
256ca8aa
TL
Thomas Leonard2002-10-17 12:58:10 +00001673 destroy_glist(&send_to_paths);
1674
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +00001675 send_to_paths = paths;
1676
86b6456e Thomas Leonard2002-03-13 16:44:30 +00001677 g_signal_connect(menu, "unmap_event", G_CALLBACK(menu_closed), NULL);
dce3d041
TL
Thomas Leonard2001-08-22 11:58:38 +00001678
1679 popup_menu = menu;
1680 show_popup_menu(menu, event, 0);
1681}
1682
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001683static void send_to(FilerWindow *filer_window)
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001684{
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001685 GList *paths;
1686 GdkEvent *event;
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001687
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001688 paths = filer_selected_items(filer_window);
1689 event = gtk_get_current_event();
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001690
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001691 /* Eats paths */
1692 show_send_to_menu(paths, event);
ccb93f45 Thomas Leonard2001-08-10 11:16:00 +00001693
3220e1a5
TL
Thomas Leonard2005-08-01 07:10:20 +00001694 if (event)
1695 gdk_event_free(event);
ccb93f45
TL
Thomas Leonard2001-08-10 11:16:00 +00001696}
1697
a1ff9747
TL
Thomas Leonard1999-07-23 15:17:02 +00001698static void xterm_here(gpointer data, guint action, GtkWidget *widget)
1699{
2d91f96f Thomas Leonard2002-03-08 16:08:31 +00001700 const char *argv[] = {"sh", "-c", NULL, NULL};
cc2e5525 Thomas Leonard2002-06-08 13:10:26 +00001701 gboolean close = action;
5b440173 Thomas Leonard1999-09-30 13:48:52 +00001702
ad4a5534 Thomas Leonard2002-02-20 18:15:43 +00001703 argv[2] = o_menu_xterm.value;
a1ff9747
TL
Thomas Leonard1999-07-23 15:17:02 +00001704
1705 g_return_if_fail(window_with_focus != NULL);
1706
cc2e5525
TL
Thomas Leonard2002-06-08 13:10:26 +00001707 if (rox_spawn(window_with_focus->sym_path, argv) && close)
1708 gtk_widget_destroy(window_with_focus->window);
a1ff9747
TL
Thomas Leonard1999-07-23 15:17:02 +00001709}
1710
bbe66c4b
TL
Thomas Leonard2001-03-14 15:45:30 +00001711static void home_directory(gpointer data, guint action, GtkWidget *widget)
1712{
1713 g_return_if_fail(window_with_focus != NULL);
1714
1715 filer_change_to(window_with_focus, home_dir, NULL);
1716}
1717
ad60a44a
TL
Thomas Leonard2002-12-01 19:19:30 +00001718static void show_bookmarks(gpointer data, guint action, GtkWidget *widget)
1719{
1720 g_return_if_fail(window_with_focus != NULL);
1721
1722 bookmarks_show_menu(window_with_focus);
1723}
1724
572c7202
TL
Thomas Leonard2007-08-19 12:39:02 +01001725static void show_log(gpointer data, guint action, GtkWidget *widget)
1726{
1727 g_return_if_fail(window_with_focus != NULL);
1728
1729 log_show_window();
1730}
1731
38be87fc
TL
Thomas Leonard2002-05-17 15:05:53 +00001732static void follow_symlinks(gpointer data, guint action, GtkWidget *widget)
1733{
1734 g_return_if_fail(window_with_focus != NULL);
1735
1736 if (strcmp(window_with_focus->real_path, window_with_focus->sym_path))
1737 filer_change_to(window_with_focus,
1738 window_with_focus->real_path, NULL);
1739 else
1740 delayed_error(_("This is already the canonical name "
1741 "for this directory."));
1742}
1743
ab588714
TL
Thomas Leonard1999-06-17 15:07:06 +00001744static void open_parent(gpointer data, guint action, GtkWidget *widget)
1745{
6fd9c5fa
TL
Thomas Leonard1999-06-23 09:04:06 +00001746 g_return_if_fail(window_with_focus != NULL);
1747
8f79e109 Thomas Leonard2000-04-23 12:19:09 +00001748 filer_open_parent(window_with_focus);
ab588714 Thomas Leonard1999-06-17 15:07:06 +00001749}
a1ff9747 Thomas Leonard1999-07-23 15:17:02 +00001750
e5df6718
TL
Thomas Leonard1999-11-14 13:09:17 +00001751static void open_parent_same(gpointer data, guint action, GtkWidget *widget)
1752{
1753 g_return_if_fail(window_with_focus != NULL);
1754
1755 change_to_parent(window_with_focus);
1756}
1757
b69128bf
TL
Thomas Leonard2000-12-28 19:20:14 +00001758static void resize(gpointer data, guint action, GtkWidget *widget)
1759{
1760 g_return_if_fail(window_with_focus != NULL);
1761
66d33128 Thomas Leonard2002-12-24 13:30:17 +00001762 view_autosize(window_with_focus->view);
b69128bf
TL
Thomas Leonard2000-12-28 19:20:14 +00001763}
1764
e5df6718
TL
Thomas Leonard1999-11-14 13:09:17 +00001765static void new_window(gpointer data, guint action, GtkWidget *widget)
1766{
1767 g_return_if_fail(window_with_focus != NULL);
1768
89a24bf0 Thomas Leonard2002-02-20 17:48:27 +00001769 if (o_unique_filer_windows.int_value)
45383ac1 Thomas Leonard2000-11-11 19:26:17 +00001770 {
e59eeee4 Thomas Leonard2001-11-26 13:53:11 +00001771 report_error(_("You can't open a second view onto "
8de9a519 Thomas Leonard2000-03-12 19:13:13 +00001772 "this directory because the `Unique Windows' option "
45312373 Thomas Leonard2000-04-18 11:21:45 +00001773 "is turned on in the Options window."));
45383ac1 Thomas Leonard2000-11-11 19:26:17 +00001774 }
8de9a519 Thomas Leonard2000-03-12 19:13:13 +00001775 else
a1896c55 Thomas Leonard2002-08-30 14:29:27 +00001776 filer_opendir(window_with_focus->sym_path, window_with_focus, NULL);
e5df6718
TL
Thomas Leonard1999-11-14 13:09:17 +00001777}
1778
1779static void close_window(gpointer data, guint action, GtkWidget *widget)
1780{
1781 g_return_if_fail(window_with_focus != NULL);
1782
48f63bc2
TL
Thomas Leonard2003-06-04 15:37:48 +00001783 if (!filer_window_delete(window_with_focus->window, NULL,
1784 window_with_focus))
1785 gtk_widget_destroy(window_with_focus->window);
e5df6718
TL
Thomas Leonard1999-11-14 13:09:17 +00001786}
1787
63a9b2b0 Thomas Leonard2001-11-14 12:00:19 +00001788static void mini_buffer(gpointer data, guint action, GtkWidget *widget)
5a706d99 Thomas Leonard2000-05-25 20:49:07 +00001789{
b48b2760
TL
Thomas Leonard2002-01-23 13:33:06 +00001790 MiniType type = (MiniType) action;
1791
5a706d99
TL
Thomas Leonard2000-05-25 20:49:07 +00001792 g_return_if_fail(window_with_focus != NULL);
1793
b48b2760
TL
Thomas Leonard2002-01-23 13:33:06 +00001794 /* Item needs to remain selected... */
1795 if (type == MINI_SHELL)
1796 window_with_focus->temp_item_selected = FALSE;
1797
1798 minibuffer_show(window_with_focus, type);
5a706d99
TL
Thomas Leonard2000-05-25 20:49:07 +00001799}
1800
e73bc442 Thomas Leonard2000-08-16 17:31:24 +00001801void menu_rox_help(gpointer data, guint action, GtkWidget *widget)
214bd481 Thomas Leonard2000-01-07 14:35:58 +00001802{
67134d89
TL
Thomas Leonard2002-07-12 12:47:38 +00001803 if (action == HELP_ABOUT)
1804 infobox_new(app_dir);
1805 else if (action == HELP_DIR)
5971abb0 Thomas Leonard2002-12-10 12:26:53 +00001806 filer_opendir(make_path(app_dir, "Help"), NULL, NULL);
4db98e05
TL
Thomas Leonard2002-07-12 12:55:09 +00001807 else if (action == HELP_MANUAL)
1808 {
497ed8db Thomas Leonard2002-07-13 14:38:10 +00001809 gchar *manual = NULL;
4db98e05 Thomas Leonard2002-07-12 12:55:09 +00001810
497ed8db Thomas Leonard2002-07-13 14:38:10 +00001811 if (current_lang)
4db98e05 Thomas Leonard2002-07-12 12:55:09 +00001812 {
497ed8db
TL
Thomas Leonard2002-07-13 14:38:10 +00001813 manual = g_strconcat(app_dir, "/Help/Manual-",
1814 current_lang, ".html", NULL);
943903e9
TL
Thomas Leonard2005-08-27 16:11:23 +00001815 if (!file_exists(manual) && strchr(current_lang, '_'))
1816 {
1817 /* Try again without the territory */
1818 strcpy(strrchr(manual, '_'), ".html");
1819 }
1820 if (!file_exists(manual))
256ca8aa Thomas Leonard2002-10-17 12:58:10 +00001821 null_g_free(&manual);
497ed8db
TL
Thomas Leonard2002-07-13 14:38:10 +00001822 }
1823
1824 if (!manual)
4db98e05
TL
Thomas Leonard2002-07-12 12:55:09 +00001825 manual = g_strconcat(app_dir,
1826 "/Help/Manual.html", NULL);
4db98e05
TL
Thomas Leonard2002-07-12 12:55:09 +00001827
1828 run_by_path(manual);
1829
1830 g_free(manual);
1831 }
67134d89
TL
Thomas Leonard2002-07-12 12:47:38 +00001832 else
1833 g_warning("Unknown help action %d\n", action);
214bd481
TL
Thomas Leonard2000-01-07 14:35:58 +00001834}
1835
b2b6a9ee Thomas Leonard2000-07-17 17:16:43 +00001836/* Set n items from position 'from' in 'menu' to the 'shaded' state */
862cbefe Thomas Leonard2000-08-17 18:30:59 +00001837void menu_set_items_shaded(GtkWidget *menu, gboolean shaded, int from, int n)
b2b6a9ee
TL
Thomas Leonard2000-07-17 17:16:43 +00001838{
1839 GList *items, *item;
1840
86b6456e Thomas Leonard2002-03-13 16:44:30 +00001841 items = gtk_container_get_children(GTK_CONTAINER(menu));
b2b6a9ee
TL
Thomas Leonard2000-07-17 17:16:43 +00001842
1843 item = g_list_nth(items, from);
1844 while (item && n--)
1845 {
1846 gtk_widget_set_sensitive(GTK_BIN(item->data)->child, !shaded);
1847 item = item->next;
1848 }
1849 g_list_free(items);
1850}
1851
1852static void save_menus(void)
1853{
1854 char *menurc;
5b509326 Thomas Leonard2001-11-24 17:42:42 +00001855
6967aa47 Stephen Watson2005-04-25 18:02:14 +00001856 menurc = choices_find_xdg_path_save(MENUS_NAME, PROJECT, SITE, TRUE);
5b509326
TL
Thomas Leonard2001-11-24 17:42:42 +00001857 if (menurc)
1858 {
1859 gtk_accel_map_save(menurc);
1860 g_free(menurc);
1861 }
2658eef1
TL
Thomas Leonard2000-07-28 21:11:07 +00001862}
1863
b5f57111
TL
Thomas Leonard2001-04-29 14:09:39 +00001864static void select_nth_item(GtkMenuShell *shell, int n)
1865{
30c262f5
TL
Thomas Leonard2002-06-01 14:39:52 +00001866 GList *items;
1867 GtkWidget *item;
b5f57111 Thomas Leonard2001-04-29 14:09:39 +00001868
86b6456e Thomas Leonard2002-03-13 16:44:30 +00001869 items = gtk_container_get_children(GTK_CONTAINER(shell));
30c262f5 Thomas Leonard2002-06-01 14:39:52 +00001870 item = g_list_nth_data(items, n);
7314c995 Thomas Leonard2001-08-23 13:34:05 +00001871
30c262f5 Thomas Leonard2002-06-01 14:39:52 +00001872 g_return_if_fail(item != NULL);
7314c995 Thomas Leonard2001-08-23 13:34:05 +00001873
dc9020e8
TL
Thomas Leonard2001-08-23 14:09:30 +00001874 g_list_free(items);
1875
b5f57111
TL
Thomas Leonard2001-04-29 14:09:39 +00001876 gtk_menu_shell_select_item(shell, item);
1877}
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001878
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +00001879static void file_op(gpointer data, FileOp action, GtkWidget *unused)
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001880{
42a9b56e Thomas Leonard2001-12-13 17:29:38 +00001881 DirItem *item;
5971abb0 Thomas Leonard2002-12-10 12:26:53 +00001882 const guchar *path;
5777df6b Thomas Leonard2002-06-11 14:47:07 +00001883 int n_selected;
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +00001884 ViewIter iter;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001885
1886 g_return_if_fail(window_with_focus != NULL);
1887
3b6cef86 Thomas Leonard2002-06-20 15:42:08 +00001888 n_selected = view_count_selected(window_with_focus->view);
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001889
5777df6b Thomas Leonard2002-06-11 14:47:07 +00001890 if (n_selected < 1)
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001891 {
2d91f96f Thomas Leonard2002-03-08 16:08:31 +00001892 const char *prompt;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001893
1894 switch (action)
1895 {
1896 case FILE_COPY_ITEM:
1897 prompt = _("Copy ... ?");
1898 break;
1899 case FILE_RENAME_ITEM:
1900 prompt = _("Rename ... ?");
1901 break;
1902 case FILE_LINK_ITEM:
1903 prompt = _("Symlink ... ?");
1904 break;
1905 case FILE_OPEN_FILE:
1906 prompt = _("Shift Open ... ?");
1907 break;
05cbc244
TL
Thomas Leonard2003-11-17 10:32:22 +00001908 case FILE_PROPERTIES:
1909 prompt = _("Properties of ... ?");
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00001910 break;
68b718ac
SW
Stephen Watson2003-12-02 19:21:24 +00001911 case FILE_SET_TYPE:
1912 prompt = _("Set type of ... ?");
1913 break;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001914 case FILE_RUN_ACTION:
1915 prompt = _("Set run action for ... ?");
1916 break;
1917 case FILE_SET_ICON:
1918 prompt = _("Set icon for ... ?");
1919 break;
1920 case FILE_SEND_TO:
1921 prompt = _("Send ... to ... ?");
1922 break;
1923 case FILE_DELETE:
1924 prompt = _("DELETE ... ?");
1925 break;
1926 case FILE_USAGE:
1927 prompt = _("Count the size of ... ?");
1928 break;
1929 case FILE_CHMOD_ITEMS:
1930 prompt = _("Set permissions on ... ?");
1931 break;
1932 case FILE_FIND:
1933 prompt = _("Search inside ... ?");
1934 break;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001935 default:
1936 g_warning("Unknown action!");
1937 return;
1938 }
1939 filer_target_mode(window_with_focus, target_callback,
1940 GINT_TO_POINTER(action), prompt);
1941 return;
1942 }
1943
1944 switch (action)
1945 {
1946 case FILE_SEND_TO:
1947 send_to(window_with_focus);
1948 return;
1949 case FILE_DELETE:
1950 delete(window_with_focus);
1951 return;
1952 case FILE_USAGE:
1953 usage(window_with_focus);
1954 return;
1955 case FILE_CHMOD_ITEMS:
1956 chmod_items(window_with_focus);
1957 return;
68b718ac
SW
Stephen Watson2003-12-02 19:21:24 +00001958 case FILE_SET_TYPE:
1959 set_type_items(window_with_focus);
1960 return;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001961 case FILE_FIND:
1962 find(window_with_focus);
1963 return;
05cbc244 Thomas Leonard2003-11-17 10:32:22 +00001964 case FILE_PROPERTIES:
30c262f5
TL
Thomas Leonard2002-06-01 14:39:52 +00001965 {
1966 GList *items;
1967
1968 items = filer_selected_items(window_with_focus);
1969 infobox_show_list(items);
256ca8aa Thomas Leonard2002-10-17 12:58:10 +00001970 destroy_glist(&items);
30c262f5
TL
Thomas Leonard2002-06-01 14:39:52 +00001971 return;
1972 }
a7cc76f5
TL
Thomas Leonard2005-01-09 13:08:37 +00001973 case FILE_RENAME_ITEM:
1974 if (n_selected > 1)
1975 {
1976 GList *items = NULL;
1977 ViewIter iter;
1978
1979 view_get_iter(window_with_focus->view, &iter, VIEW_ITER_SELECTED);
1980 while ((item = iter.next(&iter)))
1981 items = g_list_prepend(items, item->leafname);
1982 items = g_list_reverse(items);
1983
1984 bulk_rename(window_with_focus->sym_path, items);
1985 g_list_free(items);
1986 return;
1987 }
1988 break; /* Not a bulk rename... see below */
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001989 default:
1990 break;
1991 }
1992
1993 /* All the following actions require exactly one file selected */
1994
5777df6b Thomas Leonard2002-06-11 14:47:07 +00001995 if (n_selected > 1)
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00001996 {
1997 report_error(_("You cannot do this to more than "
1998 "one item at a time"));
1999 return;
2000 }
2001
f671e2e4
TL
Thomas Leonard2002-08-11 14:26:39 +00002002 view_get_iter(window_with_focus->view, &iter, VIEW_ITER_SELECTED);
2003
2004 item = iter.next(&iter);
42a9b56e Thomas Leonard2001-12-13 17:29:38 +00002005 g_return_if_fail(item != NULL);
8930adbd Thomas Leonard2002-09-03 14:11:15 +00002006 /* iter may be passed to filer_openitem... */
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +00002007
dff573ef Thomas Leonard2004-09-21 16:44:34 +00002008 if (item->base_type == TYPE_UNKNOWN)
42a9b56e
TL
Thomas Leonard2001-12-13 17:29:38 +00002009 item = dir_update_item(window_with_focus->directory,
2010 item->leafname);
2011
2012 if (!item)
2013 {
2014 report_error(_("Item no longer exists!"));
2015 return;
2016 }
2017
5971abb0 Thomas Leonard2002-12-10 12:26:53 +00002018 path = make_path(window_with_focus->sym_path, item->leafname);
42a9b56e Thomas Leonard2001-12-13 17:29:38 +00002019
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002020 switch (action)
2021 {
2022 case FILE_COPY_ITEM:
dff573ef Thomas Leonard2004-09-21 16:44:34 +00002023 src_dest_action_item(path, di_image(item),
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +00002024 _("Copy"), copy_cb,
2025 GDK_ACTION_COPY);
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002026 break;
2027 case FILE_RENAME_ITEM:
dff573ef Thomas Leonard2004-09-21 16:44:34 +00002028 src_dest_action_item(path, di_image(item),
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +00002029 _("Rename"), rename_cb,
2030 GDK_ACTION_MOVE);
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002031 break;
2032 case FILE_LINK_ITEM:
dff573ef Thomas Leonard2004-09-21 16:44:34 +00002033 src_dest_action_item(path, di_image(item),
56d8304c
TL
Thomas Leonard2003-02-23 14:20:42 +00002034 _("Symlink"), link_cb,
2035 GDK_ACTION_LINK);
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002036 break;
2037 case FILE_OPEN_FILE:
f671e2e4 Thomas Leonard2002-08-11 14:26:39 +00002038 filer_openitem(window_with_focus, &iter,
30c262f5 Thomas Leonard2002-06-01 14:39:52 +00002039 OPEN_SAME_WINDOW | OPEN_SHIFT);
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00002040 break;
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00002041 case FILE_RUN_ACTION:
42a9b56e Thomas Leonard2001-12-13 17:29:38 +00002042 run_action(item);
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002043 break;
2044 case FILE_SET_ICON:
42a9b56e Thomas Leonard2001-12-13 17:29:38 +00002045 icon_set_handler_dialog(item, path);
8c18ee07 Thomas Leonard2001-12-12 21:06:00 +00002046 break;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002047 default:
2048 g_warning("Unknown action!");
2049 return;
8c18ee07
TL
Thomas Leonard2001-12-12 21:06:00 +00002050 }
2051}
2052
f7646571
TL
Thomas Leonard2002-03-08 12:37:38 +00002053static void show_key_help(GtkWidget *button, gpointer data)
2054{
26d6e9a8
TL
Thomas Leonard2002-04-16 10:57:53 +00002055 gboolean can_change_accels;
2056
2057 g_object_get(G_OBJECT(gtk_settings_get_default()),
2058 "gtk-can-change-accels", &can_change_accels,
2059 NULL);
2060
2061 if (!can_change_accels)
2062 {
2063 info_message(_("User-definable shortcuts are disabled by "
2064 "default in Gtk2, and you have not enabled "
8a1ebd19
TL
Thomas Leonard2003-10-07 09:09:32 +00002065 "them. You can turn this feature on by:\n\n"
2066 "1) using an XSettings manager, such as ROX-Session "
2067 "or gnome-settings-daemon, or\n\n"
26d6e9a8 Thomas Leonard2002-04-16 10:57:53 +00002068 "2) adding this line to ~/.gtkrc-2.0:\n"
8a1ebd19
TL
Thomas Leonard2003-10-07 09:09:32 +00002069 "\tgtk-can-change-accels = 1\n"
2070 "\t(this only works if NOT using XSETTINGS)"));
26d6e9a8
TL
Thomas Leonard2002-04-16 10:57:53 +00002071 return;
2072 }
2073
308dbc5a Thomas Leonard2002-03-20 11:59:41 +00002074 info_message(_("To set a keyboard short-cut for a menu item:\n\n"
f7646571
TL
Thomas Leonard2002-03-08 12:37:38 +00002075 "- Open the menu over a filer window,\n"
2076 "- Move the pointer over the item you want to use,\n"
2077 "- Press the key you want attached to it.\n\n"
2078 "The key will appear next to the menu item and you can just press "
2079 "that key without opening the menu in future."));
2080}
2081
2082static GList *set_keys_button(Option *option, xmlNode *node, guchar *label)
2083{
2084 GtkWidget *button, *align;
2085
2086 g_return_val_if_fail(option == NULL, NULL);
2087
2fb9d632
TL
Thomas Leonard2002-12-09 16:08:44 +00002088 align = gtk_alignment_new(0, 0.5, 0, 0);
2089 button = gtk_button_new_with_label(_("Set keyboard shortcuts"));
f7646571 Thomas Leonard2002-03-08 12:37:38 +00002090 gtk_container_add(GTK_CONTAINER(align), button);
86b6456e Thomas Leonard2002-03-13 16:44:30 +00002091 g_signal_connect(button, "clicked", G_CALLBACK(show_key_help), NULL);
f7646571
TL
Thomas Leonard2002-03-08 12:37:38 +00002092
2093 return g_list_append(NULL, align);
2094}