From db0d01b9d6d586ce032f62baac58b8bd2f5db975 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 16 Apr 2016 11:12:49 +0300 Subject: [PATCH] Add WST_MODAL state. * WDialog::modal: remove. Use WST_MODAL instead. Signed-off-by: Andrew Borodin --- lib/widget/dialog.c | 20 +++++++++++--------- lib/widget/dialog.h | 1 - lib/widget/widget-common.h | 3 ++- src/diffviewer/ydiff.c | 10 +++++++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 60d101a03..98d7d0376 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -319,19 +319,19 @@ dlg_execute_cmd (WDialog * h, long command) break; case CK_ScreenList: - if (!h->modal) + if (!widget_get_state (WIDGET (h), WST_MODAL)) dialog_switch_list (); else ret = MSG_NOT_HANDLED; break; case CK_ScreenNext: - if (!h->modal) + if (!widget_get_state (WIDGET (h), WST_MODAL)) dialog_switch_next (); else ret = MSG_NOT_HANDLED; break; case CK_ScreenPrev: - if (!h->modal) + if (!widget_get_state (WIDGET (h), WST_MODAL)) dialog_switch_prev (); else ret = MSG_NOT_HANDLED; @@ -559,7 +559,7 @@ frontend_dlg_run (WDialog * h) event.x = -1; /* close opened editors, viewers, etc */ - if (!h->modal && mc_global.midnight_shutdown) + if (!widget_get_state (wh, WST_MODAL) && mc_global.midnight_shutdown) { send_message (h, NULL, MSG_VALIDATE, 0, NULL); return; @@ -834,9 +834,11 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, mouse_callback); widget_want_cursor (w, FALSE); w->options |= WOP_TOP_SELECT; + w->state |= WST_CONSTRUCT; + if (modal) + w->state |= WST_MODAL; - new_d->modal = modal; new_d->color = colors; new_d->help_ctx = help_ctx; new_d->flags = flags; @@ -1229,8 +1231,8 @@ dlg_init (WDialog * h) { Widget *wh = WIDGET (h); - if (top_dlg != NULL && DIALOG (top_dlg->data)->modal) - h->modal = TRUE; + if (top_dlg != NULL && widget_get_state (WIDGET (top_dlg->data), WST_MODAL)) + widget_set_state (wh, WST_MODAL, TRUE); /* add dialog to the stack */ top_dlg = g_list_prepend (top_dlg, h); @@ -1238,7 +1240,7 @@ dlg_init (WDialog * h) /* Initialize dialog manager and widgets */ if (widget_get_state (wh, WST_CONSTRUCT)) { - if (!h->modal) + if (!widget_get_state (wh, WST_MODAL)) dialog_switch_add (h); send_message (h, NULL, MSG_INIT, 0, NULL); @@ -1287,7 +1289,7 @@ dlg_run_done (WDialog * h) if (widget_get_state (WIDGET (h), WST_CLOSED)) { send_message (h, h->current->data, MSG_END, 0, NULL); - if (!h->modal) + if (!widget_get_state (WIDGET (h), WST_MODAL)) dialog_switch_remove (h); } } diff --git a/lib/widget/dialog.h b/lib/widget/dialog.h index 392259421..27778e156 100644 --- a/lib/widget/dialog.h +++ b/lib/widget/dialog.h @@ -71,7 +71,6 @@ struct WDialog Widget widget; /* Set by the user */ - gboolean modal; /* type of dialog: modal or not */ dlg_flags_t flags; /* User flags */ const char *help_ctx; /* Name of the help entry */ const int *color; /* Color set. Unused in viewer and editor */ diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index 0161b40b1..1bc3fdb34 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -76,7 +76,8 @@ typedef enum { WST_DEFAULT = (0 << 0), WST_DISABLED = (1 << 0), /* Widget cannot be selected */ - WST_IDLE = (1 << 1), /* @FIXME@: we want more correct name here */ + WST_IDLE = (1 << 1), + WST_MODAL = (1 << 2), /* Widget (dialog) is modal */ WST_CONSTRUCT = (1 << 15), /* Dialog has been constructed but not run yet */ WST_ACTIVE = (1 << 16), /* Dialog is visible and active */ diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 886fbd17a..ca7360f2e 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -2890,10 +2890,13 @@ dview_edit (WDiff * dview, diff_place_t ord) } h = WIDGET (dview)->owner; - h_modal = h->modal; + h_modal = widget_get_state (WIDGET (h), WST_MODAL); get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs); - h->modal = TRUE; /* not allow edit file in several editors */ + + /* disallow edit file in several editors */ + widget_set_state (WIDGET (h), WST_MODAL, TRUE); + { vfs_path_t *tmp_vpath; @@ -2901,7 +2904,8 @@ dview_edit (WDiff * dview, diff_place_t ord) edit_file_at_line (tmp_vpath, use_internal_edit != 0, linenum); vfs_path_free (tmp_vpath); } - h->modal = h_modal; + + widget_set_state (WIDGET (h), WST_MODAL, h_modal); dview_redo (dview); dview_update (dview); } -- 2.11.4.GIT