(editcmd_dialog_raw_key_query): take gboolean instead of boolean.
[midnight-commander.git] / src / editor / editcmd_dialogs.c
blob742eb6940e544dfa83aee1fb19ada2c34eb305b4
1 /*
2 Editor dialogs for high level editing commands
4 Copyright (C) 2009, 2011
5 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2009.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <config.h>
28 #include "lib/global.h"
29 #include "lib/tty/tty.h"
30 #include "lib/skin.h" /* INPUT_COLOR */
31 #include "lib/tty/key.h"
32 #include "lib/search.h"
33 #include "lib/strutil.h"
34 #include "lib/widget.h"
35 #ifdef HAVE_CHARSET
36 #include "lib/charsets.h"
37 #endif
39 #include "src/main.h"
40 #include "src/history.h"
42 #include "src/editor/editwidget.h"
43 #include "src/editor/etags.h"
44 #include "src/editor/editcmd_dialogs.h"
46 #ifdef HAVE_ASPELL
47 #include "src/editor/spell.h"
48 #endif
50 /*** global variables ****************************************************************************/
52 edit_search_options_t edit_search_options = {
53 .type = MC_SEARCH_T_NORMAL,
54 .case_sens = FALSE,
55 .backwards = FALSE,
56 .only_in_selection = FALSE,
57 .whole_words = FALSE,
58 .all_codepages = FALSE
61 /*** file scope macro definitions ****************************************************************/
63 #define SEARCH_DLG_WIDTH 58
64 #define SEARCH_DLG_MIN_HEIGHT 13
65 #define SEARCH_DLG_HEIGHT_SUPPLY 3
67 #define REPLACE_DLG_WIDTH 58
68 #define REPLACE_DLG_MIN_HEIGHT 17
69 #define REPLACE_DLG_HEIGHT_SUPPLY 5
71 /*** file scope type declarations ****************************************************************/
73 /*** file scope variables ************************************************************************/
75 /*** file scope functions ************************************************************************/
76 /* --------------------------------------------------------------------------------------------- */
78 static cb_ret_t
79 editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
80 dlg_msg_t msg, int parm, void *data)
82 switch (msg)
84 case DLG_KEY:
85 h->ret_value = parm;
86 dlg_stop (h);
87 return MSG_HANDLED;
88 default:
89 return default_dlg_callback (h, sender, msg, parm, data);
93 /* --------------------------------------------------------------------------------------------- */
94 /*** public functions ****************************************************************************/
95 /* --------------------------------------------------------------------------------------------- */
97 void
98 editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
99 /*@out@ */ char **search_text, /*@out@ */ char **replace_text)
101 if ((search_default == NULL) || (*search_default == '\0'))
102 search_default = INPUT_LAST_TEXT;
105 size_t num_of_types;
106 gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
107 int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
109 QuickWidget quick_widgets[] = {
110 /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
111 /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
112 #ifdef HAVE_CHARSET
113 /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT,
114 N_("&All charsets"),
115 &edit_search_options.all_codepages),
116 #endif
117 /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT,
118 N_("&Whole words"),
119 &edit_search_options.whole_words),
120 /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT,
121 N_("In se&lection"),
122 &edit_search_options.only_in_selection),
123 /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
124 &edit_search_options.backwards),
125 /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
126 N_("Cas&e sensitive"),
127 &edit_search_options.case_sens),
128 /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
129 num_of_types, (const char **) list_of_types,
130 (int *) &edit_search_options.type),
131 /* 8 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT,
132 N_("Enter replacement string:")),
133 /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
134 replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace",
135 replace_text),
136 /* 10 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT,
137 N_("Enter search string:")),
138 /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
139 search_default, REPLACE_DLG_WIDTH - 6, 0,
140 MC_HISTORY_SHARED_SEARCH, search_text),
141 QUICK_END
144 QuickDialog Quick_input = {
145 REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_("Replace"),
146 "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
149 if (quick_dialog (&Quick_input) != B_CANCEL)
151 edit->replace_mode = 0;
153 else
155 *replace_text = NULL;
156 *search_text = NULL;
159 g_strfreev (list_of_types);
163 /* --------------------------------------------------------------------------------------------- */
165 gboolean
166 editcmd_dialog_search_show (WEdit * edit)
168 char *search_text;
170 size_t num_of_types;
171 gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
172 int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
173 size_t i;
175 int dialog_result;
177 QuickWidget quick_widgets[] = {
178 /* 0 */
179 QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
180 /* 1 */
181 QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
182 /* 2 */
183 QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
184 #ifdef HAVE_CHARSET
185 /* 3 */
186 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("&All charsets"),
187 &edit_search_options.all_codepages),
188 #endif
189 /* 4 */
190 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
191 &edit_search_options.whole_words),
192 /* 5 */
193 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
194 &edit_search_options.only_in_selection),
195 /* 6 */
196 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
197 &edit_search_options.backwards),
198 /* 7 */
199 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("Cas&e sensitive"),
200 &edit_search_options.case_sens),
201 /* 8 */
202 QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
203 num_of_types, (const char **) list_of_types,
204 (int *) &edit_search_options.type),
205 /* 9 */
206 QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
207 INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0,
208 MC_HISTORY_SHARED_SEARCH, &search_text),
209 /* 10 */
210 QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")),
211 QUICK_END
214 #ifdef HAVE_CHARSET
215 size_t last_checkbox = 7;
216 #else
217 size_t last_checkbox = 6;
218 #endif
220 QuickDialog Quick_input = {
221 SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
222 "[Input Line Keys]", quick_widgets, NULL, NULL, TRUE
225 #ifdef ENABLE_NLS
226 char **list_of_types_nls;
228 /* header title */
229 Quick_input.title = _(Quick_input.title);
230 /* buttons */
231 for (i = 0; i < 3; i++)
232 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
233 /* checkboxes */
234 for (i = 3; i <= last_checkbox; i++)
235 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
236 /* label */
237 quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
239 /* radiobuttons */
240 /* create copy of radio items to avoid memory leak */
241 list_of_types_nls = g_new0 (char *, num_of_types + 1);
242 for (i = 0; i < num_of_types; i++)
243 list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
244 g_strfreev (list_of_types);
245 list_of_types = list_of_types_nls;
246 quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
247 #endif
249 /* calculate widget coordinates */
251 int len = 0;
252 int dlg_width;
253 gchar **radio = list_of_types;
254 int b0_len, b1_len, b2_len;
255 const int button_gap = 2;
257 /* length of radiobuttons */
258 while (*radio != NULL)
260 len = max (len, str_term_width1 (*radio));
261 radio++;
263 /* length of checkboxes */
264 for (i = 3; i <= last_checkbox; i++)
265 len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
267 /* preliminary dialog width */
268 dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
270 /* length of buttons */
271 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
272 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
273 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
274 len = b0_len + b1_len + b2_len + button_gap * 2;
276 /* dialog width */
277 Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
279 /* correct widget coordinates */
280 for (i = 0; i < sizeof (quick_widgets) / sizeof (quick_widgets[0]); i++)
281 quick_widgets[i].x_divisions = Quick_input.xlen;
283 /* checkbox positions */
284 for (i = 3; i <= last_checkbox; i++)
285 quick_widgets[i].relative_x = Quick_input.xlen / 2 + 2;
286 /* input length */
287 quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
288 /* button positions */
289 quick_widgets[2].relative_x = Quick_input.xlen / 2 - len / 2;
290 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
291 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
294 dialog_result = quick_dialog (&Quick_input);
296 g_strfreev (list_of_types);
298 if ((dialog_result == B_CANCEL) || (search_text == NULL) || (search_text[0] == '\0'))
300 g_free (search_text);
301 return FALSE;
304 if (dialog_result == B_USER)
305 search_create_bookmark = TRUE;
307 #ifdef HAVE_CHARSET
309 GString *tmp;
311 tmp = str_convert_to_input (search_text);
312 if (tmp != NULL)
314 g_free (search_text);
315 search_text = g_string_free (tmp, FALSE);
318 #endif
320 g_free (edit->last_search_string);
321 edit->last_search_string = search_text;
322 mc_search_free (edit->search);
324 edit->search = mc_search_new (edit->last_search_string, -1);
325 if (edit->search != NULL)
327 edit->search->search_type = edit_search_options.type;
328 edit->search->is_all_charsets = edit_search_options.all_codepages;
329 edit->search->is_case_sensitive = edit_search_options.case_sens;
330 edit->search->whole_words = edit_search_options.whole_words;
331 edit->search->search_fn = edit_search_cmd_callback;
334 return (edit->search != NULL);
337 /* --------------------------------------------------------------------------------------------- */
338 /* gets a raw key from the keyboard. Passing cancel = 1 draws
339 a cancel button thus allowing c-c etc. Alternatively, cancel = 0
340 will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c,
341 and Esc are cannot returned */
344 editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel)
346 int w;
347 struct Dlg_head *raw_dlg;
349 w = str_term_width1 (query) + 7;
351 raw_dlg =
352 create_dlg (TRUE, 0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL,
353 NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
354 add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors (),
355 2, "", 0, INPUT_COMPLETE_DEFAULT));
356 add_widget (raw_dlg, label_new (3 - cancel, 2, query));
357 if (cancel)
358 add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));
359 w = run_dlg (raw_dlg);
360 destroy_dlg (raw_dlg);
362 return (cancel && (w == ESC_CHAR || w == B_CANCEL)) ? 0 : w;
365 /* --------------------------------------------------------------------------------------------- */
366 /* let the user select its preferred completion */
368 void
369 editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
370 struct selection *compl, int num_compl)
373 int start_x, start_y, offset, i;
374 char *curr = NULL;
375 Dlg_head *compl_dlg;
376 WListbox *compl_list;
377 int compl_dlg_h; /* completion dialog height */
378 int compl_dlg_w; /* completion dialog width */
380 /* calculate the dialog metrics */
381 compl_dlg_h = num_compl + 2;
382 compl_dlg_w = max_len + 4;
383 start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) +
384 EDIT_TEXT_HORIZONTAL_OFFSET + (edit->fullscreen ? 0 : 1) + option_line_state_width;
385 start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;
387 if (start_x < 0)
388 start_x = 0;
389 if (compl_dlg_w > COLS)
390 compl_dlg_w = COLS;
391 if (compl_dlg_h > LINES - 2)
392 compl_dlg_h = LINES - 2;
394 offset = start_x + compl_dlg_w - COLS;
395 if (offset > 0)
396 start_x -= offset;
397 offset = start_y + compl_dlg_h - LINES;
398 if (offset > 0)
399 start_y -= (offset + 1);
401 /* create the dialog */
402 compl_dlg =
403 create_dlg (TRUE, start_y, start_x, compl_dlg_h, compl_dlg_w,
404 dialog_colors, NULL, NULL, "[Completion]", NULL, DLG_COMPACT);
406 /* create the listbox */
407 compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, FALSE, NULL);
409 /* add the dialog */
410 add_widget (compl_dlg, compl_list);
412 /* fill the listbox with the completions */
413 for (i = num_compl - 1; i >= 0; i--) /* reverse order */
414 listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
416 /* pop up the dialog and apply the choosen completion */
417 if (run_dlg (compl_dlg) == B_ENTER)
419 listbox_get_current (compl_list, &curr, NULL);
420 if (curr)
422 #ifdef HAVE_CHARSET
423 GString *temp, *temp2;
424 temp = g_string_new ("");
425 for (curr += word_len; *curr; curr++)
426 g_string_append_c (temp, *curr);
428 temp2 = str_convert_to_input (temp->str);
430 if (temp2 && temp2->len)
432 g_string_free (temp, TRUE);
433 temp = temp2;
435 else
436 g_string_free (temp2, TRUE);
437 for (curr = temp->str; *curr; curr++)
438 edit_insert (edit, *curr);
439 g_string_free (temp, TRUE);
440 #else
441 for (curr += word_len; *curr; curr++)
442 edit_insert (edit, *curr);
443 #endif
447 /* destroy dialog before return */
448 destroy_dlg (compl_dlg);
451 /* --------------------------------------------------------------------------------------------- */
452 /* let the user select where function definition */
454 void
455 editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len,
456 etags_hash_t * def_hash, int num_lines)
459 int start_x, start_y, offset, i;
460 char *curr = NULL;
461 etags_hash_t *curr_def = NULL;
462 Dlg_head *def_dlg;
463 WListbox *def_list;
464 int def_dlg_h; /* dialog height */
465 int def_dlg_w; /* dialog width */
466 char *label_def = NULL;
468 (void) word_len;
469 /* calculate the dialog metrics */
470 def_dlg_h = num_lines + 2;
471 def_dlg_w = max_len + 4;
472 start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) +
473 EDIT_TEXT_HORIZONTAL_OFFSET + (edit->fullscreen ? 0 : 1) + option_line_state_width;
474 start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;
476 if (start_x < 0)
477 start_x = 0;
478 if (def_dlg_w > COLS)
479 def_dlg_w = COLS;
480 if (def_dlg_h > LINES - 2)
481 def_dlg_h = LINES - 2;
483 offset = start_x + def_dlg_w - COLS;
484 if (offset > 0)
485 start_x -= offset;
486 offset = start_y + def_dlg_h - LINES;
487 if (offset > 0)
488 start_y -= (offset + 1);
490 /* create the dialog */
491 def_dlg = create_dlg (TRUE, start_y, start_x, def_dlg_h, def_dlg_w,
492 dialog_colors, NULL, NULL, "[Definitions]", match_expr, DLG_COMPACT);
494 /* create the listbox */
495 def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, FALSE, NULL);
497 /* add the dialog */
498 add_widget (def_dlg, def_list);
500 /* fill the listbox with the completions */
501 for (i = 0; i < num_lines; i++)
503 label_def =
504 g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
505 def_hash[i].line);
506 listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i]);
507 g_free (label_def);
510 /* pop up the dialog and apply the choosen completion */
511 if (run_dlg (def_dlg) == B_ENTER)
513 char *tmp_curr_def = (char *) curr_def;
514 int do_moveto = 0;
516 listbox_get_current (def_list, &curr, (void **) &tmp_curr_def);
517 curr_def = (etags_hash_t *) tmp_curr_def;
518 if (edit->modified)
520 if (!edit_query_dialog2
521 (_("Warning"),
522 _("Current text was modified without a file save.\n"
523 "Continue discards these changes."), _("C&ontinue"), _("&Cancel")))
525 edit->force |= REDRAW_COMPLETELY;
526 do_moveto = 1;
529 else
531 do_moveto = 1;
534 if (curr && do_moveto)
536 if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
538 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
539 if (edit->dir_vpath != NULL)
541 edit_history_moveto[edit_stack_iterator].filename_vpath =
542 vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL);
544 else
546 edit_history_moveto[edit_stack_iterator].filename_vpath =
547 vfs_path_clone (edit->filename_vpath);
549 edit_history_moveto[edit_stack_iterator].line = edit->start_line +
550 edit->curs_row + 1;
551 edit_stack_iterator++;
552 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
553 edit_history_moveto[edit_stack_iterator].filename_vpath =
554 vfs_path_from_str ((char *) curr_def->fullpath);
555 edit_history_moveto[edit_stack_iterator].line = curr_def->line;
556 edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
557 edit_history_moveto[edit_stack_iterator].line);
562 /* clear definition hash */
563 for (i = 0; i < MAX_DEFINITIONS; i++)
565 g_free (def_hash[i].filename);
568 /* destroy dialog before return */
569 destroy_dlg (def_dlg);
572 /* --------------------------------------------------------------------------------------------- */
575 editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos,
576 int ypos)
578 /* dialog sizes */
579 int dlg_height = 9;
580 int dlg_width = 8;
582 int retval;
583 int i;
584 int btn_pos;
586 char *repl_from, *repl_to;
587 char tmp[BUF_MEDIUM];
589 QuickWidget quick_widgets[] = {
590 /* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
591 /* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
592 /* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
593 /* 3 */ QUICK_BUTTON (4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
594 /* 4 */ QUICK_LABEL (3, dlg_width, 2, dlg_height, NULL),
595 /* 5 */ QUICK_LABEL (3, dlg_width, 3, dlg_height, N_("Replace with:")),
596 /* 6 */ QUICK_LABEL (3, dlg_width, 4, dlg_height, NULL),
597 QUICK_END
600 #ifdef ENABLE_NLS
601 for (i = 0; i < 4; i++)
602 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
603 #endif
605 /* calculate button positions */
606 btn_pos = 4;
608 for (i = 3; i > -1; i--)
610 quick_widgets[i].relative_x = btn_pos;
611 btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5;
612 if (i == 3) /* default button */
613 btn_pos += 2;
616 dlg_width = btn_pos + 2;
618 /* correct widget coordinates */
619 for (i = 0; i < 7; i++)
620 quick_widgets[i].x_divisions = dlg_width;
622 g_snprintf (tmp, sizeof (tmp), "\"%s\"", from_text);
623 repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
625 g_snprintf (tmp, sizeof (tmp), "\"%s\"", to_text);
626 repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
628 quick_widgets[4].u.label.text = repl_from;
629 quick_widgets[6].u.label.text = repl_to;
631 if (xpos == -1)
632 xpos = (edit->widget.cols - dlg_width) / 2;
634 if (ypos == -1)
635 ypos = edit->widget.lines * 2 / 3;
638 QuickDialog Quick_input = {
639 dlg_width, dlg_height, 0, 0, N_("Confirm replace"),
640 "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
643 /* Sometimes menu can hide replaced text. I don't like it */
644 if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
645 ypos -= dlg_height;
647 Quick_input.ypos = ypos;
648 Quick_input.xpos = xpos;
650 retval = quick_dialog (&Quick_input);
651 g_free (repl_from);
652 g_free (repl_to);
654 return retval;
658 /* --------------------------------------------------------------------------------------------- */