editcmd_dialogs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. Editor dialogs for high level editing commands
  3. Copyright (C) 2009 The Free Software Foundation, Inc.
  4. Written by:
  5. Slava Zanko <slavazanko@gmail.com>, 2009.
  6. This file is part of the Midnight Commander.
  7. The Midnight Commander is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11. The Midnight Commander is distributed in the hope that it will be
  12. useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  13. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. MA 02110-1301, USA.
  19. */
  20. #include <config.h>
  21. #include "../src/global.h"
  22. #include "../src/tty/tty.h"
  23. #include "../src/skin/skin.h" /* INPUT_COLOR */
  24. #include "../src/tty/key.h"
  25. #include "../src/search/search.h"
  26. #include "../src/dialog.h"
  27. #include "../src/widget.h"
  28. #include "../src/wtools.h"
  29. #include "../src/strutil.h"
  30. #include "../src/main.h"
  31. #include "../src/history.h"
  32. #include "../src/charsets.h"
  33. #include "../edit/edit-widget.h"
  34. #include "../edit/etags.h"
  35. #include "../edit/editcmd_dialogs.h"
  36. /*** global variables **************************************************/
  37. /*** file scope macro definitions **************************************/
  38. #define SEARCH_DLG_WIDTH 58
  39. #define SEARCH_DLG_MIN_HEIGHT 13
  40. #define SEARCH_DLG_HEIGHT_SUPPLY 3
  41. #define REPLACE_DLG_WIDTH 58
  42. #define REPLACE_DLG_MIN_HEIGHT 17
  43. #define REPLACE_DLG_HEIGHT_SUPPLY 5
  44. /*** file scope type declarations **************************************/
  45. /*** file scope variables **********************************************/
  46. /*** file scope functions **********************************************/
  47. static cb_ret_t
  48. editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget *sender,
  49. dlg_msg_t msg, int parm, void *data)
  50. {
  51. switch (msg) {
  52. case DLG_KEY:
  53. h->ret_value = parm;
  54. dlg_stop (h);
  55. return MSG_HANDLED;
  56. default:
  57. return default_dlg_callback (h, sender, msg, parm, data);
  58. }
  59. }
  60. /*** public functions **************************************************/
  61. void
  62. editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
  63. /*@out@ */ char **search_text, /*@out@ */ char **replace_text)
  64. {
  65. if (*search_default == '\0')
  66. search_default = INPUT_LAST_TEXT;
  67. {
  68. size_t num_of_types;
  69. gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
  70. int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
  71. QuickWidget quick_widgets[] =
  72. {
  73. /* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
  74. /* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
  75. #ifdef HAVE_CHARSET
  76. /* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages),
  77. #endif
  78. /* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words),
  79. /* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection),
  80. /* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards),
  81. /* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case),
  82. /* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
  83. num_of_types, (const char **) list_of_types, (int *) &edit->search_type),
  84. /* 8 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT, N_(" Enter replacement string:")),
  85. /* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
  86. replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace", replace_text),
  87. /* 10 */ QUICK_LABEL (2, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT, N_(" Enter search string:")),
  88. /* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
  89. search_default, REPLACE_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text),
  90. QUICK_END
  91. };
  92. QuickDialog Quick_input =
  93. {
  94. REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_(" Replace "),
  95. "[Input Line Keys]", quick_widgets, FALSE
  96. };
  97. if (quick_dialog (&Quick_input) != B_CANCEL) {
  98. edit->replace_mode = 0;
  99. } else {
  100. *replace_text = NULL;
  101. *search_text = NULL;
  102. }
  103. g_strfreev (list_of_types);
  104. }
  105. }
  106. /* --------------------------------------------------------------------------------------------- */
  107. void
  108. editcmd_dialog_search_show (WEdit * edit, char **search_text)
  109. {
  110. if (*search_text == '\0')
  111. *search_text = INPUT_LAST_TEXT;
  112. {
  113. size_t num_of_types;
  114. gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
  115. int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
  116. size_t i;
  117. int dialog_result;
  118. QuickWidget quick_widgets[] =
  119. {
  120. /* 0 */
  121. QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
  122. /* 1 */
  123. QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
  124. /* 2 */
  125. QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
  126. #ifdef HAVE_CHARSET
  127. /* 3 */
  128. QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("All charsets"), &edit->all_codepages),
  129. #endif
  130. /* 4 */
  131. QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"), &edit->whole_words),
  132. /* 5 */
  133. QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"), &edit->only_in_selection),
  134. /* 6 */
  135. QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), &edit->replace_backwards),
  136. /* 7 */
  137. QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), &edit->replace_case),
  138. /* 8 */
  139. QUICK_RADIO ( 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
  140. num_of_types, (const char **) list_of_types, (int *) &edit->search_type),
  141. /* 9 */
  142. QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
  143. *search_text, SEARCH_DLG_WIDTH - 6, 0, MC_HISTORY_SHARED_SEARCH, search_text),
  144. /* 10 */
  145. QUICK_LABEL (2, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_(" Enter search string:")),
  146. QUICK_END
  147. };
  148. #ifdef HAVE_CHARSET
  149. size_t last_checkbox = 7;
  150. #else
  151. size_t last_checkbox = 6;
  152. #endif
  153. QuickDialog Quick_input =
  154. {
  155. SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
  156. "[Input Line Keys]", quick_widgets, TRUE
  157. };
  158. #ifdef ENABLE_NLS
  159. char **list_of_types_nls;
  160. /* header title */
  161. Quick_input.title = _(Quick_input.title);
  162. /* buttons */
  163. for (i = 0; i < 3; i++)
  164. quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
  165. /* checkboxes */
  166. for (i = 3; i <= last_checkbox; i++)
  167. quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
  168. /* label */
  169. quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
  170. /* radiobuttons */
  171. /* create copy of radio items to avoid memory leak */
  172. list_of_types_nls = g_new0 (char *, num_of_types + 1);
  173. for (i = 0; i < num_of_types; i++)
  174. list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
  175. g_strfreev (list_of_types);
  176. list_of_types = list_of_types_nls;
  177. quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
  178. #endif
  179. /* calculate widget coordinates */
  180. {
  181. int len = 0;
  182. int dlg_width;
  183. gchar **radio = list_of_types;
  184. int b0_len, b1_len, b2_len;
  185. const int button_gap = 2;
  186. /* length of radiobuttons */
  187. while (*radio != NULL) {
  188. len = max (len, str_term_width1 (*radio));
  189. radio++;
  190. }
  191. /* length of checkboxes */
  192. for (i = 3; i <= last_checkbox; i++)
  193. len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
  194. /* preliminary dialog width */
  195. dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
  196. /* length of buttons */
  197. b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
  198. b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
  199. b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
  200. len = b0_len + b1_len + b2_len + button_gap * 2;
  201. /* dialog width */
  202. Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
  203. /* correct widget coordinates */
  204. for (i = 0; i < sizeof (quick_widgets)/sizeof (quick_widgets[0]); i++)
  205. quick_widgets[i].x_divisions = Quick_input.xlen;
  206. /* checkbox positions */
  207. for (i = 3; i <= last_checkbox; i++)
  208. quick_widgets[i].relative_x = Quick_input.xlen/2 + 2;
  209. /* input length */
  210. quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
  211. /* button positions */
  212. quick_widgets[2].relative_x = Quick_input.xlen/2 - len/2;
  213. quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
  214. quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
  215. }
  216. dialog_result = quick_dialog (&Quick_input);
  217. g_strfreev (list_of_types);
  218. if (dialog_result == B_CANCEL)
  219. *search_text = NULL;
  220. else if (dialog_result == B_USER)
  221. search_create_bookmark = 1;
  222. }
  223. }
  224. /* --------------------------------------------------------------------------------------------- */
  225. /* gets a raw key from the keyboard. Passing cancel = 1 draws
  226. a cancel button thus allowing c-c etc. Alternatively, cancel = 0
  227. will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c,
  228. and Esc are cannot returned */
  229. int
  230. editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel)
  231. {
  232. int w = str_term_width1 (query) + 7;
  233. struct Dlg_head *raw_dlg =
  234. create_dlg (0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb,
  235. NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
  236. add_widget (raw_dlg,
  237. input_new (3 - cancel, w - 5, INPUT_COLOR, 2, "", 0, INPUT_COMPLETE_DEFAULT));
  238. add_widget (raw_dlg, label_new (3 - cancel, 2, query));
  239. if (cancel)
  240. add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));
  241. w = run_dlg (raw_dlg);
  242. destroy_dlg (raw_dlg);
  243. if (cancel) {
  244. if (w == XCTRL ('g') || w == XCTRL ('c') || w == ESC_CHAR || w == B_CANCEL)
  245. return 0;
  246. }
  247. return w;
  248. }
  249. /* --------------------------------------------------------------------------------------------- */
  250. /* let the user select its preferred completion */
  251. void
  252. editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
  253. struct selection *compl, int num_compl)
  254. {
  255. int start_x, start_y, offset, i;
  256. char *curr = NULL;
  257. Dlg_head *compl_dlg;
  258. WListbox *compl_list;
  259. int compl_dlg_h; /* completion dialog height */
  260. int compl_dlg_w; /* completion dialog width */
  261. /* calculate the dialog metrics */
  262. compl_dlg_h = num_compl + 2;
  263. compl_dlg_w = max_len + 4;
  264. start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) +
  265. EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
  266. start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;
  267. if (start_x < 0)
  268. start_x = 0;
  269. if (compl_dlg_w > COLS)
  270. compl_dlg_w = COLS;
  271. if (compl_dlg_h > LINES - 2)
  272. compl_dlg_h = LINES - 2;
  273. offset = start_x + compl_dlg_w - COLS;
  274. if (offset > 0)
  275. start_x -= offset;
  276. offset = start_y + compl_dlg_h - LINES;
  277. if (offset > 0)
  278. start_y -= (offset + 1);
  279. /* create the dialog */
  280. compl_dlg =
  281. create_dlg (start_y, start_x, compl_dlg_h, compl_dlg_w,
  282. dialog_colors, NULL, "[Completion]", NULL, DLG_COMPACT);
  283. /* create the listbox */
  284. compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, NULL);
  285. /* add the dialog */
  286. add_widget (compl_dlg, compl_list);
  287. /* fill the listbox with the completions */
  288. for (i = num_compl - 1; i >= 0; i--) /* reverse order */
  289. listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
  290. /* pop up the dialog and apply the choosen completion */
  291. if (run_dlg (compl_dlg) == B_ENTER) {
  292. listbox_get_current (compl_list, &curr, NULL);
  293. if (curr) {
  294. #ifdef HAVE_CHARSET
  295. GString *temp, *temp2;
  296. temp = g_string_new("");
  297. for (curr += word_len; *curr; curr++)
  298. g_string_append_c(temp, *curr);
  299. temp2 = str_convert_to_input (temp->str);
  300. if (temp2 && temp2->len){
  301. g_string_free(temp, TRUE);
  302. temp = temp2;
  303. }
  304. else
  305. g_string_free(temp2, TRUE);
  306. for (curr = temp->str; *curr; curr++)
  307. edit_insert (edit, *curr);
  308. g_string_free(temp, TRUE);
  309. #else
  310. for (curr += word_len; *curr; curr++)
  311. edit_insert (edit, *curr);
  312. #endif
  313. }
  314. }
  315. /* destroy dialog before return */
  316. destroy_dlg (compl_dlg);
  317. }
  318. /* --------------------------------------------------------------------------------------------- */
  319. /* let the user select where function definition */
  320. void
  321. editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len,
  322. etags_hash_t * def_hash, int num_lines)
  323. {
  324. int start_x, start_y, offset, i;
  325. char *curr = NULL;
  326. etags_hash_t *curr_def = NULL;
  327. Dlg_head *def_dlg;
  328. WListbox *def_list;
  329. int def_dlg_h; /* dialog height */
  330. int def_dlg_w; /* dialog width */
  331. char *label_def = NULL;
  332. (void) word_len;
  333. /* calculate the dialog metrics */
  334. def_dlg_h = num_lines + 2;
  335. def_dlg_w = max_len + 4;
  336. start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) +
  337. EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
  338. start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;
  339. if (start_x < 0)
  340. start_x = 0;
  341. if (def_dlg_w > COLS)
  342. def_dlg_w = COLS;
  343. if (def_dlg_h > LINES - 2)
  344. def_dlg_h = LINES - 2;
  345. offset = start_x + def_dlg_w - COLS;
  346. if (offset > 0)
  347. start_x -= offset;
  348. offset = start_y + def_dlg_h - LINES;
  349. if (offset > 0)
  350. start_y -= (offset + 1);
  351. /* create the dialog */
  352. def_dlg = create_dlg (start_y, start_x, def_dlg_h, def_dlg_w,
  353. dialog_colors, NULL, "[Definitions]", match_expr, DLG_COMPACT);
  354. /* create the listbox */
  355. def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, NULL);
  356. /* add the dialog */
  357. add_widget (def_dlg, def_list);
  358. /* fill the listbox with the completions */
  359. for (i = 0; i < num_lines; i++) {
  360. label_def =
  361. g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
  362. def_hash[i].line);
  363. listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i]);
  364. g_free (label_def);
  365. }
  366. /* pop up the dialog */
  367. run_dlg (def_dlg);
  368. /* apply the choosen completion */
  369. if (def_dlg->ret_value == B_ENTER) {
  370. char *tmp_curr_def = (char *) curr_def;
  371. int do_moveto = 0;
  372. listbox_get_current (def_list, &curr, &tmp_curr_def);
  373. curr_def = (etags_hash_t *) tmp_curr_def;
  374. if (edit->modified) {
  375. if (!edit_query_dialog2
  376. (_("Warning"),
  377. _(" Current text was modified without a file save. \n"
  378. " Continue discards these changes. "), _("C&ontinue"), _("&Cancel"))) {
  379. edit->force |= REDRAW_COMPLETELY;
  380. do_moveto = 1;
  381. }
  382. } else {
  383. do_moveto = 1;
  384. }
  385. if (curr && do_moveto) {
  386. if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO) {
  387. g_free (edit_history_moveto[edit_stack_iterator].filename);
  388. if (edit->dir) {
  389. edit_history_moveto[edit_stack_iterator].filename =
  390. g_strdup_printf ("%s/%s", edit->dir, edit->filename);
  391. } else {
  392. edit_history_moveto[edit_stack_iterator].filename = g_strdup (edit->filename);
  393. }
  394. edit_history_moveto[edit_stack_iterator].line = edit->start_line +
  395. edit->curs_row + 1;
  396. edit_stack_iterator++;
  397. g_free (edit_history_moveto[edit_stack_iterator].filename);
  398. edit_history_moveto[edit_stack_iterator].filename =
  399. g_strdup ((char *) curr_def->fullpath);
  400. edit_history_moveto[edit_stack_iterator].line = curr_def->line;
  401. edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename,
  402. edit_history_moveto[edit_stack_iterator].line);
  403. }
  404. }
  405. }
  406. /* clear definition hash */
  407. for (i = 0; i < MAX_DEFINITIONS; i++) {
  408. g_free (def_hash[i].filename);
  409. }
  410. /* destroy dialog before return */
  411. destroy_dlg (def_dlg);
  412. }
  413. /* --------------------------------------------------------------------------------------------- */
  414. int
  415. editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos, int ypos)
  416. {
  417. /* dialog sizes */
  418. int dlg_height = 9;
  419. int dlg_width = 8;
  420. int retval;
  421. int i;
  422. int btn_pos;
  423. char *repl_from, *repl_to;
  424. char tmp [BUF_MEDIUM];
  425. QuickWidget quick_widgets[] =
  426. {
  427. /* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
  428. /* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
  429. /* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
  430. /* 3 */ QUICK_BUTTON ( 4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
  431. /* 4 */ QUICK_LABEL ( 3, dlg_width, 2, dlg_height, NULL),
  432. /* 5 */ QUICK_LABEL ( 2, dlg_width, 3, dlg_height, N_(" Replace with: ")),
  433. /* 6 */ QUICK_LABEL ( 3, dlg_width, 4, dlg_height, NULL),
  434. QUICK_END
  435. };
  436. #ifdef ENABLE_NLS
  437. for (i = 0; i < 4; i++)
  438. quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
  439. #endif
  440. /* calculate button positions */
  441. btn_pos = 4;
  442. for (i = 3; i > -1; i--) {
  443. quick_widgets[i].relative_x = btn_pos;
  444. btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5;
  445. if (i == 3) /* default button */
  446. btn_pos += 2;
  447. }
  448. dlg_width = btn_pos + 2;
  449. /* correct widget coordinates */
  450. for (i = 0; i < 7; i++)
  451. quick_widgets[i].x_divisions = dlg_width;
  452. g_snprintf (tmp, sizeof (tmp), " '%s'", from_text);
  453. repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
  454. g_snprintf (tmp, sizeof (tmp), " '%s'", to_text);
  455. repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
  456. quick_widgets[4].u.label.text = repl_from;
  457. quick_widgets[6].u.label.text = repl_to;
  458. if (xpos == -1)
  459. xpos = (edit->num_widget_columns - dlg_width) / 2;
  460. if (ypos == -1)
  461. ypos = edit->num_widget_lines * 2 / 3;
  462. {
  463. QuickDialog Quick_input =
  464. {
  465. dlg_width, dlg_height, 0, 0, N_ (" Confirm replace "),
  466. "[Input Line Keys]", quick_widgets, FALSE
  467. };
  468. /* Sometimes menu can hide replaced text. I don't like it */
  469. if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
  470. ypos -= dlg_height;
  471. Quick_input.ypos = ypos;
  472. Quick_input.xpos = xpos;
  473. retval = quick_dialog (&Quick_input);
  474. g_free (repl_from);
  475. g_free (repl_to);
  476. return retval;
  477. }
  478. }
  479. /* --------------------------------------------------------------------------------------------- */