From 2cc2f349122559f9e3f65728950530b40af8bf03 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 30 May 2010 20:19:30 +0400 Subject: [PATCH] MCView: reimplemented messages and commands handling. Signed-off-by: Andrew Borodin --- src/viewer/actions_cmd.c | 37 ++++++++++++++++++++++++------------- src/viewer/internal.h | 3 --- src/viewer/lib.c | 2 -- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index afdb8f233..e5b25f82d 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -65,6 +65,7 @@ #include "src/help.h" #include "src/keybind.h" #include "src/cmddef.h" /* CK_ cmd name const */ +#include "src/main.h" /* midnight_shutdown */ #include "internal.h" #include "mcviewer.h" @@ -437,8 +438,8 @@ mcview_execute_cmd (mcview_t * view, unsigned long command) view->move_dir = (command == CK_ViewNextFile) ? 1 : -1; /* fallthrough */ case CK_ViewQuit: - if (mcview_ok_to_quit (view)) - view->want_to_quit = TRUE; + if (!mcview_is_in_panel (view)) + dlg_stop (view->widget.owner); break; default: res = MSG_NOT_HANDLED; @@ -522,7 +523,6 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) { mcview_t *view = (mcview_t *) w; cb_ret_t i; - Dlg_head *h = view->widget.owner; mcview_compute_areas (view); mcview_update_bytes_per_line (view); @@ -547,18 +547,12 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) case WIDGET_KEY: i = mcview_handle_key (view, parm); - if (view->want_to_quit && !mcview_is_in_panel (view)) - dlg_stop (h); - else - mcview_update (view); + mcview_update (view); return i; case WIDGET_COMMAND: i = mcview_execute_cmd (view, parm); - if (view->want_to_quit && !mcview_is_in_panel (view)) - dlg_stop (h); - else - mcview_update (view); + mcview_update (view); return i; case WIDGET_FOCUS: @@ -567,9 +561,14 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) return MSG_HANDLED; case WIDGET_DESTROY: - mcview_done (view); if (mcview_is_in_panel (view)) + { delete_hook (&select_file_hook, mcview_hook); + + if (midnight_shutdown) + mcview_ok_to_quit (view); + } + mcview_done (view); return MSG_HANDLED; default: @@ -582,7 +581,7 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) cb_ret_t mcview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { - mcview_t *view = data; + mcview_t *view; switch (msg) { @@ -592,8 +591,20 @@ mcview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, case DLG_ACTION: /* command from buttonbar */ + view = (mcview_t *) data; return send_message ((Widget *) view, WIDGET_COMMAND, parm); + case DLG_VALIDATE: + view = (mcview_t *) find_widget_type (h, mcview_callback); + if (mcview_ok_to_quit (view)) + h->state = DLG_CLOSED; + else + { + h->state = DLG_ACTIVE; + mcview_update (view); + } + return MSG_HANDLED; + default: return default_dlg_callback (h, sender, msg, parm, data); } diff --git a/src/viewer/internal.h b/src/viewer/internal.h index ef8d09f09..c16228b14 100644 --- a/src/viewer/internal.h +++ b/src/viewer/internal.h @@ -161,9 +161,6 @@ typedef struct mcview_struct off_t search_start; /* First character to start searching from */ off_t search_end; /* Length of found string or 0 if none was found */ - /* Pointer to the last search command */ - gboolean want_to_quit; /* Prepare for cleanup ... */ - /* Markers */ int marker; /* mark to use */ off_t marks[10]; /* 10 marks: 0..9 */ diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 87ceb5692..881379881 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -198,8 +198,6 @@ mcview_init (mcview_t * view) view->search_start = 0; view->search_end = 0; - view->want_to_quit = FALSE; - view->marker = 0; for (i = 0; i < sizeof (view->marks) / sizeof (view->marks[0]); i++) view->marks[i] = 0;