dialog.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /*
  2. Dialog box features module for the Midnight Commander
  3. Copyright (C) 1994-2020
  4. Free Software Foundation, Inc.
  5. This file is part of the Midnight Commander.
  6. The Midnight Commander is free software: you can redistribute it
  7. and/or modify it under the terms of the GNU General Public License as
  8. published by the Free Software Foundation, either version 3 of the License,
  9. or (at your option) any later version.
  10. The Midnight Commander is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /** \file dialog.c
  18. * \brief Source: dialog box features module
  19. */
  20. #include <config.h>
  21. #include <ctype.h>
  22. #include <errno.h>
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include "lib/global.h"
  29. #include "lib/tty/tty.h"
  30. #include "lib/skin.h"
  31. #include "lib/tty/key.h"
  32. #include "lib/strutil.h"
  33. #include "lib/fileloc.h" /* MC_HISTORY_FILE */
  34. #include "lib/event.h" /* mc_event_raise() */
  35. #include "lib/util.h" /* MC_PTR_FREE */
  36. #include "lib/mcconfig.h" /* num_history_items_recorded */
  37. #include "lib/widget.h"
  38. #include "lib/widget/mouse.h"
  39. /*** global variables ****************************************************************************/
  40. /* Color styles for normal and error dialogs */
  41. dlg_colors_t dialog_colors;
  42. dlg_colors_t alarm_colors;
  43. dlg_colors_t listbox_colors;
  44. /* Primitive way to check if the the current dialog is our dialog */
  45. /* This is needed by async routines like load_prompt */
  46. GList *top_dlg = NULL;
  47. /* A hook list for idle events */
  48. hook_t *idle_hook = NULL;
  49. /* If set then dialogs just clean the screen when refreshing, else */
  50. /* they do a complete refresh, refreshing all the parts of the program */
  51. gboolean fast_refresh = FALSE;
  52. /* left click outside of dialog closes it */
  53. gboolean mouse_close_dialog = FALSE;
  54. const global_keymap_t *dialog_map = NULL;
  55. /*** file scope macro definitions ****************************************************************/
  56. /*** file scope type declarations ****************************************************************/
  57. /*** file scope variables ************************************************************************/
  58. /* --------------------------------------------------------------------------------------------- */
  59. /*** file scope functions ************************************************************************/
  60. /* --------------------------------------------------------------------------------------------- */
  61. /**
  62. * Read histories from the ${XDG_CACHE_HOME}/mc/history file
  63. */
  64. static void
  65. dlg_read_history (WDialog * h)
  66. {
  67. char *profile;
  68. ev_history_load_save_t event_data;
  69. if (num_history_items_recorded == 0) /* this is how to disable */
  70. return;
  71. profile = mc_config_get_full_path (MC_HISTORY_FILE);
  72. event_data.cfg = mc_config_init (profile, TRUE);
  73. event_data.receiver = NULL;
  74. /* create all histories in dialog */
  75. mc_event_raise (h->event_group, MCEVENT_HISTORY_LOAD, &event_data);
  76. mc_config_deinit (event_data.cfg);
  77. g_free (profile);
  78. }
  79. /* --------------------------------------------------------------------------------------------- */
  80. static void
  81. refresh_cmd (void)
  82. {
  83. #ifdef HAVE_SLANG
  84. tty_touch_screen ();
  85. mc_refresh ();
  86. #else
  87. /* Use this if the refreshes fail */
  88. clr_scr ();
  89. repaint_screen ();
  90. #endif /* HAVE_SLANG */
  91. }
  92. /* --------------------------------------------------------------------------------------------- */
  93. static cb_ret_t
  94. dlg_execute_cmd (WDialog * h, long command)
  95. {
  96. WGroup *g = GROUP (h);
  97. cb_ret_t ret = MSG_HANDLED;
  98. if (send_message (h, NULL, MSG_ACTION, command, NULL) == MSG_HANDLED)
  99. return MSG_HANDLED;
  100. switch (command)
  101. {
  102. case CK_Ok:
  103. h->ret_value = B_ENTER;
  104. dlg_stop (h);
  105. break;
  106. case CK_Cancel:
  107. h->ret_value = B_CANCEL;
  108. dlg_stop (h);
  109. break;
  110. case CK_Up:
  111. case CK_Left:
  112. group_select_prev_widget (g);
  113. break;
  114. case CK_Down:
  115. case CK_Right:
  116. group_select_next_widget (g);
  117. break;
  118. case CK_Help:
  119. {
  120. ev_help_t event_data = { NULL, h->help_ctx };
  121. mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
  122. }
  123. break;
  124. case CK_Suspend:
  125. mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
  126. refresh_cmd ();
  127. break;
  128. case CK_Refresh:
  129. refresh_cmd ();
  130. break;
  131. case CK_ScreenList:
  132. if (!widget_get_state (WIDGET (h), WST_MODAL))
  133. dialog_switch_list ();
  134. else
  135. ret = MSG_NOT_HANDLED;
  136. break;
  137. case CK_ScreenNext:
  138. if (!widget_get_state (WIDGET (h), WST_MODAL))
  139. dialog_switch_next ();
  140. else
  141. ret = MSG_NOT_HANDLED;
  142. break;
  143. case CK_ScreenPrev:
  144. if (!widget_get_state (WIDGET (h), WST_MODAL))
  145. dialog_switch_prev ();
  146. else
  147. ret = MSG_NOT_HANDLED;
  148. break;
  149. default:
  150. ret = MSG_NOT_HANDLED;
  151. }
  152. return ret;
  153. }
  154. /* --------------------------------------------------------------------------------------------- */
  155. static cb_ret_t
  156. dlg_handle_key (WDialog * h, int d_key)
  157. {
  158. long command;
  159. command = widget_lookup_key (WIDGET (h), d_key);
  160. if (command != CK_IgnoreKey)
  161. return dlg_execute_cmd (h, command);
  162. return MSG_NOT_HANDLED;
  163. }
  164. /* --------------------------------------------------------------------------------------------- */
  165. static cb_ret_t
  166. dlg_try_hotkey (WDialog * h, int d_key)
  167. {
  168. WGroup *g = GROUP (h);
  169. GList *hot_cur;
  170. Widget *current;
  171. cb_ret_t handled;
  172. int c;
  173. if (g->widgets == NULL)
  174. return MSG_NOT_HANDLED;
  175. if (g->current == NULL)
  176. g->current = g->widgets;
  177. /*
  178. * Explanation: we don't send letter hotkeys to other widgets if
  179. * the currently selected widget is an input line
  180. */
  181. current = WIDGET (g->current->data);
  182. if (widget_get_state (current, WST_DISABLED))
  183. return MSG_NOT_HANDLED;
  184. if (widget_get_options (current, WOP_IS_INPUT))
  185. {
  186. /* skip ascii control characters, anything else can valid character in
  187. * some encoding */
  188. if (d_key >= 32 && d_key < 256)
  189. return MSG_NOT_HANDLED;
  190. }
  191. /* If it's an alt key, send the message */
  192. c = d_key & ~ALT (0);
  193. if (d_key & ALT (0) && g_ascii_isalpha (c))
  194. d_key = g_ascii_tolower (c);
  195. if (!widget_get_options (current, WOP_WANT_HOTKEY))
  196. handled = MSG_NOT_HANDLED;
  197. else
  198. handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL);
  199. /* If not used, send hotkey to other widgets */
  200. if (handled == MSG_HANDLED)
  201. return MSG_HANDLED;
  202. hot_cur = group_get_widget_next_of (g->current);
  203. /* send it to all widgets */
  204. while (g->current != hot_cur && handled == MSG_NOT_HANDLED)
  205. {
  206. current = WIDGET (hot_cur->data);
  207. if (widget_get_options (current, WOP_WANT_HOTKEY)
  208. && !widget_get_state (current, WST_DISABLED))
  209. handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL);
  210. if (handled == MSG_NOT_HANDLED)
  211. hot_cur = group_get_widget_next_of (hot_cur);
  212. }
  213. if (handled == MSG_HANDLED)
  214. {
  215. current = WIDGET (hot_cur->data);
  216. widget_select (current);
  217. send_message (h, current, MSG_HOTKEY_HANDLED, 0, NULL);
  218. }
  219. return handled;
  220. }
  221. /* --------------------------------------------------------------------------------------------- */
  222. static void
  223. dlg_key_event (WDialog * h, int d_key)
  224. {
  225. WGroup *g = GROUP (h);
  226. cb_ret_t handled;
  227. if (g->widgets == NULL)
  228. return;
  229. if (g->current == NULL)
  230. g->current = g->widgets;
  231. /* TAB used to cycle */
  232. if (!widget_get_options (WIDGET (g), WOP_WANT_TAB))
  233. {
  234. if (d_key == '\t')
  235. {
  236. group_select_next_widget (g);
  237. return;
  238. }
  239. else if ((d_key & ~(KEY_M_SHIFT | KEY_M_CTRL)) == '\t')
  240. {
  241. group_select_prev_widget (g);
  242. return;
  243. }
  244. }
  245. /* first can dlalog handle the key itself */
  246. handled = send_message (h, NULL, MSG_KEY, d_key, NULL);
  247. /* next try the hotkey */
  248. if (handled == MSG_NOT_HANDLED)
  249. handled = dlg_try_hotkey (h, d_key);
  250. /* not used - then try widget_callback */
  251. if (handled == MSG_NOT_HANDLED)
  252. handled = send_message (g->current->data, NULL, MSG_KEY, d_key, NULL);
  253. /* not used - try to use the unhandled case */
  254. if (handled == MSG_NOT_HANDLED)
  255. handled = send_message (h, g->current->data, MSG_UNHANDLED_KEY, d_key, NULL);
  256. if (handled == MSG_NOT_HANDLED)
  257. handled = dlg_handle_key (h, d_key);
  258. (void) handled;
  259. send_message (h, NULL, MSG_POST_KEY, d_key, NULL);
  260. }
  261. /* --------------------------------------------------------------------------------------------- */
  262. static int
  263. dlg_handle_mouse_event (Widget * w, Gpm_Event * event)
  264. {
  265. if (w->mouse_callback != NULL)
  266. {
  267. int mou;
  268. mou = mouse_handle_event (w, event);
  269. if (mou != MOU_UNHANDLED)
  270. return mou;
  271. }
  272. return group_handle_mouse_event (w, event);
  273. }
  274. /* --------------------------------------------------------------------------------------------- */
  275. static void
  276. frontend_dlg_run (WDialog * h)
  277. {
  278. Widget *wh = WIDGET (h);
  279. Gpm_Event event;
  280. event.x = -1;
  281. /* close opened editors, viewers, etc */
  282. if (!widget_get_state (wh, WST_MODAL) && mc_global.midnight_shutdown)
  283. {
  284. send_message (h, NULL, MSG_VALIDATE, 0, NULL);
  285. return;
  286. }
  287. while (widget_get_state (wh, WST_ACTIVE))
  288. {
  289. int d_key;
  290. if (tty_got_winch ())
  291. dialog_change_screen_size ();
  292. if (is_idle ())
  293. {
  294. if (idle_hook)
  295. execute_hooks (idle_hook);
  296. while (widget_get_state (wh, WST_IDLE) && is_idle ())
  297. send_message (wh, NULL, MSG_IDLE, 0, NULL);
  298. /* Allow terminating the dialog from the idle handler */
  299. if (!widget_get_state (wh, WST_ACTIVE))
  300. break;
  301. }
  302. widget_update_cursor (wh);
  303. /* Clear interrupt flag */
  304. tty_got_interrupt ();
  305. d_key = tty_get_event (&event, GROUP (h)->mouse_status == MOU_REPEAT, TRUE);
  306. dlg_process_event (h, d_key, &event);
  307. if (widget_get_state (wh, WST_CLOSED))
  308. send_message (h, NULL, MSG_VALIDATE, 0, NULL);
  309. }
  310. }
  311. /* --------------------------------------------------------------------------------------------- */
  312. /*** public functions ****************************************************************************/
  313. /* --------------------------------------------------------------------------------------------- */
  314. /** Default dialog callback */
  315. cb_ret_t
  316. dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
  317. {
  318. switch (msg)
  319. {
  320. case MSG_IDLE:
  321. /* we don't want endless loop */
  322. widget_idle (w, FALSE);
  323. return MSG_HANDLED;
  324. default:
  325. return group_default_callback (w, sender, msg, parm, data);
  326. }
  327. }
  328. /* --------------------------------------------------------------------------------------------- */
  329. void
  330. dlg_default_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
  331. {
  332. switch (msg)
  333. {
  334. case MSG_MOUSE_CLICK:
  335. if (event->y < 0 || event->y >= w->lines || event->x < 0 || event->x >= w->cols)
  336. {
  337. DIALOG (w)->ret_value = B_CANCEL;
  338. dlg_stop (DIALOG (w));
  339. }
  340. break;
  341. default:
  342. /* return MOU_UNHANDLED */
  343. event->result.abort = TRUE;
  344. break;
  345. }
  346. }
  347. /* --------------------------------------------------------------------------------------------- */
  348. WDialog *
  349. dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flags_t pos_flags,
  350. gboolean compact, const int *colors, widget_cb_fn callback,
  351. widget_mouse_cb_fn mouse_callback, const char *help_ctx, const char *title)
  352. {
  353. WDialog *new_d;
  354. Widget *w;
  355. WGroup *g;
  356. new_d = g_new0 (WDialog, 1);
  357. w = WIDGET (new_d);
  358. g = GROUP (new_d);
  359. widget_adjust_position (pos_flags, &y1, &x1, &lines, &cols);
  360. group_init (g, y1, x1, lines, cols, callback != NULL ? callback : dlg_default_callback,
  361. mouse_callback != NULL ? mouse_callback : dlg_default_mouse_callback);
  362. w->pos_flags = pos_flags;
  363. w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
  364. w->state |= WST_CONSTRUCT | WST_FOCUSED;
  365. /* Temporary hack: dialog doesn't have an owner, own itself. */
  366. w->owner = g;
  367. w->keymap = dialog_map;
  368. w->mouse_handler = dlg_handle_mouse_event;
  369. w->mouse.forced_capture = mouse_close_dialog && (w->pos_flags & WPOS_FULLSCREEN) == 0;
  370. new_d->color = colors;
  371. new_d->help_ctx = help_ctx;
  372. new_d->compact = compact;
  373. new_d->data = NULL;
  374. if (modal)
  375. {
  376. frame_colors_t frame_colors;
  377. w->state |= WST_MODAL;
  378. if (new_d->color != NULL)
  379. {
  380. frame_colors[FRAME_COLOR_NORMAL] = new_d->color[DLG_COLOR_NORMAL];
  381. frame_colors[FRAME_COLOR_TITLE] = new_d->color[DLG_COLOR_TITLE];
  382. }
  383. new_d->bg =
  384. WIDGET (frame_new
  385. (0, 0, w->lines, w->cols, title, new_d->color != NULL ? frame_colors : NULL,
  386. FALSE, new_d->compact));
  387. group_add_widget (g, new_d->bg);
  388. frame_set_title (FRAME (new_d->bg), title);
  389. }
  390. /* unique name of event group for this dialog */
  391. new_d->event_group = g_strdup_printf ("%s_%p", MCEVENT_GROUP_DIALOG, (void *) new_d);
  392. return new_d;
  393. }
  394. /* --------------------------------------------------------------------------------------------- */
  395. void
  396. dlg_set_default_colors (void)
  397. {
  398. dialog_colors[DLG_COLOR_NORMAL] = COLOR_NORMAL;
  399. dialog_colors[DLG_COLOR_FOCUS] = COLOR_FOCUS;
  400. dialog_colors[DLG_COLOR_HOT_NORMAL] = COLOR_HOT_NORMAL;
  401. dialog_colors[DLG_COLOR_HOT_FOCUS] = COLOR_HOT_FOCUS;
  402. dialog_colors[DLG_COLOR_TITLE] = COLOR_TITLE;
  403. alarm_colors[DLG_COLOR_NORMAL] = ERROR_COLOR;
  404. alarm_colors[DLG_COLOR_FOCUS] = ERROR_FOCUS;
  405. alarm_colors[DLG_COLOR_HOT_NORMAL] = ERROR_HOT_NORMAL;
  406. alarm_colors[DLG_COLOR_HOT_FOCUS] = ERROR_HOT_FOCUS;
  407. alarm_colors[DLG_COLOR_TITLE] = ERROR_TITLE;
  408. listbox_colors[DLG_COLOR_NORMAL] = PMENU_ENTRY_COLOR;
  409. listbox_colors[DLG_COLOR_FOCUS] = PMENU_SELECTED_COLOR;
  410. listbox_colors[DLG_COLOR_HOT_NORMAL] = PMENU_ENTRY_COLOR;
  411. listbox_colors[DLG_COLOR_HOT_FOCUS] = PMENU_SELECTED_COLOR;
  412. listbox_colors[DLG_COLOR_TITLE] = PMENU_TITLE_COLOR;
  413. }
  414. /* --------------------------------------------------------------------------------------------- */
  415. void
  416. do_refresh (void)
  417. {
  418. GList *d = top_dlg;
  419. if (fast_refresh)
  420. {
  421. if (d != NULL)
  422. widget_draw (WIDGET (d->data));
  423. }
  424. else
  425. {
  426. /* Search first fullscreen dialog */
  427. for (; d != NULL; d = g_list_next (d))
  428. if ((WIDGET (d->data)->pos_flags & WPOS_FULLSCREEN) != 0)
  429. break;
  430. /* back to top dialog */
  431. for (; d != NULL; d = g_list_previous (d))
  432. widget_draw (WIDGET (d->data));
  433. }
  434. }
  435. /* --------------------------------------------------------------------------------------------- */
  436. void
  437. dlg_stop (WDialog * h)
  438. {
  439. widget_set_state (WIDGET (h), WST_CLOSED, TRUE);
  440. }
  441. /* --------------------------------------------------------------------------------------------- */
  442. /** Init the process */
  443. void
  444. dlg_init (WDialog * h)
  445. {
  446. WGroup *g = GROUP (h);
  447. Widget *wh = WIDGET (h);
  448. if (top_dlg != NULL && widget_get_state (WIDGET (top_dlg->data), WST_MODAL))
  449. widget_set_state (wh, WST_MODAL, TRUE);
  450. /* add dialog to the stack */
  451. top_dlg = g_list_prepend (top_dlg, h);
  452. /* Initialize dialog manager and widgets */
  453. if (widget_get_state (wh, WST_CONSTRUCT))
  454. {
  455. if (!widget_get_state (wh, WST_MODAL))
  456. dialog_switch_add (h);
  457. send_message (h, NULL, MSG_INIT, 0, NULL);
  458. group_default_callback (wh, NULL, MSG_INIT, 0, NULL);
  459. dlg_read_history (h);
  460. }
  461. /* Select the first widget that takes focus */
  462. while (g->current != NULL && !widget_get_options (WIDGET (g->current->data), WOP_SELECTABLE)
  463. && !widget_get_state (WIDGET (g->current->data), WST_DISABLED))
  464. group_set_current_widget_next (g);
  465. widget_set_state (wh, WST_ACTIVE, TRUE);
  466. widget_draw (wh);
  467. /* focus found widget */
  468. if (g->current != NULL)
  469. widget_set_state (WIDGET (g->current->data), WST_FOCUSED, TRUE);
  470. h->ret_value = 0;
  471. }
  472. /* --------------------------------------------------------------------------------------------- */
  473. void
  474. dlg_process_event (WDialog * h, int key, Gpm_Event * event)
  475. {
  476. switch (key)
  477. {
  478. case EV_NONE:
  479. if (tty_got_interrupt ())
  480. dlg_execute_cmd (h, CK_Cancel);
  481. break;
  482. case EV_MOUSE:
  483. {
  484. Widget *w = WIDGET (h);
  485. GROUP (h)->mouse_status = w->mouse_handler (w, event);
  486. break;
  487. }
  488. default:
  489. dlg_key_event (h, key);
  490. break;
  491. }
  492. }
  493. /* --------------------------------------------------------------------------------------------- */
  494. /** Shutdown the dlg_run */
  495. void
  496. dlg_run_done (WDialog * h)
  497. {
  498. top_dlg = g_list_remove (top_dlg, h);
  499. if (widget_get_state (WIDGET (h), WST_CLOSED))
  500. {
  501. send_message (h, GROUP (h)->current == NULL ? NULL : WIDGET (GROUP (h)->current->data),
  502. MSG_END, 0, NULL);
  503. if (!widget_get_state (WIDGET (h), WST_MODAL))
  504. dialog_switch_remove (h);
  505. }
  506. }
  507. /* --------------------------------------------------------------------------------------------- */
  508. /**
  509. * Standard run dialog routine
  510. * We have to keep this routine small so that we can duplicate it's
  511. * behavior on complex routines like the file routines, this way,
  512. * they can call the dlg_process_event without rewriting all the code
  513. */
  514. int
  515. dlg_run (WDialog * h)
  516. {
  517. dlg_init (h);
  518. frontend_dlg_run (h);
  519. dlg_run_done (h);
  520. return h->ret_value;
  521. }
  522. /* --------------------------------------------------------------------------------------------- */
  523. void
  524. dlg_destroy (WDialog * h)
  525. {
  526. /* if some widgets have history, save all history at one moment here */
  527. dlg_save_history (h);
  528. group_default_callback (WIDGET (h), NULL, MSG_DESTROY, 0, NULL);
  529. mc_event_group_del (h->event_group);
  530. g_free (h->event_group);
  531. g_free (h);
  532. do_refresh ();
  533. }
  534. /* --------------------------------------------------------------------------------------------- */
  535. /**
  536. * Write history to the ${XDG_CACHE_HOME}/mc/history file
  537. */
  538. void
  539. dlg_save_history (WDialog * h)
  540. {
  541. char *profile;
  542. int i;
  543. if (num_history_items_recorded == 0) /* this is how to disable */
  544. return;
  545. profile = mc_config_get_full_path (MC_HISTORY_FILE);
  546. i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
  547. if (i != -1)
  548. close (i);
  549. /* Make sure the history is only readable by the user */
  550. if (chmod (profile, S_IRUSR | S_IWUSR) != -1 || errno == ENOENT)
  551. {
  552. ev_history_load_save_t event_data;
  553. event_data.cfg = mc_config_init (profile, FALSE);
  554. event_data.receiver = NULL;
  555. /* get all histories in dialog */
  556. mc_event_raise (h->event_group, MCEVENT_HISTORY_SAVE, &event_data);
  557. mc_config_save_file (event_data.cfg, NULL);
  558. mc_config_deinit (event_data.cfg);
  559. }
  560. g_free (profile);
  561. }
  562. /* --------------------------------------------------------------------------------------------- */
  563. char *
  564. dlg_get_title (const WDialog * h, size_t len)
  565. {
  566. char *t;
  567. if (h == NULL)
  568. abort ();
  569. if (h->get_title != NULL)
  570. t = h->get_title (h, len);
  571. else
  572. t = g_strdup ("");
  573. return t;
  574. }
  575. /* --------------------------------------------------------------------------------------------- */