* 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.
This commit is contained in:
Pavel Roskin 2002-12-24 11:28:26 +00:00
parent 336183ab5d
commit eb781a8f06
4 changed files with 79 additions and 48 deletions

View File

@ -1,3 +1,12 @@
2002-12-24 Pavel Roskin <proski@gnu.org>
* 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 <proski@gnu.org> 2002-12-23 Pavel Roskin <proski@gnu.org>
* layout.c (init_curses) [HAVE_SLANG]: Don't call * layout.c (init_curses) [HAVE_SLANG]: Don't call

View File

@ -382,8 +382,6 @@ static void select_a_widget (Dlg_head *h, int down)
h->current = h->current->next; h->current = h->current->next;
else else
h->current = h->current->prev; h->current = h->current->prev;
(*h->callback) (h, h->current->dlg_id, DLG_ONE_DOWN);
} while (!dlg_focus (h)); } 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 */ /* Find the widget with the given callback in the dialog h */
Widget *find_widget_type (Dlg_head *h, callback_fn signature) Widget *
find_widget_type (Dlg_head *h, callback_fn signature)
{ {
Widget *w; Widget *w;
Widget_Item *item; Widget_Item *item;
@ -412,8 +411,8 @@ Widget *find_widget_type (Dlg_head *h, callback_fn signature)
return 0; return 0;
w = 0; w = 0;
for (i = 0, item = h->current; i < h->count; i++, item = item->next){ for (i = 0, item = h->current; i < h->count; i++, item = item->next) {
if (item->widget->callback == signature){ if (item->widget->callback == signature) {
w = item->widget; w = item->widget;
break; break;
} }
@ -812,6 +811,9 @@ frontend_run_dlg (Dlg_head *h)
d_key = get_event (&event, h->mouse_status == MOU_REPEAT, 1); d_key = get_event (&event, h->mouse_status == MOU_REPEAT, 1);
dlg_process_event (h, d_key, &event); dlg_process_event (h, d_key, &event);
if (!h->running)
(*h->callback) (h, 0, DLG_VALIDATE);
} }
} }

View File

@ -45,22 +45,21 @@ enum {
/* Dialog messages */ /* Dialog messages */
enum { enum {
DLG_KEY, /* Sent on keypress before sending to widget */ DLG_KEY, /* Key before sending to widget */
DLG_INIT, /* Sent on init */ DLG_INIT, /* Initialize dialog */
DLG_END, /* Sent on shutdown */ DLG_END, /* Shut down dialog */
DLG_ACTION, DLG_ACTION, /* State of check- and radioboxes has changed */
DLG_DRAW, /* Sent for updating dialog managed area */ DLG_DRAW, /* Draw dialog on screen */
DLG_FOCUS, /* Sent on give focus to a widget */ DLG_FOCUS, /* A widget has got focus */
DLG_UNFOCUS, /* Sent on remove focus from widget */ DLG_UNFOCUS, /* A widget has been unfocused */
DLG_RESIZE, /* Sent when the window size changes */ DLG_RESIZE, /* Window size has changed */
DLG_ONE_UP, /* Sent on selecting next */ DLG_POST_KEY, /* The key has been handled */
DLG_ONE_DOWN, /* Sent on selecting prev */ DLG_IDLE, /* The idle state is active */
DLG_POST_KEY, /* Sent after key has been sent */ DLG_UNHANDLED_KEY, /* Key that no widget handled */
DLG_IDLE, /* Sent if idle is active */ DLG_HOTKEY_HANDLED, /* A widget has got the hotkey */
DLG_UNHANDLED_KEY, /* Send if no widget wanted the key */ DLG_PRE_EVENT, /* About to get new event */
DLG_HOTKEY_HANDLED, /* Send if a child got the hotkey */ DLG_VALIDATE /* Dialog is to be closed */
DLG_PRE_EVENT /* Send before calling get_event */ } /* Dialog_Messages */ ;
} /* Dialog_Messages */;
/* Dialog callback */ /* Dialog callback */

View File

@ -69,7 +69,9 @@ char *find_ignore_dirs = 0;
static WInput *in_start; /* Start path */ static WInput *in_start; /* Start path */
static WInput *in_name; /* Pattern to search */ 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 int running = 0; /* nice flag */
static char *find_pattern; /* Pattern to search */ static char *find_pattern; /* Pattern to search */
static char *content_pattern; /* pattern to search inside files */ 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 */ /* FIXME: r should be local variables */
static regex_t *r; /* Pointer to compiled content_pattern */ 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 * 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. * behavior for the other two parameters.
* *
*/ */
static int case_sensitive = 1;
static int static int
find_parameters (char **start_dir, char **pattern, char **content) find_parameters (char **start_dir, char **pattern, char **content)
{ {
int return_value; int return_value;
char *temp_dir; char *temp_dir;
WCheck *case_sense;
static char *case_label = N_("case &Sensitive"); static char *case_label = N_("case &Sensitive");
static char *in_contents = NULL; static char *in_contents = NULL;
@ -191,15 +220,20 @@ find_parameters (char **start_dir, char **pattern, char **content)
if (!in_contents) if (!in_contents)
in_contents = g_strdup (""); in_contents = g_strdup ("");
find_dlg = create_dlg (0, 0, FIND_Y, FIND_X, dialog_colors, NULL, find_dlg =
"[Find File]", _("Find File"), DLG_CENTER); 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, add_widget (find_dlg,
buts[2], 0, 0, "cancel")); button_new (11, b2, B_CANCEL, NORMAL_BUTTON, buts[2], 0, 0,
add_widget (find_dlg, button_new (11, b1, B_TREE, NORMAL_BUTTON, "cancel"));
buts[1], 0, 0, "tree")); add_widget (find_dlg,
add_widget (find_dlg, button_new (11, b0, B_ENTER, DEFPUSH_BUTTON, button_new (11, b1, B_TREE, NORMAL_BUTTON, buts[1], 0, 0,
buts[0], 0, 0, "ok")); "tree"));
add_widget (find_dlg,
button_new (11, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0, 0,
"ok"));
case_sense = case_sense =
check_new (9, 3, case_sensitive, case_label, "find-case-check"); 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: default:
g_free (in_contents); g_free (in_contents);
if (in_with->buffer[0]) { 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); *content = g_strdup (in_with->buffer);
in_contents = g_strdup (*content); in_contents = g_strdup (*content);
} else { } else {