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