editcmd_dialogs.c 20 KB

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