annotate src/gui_gtk.c @ 7939:dcc0bd6b1574 v7.4.1265

commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 5 23:09:12 2016 +0100 patch 7.4.1265 Problem: Not all channel commands are tested. Solution: Add a test for "normal", "expr" and "redraw".
author Christian Brabandt <cb@256bit.org>
date Fri, 05 Feb 2016 23:15:04 +0100
parents 81794242a275
children 3456e2ebebd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * Porting to GTK+ was done by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
68
a97c6902ecd9 updated for version 7.0030
vimboss
parents: 41
diff changeset
13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * With GREAT support and continuous encouragements by Andy Kahn and of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * course Bram Moolenaar!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * Support for GTK+ 2 was added by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 * Daniel Elstner <daniel.elstner@gmx.net>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * Best supporting actor (He helped somewhat, aesthetically speaking):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * Maxime Romano <verbophobe@hotmail.com>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 # include "gui_gtk_f.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 /* GTK defines MAX and MIN, but some system header files as well. Undefine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * them and don't use them. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #ifdef MIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # undef MIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #ifdef MAX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 # undef MAX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 #ifdef FEAT_GUI_GNOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 /* Gnome redefines _() and N_(). Grrr... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 # ifdef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # undef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 # ifdef N_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 # undef N_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 # ifdef textdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 # undef textdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 # ifdef bindtextdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 # undef bindtextdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 # endif
1286
152e52624521 updated for version 7.1-001
vimboss
parents: 1215
diff changeset
56 # ifdef bind_textdomain_codeset
152e52624521 updated for version 7.1-001
vimboss
parents: 1215
diff changeset
57 # undef bind_textdomain_codeset
1215
1d08aac0aea9 updated for version 7.1b
vimboss
parents: 1025
diff changeset
58 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 # include <gnome.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 #ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 # include <gdk/gdkkeysyms.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 # include <gdk/gdk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 # ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 # include <gdk/gdkwin32.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 # include <gdk/gdkx.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 # include <gtk/gtk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 /* define these items to be able to generate prototypes without GTK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 typedef int GtkWidget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 # define gpointer int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 # define guint8 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 # define GdkPixmap int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 # define GdkBitmap int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 # define GtkIconFactory int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 # define GtkToolbar int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 # define GtkAdjustment int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 # define gboolean int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 # define GdkEventKey int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 # define CancelData int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 static void entry_activate_cb(GtkWidget *widget, gpointer data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 static void find_replace_cb(GtkWidget *widget, gpointer data);
3564
8d1b63e6d317 updated for version 7.3.542
Bram Moolenaar <bram@vim.org>
parents: 3484
diff changeset
93 #if defined(FEAT_BROWSE) || defined(PROTO)
3484
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
94 static void recent_func_log_func(
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
95 const gchar *log_domain,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
96 GLogLevelFlags log_level,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
97 const gchar *message,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
98 gpointer user_data);
3564
8d1b63e6d317 updated for version 7.3.542
Bram Moolenaar <bram@vim.org>
parents: 3484
diff changeset
99 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
101 #if defined(FEAT_TOOLBAR)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 * Table from BuiltIn## icon indices to GTK+ stock IDs. Order must exactly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 * match toolbar_names[] in menu.c! All stock icons including the "vim-*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 * ones can be overridden in your gtkrc file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 static const char * const menu_stock_ids[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 /* 00 */ GTK_STOCK_NEW,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 /* 01 */ GTK_STOCK_OPEN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 /* 02 */ GTK_STOCK_SAVE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 /* 03 */ GTK_STOCK_UNDO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 /* 04 */ GTK_STOCK_REDO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 /* 05 */ GTK_STOCK_CUT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 /* 06 */ GTK_STOCK_COPY,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /* 07 */ GTK_STOCK_PASTE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 /* 08 */ GTK_STOCK_PRINT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 /* 09 */ GTK_STOCK_HELP,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 /* 10 */ GTK_STOCK_FIND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 /* 11 */ "vim-save-all",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 /* 12 */ "vim-session-save",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 /* 13 */ "vim-session-new",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 /* 14 */ "vim-session-load",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 /* 15 */ GTK_STOCK_EXECUTE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 /* 16 */ GTK_STOCK_FIND_AND_REPLACE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 /* 17 */ GTK_STOCK_CLOSE, /* FIXME: fuzzy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 /* 18 */ "vim-window-maximize",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 /* 19 */ "vim-window-minimize",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 /* 20 */ "vim-window-split",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 /* 21 */ "vim-shell",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 /* 22 */ GTK_STOCK_GO_BACK,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 /* 23 */ GTK_STOCK_GO_FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 /* 24 */ "vim-find-help",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 /* 25 */ GTK_STOCK_CONVERT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 /* 26 */ GTK_STOCK_JUMP_TO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 /* 27 */ "vim-build-tags",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /* 28 */ "vim-window-split-vertical",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 /* 29 */ "vim-window-maximize-width",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 /* 30 */ "vim-window-minimize-width",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 /* 31 */ GTK_STOCK_QUIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142
7380
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
143 #ifdef USE_GRESOURCE
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
144 typedef struct IconNames {
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
145 const char *icon_name;
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
146 const char *file_name;
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
147 } IconNames;
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
148
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
149 static IconNames stock_vim_icons[] = {
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
150 { "vim-build-tags", "stock_vim_build_tags.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
151 { "vim-find-help", "stock_vim_find_help.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
152 { "vim-save-all", "stock_vim_save_all.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
153 { "vim-session-load", "stock_vim_session_load.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
154 { "vim-session-new", "stock_vim_session_new.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
155 { "vim-session-save", "stock_vim_session_save.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
156 { "vim-shell", "stock_vim_shell.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
157 { "vim-window-maximize", "stock_vim_window_maximize.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
158 { "vim-window-maximize-width", "stock_vim_window_maximize_width.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
159 { "vim-window-minimize", "stock_vim_window_minimize.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
160 { "vim-window-minimize-width", "stock_vim_window_minimize_width.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
161 { "vim-window-split", "stock_vim_window_split.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
162 { "vim-window-split-vertical", "stock_vim_window_split_vertical.png" },
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
163 { NULL, NULL }
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
164 };
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
165 #endif
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
166
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
167 #ifndef USE_GRESOURCE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 add_stock_icon(GtkIconFactory *factory,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 const char *stock_id,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 const guint8 *inline_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 int data_length)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 GdkPixbuf *pixbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 GtkIconSet *icon_set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 pixbuf = gdk_pixbuf_new_from_inline(data_length, inline_data, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 gtk_icon_factory_add(factory, stock_id, icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 gtk_icon_set_unref(icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 g_object_unref(pixbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 }
7380
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
185 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 lookup_menu_iconfile(char_u *iconfile, char_u *dest)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 expand_env(iconfile, dest, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 if (mch_isFullName(dest))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 return vim_fexists(dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 static const char suffixes[][4] = {"png", "xpm", "bmp"};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 char_u buf[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 unsigned int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 for (i = 0; i < G_N_ELEMENTS(suffixes); ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 if (gui_find_bitmap(dest, buf, (char *)suffixes[i]) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 STRCPY(dest, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 load_menu_iconfile(char_u *name, GtkIconSize icon_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 GtkWidget *image = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 GtkIconSet *icon_set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 GtkIconSource *icon_source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 * Rather than loading the icon directly into a GtkImage, create
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 * a new GtkIconSet and put it in there. This way we can easily
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 * scale the toolbar icons on the fly when needed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 icon_set = gtk_icon_set_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 icon_source = gtk_icon_source_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 gtk_icon_source_set_filename(icon_source, (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 gtk_icon_set_add_source(icon_set, icon_source);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 image = gtk_image_new_from_icon_set(icon_set, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 gtk_icon_source_free(icon_source);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 gtk_icon_set_unref(icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 return image;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 create_menu_icon(vimmenu_T *menu, GtkIconSize icon_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 GtkWidget *image = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 char_u buf[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 /* First use a specified "icon=" argument. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 if (menu->iconfile != NULL && lookup_menu_iconfile(menu->iconfile, buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 image = load_menu_iconfile(buf, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 /* If not found and not builtin specified try using the menu name. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 if (image == NULL && !menu->icon_builtin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 && lookup_menu_iconfile(menu->name, buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 image = load_menu_iconfile(buf, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 /* Still not found? Then use a builtin icon, a blank one as fallback. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 if (image == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 const char *stock_id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 const int n_ids = G_N_ELEMENTS(menu_stock_ids);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 if (menu->iconidx >= 0 && menu->iconidx < n_ids)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 stock_id = menu_stock_ids[menu->iconidx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 stock_id = GTK_STOCK_MISSING_IMAGE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 image = gtk_image_new_from_stock(stock_id, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 return image;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
271 static gint
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
272 toolbar_button_focus_in_event(GtkWidget *widget UNUSED,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
273 GdkEventFocus *event UNUSED,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
274 gpointer data UNUSED)
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
275 {
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
276 /* When we're in a GtkPlug, we don't have window focus events, only widget
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
277 * focus. To emulate stand-alone gvim, if a button gets focus (e.g.,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
278 * <Tab> into GtkPlug) immediately pass it to mainwin. */
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
279 if (gtk_socket_id != 0)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
280 gtk_widget_grab_focus(gui.drawarea);
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
281
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
282 return TRUE;
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
283 }
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
284 #endif /* FEAT_TOOLBAR */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
286 #if defined(FEAT_TOOLBAR) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 gui_gtk_register_stock_icons(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 {
7380
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
291 #ifndef USE_GRESOURCE
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
292 # include "../pixmaps/stock_icons.h"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 GtkIconFactory *factory;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 factory = gtk_icon_factory_new();
7380
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
296 # define ADD_ICON(Name, Data) add_stock_icon(factory, Name, Data, (int)sizeof(Data))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 ADD_ICON("vim-build-tags", stock_vim_build_tags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 ADD_ICON("vim-find-help", stock_vim_find_help);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 ADD_ICON("vim-save-all", stock_vim_save_all);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 ADD_ICON("vim-session-load", stock_vim_session_load);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 ADD_ICON("vim-session-new", stock_vim_session_new);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 ADD_ICON("vim-session-save", stock_vim_session_save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 ADD_ICON("vim-shell", stock_vim_shell);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 ADD_ICON("vim-window-maximize", stock_vim_window_maximize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 ADD_ICON("vim-window-maximize-width", stock_vim_window_maximize_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 ADD_ICON("vim-window-minimize", stock_vim_window_minimize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 ADD_ICON("vim-window-minimize-width", stock_vim_window_minimize_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 ADD_ICON("vim-window-split", stock_vim_window_split);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 ADD_ICON("vim-window-split-vertical", stock_vim_window_split_vertical);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
7380
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
312 # undef ADD_ICON
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
313 #else
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
314 GtkIconFactory * const factory = gtk_icon_factory_new();
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
315 const char * const path_prefix = "/org/vim/gui/icon";
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
316 IconNames *names;
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
317
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
318 for (names = stock_vim_icons; names->icon_name != NULL; names++)
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
319 {
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
320 char path[MAXPATHL];
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
321 GdkPixbuf *pixbuf;
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
322
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
323 vim_snprintf(path, MAXPATHL, "%s/%s", path_prefix, names->file_name);
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
324 pixbuf = gdk_pixbuf_new_from_resource(path, NULL);
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
325 if (pixbuf != NULL)
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
326 {
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
327 GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
328 gtk_icon_factory_add(factory, names->icon_name, icon_set);
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
329 gtk_icon_set_unref(icon_set);
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
330 g_object_unref(pixbuf);
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
331 }
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
332 }
055a0b587a3e commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents: 5092
diff changeset
333 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 gtk_icon_factory_add_default(factory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 g_object_unref(factory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
338 #endif /* FEAT_TOOLBAR */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 * Translate Vim's mnemonic tagging to GTK+ style and convert to UTF-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 * if necessary. The caller must vim_free() the returned string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 * Input Output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 * _ __
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 * && &
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 * & _ stripped if use_mnemonic == FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 * <Tab> end of menu label text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 translate_mnemonic_tag(char_u *name, int use_mnemonic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 char_u *psrc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 char_u *pdest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 int n_underscores = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 name = CONVERT_TO_UTF8(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 if (*psrc == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 ++n_underscores;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 buf = alloc((unsigned)(psrc - name + n_underscores + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 pdest = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 if (*psrc == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 else if (*psrc != '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 *pdest++ = *psrc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 else if (*(psrc + 1) == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 *pdest++ = *psrc++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 else if (use_mnemonic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 *pdest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 CONVERT_TO_UTF8_FREE(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 GtkWidget *box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 int use_mnemonic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 /* It would be neat to have image menu items, but that would require major
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 * changes to Vim's menu system. Not to mention that all the translations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 * had to be updated. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 menu->id = gtk_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 box = gtk_hbox_new(FALSE, 20);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 use_mnemonic = (p_wak[0] != 'n' || !GTK_IS_MENU_BAR(parent_widget));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 text = translate_mnemonic_tag(menu->name, use_mnemonic);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 menu->label = gtk_label_new_with_mnemonic((const char *)text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 vim_free(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 gtk_box_pack_start(GTK_BOX(box), menu->label, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 if (menu->actext != NULL && menu->actext[0] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 text = CONVERT_TO_UTF8(menu->actext);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 gtk_box_pack_end(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 gtk_label_new((const char *)text),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 gtk_container_add(GTK_CONTAINER(menu->id), box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 gtk_widget_show_all(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 gui_mch_add_menu(vimmenu_T *menu, int idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 vimmenu_T *parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 GtkWidget *parent_widget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 if (menu->name[0] == ']' || menu_is_popup(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 menu->submenu_id = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 parent = menu->parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 if ((parent != NULL && parent->submenu_id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 || !menu_is_menubar(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 parent_widget = (parent != NULL) ? parent->submenu_id : gui.menubar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 menu_item_new(menu, parent_widget);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 /* since the tearoff should always appear first, increment idx */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 if (parent != NULL && !menu_is_popup(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 ++idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 gtk_menu_shell_insert(GTK_MENU_SHELL(parent_widget), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 menu->submenu_id = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 gtk_menu_set_accel_group(GTK_MENU(menu->submenu_id), gui.accel_group);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->id), menu->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 menu->tearoff_handle = gtk_tearoff_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 if (vim_strchr(p_go, GO_TEAROFF) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 gtk_widget_show(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 gtk_menu_prepend(GTK_MENU(menu->submenu_id), menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
475 menu_item_activate(GtkWidget *widget UNUSED, gpointer data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 gui_menu_cb((vimmenu_T *)data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 gui_mch_add_menu_item(vimmenu_T *menu, int idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 vimmenu_T *parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 parent = menu->parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 # ifdef FEAT_TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 if (menu_is_toolbar(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 GtkToolbar *toolbar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 toolbar = GTK_TOOLBAR(gui.toolbar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 menu->submenu_id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 gtk_toolbar_insert_space(toolbar, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 menu->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 char_u *tooltip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 text = CONVERT_TO_UTF8(menu->dname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
26
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
507 if (tooltip != NULL && !utf_valid_string(tooltip, NULL))
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
508 /* Invalid text, can happen when 'encoding' is changed. Avoid
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
509 * a nasty GTK error message, skip the tooltip. */
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
510 CONVERT_TO_UTF8_FREE(tooltip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 menu->id = gtk_toolbar_insert_item(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 toolbar,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 (const char *)text,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 (const char *)tooltip,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 create_menu_icon(menu, gtk_toolbar_get_icon_size(toolbar)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 G_CALLBACK(&menu_item_activate),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 menu,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
522 if (gtk_socket_id != 0)
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
523 gtk_signal_connect(GTK_OBJECT(menu->id), "focus_in_event",
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
524 GTK_SIGNAL_FUNC(toolbar_button_focus_in_event), NULL);
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
525
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 CONVERT_TO_UTF8_FREE(tooltip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 # endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 /* No parent, must be a non-menubar menu */
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
534 if (parent == NULL || parent->submenu_id == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 /* Make place for the possible tearoff handle item. Not in the popup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 * menu, it doesn't have a tearoff item. */
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
539 if (!menu_is_popup(parent->name))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 ++idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 /* Separator: Just add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 menu->id = gtk_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 gtk_widget_set_sensitive(menu->id, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 gtk_widget_show(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 /* Add textual menu item. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 menu_item_new(menu, parent->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 gtk_widget_show(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 gtk_signal_connect(GTK_OBJECT(menu->id), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 GTK_SIGNAL_FUNC(menu_item_activate), menu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 gui_mch_set_text_area_pos(int x, int y, int w, int h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 gtk_form_move_resize(GTK_FORM(gui.formwin), gui.drawarea, x, y, w, h);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 /*
1215
1d08aac0aea9 updated for version 7.1b
vimboss
parents: 1025
diff changeset
575 * Enable or disable accelerators for the toplevel menus.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 gui_gtk_set_mnemonics(int enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 vimmenu_T *menu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 for (menu = root_menu; menu != NULL; menu = menu->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 if (menu->id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 name = translate_mnemonic_tag(menu->name, enable);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 gtk_label_set_text_with_mnemonic(GTK_LABEL(menu->label),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 recurse_tearoffs(vimmenu_T *menu, int val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 for (; menu != NULL; menu = menu->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 if (menu->submenu_id != NULL && menu->tearoff_handle != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 && menu->name[0] != ']' && !menu_is_popup(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 if (val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 gtk_widget_show(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 gtk_widget_hide(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 recurse_tearoffs(menu->children, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 gui_mch_toggle_tearoffs(int enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 recurse_tearoffs(root_menu, enable);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
619 #if defined(FEAT_TOOLBAR)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 get_menu_position(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 vimmenu_T *node;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
624 int idx = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 for (node = menu->parent->children; node != menu; node = node->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 g_return_val_if_fail(node != NULL, -1);
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
629 ++idx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
632 return idx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 }
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
634 #endif /* FEAT_TOOLBAR */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 #if defined(FEAT_TOOLBAR) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 gui_mch_menu_set_tip(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 if (menu->id != NULL && menu->parent != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 && gui.toolbar != NULL && menu_is_toolbar(menu->parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 char_u *tooltip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
26
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
647 if (tooltip == NULL || utf_valid_string(tooltip, NULL))
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
648 /* Only set the tooltip when it's valid utf-8. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 gtk_tooltips_set_tip(GTK_TOOLBAR(gui.toolbar)->tooltips,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 menu->id, (const char *)tooltip, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 CONVERT_TO_UTF8_FREE(tooltip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 #endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 * Destroy the machine specific menu widget.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 gui_mch_destroy_menu(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 {
5092
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
664 /* Don't let gtk_container_remove automatically destroy menu->id. */
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
665 if (menu->id != NULL)
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
666 g_object_ref(menu->id);
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
667
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
668 /* Workaround for a spurious gtk warning in Ubuntu: "Trying to remove
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
669 * a child that doesn't believe we're it's parent."
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
670 * Remove widget from gui.menubar before destroying it. */
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
671 if (menu->id != NULL && gui.menubar != NULL
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
672 && gtk_widget_get_parent(menu->id) == gui.menubar)
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
673 gtk_container_remove(GTK_CONTAINER(gui.menubar), menu->id);
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
674
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 # ifdef FEAT_TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 if (menu->parent != NULL && menu_is_toolbar(menu->parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 gtk_toolbar_remove_space(GTK_TOOLBAR(gui.toolbar),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 get_menu_position(menu));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 else if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 gtk_widget_destroy(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 # endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 if (menu->submenu_id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 gtk_widget_destroy(menu->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 gtk_widget_destroy(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693
5092
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
694 if (menu->id != NULL)
1ed945570d47 updated for version 7.3.1289
Bram Moolenaar <bram@vim.org>
parents: 3871
diff changeset
695 g_object_unref(menu->id);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 menu->submenu_id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 menu->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 * Scrollbar stuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 gui_mch_set_scrollbar_thumb(scrollbar_T *sb, long val, long size, long max)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 GtkAdjustment *adjustment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 adjustment->lower = 0.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 adjustment->value = val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 adjustment->upper = max + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 adjustment->page_size = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 adjustment->page_increment = size < 3L ? 1L : size - 2L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 adjustment->step_increment = 1.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 g_signal_handler_block(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 (gulong)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 gtk_adjustment_changed(adjustment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 g_signal_handler_unblock(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 (gulong)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 gtk_form_move_resize(GTK_FORM(gui.formwin), sb->id, x, y, w, h);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 * Take action upon scrollbar dragging.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 adjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 scrollbar_T *sb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 long value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 int dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 #ifdef FEAT_XIM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 /* cancel any preediting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 if (im_is_preediting())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 xim_reset();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 sb = gui_find_scrollbar((long)data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 value = (long)adjustment->value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 * The dragging argument must be right for the scrollbar to work with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 * closed folds. This isn't documented, hopefully this will keep on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 * working in later GTK versions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 * FIXME: Well, it doesn't work in GTK2. :)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 * HACK: Get the mouse pointer position, if it appears to be on an arrow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 * button set "dragging" to FALSE. This assumes square buttons!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 if (sb != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 dragging = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 if (sb->wp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 int y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 GdkModifierType state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 int height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 /* vertical scrollbar: need to set "dragging" properly in case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 * there are closed folds. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 gdk_window_get_pointer(sb->id->window, &x, &y, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 gdk_window_get_size(sb->id->window, &width, &height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 if (x >= 0 && x < width && y >= 0 && y < height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 if (y < width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 /* up arrow: move one (closed fold) line up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 value = sb->wp->w_topline - 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 else if (y > height - width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 /* down arrow: move one (closed fold) line down */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 value = sb->wp->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 gui_drag_scrollbar(sb, value, dragging);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 /* SBAR_VERT or SBAR_HORIZ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 gui_mch_create_scrollbar(scrollbar_T *sb, int orient)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 if (orient == SBAR_HORIZ)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 sb->id = gtk_hscrollbar_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 else if (orient == SBAR_VERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 sb->id = gtk_vscrollbar_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 GtkAdjustment *adjustment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 GTK_WIDGET_UNSET_FLAGS(sb->id, GTK_CAN_FOCUS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 gtk_form_put(GTK_FORM(gui.formwin), sb->id, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 sb->handler_id = gtk_signal_connect(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 GTK_OBJECT(adjustment), "value_changed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 GTK_SIGNAL_FUNC(adjustment_value_changed),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 GINT_TO_POINTER(sb->ident));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 gui_mch_update();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 #if defined(FEAT_WINDOWS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 gui_mch_destroy_scrollbar(scrollbar_T *sb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 gtk_widget_destroy(sb->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 sb->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 gui_mch_update();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 #if defined(FEAT_BROWSE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 * Implementation of the file selector related stuff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 */
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
843
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
844 #ifndef USE_FILE_CHOOSER
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
846 browse_ok_cb(GtkWidget *widget UNUSED, gpointer cbdata)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 gui_T *vw = (gui_T *)cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 if (vw->browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 g_free(vw->browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 GTK_FILE_SELECTION(vw->filedlg)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 gtk_widget_hide(vw->filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
859 browse_cancel_cb(GtkWidget *widget UNUSED, gpointer cbdata)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 gui_T *vw = (gui_T *)cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 if (vw->browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 g_free(vw->browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 vw->browse_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 gtk_widget_hide(vw->filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 static gboolean
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
872 browse_destroy_cb(GtkWidget *widget UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 if (gui.browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 g_free(gui.browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 gui.browse_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 gui.filedlg = NULL;
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
880 gtk_main_quit();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 }
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
883 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 * Put up a file requester.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 * Returns the selected name in allocated memory, or NULL for Cancel.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 * saving, select file to write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 * title title for the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 * dflt default name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 * ext not used (extension added)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 * initdir initial directory, NULL for current dir
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 * filter not used (file name filter)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 char_u *
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
896 gui_mch_browse(int saving UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 char_u *title,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 char_u *dflt,
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
899 char_u *ext UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 char_u *initdir,
3664
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
901 char_u *filter)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 {
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
903 #ifdef USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
904 GtkWidget *fc;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
905 #endif
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
906 char_u dirbuf[MAXPATHL];
3484
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
907 guint log_handler;
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
908 const gchar *domain = "Gtk";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 title = CONVERT_TO_UTF8(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911
1003
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
912 /* GTK has a bug, it only works with an absolute path. */
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
913 if (initdir == NULL || *initdir == NUL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
914 mch_dirname(dirbuf, MAXPATHL);
1003
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
915 else if (vim_FullName(initdir, dirbuf, MAXPATHL - 2, FALSE) == FAIL)
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
916 dirbuf[0] = NUL;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
917 /* Always need a trailing slash for a directory. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
918 add_pathsep(dirbuf);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
919
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
920 /* If our pointer is currently hidden, then we should show it. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
921 gui_mch_mousehide(FALSE);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
922
3484
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
923 /* Hack: The GTK file dialog warns when it can't access a new file, this
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
924 * makes it shut up. http://bugzilla.gnome.org/show_bug.cgi?id=664587 */
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
925 log_handler = g_log_set_handler(domain, G_LOG_LEVEL_WARNING,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
926 recent_func_log_func, NULL);
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
927
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
928 #ifdef USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
929 /* We create the dialog each time, so that the button text can be "Open"
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
930 * or "Save" according to the action. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
931 fc = gtk_file_chooser_dialog_new((const gchar *)title,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
932 GTK_WINDOW(gui.mainwin),
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
933 saving ? GTK_FILE_CHOOSER_ACTION_SAVE
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
934 : GTK_FILE_CHOOSER_ACTION_OPEN,
1025
b6627f01c67d updated for version 7.0-151
vimboss
parents: 1003
diff changeset
935 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
936 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
937 NULL);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
938 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
939 (const gchar *)dirbuf);
3664
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
940
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
941 if (filter != NULL && *filter != NUL)
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
942 {
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
943 int i = 0;
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
944 char_u *patt;
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
945 char_u *p = filter;
3871
337a4368fd2b updated for version 7.3.692
Bram Moolenaar <bram@vim.org>
parents: 3666
diff changeset
946 GtkFileFilter *gfilter;
3664
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
947
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
948 gfilter = gtk_file_filter_new();
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
949 patt = alloc(STRLEN(filter));
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
950 while (p != NULL && *p != NUL)
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
951 {
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
952 if (*p == '\n' || *p == ';' || *p == '\t')
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
953 {
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
954 STRNCPY(patt, filter, i);
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
955 patt[i] = '\0';
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
956 if (*p == '\t')
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
957 gtk_file_filter_set_name(gfilter, (gchar *)patt);
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
958 else
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
959 {
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
960 gtk_file_filter_add_pattern(gfilter, (gchar *)patt);
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
961 if (*p == '\n')
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
962 {
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
963 gtk_file_chooser_add_filter((GtkFileChooser *)fc,
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
964 gfilter);
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
965 if (*(p + 1) != NUL)
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
966 gfilter = gtk_file_filter_new();
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
967 }
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
968 }
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
969 filter = ++p;
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
970 i = 0;
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
971 }
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
972 else
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
973 {
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
974 p++;
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
975 i++;
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
976 }
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
977 }
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
978 vim_free(patt);
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
979 }
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
980 if (saving && dflt != NULL && *dflt != NUL)
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
981 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt);
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
982
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
983 gui.browse_fname = NULL;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
984 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
986 char *filename;
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
987
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
988 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
989 gui.browse_fname = (char_u *)g_strdup(filename);
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
990 g_free(filename);
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
991 }
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
992 gtk_widget_destroy(GTK_WIDGET(fc));
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
993
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
994 #else
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
995
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
996 if (gui.filedlg == NULL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
997 {
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
998 GtkFileSelection *fs; /* shortcut */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
999
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 gui.filedlg = gtk_file_selection_new((const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 gtk_window_set_modal(GTK_WINDOW(gui.filedlg), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 gtk_window_set_transient_for(GTK_WINDOW(gui.filedlg),
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1003 GTK_WINDOW(gui.mainwin));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 fs = GTK_FILE_SELECTION(gui.filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 gtk_container_border_width(GTK_CONTAINER(fs), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 gtk_signal_connect(GTK_OBJECT(fs->ok_button),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 "clicked", GTK_SIGNAL_FUNC(browse_ok_cb), &gui);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 gtk_signal_connect(GTK_OBJECT(fs->cancel_button),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 "clicked", GTK_SIGNAL_FUNC(browse_cancel_cb), &gui);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 /* gtk_signal_connect() doesn't work for destroy, it causes a hang */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 gtk_signal_connect_object(GTK_OBJECT(gui.filedlg),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 "destroy", GTK_SIGNAL_FUNC(browse_destroy_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 GTK_OBJECT(gui.filedlg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 gtk_window_set_title(GTK_WINDOW(gui.filedlg), (const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019
1003
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
1020 /* Concatenate "initdir" and "dflt". */
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
1021 if (dflt != NULL && *dflt != NUL
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
1022 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL)
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
1023 STRCAT(dirbuf, dflt);
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
1024
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 (const gchar *)dirbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 gtk_widget_show(gui.filedlg);
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
1029 gtk_main();
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1030 #endif
3484
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
1031 g_log_remove_handler(domain, log_handler);
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1032
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1033 CONVERT_TO_UTF8_FREE(title);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 if (gui.browse_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 /* shorten the file name if possible */
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1355
diff changeset
1038 return vim_strsave(shorten_fname1(gui.browse_fname));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1041 /*
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1042 * Put up a directory selector
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1043 * Returns the selected name in allocated memory, or NULL for Cancel.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1044 * title title for the window
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1045 * dflt default name
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1046 * initdir initial directory, NULL for current dir
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1047 */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1048 char_u *
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1049 gui_mch_browsedir(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1050 char_u *title,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1051 char_u *initdir)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1052 {
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1053 # if defined(GTK_FILE_CHOOSER) /* Only in GTK 2.4 and later. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1054 char_u dirbuf[MAXPATHL];
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1055 char_u *p;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1056 GtkWidget *dirdlg; /* file selection dialog */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1057 char_u *dirname = NULL;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1058
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1059 title = CONVERT_TO_UTF8(title);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1060
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1061 dirdlg = gtk_file_chooser_dialog_new(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1062 (const gchar *)title,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1063 GTK_WINDOW(gui.mainwin),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1064 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1065 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1066 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1067 NULL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1068
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1069 CONVERT_TO_UTF8_FREE(title);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1070
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1071 /* if our pointer is currently hidden, then we should show it. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1072 gui_mch_mousehide(FALSE);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1073
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1074 /* GTK appears to insist on an absolute path. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1075 if (initdir == NULL || *initdir == NUL
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1076 || vim_FullName(initdir, dirbuf, MAXPATHL - 10, FALSE) == FAIL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1077 mch_dirname(dirbuf, MAXPATHL - 10);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1078
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1079 /* Always need a trailing slash for a directory.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1080 * Also add a dummy file name, so that we get to the directory. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1081 add_pathsep(dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1082 STRCAT(dirbuf, "@zd(*&1|");
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1083 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dirdlg),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1084 (const gchar *)dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1085
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1086 /* Run the dialog. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1087 if (gtk_dialog_run(GTK_DIALOG(dirdlg)) == GTK_RESPONSE_ACCEPT)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1088 dirname = (char_u *)gtk_file_chooser_get_filename(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1089 GTK_FILE_CHOOSER(dirdlg));
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1090 gtk_widget_destroy(dirdlg);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1091 if (dirname == NULL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1092 return NULL;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1093
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1094 /* shorten the file name if possible */
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1355
diff changeset
1095 p = vim_strsave(shorten_fname1(dirname));
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1096 g_free(dirname);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1097 return p;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1098
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1099 # else
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1100 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1101 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1102 # endif
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1103 }
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1104
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1105
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 #endif /* FEAT_BROWSE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1108 #if defined(FEAT_GUI_DIALOG) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 create_message_dialog(int type, char_u *title, char_u *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 GtkMessageType message_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 case VIM_ERROR: message_type = GTK_MESSAGE_ERROR; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 case VIM_WARNING: message_type = GTK_MESSAGE_WARNING; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 case VIM_QUESTION: message_type = GTK_MESSAGE_QUESTION; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 default: message_type = GTK_MESSAGE_INFO; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 message = CONVERT_TO_UTF8(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 dialog = gtk_message_dialog_new(GTK_WINDOW(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 GTK_DIALOG_DESTROY_WITH_PARENT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 message_type,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 GTK_BUTTONS_NONE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 "%s", (const char *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 CONVERT_TO_UTF8_FREE(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 if (title != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 title = CONVERT_TO_UTF8(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 gtk_window_set_title(GTK_WINDOW(dialog), (const char *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 CONVERT_TO_UTF8_FREE(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 else if (type == VIM_GENERIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 gtk_window_set_title(GTK_WINDOW(dialog), "VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 return dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 * Split up button_string into individual button labels by inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 * NUL bytes. Also replace the Vim-style mnemonic accelerator prefix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 * '&' with '_'. button_string must point to allocated memory!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 * Return an allocated array of pointers into button_string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 static char **
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 split_button_string(char_u *button_string, int *n_buttons)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 char **array;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 unsigned int count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 for (p = button_string; *p != NUL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 array = (char **)alloc((count + 1) * sizeof(char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 if (array != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 array[count++] = (char *)button_string;
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1169 for (p = button_string; *p != NUL; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 {
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1173 *p++ = NUL;
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1174 array[count++] = (char *)p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 else if (*p == DLG_HOTKEY_CHAR)
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1177 *p++ = '_';
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1178 else
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1179 mb_ptr_adv(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 array[count] = NULL; /* currently not relied upon, but doesn't hurt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 *n_buttons = count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 return array;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 static char **
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 split_button_translation(const char *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 char **buttons = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 int n_buttons = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 int n_expected = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 for (str = (char_u *)message; *str != NUL; ++str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 if (*str == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 ++n_expected;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 str = (char_u *)_(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 if (output_conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 str = string_convert(&output_conv, str, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 str = vim_strsave(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 buttons = split_button_string(str, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 * Uh-oh... this should never ever happen. But we don't wanna crash
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 * if the translation is broken, thus fall back to the untranslated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 * buttons string in case of emergency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 if (buttons == NULL || n_buttons != n_expected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 vim_free(buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 buttons = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 str = vim_strsave((char_u *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 buttons = split_button_string(str, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 if (buttons == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 return buttons;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 button_equal(const char *a, const char *b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 while (*a != '\0' && *b != '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 if (*a == '_' && *++a == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 if (*b == '_' && *++b == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 if (g_unichar_tolower(g_utf8_get_char(a))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 != g_unichar_tolower(g_utf8_get_char(b)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 a = g_utf8_next_char(a);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 b = g_utf8_next_char(b);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 return (*a == '\0' && *b == '\0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 dialog_add_buttons(GtkDialog *dialog, char_u *button_string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 char **ok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 char **ync; /* "yes no cancel" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 char **buttons;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 int n_buttons = 0;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1260 int idx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 button_string = vim_strsave(button_string); /* must be writable */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 if (button_string == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 /* Check 'v' flag in 'guioptions': vertical button placement. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 if (vim_strchr(p_go, GO_VERTICAL) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 GtkWidget *vbutton_box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 vbutton_box = gtk_vbutton_box_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 gtk_widget_show(vbutton_box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->vbox),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 vbutton_box, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 /* Overrule the "action_area" value, hopefully this works... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 GTK_DIALOG(dialog)->action_area = vbutton_box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 * Yes this is ugly, I don't particularly like it either. But doing it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 * this way has the compelling advantage that translations need not to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 * be touched at all. See below what 'ok' and 'ync' are used for.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 ok = split_button_translation(N_("&Ok"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 ync = split_button_translation(N_("&Yes\n&No\n&Cancel"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 buttons = split_button_string(button_string, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 * Yes, the buttons are in reversed order to match the GNOME 2 desktop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 * environment. Don't hit me -- it's all about consistency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 * Well, apparently somebody changed his mind: with GTK 2.2.4 it works the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 * other way around...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 */
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1294 for (idx = 1; idx <= n_buttons; ++idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 char *label;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 char_u *label8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1299 label = buttons[idx - 1];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 * Perform some guesswork to find appropriate stock items for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 * buttons. We have to compare with a sample of the translated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 * button string to get things right. Yes, this is hackish :/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 * But even the common button labels aren't necessarily translated,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 * since anyone can create their own dialogs using Vim functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 * Thus we have to check for those too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 if (ok != NULL && ync != NULL) /* almost impossible to fail */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 if (button_equal(label, ok[0])) label = GTK_STOCK_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 else if (button_equal(label, ync[0])) label = GTK_STOCK_YES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 else if (button_equal(label, ync[1])) label = GTK_STOCK_NO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 else if (button_equal(label, ync[2])) label = GTK_STOCK_CANCEL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 else if (button_equal(label, "Ok")) label = GTK_STOCK_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 else if (button_equal(label, "Yes")) label = GTK_STOCK_YES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 else if (button_equal(label, "No")) label = GTK_STOCK_NO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 else if (button_equal(label, "Cancel")) label = GTK_STOCK_CANCEL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 label8 = CONVERT_TO_UTF8((char_u *)label);
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1321 gtk_dialog_add_button(dialog, (const gchar *)label8, idx);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 CONVERT_TO_UTF8_FREE(label8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 if (ok != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 vim_free(*ok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 if (ync != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 vim_free(*ync);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 vim_free(ok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 vim_free(ync);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 vim_free(buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 vim_free(button_string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 * Allow mnemonic accelerators to be activated without pressing <Alt>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 * I'm not sure if it's a wise idea to do this. However, the old GTK+ 1.2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 * GUI used to work this way, and I consider the impact on UI consistency
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 * low enough to justify implementing this as a special Vim feature.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 typedef struct _DialogInfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 int ignore_enter; /* no default button, ignore "Enter" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 int noalt; /* accept accelerators without Alt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 GtkDialog *dialog; /* Widget of the dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 } DialogInfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 static gboolean
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 DialogInfo *di = (DialogInfo *)data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352
1355
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1353 /* Ignore hitting Enter (or Space) when there is no default button. */
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1354 if (di->ignore_enter && (event->keyval == GDK_Return
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1355 || event->keyval == ' '))
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1356 return TRUE;
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1357 else /* A different key was pressed, return to normal behavior */
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1358 di->ignore_enter = FALSE;
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1359
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 /* Close the dialog when hitting "Esc". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 if (event->keyval == GDK_Escape)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 gtk_dialog_response(di->dialog, GTK_RESPONSE_REJECT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 if (di->noalt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 && (event->state & gtk_accelerator_get_default_mod_mask()) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 return gtk_window_mnemonic_activate(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 GTK_WINDOW(widget), event->keyval,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 gtk_window_get_mnemonic_modifier(GTK_WINDOW(widget)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 return FALSE; /* continue emission */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 gui_mch_dialog(int type, /* type of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 char_u *title, /* title of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 char_u *message, /* message text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 char_u *buttons, /* names of buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 int def_but, /* default button */
2684
951641b8784d updated for version 7.3.102
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1384 char_u *textfield, /* text for textfield or NULL */
951641b8784d updated for version 7.3.102
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1385 int ex_cmd UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 GtkWidget *entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 int response;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 DialogInfo dialoginfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 dialog = create_message_dialog(type, title, message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 dialoginfo.dialog = GTK_DIALOG(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 dialog_add_buttons(GTK_DIALOG(dialog), buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 GtkWidget *alignment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 entry = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 gtk_widget_show(entry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403
2649
b2789846ed39 updated for version 7.3.069
Bram Moolenaar <bram@vim.org>
parents: 2301
diff changeset
1404 /* Make Enter work like pressing OK. */
3664
0e06193d4bd7 updated for version 7.3.592
Bram Moolenaar <bram@vim.org>
parents: 3564
diff changeset
1405 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
2649
b2789846ed39 updated for version 7.3.069
Bram Moolenaar <bram@vim.org>
parents: 2301
diff changeset
1406
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 text = CONVERT_TO_UTF8(textfield);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 alignment = gtk_alignment_new((float)0.5, (float)0.5,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 (float)1.0, (float)1.0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 gtk_container_add(GTK_CONTAINER(alignment), entry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 gtk_container_set_border_width(GTK_CONTAINER(alignment), 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 gtk_widget_show(alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 alignment, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 dialoginfo.noalt = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 dialoginfo.noalt = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 /* Allow activation of mnemonic accelerators without pressing <Alt> when
864
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 856
diff changeset
1425 * there is no textfield. Handle pressing Esc. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 g_signal_connect(G_OBJECT(dialog), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 G_CALLBACK(&dialog_key_press_event_cb), &dialoginfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 if (def_but > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 gtk_dialog_set_default_response(GTK_DIALOG(dialog), def_but);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 dialoginfo.ignore_enter = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 /* No default button, ignore pressing Enter. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 dialoginfo.ignore_enter = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 /* Show the mouse pointer if it's currently hidden. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 gui_mch_mousehide(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 response = gtk_dialog_run(GTK_DIALOG(dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 /* GTK_RESPONSE_NONE means the dialog was programmatically destroyed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 if (response != GTK_RESPONSE_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 {
314
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
1446 if (response == GTK_RESPONSE_ACCEPT) /* Enter pressed */
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
1447 response = def_but;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 text = (char_u *)gtk_entry_get_text(GTK_ENTRY(entry));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 text = CONVERT_FROM_UTF8(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 401
diff changeset
1453 vim_strncpy(textfield, text, IOSIZE - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 CONVERT_FROM_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 gtk_widget_destroy(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 return response > 0 ? response : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1463 #endif /* FEAT_GUI_DIALOG */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 gui_mch_show_popupmenu(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 {
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1471 # if defined(FEAT_XIM)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 * Append a submenu for selecting an input method. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 * currently the only way to switch input methods at runtime.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 if (xic != NULL && g_object_get_data(G_OBJECT(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 "vim-has-im-menu") == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 GtkWidget *menuitem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 GtkWidget *submenu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 menuitem = gtk_separator_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 gtk_widget_show(menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 name = (char_u *)_("Input _Methods");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 name = CONVERT_TO_UTF8(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 menuitem = gtk_menu_item_new_with_mnemonic((const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 CONVERT_TO_UTF8_FREE(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 gtk_widget_show(menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 submenu = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(xic),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 GTK_MENU_SHELL(submenu));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 g_object_set_data(G_OBJECT(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 "vim-has-im-menu", GINT_TO_POINTER(TRUE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 }
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1502 # endif /* FEAT_XIM */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 gtk_menu_popup(GTK_MENU(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 (GtkMenuPositionFunc)NULL, NULL,
2923
7653420fdc45 updated for version 7.3.234
Bram Moolenaar <bram@vim.org>
parents: 2684
diff changeset
1507 3U, gui.event_time);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1510 /* Ugly global variable to pass "mouse_pos" flag from gui_make_popup() to
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1511 * popup_menu_position_func(). */
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1512 static int popup_mouse_pos;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1513
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 * Menu position callback; used by gui_make_popup() to place the menu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 * at the current text cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 * Note: The push_in output argument seems to affect scrolling of huge
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 * menus that don't fit on the screen. Leave it at the default for now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1522 popup_menu_position_func(GtkMenu *menu UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 gint *x, gint *y,
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1524 gboolean *push_in UNUSED,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1525 gpointer user_data UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 {
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1527 gdk_window_get_origin(gui.drawarea->window, x, y);
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1528
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1529 if (popup_mouse_pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 {
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1531 int mx, my;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1532
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1533 gui_mch_getmouse(&mx, &my);
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1534 *x += mx;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1535 *y += my;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1536 }
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1537 else if (curwin != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL)
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1538 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 /* Find the cursor position in the current window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 *x += FILL_X(W_WINCOL(curwin) + curwin->w_wcol + 1) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 *y += FILL_Y(W_WINROW(curwin) + curwin->w_wrow + 1) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 void
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1546 gui_make_popup(char_u *path_name, int mouse_pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 vimmenu_T *menu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1550 popup_mouse_pos = mouse_pos;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1551
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 menu = gui_find_menu(path_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 if (menu != NULL && menu->submenu_id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 gtk_menu_popup(GTK_MENU(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 &popup_menu_position_func, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 0U, (guint32)GDK_CURRENT_TIME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 * We don't create it twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 typedef struct _SharedFindReplace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 GtkWidget *dialog; /* the main dialog widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 GtkWidget *wword; /* 'Whole word only' check button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 GtkWidget *mcase; /* 'Match case' check button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 GtkWidget *up; /* search direction 'Up' radio button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 GtkWidget *down; /* search direction 'Down' radio button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 GtkWidget *what; /* 'Find what' entry text widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 GtkWidget *with; /* 'Replace with' entry text widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 GtkWidget *find; /* 'Find Next' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 GtkWidget *replace; /* 'Replace With' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 GtkWidget *all; /* 'Replace All' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 } SharedFindReplace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1584 static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1585 static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1586
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 find_key_press_event(
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1589 GtkWidget *widget UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 GdkEventKey *event,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 SharedFindReplace *frdp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 /* If the user is holding one of the key modifiers we will just bail out,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 * thus preserving the possibility of normal focus traversal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 /* the Escape key synthesizes a cancellation action */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 if (event->keyval == GDK_Escape)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 gtk_widget_hide(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606
1215
1d08aac0aea9 updated for version 7.1b
vimboss
parents: 1025
diff changeset
1607 /* It would be delightful if it where possible to do search history
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 * operations on the K_UP and K_DOWN keys here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 create_image_button(const char *stock_id, const char *label)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 GtkWidget *box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 GtkWidget *alignment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 GtkWidget *button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 text = CONVERT_TO_UTF8((char_u *)label);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 box = gtk_hbox_new(FALSE, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 gtk_box_pack_start(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 gtk_box_pack_start(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 gtk_label_new((const char *)text),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 alignment = gtk_alignment_new((float)0.5, (float)0.5,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 (float)0.0, (float)0.0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 gtk_container_add(GTK_CONTAINER(alignment), box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 gtk_widget_show_all(alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 button = gtk_button_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 gtk_container_add(GTK_CONTAINER(button), alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 return button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 * This is currently only used by find_replace_dialog_create(), and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 * I'd really like to keep it at that. In other words: don't spread
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 * this nasty hack all over the code. Think twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 static const char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 convert_localized_message(char_u **buffer, const char *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 if (output_conv.vc_type == CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 return message;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 vim_free(*buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 *buffer = string_convert(&output_conv, (char_u *)message, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 return (const char *)*buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 find_replace_dialog_create(char_u *arg, int do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 GtkWidget *hbox; /* main top down box */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 GtkWidget *actionarea;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 GtkWidget *table;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 GtkWidget *tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 GtkWidget *vbox;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 gboolean sensitive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 SharedFindReplace *frdp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 char_u *entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 int wword = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 int mcase = !p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 char_u *conv_buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 # define CONV(message) convert_localized_message(&conv_buffer, (message))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 /* Get the search string to use. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 if (entry_text != NULL && output_conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 char_u *old_text = entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 entry_text = string_convert(&output_conv, entry_text, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 vim_free(old_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 * If the dialog already exists, just raise it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 if (frdp->dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 if (entry_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 (gboolean)wword);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 (gboolean)mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 gtk_window_present(GTK_WINDOW(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 vim_free(entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 frdp->dialog = gtk_dialog_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 gtk_dialog_set_has_separator(GTK_DIALOG(frdp->dialog), FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 gtk_window_set_transient_for(GTK_WINDOW(frdp->dialog), GTK_WINDOW(gui.mainwin));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 gtk_window_set_destroy_with_parent(GTK_WINDOW(frdp->dialog), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 gtk_window_set_title(GTK_WINDOW(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 CONV(_("VIM - Search and Replace...")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 gtk_window_set_title(GTK_WINDOW(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 CONV(_("VIM - Search...")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 hbox = gtk_hbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(frdp->dialog)->vbox), hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 table = gtk_table_new(1024, 4, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 table = gtk_table_new(1024, 3, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 gtk_container_border_width(GTK_CONTAINER(table), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 tmp = gtk_label_new(CONV(_("Find what:")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 frdp->what = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 sensitive = (entry_text != NULL && entry_text[0] != NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 if (entry_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 gtk_signal_connect(GTK_OBJECT(frdp->what), "changed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 GTK_SIGNAL_FUNC(entry_changed_cb), frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 gtk_signal_connect_after(GTK_OBJECT(frdp->what), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 GTK_SIGNAL_FUNC(find_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 (gpointer) frdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 gtk_table_attach(GTK_TABLE(table), frdp->what, 1, 1024, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 tmp = gtk_label_new(CONV(_("Replace with:")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 frdp->with = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 gtk_signal_connect(GTK_OBJECT(frdp->with), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 GINT_TO_POINTER(FRD_R_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 gtk_signal_connect_after(GTK_OBJECT(frdp->with), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 GTK_SIGNAL_FUNC(find_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 (gpointer) frdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 gtk_table_attach(GTK_TABLE(table), frdp->with, 1, 1024, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 * Make the entry activation only change the input focus onto the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 * with item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 GTK_SIGNAL_FUNC(entry_activate_cb), frdp->with);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 * Make the entry activation do the search.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 GINT_TO_POINTER(FRD_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 /* whole word only button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 frdp->wword = gtk_check_button_new_with_label(CONV(_("Match whole word only")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 (gboolean)wword);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 2, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 /* match case button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 frdp->mcase = gtk_check_button_new_with_label(CONV(_("Match case")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 (gboolean)mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 3, 4,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 2, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 tmp = gtk_frame_new(CONV(_("Direction")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 2, 4,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 GTK_FILL, GTK_FILL, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 1, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 GTK_FILL, GTK_FILL, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 vbox = gtk_vbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 gtk_container_border_width(GTK_CONTAINER(vbox), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 gtk_container_add(GTK_CONTAINER(tmp), vbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 /* 'Up' and 'Down' buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 frdp->up = gtk_radio_button_new_with_label(NULL, CONV(_("Up")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 gtk_box_pack_start(GTK_BOX(vbox), frdp->up, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 frdp->down = gtk_radio_button_new_with_label(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 gtk_radio_button_group(GTK_RADIO_BUTTON(frdp->up)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 CONV(_("Down")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->down), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 gtk_box_pack_start(GTK_BOX(vbox), frdp->down, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 /* vbox to hold the action buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 actionarea = gtk_vbutton_box_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 gtk_container_border_width(GTK_CONTAINER(actionarea), 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 gtk_box_pack_end(GTK_BOX(hbox), actionarea, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 /* 'Find Next' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 frdp->find = create_image_button(GTK_STOCK_FIND, _("Find Next"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 gtk_widget_set_sensitive(frdp->find, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 (do_replace) ? GINT_TO_POINTER(FRD_R_FINDNEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 : GINT_TO_POINTER(FRD_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 GTK_WIDGET_SET_FLAGS(frdp->find, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 gtk_box_pack_start(GTK_BOX(actionarea), frdp->find, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 gtk_widget_grab_default(frdp->find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 /* 'Replace' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 frdp->replace = create_image_button(GTK_STOCK_CONVERT, _("Replace"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 gtk_widget_set_sensitive(frdp->replace, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 GTK_WIDGET_SET_FLAGS(frdp->replace, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 GINT_TO_POINTER(FRD_REPLACE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 /* 'Replace All' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 frdp->all = create_image_button(GTK_STOCK_CONVERT, _("Replace All"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 gtk_widget_set_sensitive(frdp->all, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 GTK_WIDGET_SET_FLAGS(frdp->all, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 GINT_TO_POINTER(FRD_REPLACEALL));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 /* 'Cancel' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 tmp = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 gtk_box_pack_end(GTK_BOX(actionarea), tmp, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 gtk_signal_connect_object(GTK_OBJECT(tmp),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 GTK_OBJECT(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 gtk_signal_connect_object(GTK_OBJECT(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 GTK_OBJECT(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 tmp = gtk_vseparator_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, FALSE, 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 /* Suppress automatic show of the unused action area */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 gtk_widget_hide(GTK_DIALOG(frdp->dialog)->action_area);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 gtk_widget_show_all(hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 gtk_widget_show(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 vim_free(entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 vim_free(conv_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 #undef CONV
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 gui_mch_find_dialog(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 find_replace_dialog_create(eap->arg, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 gui_mch_replace_dialog(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 find_replace_dialog_create(eap->arg, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 * Callback for actions of the find and replace dialogs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1908 find_replace_cb(GtkWidget *widget UNUSED, gpointer data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 char_u *find_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 char_u *repl_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 gboolean direction_down;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 SharedFindReplace *sfr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 flags = (int)(long)data; /* avoid a lint warning here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 /* Get the search/replace strings from the dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 if (flags == FRD_FINDNEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 repl_text = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 sfr = &find_widgets;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 repl_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(repl_widgets.with));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 sfr = &repl_widgets;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 find_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(sfr->what));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 direction_down = GTK_TOGGLE_BUTTON(sfr->down)->active;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 if (GTK_TOGGLE_BUTTON(sfr->wword)->active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 flags |= FRD_WHOLE_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 if (GTK_TOGGLE_BUTTON(sfr->mcase)->active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 flags |= FRD_MATCH_CASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 repl_text = CONVERT_FROM_UTF8(repl_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 find_text = CONVERT_FROM_UTF8(find_text);
2656
4549e0e7fbb6 updated for version 7.3.076
Bram Moolenaar <bram@vim.org>
parents: 2649
diff changeset
1940 gui_do_findrepl(flags, find_text, repl_text, direction_down);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 CONVERT_FROM_UTF8_FREE(repl_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 CONVERT_FROM_UTF8_FREE(find_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 /* our usual callback function */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1947 entry_activate_cb(GtkWidget *widget UNUSED, gpointer data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 gtk_widget_grab_focus(GTK_WIDGET(data));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 * Syncing the find/replace dialogs on the fly is utterly useless crack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 * and causes nothing but problems. Please tell me a use case for which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 * you'd need both a find dialog and a find/replace one at the same time,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 * without being able to actually use them separately since they're syncing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 * all the time. I don't think it's worthwhile to fix this nonsense,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 * particularly evil incarnation of braindeadness, whatever; I'd much rather
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 * see it extinguished from this planet. Thanks for listening. Sorry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 entry_changed_cb(GtkWidget * entry, GtkWidget * dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 const gchar *entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 gboolean nonempty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 if (!entry_text)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 return; /* shouldn't happen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 nonempty = (entry_text[0] != '\0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 if (dialog == find_widgets.dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 gtk_widget_set_sensitive(find_widgets.find, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 if (dialog == repl_widgets.dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 gtk_widget_set_sensitive(repl_widgets.find, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 gtk_widget_set_sensitive(repl_widgets.replace, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 gtk_widget_set_sensitive(repl_widgets.all, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 * ":helpfind"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 void
7821
81794242a275 commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents: 7380
diff changeset
1991 ex_helpfind(exarg_T *eap UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 /* This will fail when menus are not loaded. Well, it's only for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 * backwards compatibility anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 }
3484
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
1997
3564
8d1b63e6d317 updated for version 7.3.542
Bram Moolenaar <bram@vim.org>
parents: 3484
diff changeset
1998 #if defined(FEAT_BROWSE) || defined(PROTO)
3484
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
1999 static void
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2000 recent_func_log_func(const gchar *log_domain UNUSED,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2001 GLogLevelFlags log_level UNUSED,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2002 const gchar *message UNUSED,
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2003 gpointer user_data UNUSED)
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2004 {
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2005 /* We just want to suppress the warnings. */
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2006 /* http://bugzilla.gnome.org/show_bug.cgi?id=664587 */
982f84487daf updated for version 7.3.506
Bram Moolenaar <bram@vim.org>
parents: 2923
diff changeset
2007 }
3564
8d1b63e6d317 updated for version 7.3.542
Bram Moolenaar <bram@vim.org>
parents: 3484
diff changeset
2008 #endif