1
0
mirror of https://github.com/MidnightCommander/mc synced 2025-01-12 14:29:41 +03:00

Widget: implement destroy callback.

(dlg_destroy): remove. Use widget_destroy() to destroy any dialog.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-10-31 19:32:29 +03:00
parent e7fab254f9
commit 231c84caeb
29 changed files with 93 additions and 70 deletions

View File

@ -268,7 +268,7 @@ dialog_switch_process_pending (void)
ret = dlg_run (h);
if (widget_get_state (wh, WST_CLOSED))
{
dlg_destroy (h);
widget_destroy (wh);
/* return to panels */
if (mc_global.mc_run_mode == MC_RUN_FULL)
@ -306,7 +306,7 @@ dialog_switch_shutdown (void)
WDialog *dlg = DIALOG (mc_dialogs->data);
dlg_run (dlg);
dlg_destroy (dlg);
widget_destroy (WIDGET (dlg));
}
}

View File

@ -324,6 +324,23 @@ frontend_dlg_run (WDialog * h)
}
}
/* --------------------------------------------------------------------------------------------- */
static void
dlg_default_destroy (Widget * w)
{
WDialog *h = DIALOG (w);
/* if some widgets have history, save all histories at one moment here */
dlg_save_history (h);
group_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
mc_event_group_del (h->event_group);
g_free (h->event_group);
g_free (h);
do_refresh ();
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -403,6 +420,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
w->mouse_handler = dlg_handle_mouse_event;
w->mouse.forced_capture = mouse_close_dialog && (w->pos_flags & WPOS_FULLSCREEN) == 0;
w->destroy = dlg_default_destroy;
w->get_colors = dlg_default_get_colors;
new_d->colors = colors;
@ -586,22 +604,6 @@ dlg_run (WDialog * h)
/* --------------------------------------------------------------------------------------------- */
void
dlg_destroy (WDialog * h)
{
/* if some widgets have history, save all history at one moment here */
dlg_save_history (h);
group_default_callback (WIDGET (h), NULL, MSG_DESTROY, 0, NULL);
send_message (WIDGET (h), NULL, MSG_DESTROY, 0, NULL);
mc_event_group_del (h->event_group);
g_free (h->event_group);
g_free (h);
do_refresh ();
}
/* --------------------------------------------------------------------------------------------- */
/**
* Write history to the ${XDG_CACHE_HOME}/mc/history file
*/

View File

@ -106,7 +106,6 @@ void dlg_set_default_colors (void);
void dlg_init (WDialog * h);
int dlg_run (WDialog * d);
void dlg_destroy (WDialog * h);
void dlg_run_done (WDialog * h);
void dlg_save_history (WDialog * h);

View File

@ -288,7 +288,7 @@ history_show (history_descriptor_t * hd)
if (WIDGET (query_dlg)->y < hd->y)
z = g_list_reverse (z);
dlg_destroy (query_dlg);
widget_destroy (WIDGET (query_dlg));
hd->list = g_list_first (hd->list);
g_list_free_full (hd->list, hd->free);

View File

@ -1282,7 +1282,7 @@ complete_engine (WInput * in, int what_to_do)
}
if (q != NULL || end != min_end)
input_complete_free (in);
dlg_destroy (complete_dlg);
widget_destroy (WIDGET (complete_dlg));
/* B_USER if user wants to start over again */
return (i == B_USER);

View File

@ -132,7 +132,7 @@ run_listbox (Listbox * l)
if (dlg_run (l->dlg) != B_CANCEL)
val = l->list->pos;
dlg_destroy (l->dlg);
widget_destroy (WIDGET (l->dlg));
g_free (l);
return val;
}
@ -167,7 +167,7 @@ run_listbox_with_data (Listbox * l, const void *select)
}
}
dlg_destroy (l->dlg);
widget_destroy (WIDGET (l->dlg));
g_free (l);
return val;
}

View File

@ -611,7 +611,7 @@ quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip)
}
}
dlg_destroy (dd);
widget_destroy (WIDGET (dd));
g_list_free_full (input_labels, g_free); /* destroy input labels created before */
g_array_free (widgets, TRUE);

View File

@ -345,20 +345,12 @@ widget_init (Widget * w, int y, int x, int lines, int cols,
w->find_by_id = widget_default_find_by_id;
w->set_state = widget_default_set_state;
w->destroy = widget_default_destroy;
w->get_colors = widget_default_get_colors;
}
/* --------------------------------------------------------------------------------------------- */
void
widget_destroy (Widget * w)
{
send_message (w, NULL, MSG_DESTROY, 0, NULL);
g_free (w);
}
/* --------------------------------------------------------------------------------------------- */
/* Default callback for widgets */
cb_ret_t
widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
@ -879,6 +871,20 @@ widget_default_set_state (Widget * w, widget_state_t state, gboolean enable)
return ret;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Default callback function to destroy widget.
*
* @param w widget
*/
void
widget_default_destroy (Widget * w)
{
send_message (w, NULL, MSG_DESTROY, 0, NULL);
g_free (w);
}
/* --------------------------------------------------------------------------------------------- */
/* get mouse pointer location within widget */

View File

@ -168,6 +168,7 @@ struct Widget
/* *INDENT-OFF* */
cb_ret_t (*set_state) (Widget * w, widget_state_t state, gboolean enable);
/* *INDENT-ON* */
void (*destroy) (Widget * w);
const int *(*get_colors) (const Widget * w);
};
@ -203,7 +204,6 @@ char *hotkey_get_text (const hotkey_t hotkey);
/* widget initialization */
void widget_init (Widget * w, int y, int x, int lines, int cols,
widget_cb_fn callback, widget_mouse_cb_fn mouse_callback);
void widget_destroy (Widget * w);
/* Default callback for widgets */
cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
void *data);
@ -233,6 +233,8 @@ Widget *widget_default_find_by_id (const Widget * w, unsigned long id);
cb_ret_t widget_default_set_state (Widget * w, widget_state_t state, gboolean enable);
void widget_default_destroy (Widget * w);
/* get mouse pointer location within widget */
Gpm_Event mouse_get_local (const Gpm_Event * global, const Widget * w);
gboolean mouse_global_in_widget (const Gpm_Event * event, const Widget * w);
@ -380,6 +382,19 @@ widget_set_state (Widget * w, widget_state_t state, gboolean enable)
return w->set_state (w, state, enable);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Destroy widget.
*
* @param w widget
*/
static inline void
widget_destroy (Widget * w)
{
w->destroy (w);
}
/* --------------------------------------------------------------------------------------------- */
/**

View File

@ -150,10 +150,9 @@ fg_message (int flags, const char *title, const char *text)
d = do_create_message (flags, title, text);
tty_getch ();
dlg_run_done (d);
dlg_destroy (d);
widget_destroy (WIDGET (d));
}
/* --------------------------------------------------------------------------------------------- */
/** Show message box from background */
@ -356,7 +355,7 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
}
/* free used memory */
dlg_destroy (query_dlg);
widget_destroy (WIDGET (query_dlg));
}
else
{
@ -380,7 +379,7 @@ query_set_sel (int new_sel)
/* --------------------------------------------------------------------------------------------- */
/**
* Create message dialog. The caller must call dlg_run_done() and
* dlg_destroy() to dismiss it. Not safe to call from background.
* widget_destroy() to dismiss it. Not safe to call from background.
*/
WDialog *
@ -628,7 +627,7 @@ status_msg_deinit (status_msg_t * sm)
/* close and destroy dialog */
dlg_run_done (sm->dlg);
dlg_destroy (sm->dlg);
widget_destroy (WIDGET (sm->dlg));
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -3470,7 +3470,7 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
dlg_run (dview_dlg);
if (error != 0 || widget_get_state (dw, WST_CLOSED))
dlg_destroy (dview_dlg);
widget_destroy (dw);
return error == 0 ? 1 : 0;
}

View File

@ -358,7 +358,7 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean c
}
w = dlg_run (raw_dlg);
dlg_destroy (raw_dlg);
widget_destroy (WIDGET (raw_dlg));
return (cancel && (w == ESC_CHAR || w == B_CANCEL)) ? 0 : w;
}
@ -424,7 +424,7 @@ editcmd_dialog_completion_show (const WEdit * edit, GQueue * compl, int max_widt
}
/* destroy dialog before return */
dlg_destroy (compl_dlg);
widget_destroy (WIDGET (compl_dlg));
return curr;
}
@ -523,7 +523,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, GPtrArray
}
/* destroy dialog before return */
dlg_destroy (def_dlg);
widget_destroy (WIDGET (def_dlg));
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1280,7 +1280,7 @@ edit_files (const GList * files)
dlg_run (edit_dlg);
if (!ok || widget_get_state (wd, WST_CLOSED))
dlg_destroy (edit_dlg);
widget_destroy (wd);
return ok;
}

View File

@ -141,7 +141,7 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
*new_word = tmp;
}
dlg_destroy (sug_dlg);
widget_destroy (WIDGET (sug_dlg));
g_free (lang_label);
g_free (word_label);

View File

@ -642,7 +642,7 @@ user_group_button_cb (WButton * button, int action)
}
/* Here we used to redraw the window */
dlg_destroy (chl_dlg);
widget_destroy (WIDGET (chl_dlg));
}
while (chl_end);
@ -1091,7 +1091,7 @@ advanced_chown_cmd (WPanel * panel)
vfs_path_free (vpath, TRUE);
dlg_destroy (ch_dlg);
widget_destroy (WIDGET (ch_dlg));
}
while (panel->marked != 0 && !end_chown);

View File

@ -267,7 +267,7 @@ sel_skin_button (WButton * button, int action)
button_set_text (button, str_fit_to_term (skin_label, 20, J_LEFT_FIT));
}
dlg_destroy (skin_dlg);
widget_destroy (WIDGET (skin_dlg));
return 0;
}
@ -1096,7 +1096,7 @@ tree_box (const char *current_dir)
val = g_strdup (vfs_path_as_str (selected_name));
}
dlg_destroy (dlg);
widget_destroy (wd);
return val;
}
@ -1315,7 +1315,7 @@ jobs_box (void)
}
(void) dlg_run (jobs_dlg);
dlg_destroy (jobs_dlg);
widget_destroy (WIDGET (jobs_dlg));
}
#endif /* ENABLE_BACKGROUND */

View File

@ -1243,7 +1243,7 @@ chattr_cmd (WPanel * panel)
ch_dlg = chattr_dlg_create (panel, fname->str, flags);
result = dlg_run (ch_dlg);
dlg_destroy (ch_dlg);
widget_destroy (WIDGET (ch_dlg));
switch (result)
{

View File

@ -650,7 +650,7 @@ chmod_cmd (WPanel * panel)
vfs_path_free (vpath, TRUE);
dlg_destroy (ch_dlg);
widget_destroy (WIDGET (ch_dlg));
}
while (panel->marked != 0 && !end_chmod);

View File

@ -539,7 +539,7 @@ chown_cmd (WPanel * panel)
vfs_path_free (vpath, TRUE);
dlg_destroy (ch_dlg);
widget_destroy (WIDGET (ch_dlg));
}
while (panel->marked != 0 && !end_chown);

View File

@ -671,7 +671,7 @@ overwrite_query_dialog (file_op_context_t * ctx, enum OperationMode mode)
if (result != B_CANCEL)
ui->dont_overwrite_with_zero = CHECK (dlg_widgets[14].widget)->state;
dlg_destroy (ui->replace_dlg);
widget_destroy (wd);
return (result == B_CANCEL) ? REPLACE_ABORT : (replace_action_t) result;
@ -950,7 +950,7 @@ file_op_context_destroy_ui (file_op_context_t * ctx)
file_op_context_ui_t *ui = (file_op_context_ui_t *) ctx->ui;
dlg_run_done (ui->op_dlg);
dlg_destroy (ui->op_dlg);
widget_destroy (WIDGET (ui->op_dlg));
MC_PTR_FREE (ctx->ui);
}
}

View File

@ -1841,7 +1841,7 @@ do_nc (void)
ret = TRUE;
/* dlg_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
/* widget_destroy destroys even current_panel->cwd_vpath, so we have to save a copy :) */
if (mc_args__last_wd_file != NULL && vfs_current_is_local ())
last_wd_string = g_strdup (vfs_path_as_str (current_panel->cwd_vpath));
@ -1855,7 +1855,7 @@ do_nc (void)
mc_global.midnight_shutdown = TRUE;
dialog_switch_shutdown ();
done_mc ();
dlg_destroy (filemanager);
widget_destroy (WIDGET (filemanager));
current_panel = NULL;
#ifdef USE_INTERNAL_EDIT

View File

@ -872,7 +872,7 @@ find_parameters (WPanel * panel, char **start_dir, ssize_t * start_dir_len,
}
}
dlg_destroy (find_dlg);
widget_destroy (WIDGET (find_dlg));
return return_value;
}
@ -1767,8 +1767,10 @@ run_process (void)
static void
kill_gui (void)
{
widget_idle (WIDGET (find_dlg), FALSE);
dlg_destroy (find_dlg);
Widget *w = WIDGET (find_dlg);
widget_idle (w, FALSE);
widget_destroy (w);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -350,7 +350,7 @@ hotlist_run_cmd (int action)
hotlist_state.moving = FALSE;
listbox_get_current (l_movelist, NULL, (void **) &moveto_item);
moveto_group = current_group;
dlg_destroy (movelist_dlg);
widget_destroy (WIDGET (movelist_dlg));
current_group = saved;
if (ret == B_CANCEL)
return 0;
@ -891,7 +891,7 @@ init_movelist (struct hotlist *item)
static void
hotlist_done (void)
{
dlg_destroy (hotlist_dlg);
widget_destroy (WIDGET (hotlist_dlg));
l_hotlist = NULL;
#if 0
update_panels (UP_OPTIMIZE, UP_KEEPSEL);

View File

@ -740,7 +740,7 @@ layout_box (void)
else
layout_restore ();
dlg_destroy (layout_dlg);
widget_destroy (WIDGET (layout_dlg));
layout_change ();
do_refresh ();
}

View File

@ -273,7 +273,7 @@ init_listmode (char *oldlistformat)
static void
listmode_done (WDialog * h)
{
dlg_destroy (h);
widget_destroy (WIDGET (h));
if (0)
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();

View File

@ -217,7 +217,7 @@ init_panelize (void)
static void
panelize_done (void)
{
dlg_destroy (panelize_dlg);
widget_destroy (WIDGET (panelize_dlg));
repaint_screen ();
}
@ -623,7 +623,7 @@ external_panelize (void)
char *cmd;
cmd = g_strdup (pname->buffer);
dlg_destroy (panelize_dlg);
widget_destroy (WIDGET (panelize_dlg));
do_external_panelize (cmd);
g_free (cmd);
repaint_screen ();

View File

@ -1175,7 +1175,7 @@ help_interactive_display (const gchar * event_group_name, const gchar * event_na
dlg_run (whelp);
interactive_display_finish ();
dlg_destroy (whelp);
widget_destroy (wh);
return TRUE;
}

View File

@ -122,7 +122,7 @@ learn_button (WButton * button, int action)
}
dlg_run_done (d);
dlg_destroy (d);
widget_destroy (WIDGET (d));
widget_select (learnkeys[action - B_USER].button);
@ -343,7 +343,7 @@ init_learn (void)
static void
learn_done (void)
{
dlg_destroy (learn_dlg);
widget_destroy (WIDGET (learn_dlg));
repaint_screen ();
}

View File

@ -265,7 +265,7 @@ mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_lin
dlg_stop (view_dlg);
if (widget_get_state (vw, WST_CLOSED))
dlg_destroy (view_dlg);
widget_destroy (vw);
return succeeded;
}