Set fullscreen layout as previous editor look'n'feel.
[midnight-commander.git] / src / editor / editcmd_dialogs.c
blob764cc2f25b267c9d428b263657b45edc48060b90
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 #include "lib/charsets.h"
37 #include "src/main.h"
38 #include "src/history.h"
40 #include "src/editor/editwidget.h"
41 #include "src/editor/etags.h"
42 #include "src/editor/editcmd_dialogs.h"
44 /*** global variables ****************************************************************************/
46 edit_search_options_t edit_search_options = {
47 .type = MC_SEARCH_T_NORMAL,
48 .case_sens = FALSE,
49 .backwards = FALSE,
50 .only_in_selection = FALSE,
51 .whole_words = FALSE,
52 .all_codepages = FALSE
55 /*** file scope macro definitions ****************************************************************/
57 #define SEARCH_DLG_WIDTH 58
58 #define SEARCH_DLG_MIN_HEIGHT 13
59 #define SEARCH_DLG_HEIGHT_SUPPLY 3
61 #define REPLACE_DLG_WIDTH 58
62 #define REPLACE_DLG_MIN_HEIGHT 17
63 #define REPLACE_DLG_HEIGHT_SUPPLY 5
65 /*** file scope type declarations ****************************************************************/
67 /*** file scope variables ************************************************************************/
69 /*** file scope functions ************************************************************************/
70 /* --------------------------------------------------------------------------------------------- */
72 static cb_ret_t
73 editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
74 dlg_msg_t msg, int parm, void *data)
76 switch (msg)
78 case DLG_KEY:
79 h->ret_value = parm;
80 dlg_stop (h);
81 return MSG_HANDLED;
82 default:
83 return default_dlg_callback (h, sender, msg, parm, data);
87 /* --------------------------------------------------------------------------------------------- */
88 /*** public functions ****************************************************************************/
89 /* --------------------------------------------------------------------------------------------- */
91 void
92 editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
93 /*@out@ */ char **search_text, /*@out@ */ char **replace_text)
95 if ((search_default == NULL) || (*search_default == '\0'))
96 search_default = INPUT_LAST_TEXT;
99 size_t num_of_types;
100 gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
101 int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
103 QuickWidget quick_widgets[] = {
104 /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
105 /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
106 #ifdef HAVE_CHARSET
107 /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT,
108 N_("&All charsets"),
109 &edit_search_options.all_codepages),
110 #endif
111 /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT,
112 N_("&Whole words"),
113 &edit_search_options.whole_words),
114 /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT,
115 N_("In se&lection"),
116 &edit_search_options.only_in_selection),
117 /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
118 &edit_search_options.backwards),
119 /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
120 N_("Cas&e sensitive"),
121 &edit_search_options.case_sens),
122 /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
123 num_of_types, (const char **) list_of_types,
124 (int *) &edit_search_options.type),
125 /* 8 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT,
126 N_("Enter replacement string:")),
127 /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
128 replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace",
129 replace_text),
130 /* 10 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT,
131 N_("Enter search string:")),
132 /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
133 search_default, REPLACE_DLG_WIDTH - 6, 0,
134 MC_HISTORY_SHARED_SEARCH, search_text),
135 QUICK_END
138 QuickDialog Quick_input = {
139 REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_("Replace"),
140 "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
143 if (quick_dialog (&Quick_input) != B_CANCEL)
145 edit->replace_mode = 0;
147 else
149 *replace_text = NULL;
150 *search_text = NULL;
153 g_strfreev (list_of_types);
157 /* --------------------------------------------------------------------------------------------- */
159 gboolean
160 editcmd_dialog_search_show (WEdit * edit)
162 char *search_text;
164 size_t num_of_types;
165 gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
166 int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
167 size_t i;
169 int dialog_result;
171 QuickWidget quick_widgets[] = {
172 /* 0 */
173 QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
174 /* 1 */
175 QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
176 /* 2 */
177 QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
178 #ifdef HAVE_CHARSET
179 /* 3 */
180 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("&All charsets"),
181 &edit_search_options.all_codepages),
182 #endif
183 /* 4 */
184 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
185 &edit_search_options.whole_words),
186 /* 5 */
187 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
188 &edit_search_options.only_in_selection),
189 /* 6 */
190 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
191 &edit_search_options.backwards),
192 /* 7 */
193 QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("Cas&e sensitive"),
194 &edit_search_options.case_sens),
195 /* 8 */
196 QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
197 num_of_types, (const char **) list_of_types,
198 (int *) &edit_search_options.type),
199 /* 9 */
200 QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
201 INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0,
202 MC_HISTORY_SHARED_SEARCH, &search_text),
203 /* 10 */
204 QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")),
205 QUICK_END
208 #ifdef HAVE_CHARSET
209 size_t last_checkbox = 7;
210 #else
211 size_t last_checkbox = 6;
212 #endif
214 QuickDialog Quick_input = {
215 SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
216 "[Input Line Keys]", quick_widgets, NULL, NULL, TRUE
219 #ifdef ENABLE_NLS
220 char **list_of_types_nls;
222 /* header title */
223 Quick_input.title = _(Quick_input.title);
224 /* buttons */
225 for (i = 0; i < 3; i++)
226 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
227 /* checkboxes */
228 for (i = 3; i <= last_checkbox; i++)
229 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
230 /* label */
231 quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
233 /* radiobuttons */
234 /* create copy of radio items to avoid memory leak */
235 list_of_types_nls = g_new0 (char *, num_of_types + 1);
236 for (i = 0; i < num_of_types; i++)
237 list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
238 g_strfreev (list_of_types);
239 list_of_types = list_of_types_nls;
240 quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
241 #endif
243 /* calculate widget coordinates */
245 int len = 0;
246 int dlg_width;
247 gchar **radio = list_of_types;
248 int b0_len, b1_len, b2_len;
249 const int button_gap = 2;
251 /* length of radiobuttons */
252 while (*radio != NULL)
254 len = max (len, str_term_width1 (*radio));
255 radio++;
257 /* length of checkboxes */
258 for (i = 3; i <= last_checkbox; i++)
259 len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
261 /* preliminary dialog width */
262 dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
264 /* length of buttons */
265 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
266 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
267 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
268 len = b0_len + b1_len + b2_len + button_gap * 2;
270 /* dialog width */
271 Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
273 /* correct widget coordinates */
274 for (i = 0; i < sizeof (quick_widgets) / sizeof (quick_widgets[0]); i++)
275 quick_widgets[i].x_divisions = Quick_input.xlen;
277 /* checkbox positions */
278 for (i = 3; i <= last_checkbox; i++)
279 quick_widgets[i].relative_x = Quick_input.xlen / 2 + 2;
280 /* input length */
281 quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
282 /* button positions */
283 quick_widgets[2].relative_x = Quick_input.xlen / 2 - len / 2;
284 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
285 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
288 dialog_result = quick_dialog (&Quick_input);
290 g_strfreev (list_of_types);
292 if ((dialog_result == B_CANCEL) || (search_text == NULL) || (search_text[0] == '\0'))
294 g_free (search_text);
295 return FALSE;
298 if (dialog_result == B_USER)
299 search_create_bookmark = TRUE;
301 #ifdef HAVE_CHARSET
303 GString *tmp;
305 tmp = str_convert_to_input (search_text);
306 if (tmp != NULL)
308 g_free (search_text);
309 search_text = g_string_free (tmp, FALSE);
312 #endif
314 g_free (edit->last_search_string);
315 edit->last_search_string = search_text;
316 mc_search_free (edit->search);
318 edit->search = mc_search_new (edit->last_search_string, -1);
319 if (edit->search != NULL)
321 edit->search->search_type = edit_search_options.type;
322 edit->search->is_all_charsets = edit_search_options.all_codepages;
323 edit->search->is_case_sensitive = edit_search_options.case_sens;
324 edit->search->whole_words = edit_search_options.whole_words;
325 edit->search->search_fn = edit_search_cmd_callback;
328 return (edit->search != NULL);
331 /* --------------------------------------------------------------------------------------------- */
332 /* gets a raw key from the keyboard. Passing cancel = 1 draws
333 a cancel button thus allowing c-c etc. Alternatively, cancel = 0
334 will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c,
335 and Esc are cannot returned */
338 editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel)
340 int w = str_term_width1 (query) + 7;
342 struct Dlg_head *raw_dlg =
343 create_dlg (TRUE, 0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL,
344 NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
345 add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors (),
346 2, "", 0, INPUT_COMPLETE_DEFAULT));
347 add_widget (raw_dlg, label_new (3 - cancel, 2, query));
348 if (cancel)
349 add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));
350 w = run_dlg (raw_dlg);
351 destroy_dlg (raw_dlg);
353 return (cancel && (w == ESC_CHAR || w == B_CANCEL)) ? 0 : w;
356 /* --------------------------------------------------------------------------------------------- */
357 /* let the user select its preferred completion */
359 void
360 editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
361 struct selection *compl, int num_compl)
364 int start_x, start_y, offset, i;
365 char *curr = NULL;
366 Dlg_head *compl_dlg;
367 WListbox *compl_list;
368 int compl_dlg_h; /* completion dialog height */
369 int compl_dlg_w; /* completion dialog width */
371 /* calculate the dialog metrics */
372 compl_dlg_h = num_compl + 2;
373 compl_dlg_w = max_len + 4;
374 start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) +
375 EDIT_TEXT_HORIZONTAL_OFFSET + (edit->fullscreen ? 0 : 1) + option_line_state_width;
376 start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;
378 if (start_x < 0)
379 start_x = 0;
380 if (compl_dlg_w > COLS)
381 compl_dlg_w = COLS;
382 if (compl_dlg_h > LINES - 2)
383 compl_dlg_h = LINES - 2;
385 offset = start_x + compl_dlg_w - COLS;
386 if (offset > 0)
387 start_x -= offset;
388 offset = start_y + compl_dlg_h - LINES;
389 if (offset > 0)
390 start_y -= (offset + 1);
392 /* create the dialog */
393 compl_dlg =
394 create_dlg (TRUE, start_y, start_x, compl_dlg_h, compl_dlg_w,
395 dialog_colors, NULL, NULL, "[Completion]", NULL, DLG_COMPACT);
397 /* create the listbox */
398 compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, FALSE, NULL);
400 /* add the dialog */
401 add_widget (compl_dlg, compl_list);
403 /* fill the listbox with the completions */
404 for (i = num_compl - 1; i >= 0; i--) /* reverse order */
405 listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
407 /* pop up the dialog and apply the choosen completion */
408 if (run_dlg (compl_dlg) == B_ENTER)
410 listbox_get_current (compl_list, &curr, NULL);
411 if (curr)
413 #ifdef HAVE_CHARSET
414 GString *temp, *temp2;
415 temp = g_string_new ("");
416 for (curr += word_len; *curr; curr++)
417 g_string_append_c (temp, *curr);
419 temp2 = str_convert_to_input (temp->str);
421 if (temp2 && temp2->len)
423 g_string_free (temp, TRUE);
424 temp = temp2;
426 else
427 g_string_free (temp2, TRUE);
428 for (curr = temp->str; *curr; curr++)
429 edit_insert (edit, *curr);
430 g_string_free (temp, TRUE);
431 #else
432 for (curr += word_len; *curr; curr++)
433 edit_insert (edit, *curr);
434 #endif
438 /* destroy dialog before return */
439 destroy_dlg (compl_dlg);
442 /* --------------------------------------------------------------------------------------------- */
443 /* let the user select where function definition */
445 void
446 editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len,
447 etags_hash_t * def_hash, int num_lines)
450 int start_x, start_y, offset, i;
451 char *curr = NULL;
452 etags_hash_t *curr_def = NULL;
453 Dlg_head *def_dlg;
454 WListbox *def_list;
455 int def_dlg_h; /* dialog height */
456 int def_dlg_w; /* dialog width */
457 char *label_def = NULL;
459 (void) word_len;
460 /* calculate the dialog metrics */
461 def_dlg_h = num_lines + 2;
462 def_dlg_w = max_len + 4;
463 start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) +
464 EDIT_TEXT_HORIZONTAL_OFFSET + (edit->fullscreen ? 0 : 1) + option_line_state_width;
465 start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;
467 if (start_x < 0)
468 start_x = 0;
469 if (def_dlg_w > COLS)
470 def_dlg_w = COLS;
471 if (def_dlg_h > LINES - 2)
472 def_dlg_h = LINES - 2;
474 offset = start_x + def_dlg_w - COLS;
475 if (offset > 0)
476 start_x -= offset;
477 offset = start_y + def_dlg_h - LINES;
478 if (offset > 0)
479 start_y -= (offset + 1);
481 /* create the dialog */
482 def_dlg = create_dlg (TRUE, start_y, start_x, def_dlg_h, def_dlg_w,
483 dialog_colors, NULL, NULL, "[Definitions]", match_expr, DLG_COMPACT);
485 /* create the listbox */
486 def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, FALSE, NULL);
488 /* add the dialog */
489 add_widget (def_dlg, def_list);
491 /* fill the listbox with the completions */
492 for (i = 0; i < num_lines; i++)
494 label_def =
495 g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
496 def_hash[i].line);
497 listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i]);
498 g_free (label_def);
501 /* pop up the dialog and apply the choosen completion */
502 if (run_dlg (def_dlg) == B_ENTER)
504 char *tmp_curr_def = (char *) curr_def;
505 int do_moveto = 0;
507 listbox_get_current (def_list, &curr, (void **) &tmp_curr_def);
508 curr_def = (etags_hash_t *) tmp_curr_def;
509 if (edit->modified)
511 if (!edit_query_dialog2
512 (_("Warning"),
513 _("Current text was modified without a file save.\n"
514 "Continue discards these changes."), _("C&ontinue"), _("&Cancel")))
516 edit->force |= REDRAW_COMPLETELY;
517 do_moveto = 1;
520 else
522 do_moveto = 1;
525 if (curr && do_moveto)
527 if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
529 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
530 if (edit->dir_vpath != NULL)
532 edit_history_moveto[edit_stack_iterator].filename_vpath =
533 vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL);
535 else
537 edit_history_moveto[edit_stack_iterator].filename_vpath =
538 vfs_path_clone (edit->filename_vpath);
540 edit_history_moveto[edit_stack_iterator].line = edit->start_line +
541 edit->curs_row + 1;
542 edit_stack_iterator++;
543 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
544 edit_history_moveto[edit_stack_iterator].filename_vpath =
545 vfs_path_from_str ((char *) curr_def->fullpath);
546 edit_history_moveto[edit_stack_iterator].line = curr_def->line;
547 edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
548 edit_history_moveto[edit_stack_iterator].line);
553 /* clear definition hash */
554 for (i = 0; i < MAX_DEFINITIONS; i++)
556 g_free (def_hash[i].filename);
559 /* destroy dialog before return */
560 destroy_dlg (def_dlg);
563 /* --------------------------------------------------------------------------------------------- */
566 editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos,
567 int ypos)
569 /* dialog sizes */
570 int dlg_height = 9;
571 int dlg_width = 8;
573 int retval;
574 int i;
575 int btn_pos;
577 char *repl_from, *repl_to;
578 char tmp[BUF_MEDIUM];
580 QuickWidget quick_widgets[] = {
581 /* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
582 /* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
583 /* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
584 /* 3 */ QUICK_BUTTON (4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
585 /* 4 */ QUICK_LABEL (3, dlg_width, 2, dlg_height, NULL),
586 /* 5 */ QUICK_LABEL (3, dlg_width, 3, dlg_height, N_("Replace with:")),
587 /* 6 */ QUICK_LABEL (3, dlg_width, 4, dlg_height, NULL),
588 QUICK_END
591 #ifdef ENABLE_NLS
592 for (i = 0; i < 4; i++)
593 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
594 #endif
596 /* calculate button positions */
597 btn_pos = 4;
599 for (i = 3; i > -1; i--)
601 quick_widgets[i].relative_x = btn_pos;
602 btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5;
603 if (i == 3) /* default button */
604 btn_pos += 2;
607 dlg_width = btn_pos + 2;
609 /* correct widget coordinates */
610 for (i = 0; i < 7; i++)
611 quick_widgets[i].x_divisions = dlg_width;
613 g_snprintf (tmp, sizeof (tmp), "\"%s\"", from_text);
614 repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
616 g_snprintf (tmp, sizeof (tmp), "\"%s\"", to_text);
617 repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
619 quick_widgets[4].u.label.text = repl_from;
620 quick_widgets[6].u.label.text = repl_to;
622 if (xpos == -1)
623 xpos = (edit->widget.cols - dlg_width) / 2;
625 if (ypos == -1)
626 ypos = edit->widget.lines * 2 / 3;
629 QuickDialog Quick_input = {
630 dlg_width, dlg_height, 0, 0, N_("Confirm replace"),
631 "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
634 /* Sometimes menu can hide replaced text. I don't like it */
635 if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
636 ypos -= dlg_height;
638 Quick_input.ypos = ypos;
639 Quick_input.xpos = xpos;
641 retval = quick_dialog (&Quick_input);
642 g_free (repl_from);
643 g_free (repl_to);
645 return retval;
649 /* --------------------------------------------------------------------------------------------- */