Browse Source

Ticket #2161 (del - clear input field)

    new behavior: DEL - clear current field of dialog if text in the field is not modify and cursor not moved.

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>

Code cleanups: avoid compiler warnings

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Ilia Maslakov 15 years ago
parent
commit
72bb075828
10 changed files with 141 additions and 77 deletions
  1. 48 48
      lib/skin.h
  2. 3 0
      lib/skin/colors.c
  3. 21 7
      src/boxes.c
  4. 8 2
      src/command.c
  5. 9 2
      src/editor/editcmd_dialogs.c
  6. 12 5
      src/find.c
  7. 9 2
      src/panelize.c
  8. 15 7
      src/widget.c
  9. 6 2
      src/widget.h
  10. 10 2
      src/wtools.c

+ 48 - 48
lib/skin.h

@@ -13,77 +13,77 @@
    See color-slang.h (A_*) */
 
 /* cache often used colors*/
-#define DEFAULT_COLOR           mc_skin_color__cache[0]
-#define NORMAL_COLOR            mc_skin_color__cache[1]
-#define MARKED_COLOR            mc_skin_color__cache[2]
-#define SELECTED_COLOR          mc_skin_color__cache[3]
-#define MARKED_SELECTED_COLOR   mc_skin_color__cache[4]
-#define REVERSE_COLOR           mc_skin_color__cache[5]
+#define DEFAULT_COLOR             mc_skin_color__cache[0]
+#define NORMAL_COLOR              mc_skin_color__cache[1]
+#define MARKED_COLOR              mc_skin_color__cache[2]
+#define SELECTED_COLOR            mc_skin_color__cache[3]
+#define MARKED_SELECTED_COLOR     mc_skin_color__cache[4]
+#define REVERSE_COLOR             mc_skin_color__cache[5]
+#define COMMAND_MARK_COLOR        mc_skin_color__cache[6]
 
 /* Dialog colors */
-#define COLOR_NORMAL            mc_skin_color__cache[6]
-#define COLOR_FOCUS             mc_skin_color__cache[7]
-#define COLOR_HOT_NORMAL        mc_skin_color__cache[8]
-#define COLOR_HOT_FOCUS         mc_skin_color__cache[9]
+#define COLOR_NORMAL              mc_skin_color__cache[7]
+#define COLOR_FOCUS               mc_skin_color__cache[8]
+#define COLOR_HOT_NORMAL          mc_skin_color__cache[9]
+#define COLOR_HOT_FOCUS           mc_skin_color__cache[10]
 
 /* Error dialog colors */
-#define ERROR_COLOR             mc_skin_color__cache[10]
-#define ERROR_HOT_NORMAL        mc_skin_color__cache[11]
-#define ERROR_HOT_FOCUS         mc_skin_color__cache[12]
+#define ERROR_COLOR               mc_skin_color__cache[11]
+#define ERROR_HOT_NORMAL          mc_skin_color__cache[12]
+#define ERROR_HOT_FOCUS           mc_skin_color__cache[13]
 
 /* Menu colors */
-#define MENU_ENTRY_COLOR        mc_skin_color__cache[13]
-#define MENU_SELECTED_COLOR     mc_skin_color__cache[14]
-#define MENU_HOT_COLOR          mc_skin_color__cache[15]
-#define MENU_HOTSEL_COLOR       mc_skin_color__cache[16]
-#define MENU_INACTIVE_COLOR     mc_skin_color__cache[17]
+#define MENU_ENTRY_COLOR          mc_skin_color__cache[14]
+#define MENU_SELECTED_COLOR       mc_skin_color__cache[15]
+#define MENU_HOT_COLOR            mc_skin_color__cache[16]
+#define MENU_HOTSEL_COLOR         mc_skin_color__cache[17]
+#define MENU_INACTIVE_COLOR       mc_skin_color__cache[18]
 
 /*
  * This should be selectable independently. Default has to be black background
  * foreground does not matter at all.
  */
-#define GAUGE_COLOR             mc_skin_color__cache[18]
-#define INPUT_COLOR             mc_skin_color__cache[19]
+#define GAUGE_COLOR               mc_skin_color__cache[19]
+#define INPUT_COLOR               mc_skin_color__cache[20]
+#define INPUT_INACTIVE_COLOR      mc_skin_color__cache[21]
+#define INPUT_MARK_COLOR          mc_skin_color__cache[22]
 
-#define HELP_NORMAL_COLOR       mc_skin_color__cache[20]
-#define HELP_ITALIC_COLOR       mc_skin_color__cache[21]
-#define HELP_BOLD_COLOR         mc_skin_color__cache[22]
-#define HELP_LINK_COLOR         mc_skin_color__cache[23]
-#define HELP_SLINK_COLOR        mc_skin_color__cache[24]
+#define HELP_NORMAL_COLOR         mc_skin_color__cache[23]
+#define HELP_ITALIC_COLOR         mc_skin_color__cache[24]
+#define HELP_BOLD_COLOR           mc_skin_color__cache[25]
+#define HELP_LINK_COLOR           mc_skin_color__cache[26]
+#define HELP_SLINK_COLOR          mc_skin_color__cache[27]
 
-#define VIEW_UNDERLINED_COLOR   mc_skin_color__cache[25]
+#define VIEW_UNDERLINED_COLOR     mc_skin_color__cache[28]
 
 /*
  * editor colors - only 4 for normal, search->found, select, and whitespace
  * respectively
  * Last is defined to view color.
  */
-#define EDITOR_NORMAL_COLOR     mc_skin_color__cache[26]
-#define EDITOR_BOLD_COLOR       mc_skin_color__cache[27]
-#define EDITOR_MARKED_COLOR     mc_skin_color__cache[28]
-#define EDITOR_WHITESPACE_COLOR mc_skin_color__cache[29]
-#define EDITOR_RIGHT_MARGIN_COLOR mc_skin_color__cache[30]
+#define EDITOR_NORMAL_COLOR       mc_skin_color__cache[29]
+#define EDITOR_BOLD_COLOR         mc_skin_color__cache[30]
+#define EDITOR_MARKED_COLOR       mc_skin_color__cache[31]
+#define EDITOR_WHITESPACE_COLOR   mc_skin_color__cache[32]
+#define EDITOR_RIGHT_MARGIN_COLOR mc_skin_color__cache[33]
 /* color of left 8 char status per line */
-#define LINE_STATE_COLOR        mc_skin_color__cache[31]
-#define BOOK_MARK_COLOR         mc_skin_color__cache[32]
-#define BOOK_MARK_FOUND_COLOR   mc_skin_color__cache[33]
+#define LINE_STATE_COLOR          mc_skin_color__cache[34]
+#define BOOK_MARK_COLOR           mc_skin_color__cache[35]
+#define BOOK_MARK_FOUND_COLOR     mc_skin_color__cache[36]
 
-#define BUTTONBAR_HOTKEY_COLOR   mc_skin_color__cache[34]
-#define BUTTONBAR_BUTTON_COLOR   mc_skin_color__cache[35]
+#define BUTTONBAR_HOTKEY_COLOR    mc_skin_color__cache[37]
+#define BUTTONBAR_BUTTON_COLOR    mc_skin_color__cache[38]
 
 /* Diff colors */
-#define DFF_ADD_COLOR            mc_skin_color__cache[36]
-#define DFF_CHG_COLOR            mc_skin_color__cache[37]
-#define DFF_CHH_COLOR            mc_skin_color__cache[38]
-#define DFF_CHD_COLOR            mc_skin_color__cache[39]
-#define DFF_DEL_COLOR            mc_skin_color__cache[40]
-#define DFF_FOLDER_COLOR         mc_skin_color__cache[41]
-#define DFF_ERROR_COLOR          mc_skin_color__cache[42]
-
-
-
-#define MC_SKIN_COLOR_CACHE_COUNT 43
-
+#define DFF_ADD_COLOR             mc_skin_color__cache[39]
+#define DFF_CHG_COLOR             mc_skin_color__cache[40]
+#define DFF_CHH_COLOR             mc_skin_color__cache[41]
+#define DFF_CHD_COLOR             mc_skin_color__cache[42]
+#define DFF_DEL_COLOR             mc_skin_color__cache[43]
+#define DFF_FOLDER_COLOR          mc_skin_color__cache[44]
+#define DFF_ERROR_COLOR           mc_skin_color__cache[45]
+
+#define MC_SKIN_COLOR_CACHE_COUNT 46
 
 /*** enums ***************************************************************************************/
 

+ 3 - 0
lib/skin/colors.c

@@ -202,6 +202,7 @@ mc_skin_color_cache_init (void)
     SELECTED_COLOR = mc_skin_color_get ("core", "selected");
     MARKED_SELECTED_COLOR = mc_skin_color_get ("core", "markselect");
     REVERSE_COLOR = mc_skin_color_get ("core", "reverse");
+    COMMAND_MARK_COLOR = mc_skin_color_get ("core", "commandlinemark");
 
     COLOR_NORMAL = mc_skin_color_get ("dialog", "_default_");
     COLOR_FOCUS = mc_skin_color_get ("dialog", "dfocus");
@@ -220,6 +221,8 @@ mc_skin_color_cache_init (void)
 
     GAUGE_COLOR = mc_skin_color_get ("core", "gauge");
     INPUT_COLOR = mc_skin_color_get ("core", "input");
+    INPUT_MARK_COLOR = mc_skin_color_get ("core", "inputmark");
+    INPUT_INACTIVE_COLOR = mc_skin_color_get ("core", "inputinactive");
 
     HELP_NORMAL_COLOR = mc_skin_color_get ("help", "_default_");
     HELP_ITALIC_COLOR = mc_skin_color_get ("help", "helpitalic");

+ 21 - 7
src/boxes.c

@@ -136,6 +136,13 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status)
     int dlg_width = 48, dlg_height = 15;
     Dlg_head *dd;
 
+    const int input_colors[3] =
+    {
+        INPUT_COLOR,
+        INPUT_INACTIVE_COLOR,
+        INPUT_MARK_COLOR
+    };
+
     /* Controls whether the array strings have been translated */
     const char *displays[LIST_TYPES] = {
         N_("&Full file list"),
@@ -202,7 +209,7 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status)
     add_widget (dd, cancel_button);
     add_widget (dd, ok_button);
 
-    display_mini_status = input_new (10, 8, INPUT_COLOR, dlg_width - 12, _status[radio_sel],
+    display_mini_status = input_new (10, 8, (int *) input_colors, dlg_width - 12, _status[radio_sel],
                                      "mini-input", INPUT_COMPLETE_DEFAULT);
     add_widget (dd, display_mini_status);
     input_set_point (display_mini_status, 0);
@@ -210,7 +217,7 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status)
     display_check_status = check_new (9, 4, _check_status, user_mini_status);
     add_widget (dd, display_check_status);
 
-    display_user_format = input_new (7, 8, INPUT_COLOR, dlg_width - 12, init_text,
+    display_user_format = input_new (7, 8, (int *) input_colors, dlg_width - 12, init_text,
                                      "user-fmt-input", INPUT_COMPLETE_DEFAULT);
     add_widget (dd, display_user_format);
     input_set_point (display_user_format, 0);
@@ -1015,6 +1022,13 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, c
     WInput *in_domain;
     Dlg_head *auth_dlg;
 
+    const int input_colors[3] =
+    {
+        INPUT_COLOR,
+        INPUT_INACTIVE_COLOR,
+        INPUT_MARK_COLOR
+    };
+
 #ifdef ENABLE_NLS
     static int i18n_flag = 0;
 
@@ -1063,17 +1077,17 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, c
 
     g_free (title);
 
-    in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
+    in_user = input_new (5, istart, (int *) input_colors, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
     add_widget (auth_dlg, in_user);
 
-    in_domain =
-        input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
+    in_domain = input_new (3, istart, (int *) input_colors, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
+
     add_widget (auth_dlg, in_domain);
     add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
     add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
 
-    in_password =
-        input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
+    in_password  = input_new (7, istart, (int *) input_colors, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
+
     in_password->completion_flags = 0;
     in_password->is_password = 1;
     add_widget (auth_dlg, in_password);

+ 8 - 2
src/command.c

@@ -305,8 +305,14 @@ WInput *
 command_new (int y, int x, int cols)
 {
     WInput *cmd;
-
-    cmd = input_new (y, x, DEFAULT_COLOR, cols, "", "cmdline",
+    const int command_colors[3] =
+    {
+        DEFAULT_COLOR,
+        DEFAULT_COLOR,
+        COMMAND_MARK_COLOR
+    };
+
+    cmd = input_new (y, x, (int *) command_colors, cols, "", "cmdline",
 	INPUT_COMPLETE_DEFAULT | INPUT_COMPLETE_CD | INPUT_COMPLETE_COMMANDS | INPUT_COMPLETE_SHELL_ESC);
 
     /* Add our hooks */

+ 9 - 2
src/editor/editcmd_dialogs.c

@@ -312,11 +312,18 @@ int
 editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel)
 {
     int w = str_term_width1 (query) + 7;
+    const int input_colors[3] =
+    {
+        INPUT_COLOR,
+        INPUT_INACTIVE_COLOR,
+        INPUT_MARK_COLOR
+    };
+
     struct Dlg_head *raw_dlg =
         create_dlg (0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb,
                     NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
-    add_widget (raw_dlg,
-                input_new (3 - cancel, w - 5, INPUT_COLOR, 2, "", 0, INPUT_COMPLETE_DEFAULT));
+    add_widget (raw_dlg, input_new (3 - cancel, w - 5, (int *) input_colors,
+                                    2, "", 0, INPUT_COMPLETE_DEFAULT));
     add_widget (raw_dlg, label_new (3 - cancel, 2, query));
     if (cancel)
         add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));

+ 12 - 5
src/find.c

@@ -384,6 +384,13 @@ find_parameters (char **start_dir, char **pattern, char **content)
 
     const char *buts[] = { N_("&OK"), N_("&Cancel"), N_("&Tree") };
 
+    const int input_colors[3] =
+    {
+        INPUT_COLOR,
+        INPUT_INACTIVE_COLOR,
+        INPUT_MARK_COLOR
+    };
+
     int b0, b1, b2;
 
 #ifdef ENABLE_NLS
@@ -467,20 +474,20 @@ find_parameters (char **start_dir, char **pattern, char **content)
     file_case_sens_cbox = check_new (7, 3, options.file_case_sens, file_case_label);
     add_widget (find_dlg, file_case_sens_cbox);
 
-    in_with = input_new (6, FIND_X / 2 + 1, INPUT_COLOR, FIND_X / 2 - 4, INPUT_LAST_TEXT,
+    in_with = input_new (6, FIND_X / 2 + 1, (int *) input_colors, FIND_X / 2 - 4, INPUT_LAST_TEXT,
                          MC_HISTORY_SHARED_SEARCH, INPUT_COMPLETE_DEFAULT);
     add_widget (find_dlg, in_with);
     add_widget (find_dlg, label_new (5, FIND_X / 2 + 1, _("Content:")));
 
-    in_name = input_new (6, 3, INPUT_COLOR, FIND_X / 2 - 4, INPUT_LAST_TEXT, "name",
-                         INPUT_COMPLETE_DEFAULT);
+    in_name = input_new (6, 3, (int *) input_colors,
+                         FIND_X / 2 - 4, INPUT_LAST_TEXT, "name", INPUT_COMPLETE_DEFAULT);
     add_widget (find_dlg, in_name);
     add_widget (find_dlg, label_new (5, 3, _("File name:")));
 
     add_widget (find_dlg, button_new (3, FIND_X - b2 - 2, B_TREE, NORMAL_BUTTON, buts[2], 0));
 
-    in_start = input_new (3, 3, INPUT_COLOR, FIND_X - b2 - 6, in_start_dir, "start",
-                          INPUT_COMPLETE_DEFAULT);
+    in_start = input_new (3, 3, (int *) input_colors,
+                          FIND_X - b2 - 6, in_start_dir, "start", INPUT_COMPLETE_DEFAULT);
     add_widget (find_dlg, in_start);
     add_widget (find_dlg, label_new (2, 3, _("Start at:")));
 

+ 9 - 2
src/panelize.c

@@ -139,6 +139,13 @@ init_panelize (void)
     static int i18n_flag = 0;
     static int maxlen = 0;
 
+    const int input_colors[3] =
+    {
+        INPUT_COLOR,
+        INPUT_INACTIVE_COLOR,
+        INPUT_MARK_COLOR
+    };
+
     if (!i18n_flag)
     {
         i = sizeof (panelize_but) / sizeof (panelize_but[0]);
@@ -176,8 +183,8 @@ init_panelize (void)
                                 panelize_but[i].flags, panelize_but[i].text, 0));
 
     pname =
-        input_new (UY + 14, UX, INPUT_COLOR, panelize_dlg->cols - 10, "",
-                   "in", INPUT_COMPLETE_DEFAULT);
+        input_new (UY + 14, UX, (int *) input_colors,
+                   panelize_dlg->cols - 10, "", "in", INPUT_COMPLETE_DEFAULT);
     add_widget (panelize_dlg, pname);
 
     add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command")));

+ 15 - 7
src/widget.c

@@ -1079,7 +1079,10 @@ update_input (WInput * in, int clear_first)
     if (has_history)
         draw_history_button (in);
 
-    tty_setcolor (in->color);
+    if (in->first)
+        tty_setcolor (in->inactive_color);
+    else
+        tty_setcolor (in->color);
 
     widget_move (&in->widget, 0, 0);
 
@@ -1103,7 +1106,7 @@ update_input (WInput * in, int clear_first)
     }
 
     if (clear_first)
-        in->first = 0;
+        in->first = FALSE;
 }
 
 void
@@ -1920,7 +1923,7 @@ port_region_marked_for_delete (WInput * in)
 {
     in->buffer[0] = '\0';
     in->point = 0;
-    in->first = 0;
+    in->first = FALSE;
     in->charpoint = 0;
 }
 
@@ -1965,7 +1968,10 @@ input_execute_cmd (WInput * in, unsigned long command)
         backward_delete (in);
         break;
     case CK_InputDeleteChar:
-        delete_char (in);
+        if (in->first)
+            port_region_marked_for_delete (in);
+        else
+            delete_char (in);
         break;
     case CK_InputKillWord:
         kill_word (in);
@@ -2179,7 +2185,7 @@ input_event (Gpm_Event * event, void *data)
 }
 
 WInput *
-input_new (int y, int x, int color, int width, const char *def_text,
+input_new (int y, int x, int *input_colors, int width, const char *def_text,
            const char *histname, INPUT_COMPLETE_FLAGS completion_flags)
 {
     WInput *in = g_new (WInput, 1);
@@ -2212,9 +2218,11 @@ input_new (int y, int x, int color, int width, const char *def_text,
     in->completion_flags = completion_flags;
     in->current_max_size = initial_buffer_len;
     in->buffer = g_new (char, initial_buffer_len);
-    in->color = color;
+    in->color = input_colors[0];
+    in->mark_color = input_colors[2];
+    in->inactive_color = input_colors[1];
     in->field_width = width;
-    in->first = 1;
+    in->first = TRUE;
     in->term_first_shown = 0;
     in->disable_update = 0;
     in->mark = 0;

+ 6 - 2
src/widget.h

@@ -106,7 +106,9 @@ typedef struct {
     size_t current_max_size;	/* Maximum length of input line (bytes) */
     int  field_width;		/* width of the editing field */
     int  color;			/* color used */
-    int  first;			/* Is first keystroke? */
+    int  mark_color;		/* color for marked text */
+    int  inactive_color;	/* color for inactive text (Is first keystroke) */
+    gboolean first;		/* Is first keystroke? */
     int  disable_update;	/* Do we want to skip updates? */
     int  is_password;		/* Is this a password input line? */
     char *buffer;		/* pointer to editing buffer */
@@ -192,7 +194,9 @@ WButton *button_new   (int y, int x, int action, int flags, const char *text,
 		      bcback callback);
 WRadio  *radio_new    (int y, int x, int count, const char **text);
 WCheck  *check_new    (int y, int x, int state,  const char *text);
-WInput  *input_new    (int y, int x, int color, int len, const char *text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags);
+WInput  *input_new    (int y, int x, int *input_colors,
+                       int len, const char *text, const char *histname,
+                       INPUT_COMPLETE_FLAGS completion_flags);
 WLabel  *label_new    (int y, int x, const char *text);
 WHLine  *hline_new    (int y, int x, int width);
 

+ 10 - 2
src/wtools.c

@@ -367,6 +367,13 @@ quick_dialog_skip (QuickDialog *qd, int nskip)
     WRadio *r;
     int return_val;
 
+    const int input_colors[3] =
+    {
+        INPUT_COLOR,
+        INPUT_INACTIVE_COLOR,
+        INPUT_MARK_COLOR
+    };
+
     I18N (qd->title);
 
     if ((qd->xpos == -1) || (qd->ypos == -1))
@@ -397,8 +404,9 @@ quick_dialog_skip (QuickDialog *qd, int nskip)
 	    break;
 
 	case quick_input:
-	    in = input_new (ypos, xpos, INPUT_COLOR, qw->u.input.len,
-			    qw->u.input.text, qw->u.input.histname, INPUT_COMPLETE_DEFAULT);
+	    in = input_new (ypos, xpos, (int *) input_colors,
+	                    qw->u.input.len, qw->u.input.text, qw->u.input.histname,
+	                    INPUT_COMPLETE_DEFAULT);
 	    in->is_password = (qw->u.input.flags == 1);
 	    in->point = 0;
 	    if ((qw->u.input.flags & 2) != 0)