(editcmd_dialog_raw_key_query): take gboolean instead of int.
[midnight-commander.git] / src / editor / editcmd_dialogs.c
blob9a6c80cd769be89271240e92292917c9b69bfb48
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 /*** global variables ****************************************************************************/
48 edit_search_options_t edit_search_options = {
49 .type = MC_SEARCH_T_NORMAL,
50 .case_sens = FALSE,
51 .backwards = FALSE,
52 .only_in_selection = FALSE,
53 .whole_words = FALSE,
54 .all_codepages = FALSE
57 /*** file scope macro definitions ****************************************************************/
59 #define SEARCH_DLG_WIDTH 58
60 #define SEARCH_DLG_MIN_HEIGHT 13
61 #define SEARCH_DLG_HEIGHT_SUPPLY 3
63 #define REPLACE_DLG_WIDTH 58
64 #define REPLACE_DLG_MIN_HEIGHT 17
65 #define REPLACE_DLG_HEIGHT_SUPPLY 5
67 /*** file scope type declarations ****************************************************************/
69 /*** file scope variables ************************************************************************/
71 /*** file scope functions ************************************************************************/
72 /* --------------------------------------------------------------------------------------------- */
74 static cb_ret_t
75 editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
76 dlg_msg_t msg, int parm, void *data)
78 switch (msg)
80 case DLG_KEY:
81 h->ret_value = parm;
82 dlg_stop (h);
83 return MSG_HANDLED;
84 default:
85 return default_dlg_callback (h, sender, msg, parm, data);
89 /* --------------------------------------------------------------------------------------------- */
90 /*** public functions ****************************************************************************/
91 /* --------------------------------------------------------------------------------------------- */
93 void
94 editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
95 /*@out@ */ char **search_text, /*@out@ */ char **replace_text)
97 if ((search_default == NULL) || (*search_default == '\0'))
98 search_default = INPUT_LAST_TEXT;
101 size_t num_of_types;
102 gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
103 int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
105 QuickWidget quick_widgets[] = {
106 /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
107 /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
108 #ifdef HAVE_CHARSET
109 /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT,
110 N_("&All charsets"),
111 &edit_search_options.all_codepages),
112 #endif
113 /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT,
114 N_("&Whole words"),
115 &edit_search_options.whole_words),
116 /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT,
117 N_("In se&lection"),
118 &edit_search_options.only_in_selection),
119 /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
120 &edit_search_options.backwards),
121 /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
122 N_("Cas&e sensitive"),
123 &edit_search_options.case_sens),
124 /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
125 num_of_types, (const char **) list_of_types,
126 (int *) &edit_search_options.type),
127 /* 8 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT,
128 N_("Enter replacement string:")),
129 /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
130 replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace",
131 replace_text),
132 /* 10 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT,
133 N_("Enter search string:")),
134 /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
135 search_default, REPLACE_DLG_WIDTH - 6, 0,
136 MC_HISTORY_SHARED_SEARCH, search_text),
137 QUICK_END
140 QuickDialog Quick_input = {
141 REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_("Replace"),
142 "[Input Line Keys]", quick_widgets, NULL, FALSE
145 if (quick_dialog (&Quick_input) != B_CANCEL)
147 edit->replace_mode = 0;
149 else
151 *replace_text = NULL;
152 *search_text = NULL;
155 g_strfreev (list_of_types);
159 /* --------------------------------------------------------------------------------------------- */
161 gboolean
162 editcmd_dialog_search_show (WEdit * edit)
164 char *search_text;
166 size_t num_of_types;
167 gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
168 int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
169 size_t i;
171 int dialog_result;
173 QuickWidget quick_widgets[] = {
174 /* 0 */
175 QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
176 /* 1 */
177 QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
178 /* 2 */
179 QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
180 #ifdef HAVE_CHARSET
181 /* 3 */
182 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("&All charsets"),
183 &edit_search_options.all_codepages),
184 #endif
185 /* 4 */
186 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
187 &edit_search_options.whole_words),
188 /* 5 */
189 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
190 &edit_search_options.only_in_selection),
191 /* 6 */
192 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
193 &edit_search_options.backwards),
194 /* 7 */
195 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("Cas&e sensitive"),
196 &edit_search_options.case_sens),
197 /* 8 */
198 QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
199 num_of_types, (const char **) list_of_types,
200 (int *) &edit_search_options.type),
201 /* 9 */
202 QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
203 INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0,
204 MC_HISTORY_SHARED_SEARCH, &search_text),
205 /* 10 */
206 QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")),
207 QUICK_END
210 #ifdef HAVE_CHARSET
211 size_t last_checkbox = 7;
212 #else
213 size_t last_checkbox = 6;
214 #endif
216 QuickDialog Quick_input = {
217 SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
218 "[Input Line Keys]", quick_widgets, NULL, TRUE
221 #ifdef ENABLE_NLS
222 char **list_of_types_nls;
224 /* header title */
225 Quick_input.title = _(Quick_input.title);
226 /* buttons */
227 for (i = 0; i < 3; i++)
228 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
229 /* checkboxes */
230 for (i = 3; i <= last_checkbox; i++)
231 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
232 /* label */
233 quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
235 /* radiobuttons */
236 /* create copy of radio items to avoid memory leak */
237 list_of_types_nls = g_new0 (char *, num_of_types + 1);
238 for (i = 0; i < num_of_types; i++)
239 list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
240 g_strfreev (list_of_types);
241 list_of_types = list_of_types_nls;
242 quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
243 #endif
245 /* calculate widget coordinates */
247 int len = 0;
248 int dlg_width;
249 gchar **radio = list_of_types;
250 int b0_len, b1_len, b2_len;
251 const int button_gap = 2;
253 /* length of radiobuttons */
254 while (*radio != NULL)
256 len = max (len, str_term_width1 (*radio));
257 radio++;
259 /* length of checkboxes */
260 for (i = 3; i <= last_checkbox; i++)
261 len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
263 /* preliminary dialog width */
264 dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
266 /* length of buttons */
267 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
268 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
269 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
270 len = b0_len + b1_len + b2_len + button_gap * 2;
272 /* dialog width */
273 Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
275 /* correct widget coordinates */
276 for (i = 0; i < sizeof (quick_widgets) / sizeof (quick_widgets[0]); i++)
277 quick_widgets[i].x_divisions = Quick_input.xlen;
279 /* checkbox positions */
280 for (i = 3; i <= last_checkbox; i++)
281 quick_widgets[i].relative_x = Quick_input.xlen / 2 + 2;
282 /* input length */
283 quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
284 /* button positions */
285 quick_widgets[2].relative_x = Quick_input.xlen / 2 - len / 2;
286 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
287 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
290 dialog_result = quick_dialog (&Quick_input);
292 g_strfreev (list_of_types);
294 if ((dialog_result == B_CANCEL) || (search_text == NULL) || (search_text[0] == '\0'))
296 g_free (search_text);
297 return FALSE;
300 if (dialog_result == B_USER)
301 search_create_bookmark = TRUE;
303 #ifdef HAVE_CHARSET
305 GString *tmp;
307 tmp = str_convert_to_input (search_text);
308 if (tmp != NULL)
310 g_free (search_text);
311 search_text = g_string_free (tmp, FALSE);
314 #endif
316 g_free (edit->last_search_string);
317 edit->last_search_string = search_text;
318 mc_search_free (edit->search);
320 edit->search = mc_search_new (edit->last_search_string, -1);
321 if (edit->search != NULL)
323 edit->search->search_type = edit_search_options.type;
324 edit->search->is_all_charsets = edit_search_options.all_codepages;
325 edit->search->is_case_sensitive = edit_search_options.case_sens;
326 edit->search->whole_words = edit_search_options.whole_words;
327 edit->search->search_fn = edit_search_cmd_callback;
330 return (edit->search != NULL);
333 /* --------------------------------------------------------------------------------------------- */
334 /* gets a raw key from the keyboard. Passing cancel = 1 draws
335 a cancel button thus allowing c-c etc. Alternatively, cancel = 0
336 will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c,
337 and Esc are cannot returned */
340 editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel)
342 int w;
343 struct Dlg_head *raw_dlg;
345 w = str_term_width1 (query) + 7;
347 raw_dlg =
348 create_dlg (TRUE, 0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb,
349 NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
350 add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors (),
351 2, "", 0, INPUT_COMPLETE_DEFAULT));
352 add_widget (raw_dlg, label_new (3 - cancel, 2, query));
353 if (cancel)
354 add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));
355 w = run_dlg (raw_dlg);
356 destroy_dlg (raw_dlg);
358 return (cancel && (w == ESC_CHAR || w == B_CANCEL)) ? 0 : w;
361 /* --------------------------------------------------------------------------------------------- */
362 /* let the user select its preferred completion */
364 void
365 editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
366 struct selection *compl, int num_compl)
369 int start_x, start_y, offset, i;
370 char *curr = NULL;
371 Dlg_head *compl_dlg;
372 WListbox *compl_list;
373 int compl_dlg_h; /* completion dialog height */
374 int compl_dlg_w; /* completion dialog width */
376 /* calculate the dialog metrics */
377 compl_dlg_h = num_compl + 2;
378 compl_dlg_w = max_len + 4;
379 start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) +
380 EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
381 start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;
383 if (start_x < 0)
384 start_x = 0;
385 if (compl_dlg_w > COLS)
386 compl_dlg_w = COLS;
387 if (compl_dlg_h > LINES - 2)
388 compl_dlg_h = LINES - 2;
390 offset = start_x + compl_dlg_w - COLS;
391 if (offset > 0)
392 start_x -= offset;
393 offset = start_y + compl_dlg_h - LINES;
394 if (offset > 0)
395 start_y -= (offset + 1);
397 /* create the dialog */
398 compl_dlg =
399 create_dlg (TRUE, start_y, start_x, compl_dlg_h, compl_dlg_w,
400 dialog_colors, NULL, "[Completion]", NULL, DLG_COMPACT);
402 /* create the listbox */
403 compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, FALSE, NULL);
405 /* add the dialog */
406 add_widget (compl_dlg, compl_list);
408 /* fill the listbox with the completions */
409 for (i = num_compl - 1; i >= 0; i--) /* reverse order */
410 listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
412 /* pop up the dialog and apply the choosen completion */
413 if (run_dlg (compl_dlg) == B_ENTER)
415 listbox_get_current (compl_list, &curr, NULL);
416 if (curr)
418 #ifdef HAVE_CHARSET
419 GString *temp, *temp2;
420 temp = g_string_new ("");
421 for (curr += word_len; *curr; curr++)
422 g_string_append_c (temp, *curr);
424 temp2 = str_convert_to_input (temp->str);
426 if (temp2 && temp2->len)
428 g_string_free (temp, TRUE);
429 temp = temp2;
431 else
432 g_string_free (temp2, TRUE);
433 for (curr = temp->str; *curr; curr++)
434 edit_insert (edit, *curr);
435 g_string_free (temp, TRUE);
436 #else
437 for (curr += word_len; *curr; curr++)
438 edit_insert (edit, *curr);
439 #endif
443 /* destroy dialog before return */
444 destroy_dlg (compl_dlg);
447 /* --------------------------------------------------------------------------------------------- */
448 /* let the user select where function definition */
450 void
451 editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len,
452 etags_hash_t * def_hash, int num_lines)
455 int start_x, start_y, offset, i;
456 char *curr = NULL;
457 etags_hash_t *curr_def = NULL;
458 Dlg_head *def_dlg;
459 WListbox *def_list;
460 int def_dlg_h; /* dialog height */
461 int def_dlg_w; /* dialog width */
462 char *label_def = NULL;
464 (void) word_len;
465 /* calculate the dialog metrics */
466 def_dlg_h = num_lines + 2;
467 def_dlg_w = max_len + 4;
468 start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) +
469 EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
470 start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;
472 if (start_x < 0)
473 start_x = 0;
474 if (def_dlg_w > COLS)
475 def_dlg_w = COLS;
476 if (def_dlg_h > LINES - 2)
477 def_dlg_h = LINES - 2;
479 offset = start_x + def_dlg_w - COLS;
480 if (offset > 0)
481 start_x -= offset;
482 offset = start_y + def_dlg_h - LINES;
483 if (offset > 0)
484 start_y -= (offset + 1);
486 /* create the dialog */
487 def_dlg = create_dlg (TRUE, start_y, start_x, def_dlg_h, def_dlg_w,
488 dialog_colors, NULL, "[Definitions]", match_expr, DLG_COMPACT);
490 /* create the listbox */
491 def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, FALSE, NULL);
493 /* add the dialog */
494 add_widget (def_dlg, def_list);
496 /* fill the listbox with the completions */
497 for (i = 0; i < num_lines; i++)
499 label_def =
500 g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
501 def_hash[i].line);
502 listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i]);
503 g_free (label_def);
506 /* pop up the dialog and apply the choosen completion */
507 if (run_dlg (def_dlg) == B_ENTER)
509 char *tmp_curr_def = (char *) curr_def;
510 int do_moveto = 0;
512 listbox_get_current (def_list, &curr, (void **) &tmp_curr_def);
513 curr_def = (etags_hash_t *) tmp_curr_def;
514 if (edit->modified)
516 if (!edit_query_dialog2
517 (_("Warning"),
518 _("Current text was modified without a file save.\n"
519 "Continue discards these changes."), _("C&ontinue"), _("&Cancel")))
521 edit->force |= REDRAW_COMPLETELY;
522 do_moveto = 1;
525 else
527 do_moveto = 1;
530 if (curr && do_moveto)
532 if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
534 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
535 if (edit->dir_vpath != NULL)
537 edit_history_moveto[edit_stack_iterator].filename_vpath =
538 vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL);
540 else
542 edit_history_moveto[edit_stack_iterator].filename_vpath =
543 vfs_path_clone (edit->filename_vpath);
545 edit_history_moveto[edit_stack_iterator].line = edit->start_line +
546 edit->curs_row + 1;
547 edit_stack_iterator++;
548 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
549 edit_history_moveto[edit_stack_iterator].filename_vpath =
550 vfs_path_from_str ((char *) curr_def->fullpath);
551 edit_history_moveto[edit_stack_iterator].line = curr_def->line;
552 edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
553 edit_history_moveto[edit_stack_iterator].line);
558 /* clear definition hash */
559 for (i = 0; i < MAX_DEFINITIONS; i++)
561 g_free (def_hash[i].filename);
564 /* destroy dialog before return */
565 destroy_dlg (def_dlg);
568 /* --------------------------------------------------------------------------------------------- */
571 editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos,
572 int ypos)
574 /* dialog sizes */
575 int dlg_height = 9;
576 int dlg_width = 8;
578 int retval;
579 int i;
580 int btn_pos;
582 char *repl_from, *repl_to;
583 char tmp[BUF_MEDIUM];
585 QuickWidget quick_widgets[] = {
586 /* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
587 /* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
588 /* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
589 /* 3 */ QUICK_BUTTON (4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
590 /* 4 */ QUICK_LABEL (3, dlg_width, 2, dlg_height, NULL),
591 /* 5 */ QUICK_LABEL (3, dlg_width, 3, dlg_height, N_("Replace with:")),
592 /* 6 */ QUICK_LABEL (3, dlg_width, 4, dlg_height, NULL),
593 QUICK_END
596 #ifdef ENABLE_NLS
597 for (i = 0; i < 4; i++)
598 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
599 #endif
601 /* calculate button positions */
602 btn_pos = 4;
604 for (i = 3; i > -1; i--)
606 quick_widgets[i].relative_x = btn_pos;
607 btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5;
608 if (i == 3) /* default button */
609 btn_pos += 2;
612 dlg_width = btn_pos + 2;
614 /* correct widget coordinates */
615 for (i = 0; i < 7; i++)
616 quick_widgets[i].x_divisions = dlg_width;
618 g_snprintf (tmp, sizeof (tmp), "\"%s\"", from_text);
619 repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
621 g_snprintf (tmp, sizeof (tmp), "\"%s\"", to_text);
622 repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
624 quick_widgets[4].u.label.text = repl_from;
625 quick_widgets[6].u.label.text = repl_to;
627 if (xpos == -1)
628 xpos = (edit->widget.cols - dlg_width) / 2;
630 if (ypos == -1)
631 ypos = edit->widget.lines * 2 / 3;
634 QuickDialog Quick_input = {
635 dlg_width, dlg_height, 0, 0, N_("Confirm replace"),
636 "[Input Line Keys]", quick_widgets, NULL, FALSE
639 /* Sometimes menu can hide replaced text. I don't like it */
640 if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
641 ypos -= dlg_height;
643 Quick_input.ypos = ypos;
644 Quick_input.xpos = xpos;
646 retval = quick_dialog (&Quick_input);
647 g_free (repl_from);
648 g_free (repl_to);
650 return retval;
654 /* --------------------------------------------------------------------------------------------- */