From eb781a8f061e47e3b4b2894f14c0296fe6e7892c Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 24 Dec 2002 11:28:26 +0000 Subject: [PATCH] * dlg.h: Add new event DLG_VALIDATE. * dlg.c (frontend_run_dlg): Send DLG_VALIDATE. (select_a_widget): Don't send DLG_ONE_DOWN, nobody uses it. * find.c (find_parm_callback): New callback for the parameter dialog. Don't allow stopping the dialog if the regular expression is invalid. --- src/ChangeLog | 9 +++++++ src/dlg.c | 14 +++++----- src/dlg.h | 31 +++++++++++----------- src/find.c | 73 +++++++++++++++++++++++++++++++++------------------ 4 files changed, 79 insertions(+), 48 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index c083a8f1a..d425ea9ed 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2002-12-24 Pavel Roskin + + * dlg.h: Add new event DLG_VALIDATE. + * dlg.c (frontend_run_dlg): Send DLG_VALIDATE. + (select_a_widget): Don't send DLG_ONE_DOWN, nobody uses it. + * find.c (find_parm_callback): New callback for the parameter + dialog. Don't allow stopping the dialog if the regular + expression is invalid. + 2002-12-23 Pavel Roskin * layout.c (init_curses) [HAVE_SLANG]: Don't call diff --git a/src/dlg.c b/src/dlg.c index 8bfe4a180..0f70bfd75 100644 --- a/src/dlg.c +++ b/src/dlg.c @@ -382,8 +382,6 @@ static void select_a_widget (Dlg_head *h, int down) h->current = h->current->next; else h->current = h->current->prev; - - (*h->callback) (h, h->current->dlg_id, DLG_ONE_DOWN); } while (!dlg_focus (h)); } @@ -399,8 +397,9 @@ int dlg_overlap (Widget *a, Widget *b) } -/* Searches a widget, uses the callback as a signature in the dialog h */ -Widget *find_widget_type (Dlg_head *h, callback_fn signature) +/* Find the widget with the given callback in the dialog h */ +Widget * +find_widget_type (Dlg_head *h, callback_fn signature) { Widget *w; Widget_Item *item; @@ -412,8 +411,8 @@ Widget *find_widget_type (Dlg_head *h, callback_fn signature) return 0; w = 0; - for (i = 0, item = h->current; i < h->count; i++, item = item->next){ - if (item->widget->callback == signature){ + for (i = 0, item = h->current; i < h->count; i++, item = item->next) { + if (item->widget->callback == signature) { w = item->widget; break; } @@ -812,6 +811,9 @@ frontend_run_dlg (Dlg_head *h) d_key = get_event (&event, h->mouse_status == MOU_REPEAT, 1); dlg_process_event (h, d_key, &event); + + if (!h->running) + (*h->callback) (h, 0, DLG_VALIDATE); } } diff --git a/src/dlg.h b/src/dlg.h index 94e9dde02..55cca5a13 100644 --- a/src/dlg.h +++ b/src/dlg.h @@ -45,22 +45,21 @@ enum { /* Dialog messages */ enum { - DLG_KEY, /* Sent on keypress before sending to widget */ - DLG_INIT, /* Sent on init */ - DLG_END, /* Sent on shutdown */ - DLG_ACTION, - DLG_DRAW, /* Sent for updating dialog managed area */ - DLG_FOCUS, /* Sent on give focus to a widget */ - DLG_UNFOCUS, /* Sent on remove focus from widget */ - DLG_RESIZE, /* Sent when the window size changes */ - DLG_ONE_UP, /* Sent on selecting next */ - DLG_ONE_DOWN, /* Sent on selecting prev */ - DLG_POST_KEY, /* Sent after key has been sent */ - DLG_IDLE, /* Sent if idle is active */ - DLG_UNHANDLED_KEY, /* Send if no widget wanted the key */ - DLG_HOTKEY_HANDLED, /* Send if a child got the hotkey */ - DLG_PRE_EVENT /* Send before calling get_event */ -} /* Dialog_Messages */; + DLG_KEY, /* Key before sending to widget */ + DLG_INIT, /* Initialize dialog */ + DLG_END, /* Shut down dialog */ + DLG_ACTION, /* State of check- and radioboxes has changed */ + DLG_DRAW, /* Draw dialog on screen */ + DLG_FOCUS, /* A widget has got focus */ + DLG_UNFOCUS, /* A widget has been unfocused */ + DLG_RESIZE, /* Window size has changed */ + DLG_POST_KEY, /* The key has been handled */ + DLG_IDLE, /* The idle state is active */ + DLG_UNHANDLED_KEY, /* Key that no widget handled */ + DLG_HOTKEY_HANDLED, /* A widget has got the hotkey */ + DLG_PRE_EVENT, /* About to get new event */ + DLG_VALIDATE /* Dialog is to be closed */ +} /* Dialog_Messages */ ; /* Dialog callback */ diff --git a/src/find.c b/src/find.c index 19c5468d6..8de654357 100644 --- a/src/find.c +++ b/src/find.c @@ -69,7 +69,9 @@ char *find_ignore_dirs = 0; static WInput *in_start; /* Start path */ static WInput *in_name; /* Pattern to search */ -static WInput *in_with; /* text inside filename */ +static WInput *in_with; /* Text inside filename */ +static WCheck *case_sense; /* "case sensitive" checkbox */ + static int running = 0; /* nice flag */ static char *find_pattern; /* Pattern to search */ static char *content_pattern; /* pattern to search inside files */ @@ -115,6 +117,37 @@ static void get_list_info (char **file, char **dir); /* FIXME: r should be local variables */ static regex_t *r; /* Pointer to compiled content_pattern */ +static int case_sensitive = 1; + +/* + * Callback for the parameter dialog. + * Validate regex, prevent closing the dialog if it's invalid. + */ +static int +find_parm_callback (struct Dlg_head *h, int id, int Msg) +{ + int flags; + + switch (Msg) { + case DLG_VALIDATE: + if ((h->ret_value != B_ENTER) || !in_with->buffer[0]) + return MSG_HANDLED; + + flags = REG_EXTENDED | REG_NOSUB; + + if (!(case_sense->state & C_BOOL)) + flags |= REG_ICASE; + + if (regcomp (r, in_with->buffer, flags)) { + message (1, MSG_ERROR, _(" Malformed regular expression ")); + dlg_select_widget (h, in_with); + h->running = 1; /* Don't stop the dialog */ + } + return MSG_HANDLED; + } + return default_dlg_callback (h, id, Msg); +} + /* * find_parameters: gets information from the user * @@ -128,15 +161,11 @@ static regex_t *r; /* Pointer to compiled content_pattern */ * behavior for the other two parameters. * */ - -static int case_sensitive = 1; - static int find_parameters (char **start_dir, char **pattern, char **content) { int return_value; char *temp_dir; - WCheck *case_sense; static char *case_label = N_("case &Sensitive"); static char *in_contents = NULL; @@ -191,15 +220,20 @@ find_parameters (char **start_dir, char **pattern, char **content) if (!in_contents) in_contents = g_strdup (""); - find_dlg = create_dlg (0, 0, FIND_Y, FIND_X, dialog_colors, NULL, - "[Find File]", _("Find File"), DLG_CENTER); + find_dlg = + create_dlg (0, 0, FIND_Y, FIND_X, dialog_colors, + find_parm_callback, "[Find File]", _("Find File"), + DLG_CENTER); - add_widget (find_dlg, button_new (11, b2, B_CANCEL, NORMAL_BUTTON, - buts[2], 0, 0, "cancel")); - add_widget (find_dlg, button_new (11, b1, B_TREE, NORMAL_BUTTON, - buts[1], 0, 0, "tree")); - add_widget (find_dlg, button_new (11, b0, B_ENTER, DEFPUSH_BUTTON, - buts[0], 0, 0, "ok")); + add_widget (find_dlg, + button_new (11, b2, B_CANCEL, NORMAL_BUTTON, buts[2], 0, 0, + "cancel")); + add_widget (find_dlg, + button_new (11, b1, B_TREE, NORMAL_BUTTON, buts[1], 0, 0, + "tree")); + add_widget (find_dlg, + button_new (11, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0, 0, + "ok")); case_sense = check_new (9, 3, case_sensitive, case_label, "find-case-check"); @@ -249,19 +283,6 @@ find_parameters (char **start_dir, char **pattern, char **content) default: g_free (in_contents); if (in_with->buffer[0]) { - int flags = REG_EXTENDED | REG_NOSUB; - - if (!(case_sense->state & C_BOOL)) - flags |= REG_ICASE; - - if (regcomp (r, in_with->buffer, flags)) { - *content = in_contents = NULL; - r = 0; - message (1, MSG_ERROR, - _(" Malformed regular expression ")); - return_value = 0; - break; - } *content = g_strdup (in_with->buffer); in_contents = g_strdup (*content); } else {