From c59a14d4385ef0c2fdf755f0976f8e2eb32d9902 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 9 Sep 2012 18:02:29 +0400 Subject: [PATCH] Associate label with input line and enable/disable them as pair. Signed-off-by: Andrew Borodin --- lib/widget/input.c | 23 ++++++++++++++++++++++- lib/widget/input.h | 1 + src/filemanager/find.c | 6 ++---- src/filemanager/option.c | 7 ++++--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/widget/input.c b/lib/widget/input.c index 2d60140e5..58d4a9ab7 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -972,6 +972,25 @@ input_event (Gpm_Event * event, void *data) } /* --------------------------------------------------------------------------------------------- */ + +/** + * Callback for applying new options to input widget. + * + * @param w widget + * @param options options set + * @param enable TRUE if specified options should be added, FALSE if options should be removed + */ +static void +input_set_options_callback (Widget *w, widget_options_t options, gboolean enable) +{ + WInput *in = (WInput *) w; + + widget_default_set_options_callback (w, options, enable); + if (in->label != NULL) + widget_set_options (WIDGET (in->label), options, enable); +} + +/* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -996,6 +1015,7 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex w = WIDGET (in); init_widget (w, y, x, 1, width, input_callback, input_event); w->options |= W_IS_INPUT; + w->set_options = input_set_options_callback; memmove (in->color, input_colors, sizeof (input_colors_t)); @@ -1027,9 +1047,10 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex in->history_name = NULL; if ((histname != NULL) && (*histname != '\0')) in->history_name = g_strdup (histname); - /* history will be loaded later */ + in->label = NULL; + return in; } diff --git a/lib/widget/input.h b/lib/widget/input.h index 3c217ac8b..42dc5bf1e 100644 --- a/lib/widget/input.h +++ b/lib/widget/input.h @@ -68,6 +68,7 @@ typedef struct input_complete_t completion_flags; char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */ size_t charpoint; /* point to end of mulibyte sequence in charbuf */ + WLabel *label; /* label associated with this input line*/ } WInput; /*** global variables defined in .c file *********************************************************/ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 75006d703..ece4c9fd0 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -405,7 +405,6 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void { gboolean disable = !(content_use_cbox->state & C_BOOL); - widget_disable (WIDGET (content_label), disable); widget_disable (WIDGET (in_with), disable); widget_disable (WIDGET (content_first_hit_cbox), disable); widget_disable (WIDGET (content_regexp_cbox), disable); @@ -610,11 +609,10 @@ find_parameters (char **start_dir, ssize_t * start_dir_len, in_with = input_new (8, FIND_X / 2 + 1, input_get_default_colors (), FIND_X / 2 - 4, INPUT_LAST_TEXT, MC_HISTORY_SHARED_SEARCH, INPUT_COMPLETE_DEFAULT); + content_label = label_new (7, FIND_X / 2 + 1, _("Content:")); + in_with->label = content_label; widget_disable (WIDGET (in_with), disable); add_widget (find_dlg, in_with); - - content_label = label_new (7, FIND_X / 2 + 1, _("Content:")); - widget_disable (WIDGET (content_label), disable); add_widget (find_dlg, content_label); in_name = input_new (8, 3, input_get_default_colors (), diff --git a/src/filemanager/option.c b/src/filemanager/option.c index ed5f03504..948d542db 100644 --- a/src/filemanager/option.c +++ b/src/filemanager/option.c @@ -80,12 +80,13 @@ configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void { const gboolean not_single = !(((WCheck *) sender)->state & C_BOOL); Widget *w; + WInput *in; - /* label */ - w = dlg_find_by_id (h, sender->id - 1); - widget_disable (w, not_single); /* input */ w = dlg_find_by_id (h, sender->id - 2); + in = (WInput *) w; + if (in->label == NULL) + in->label = (WLabel *) dlg_find_by_id (h, sender->id - 1); widget_disable (w, not_single); return MSG_HANDLED; -- 2.11.4.GIT