editcmd_dialogs.c 22 KB

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