Implementation of keybindings for WListbox.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-08-12 13:17:58 +04:00
parent 2f62fadabb
commit 44d07b20ab
7 changed files with 154 additions and 88 deletions

View File

@ -337,6 +337,16 @@ InputWordRightHighlight = ctrl-shift-right
InputBolHighlight = shift-home
InputEolHighlight = shift-end
[listbox]
ListboxMoveUp = up; ctrl-p
ListboxMoveDown = down; ctrl-n
ListboxMoveHome = home; alt-lt; a1
ListboxMoveEnd = end; alt-gt; c1
ListboxMovePgUp = pgup; alt-v
ListboxMovePgDn = pgdn; ctrl-v
ListboxDeleteItem = delete; d
ListboxDeleteAll = shift-delete; shift-d
[tree]
TreeHelp = f1
TreeForget = f3

View File

@ -341,6 +341,16 @@ InputWordRightHighlight =
InputBolHighlight =
InputEolHighlight =
[listbox]
ListboxMoveUp = up; ctrl-p
ListboxMoveDown = down; ctrl-n
ListboxMoveHome = home; alt-lt; a1
ListboxMoveEnd = end; alt-gt; c1
ListboxMovePgUp = pgup; alt-v
ListboxMovePgDn = pgdn; ctrl-v
ListboxDeleteItem = delete; d
ListboxDeleteAll = shift-delete; shift-d
[tree]
TreeHelp = f1
TreeForget = f3

View File

@ -219,7 +219,7 @@
#define CK_StartExtMap1 2021
#define CK_StartExtMap2 2022
/* Dialog */
/* dialog */
#define CK_DialogOK 3001
#define CK_DialogCancel 3002
#define CK_DialogPrevItem 3003
@ -228,7 +228,7 @@
#define CK_DialogSuspend 3006
#define CK_DialogRefresh 3007
/* text fields*/
/* text fields */
#define CK_InputBol 4001
#define CK_InputEol 4002
#define CK_InputMoveLeft 4003
@ -254,7 +254,6 @@
#define CK_InputComplete 4024
#define CK_InputPaste 4025
#define CK_InputClearLine 4026
#define CK_InputLeftHighlight 4027
#define CK_InputRightHighlight 4028
#define CK_InputWordLeftHighlight 4029
@ -262,7 +261,17 @@
#define CK_InputBolHighlight 4031
#define CK_InputEolHighlight 4032
/* Viewer */
/* listbox */
#define CK_ListboxMoveUp 4500
#define CK_ListboxMoveDown 4501
#define CK_ListboxMoveHome 4502
#define CK_ListboxMoveEnd 4503
#define CK_ListboxMovePgUp 4504
#define CK_ListboxMovePgDn 4505
#define CK_ListboxDeleteItem 4506
#define CK_ListboxDeleteAll 4507
/* viewer */
#define CK_ViewHelp 5001
#define CK_ViewToggleWrapMode 5002
#define CK_ViewToggleHexEditMode 5003
@ -291,7 +300,7 @@
#define CK_ViewToggleRuler 5026
#define CK_ViewToggleHexNavMode 5027
/* Tree */
/* tree */
#define CK_TreeHelp 6001
#define CK_TreeForget 6003
#define CK_TreeToggleNav 6004

View File

@ -58,6 +58,7 @@ GArray *viewer_keymap = NULL;
GArray *viewer_hex_keymap = NULL;
GArray *panel_keymap = NULL;
GArray *input_keymap = NULL;
GArray *listbox_keymap = NULL;
GArray *tree_keymap = NULL;
GArray *help_keymap = NULL;
GArray *dialog_keymap = NULL;
@ -72,6 +73,7 @@ const global_keymap_t *main_map;
const global_keymap_t *main_x_map;
const global_keymap_t *panel_map;
const global_keymap_t *input_map;
const global_keymap_t *listbox_map;
const global_keymap_t *tree_map;
const global_keymap_t *help_map;
const global_keymap_t *dialog_map;
@ -483,11 +485,21 @@ static name_keymap_t command_names[] = {
{ "InputXPaste", CK_InputPaste },
{ "InputClearLine", CK_InputClearLine },
{ "InputLeftHighlight", CK_InputLeftHighlight },
{ "InputRightHighlight", CK_InputRightHighlight},
{ "InputWordLeftHighlight", CK_InputWordLeftHighlight},
{ "InputWordRightHighlight", CK_InputWordRightHighlight},
{ "InputBolHighlight", CK_InputBolHighlight},
{ "InputEolHighlight", CK_InputEolHighlight},
{ "InputRightHighlight", CK_InputRightHighlight },
{ "InputWordLeftHighlight", CK_InputWordLeftHighlight },
{ "InputWordRightHighlight", CK_InputWordRightHighlight },
{ "InputBolHighlight", CK_InputBolHighlight },
{ "InputEolHighlight", CK_InputEolHighlight },
/* listbox */
{ "ListboxMoveUp", CK_ListboxMoveUp },
{ "ListboxMoveDown", CK_ListboxMoveDown },
{ "ListboxMoveHome", CK_ListboxMoveHome },
{ "ListboxMoveEnd", CK_ListboxMoveEnd },
{ "ListboxMovePgUp", CK_ListboxMovePgUp },
{ "ListboxMovePgDn", CK_ListboxMovePgDn },
{ "ListboxDeleteItem", CK_ListboxDeleteItem },
{ "ListboxDeleteAll", CK_ListboxDeleteAll },
/* common */
{ "ExtMap1", CK_StartExtMap1 },
@ -504,6 +516,7 @@ static name_keymap_t command_names[] = {
{ "DialogSuspend", CK_DialogSuspend },
{ "DialogRefresh", CK_DialogRefresh },
#ifdef USE_DIFF_VIEW
/* diff viewer */
{ "DiffDisplaySymbols", CK_DiffDisplaySymbols},
{ "DiffDisplayNumbers", CK_DiffDisplayNumbers},
@ -541,6 +554,7 @@ static name_keymap_t command_names[] = {
{ "DiffMergeCurrentHunk", CK_DiffMergeCurrentHunk},
{ "DiffSave", CK_DiffSave},
{ "DiffOptions", CK_DiffOptions},
#endif
{ NULL, CK_Ignore_Key }
};
@ -871,7 +885,7 @@ const global_keymap_t default_help_keymap[] = {
{ 0, CK_Ignore_Key, "" }
};
/* screen.c */
/* panel */
const global_keymap_t default_panel_keymap[] = {
{ ALT ('o'), CK_PanelChdirOtherPanel, "M-o" },
{ ALT ('l'), CK_PanelChdirToReadlink, "M-l" },
@ -1033,6 +1047,30 @@ const global_keymap_t default_input_keymap[] = {
{ 0, CK_Ignore_Key, "" }
};
const global_keymap_t default_listbox_keymap[] = {
{ KEY_UP, CK_ListboxMoveUp, "Up" },
{ XCTRL ('p'), CK_ListboxMoveUp, "C-p" },
{ KEY_DOWN, CK_ListboxMoveDown, "Down" },
{ XCTRL ('n'), CK_ListboxMoveDown, "C-n" },
{ KEY_HOME, CK_ListboxMoveHome, "Home" },
{ ALT ('<'), CK_ListboxMoveHome, "M-<" },
{ KEY_A1, CK_ListboxMoveHome, "A1" },
{ KEY_END, CK_ListboxMoveEnd, "End" },
{ ALT ('>'), CK_ListboxMoveEnd, "M->" },
{ KEY_C1, CK_ListboxMoveEnd, "C1" },
{ KEY_PPAGE, CK_ListboxMovePgUp, "PgUp" },
{ ALT ('v'), CK_ListboxMovePgUp, "M-v" },
{ KEY_NPAGE, CK_ListboxMovePgDn, "PgDn" },
{ XCTRL ('v'), CK_ListboxMovePgDn, "C-v" },
{ KEY_DC, CK_ListboxDeleteItem, "Delete" },
{ 'd', CK_ListboxDeleteItem, "d" },
{ KEY_M_SHIFT | KEY_DC, CK_ListboxDeleteAll, "S-Delete" },
{ 'D', CK_ListboxDeleteAll, "D" },
{ 0, CK_Ignore_Key, "" }
};
#ifdef USE_DIFF_VIEW
/* diff viewer */
const global_keymap_t default_diff_keymap[] = {
@ -1081,6 +1119,7 @@ const global_keymap_t default_diff_keymap[] = {
{ 0, CK_Ignore_Key, "" }
};
#endif
static int
name_keymap_comparator (const void *p1, const void *p2)

View File

@ -43,6 +43,7 @@ extern GArray *main_keymap;
extern GArray *main_x_keymap;
extern GArray *panel_keymap;
extern GArray *input_keymap;
extern GArray *listbox_keymap;
extern GArray *tree_keymap;
extern GArray *help_keymap;
extern GArray *dialog_keymap;
@ -54,6 +55,7 @@ extern const global_keymap_t *main_map;
extern const global_keymap_t *main_x_map;
extern const global_keymap_t *panel_map;
extern const global_keymap_t *input_map;
extern const global_keymap_t *listbox_map;
extern const global_keymap_t *tree_map;
extern const global_keymap_t *help_map;
extern const global_keymap_t *dialog_map;
@ -76,6 +78,7 @@ extern const global_keymap_t default_panel_keymap[];
/* widget.c */
extern const global_keymap_t default_input_keymap[];
extern const global_keymap_t default_listbox_keymap[];
/* main.c */
extern const global_keymap_t default_main_map[];

View File

@ -1031,6 +1031,9 @@ load_keymap_defs (void)
input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("input", input_keymap, mc_global_keymap);
listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("listbox", listbox_keymap, mc_global_keymap);
tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("tree", tree_keymap, mc_global_keymap);
@ -1063,6 +1066,10 @@ load_keymap_defs (void)
if (input_keymap && input_keymap->len > 0)
input_map = (global_keymap_t *) input_keymap->data;
listbox_map = default_listbox_keymap;
if (listbox_keymap && listbox_keymap->len > 0)
listbox_map = (global_keymap_t *) listbox_keymap->data;
tree_map = default_tree_keymap;
if (tree_keymap && tree_keymap->len > 0)
tree_map = (global_keymap_t *) tree_keymap->data;
@ -1104,6 +1111,8 @@ free_keymap_defs (void)
g_array_free (panel_keymap, TRUE);
if (input_keymap != NULL)
g_array_free (input_keymap, TRUE);
if (listbox_keymap != NULL)
g_array_free (listbox_keymap, TRUE);
if (tree_keymap != NULL)
g_array_free (tree_keymap, TRUE);
if (help_keymap != NULL)

View File

@ -2220,7 +2220,7 @@ handle_char (WInput * in, int key)
break;
}
}
if (input_map[i].command == 0)
if (input_map[i].command == CK_Ignore_Key)
{
if (key > 255)
return MSG_NOT_HANDLED;
@ -2649,13 +2649,65 @@ listbox_back (WListbox * l)
listbox_select_entry (l, l->pos - 1);
}
static cb_ret_t
listbox_execute_cmd (WListbox * l, unsigned long command)
{
cb_ret_t ret = MSG_HANDLED;
int i;
switch (command)
{
case CK_ListboxMoveUp:
listbox_back (l);
break;
case CK_ListboxMoveDown:
listbox_fwd (l);
break;
case CK_ListboxMoveHome:
listbox_select_first (l);
break;
case CK_ListboxMoveEnd:
listbox_select_last (l);
break;
case CK_ListboxMovePgUp:
for (i = 0; (i < l->widget.lines - 1) && (l->pos > 0); i++)
listbox_back (l);
break;
case CK_ListboxMovePgDn:
for (i = 0; (i < l->widget.lines - 1) && (l->pos < l->count - 1); i++)
listbox_fwd (l);
break;
case CK_ListboxDeleteItem:
if (l->deletable)
{
gboolean is_last = (l->pos + 1 >= l->count);
gboolean is_more = (l->top + l->widget.lines >= l->count);
listbox_remove_current (l);
if ((l->top > 0) && (is_last || is_more))
l->top--;
}
break;
case CK_ListboxDeleteAll:
if (l->deletable && confirm_history_cleanup
/* TRANSLATORS: no need to translate 'DialogTitle', it's just a context prefix */
&& (query_dialog (Q_ ("DialogTitle|History cleanup"),
_("Do you want clean this history?"),
D_ERROR, 2, _("&Yes"), _("&No")) == 0))
listbox_remove_list (l);
break;
default:
ret = MSG_NOT_HANDLED;
}
return ret;
}
/* Return MSG_HANDLED if we want a redraw */
static cb_ret_t
listbox_key (WListbox * l, int key)
{
int i;
cb_ret_t j = MSG_NOT_HANDLED;
unsigned long command;
if (l->list == NULL)
return MSG_NOT_HANDLED;
@ -2673,79 +2725,10 @@ listbox_key (WListbox * l, int key)
return MSG_HANDLED;
}
switch (key)
{
case KEY_HOME:
case KEY_A1:
case ALT ('<'):
listbox_select_first (l);
return MSG_HANDLED;
case KEY_END:
case KEY_C1:
case ALT ('>'):
listbox_select_last (l);
return MSG_HANDLED;
case XCTRL ('p'):
case KEY_UP:
listbox_back (l);
return MSG_HANDLED;
case XCTRL ('n'):
case KEY_DOWN:
listbox_fwd (l);
return MSG_HANDLED;
case KEY_NPAGE:
case XCTRL ('v'):
for (i = 0; (i < l->widget.lines - 1) && (l->pos < l->count - 1); i++)
{
listbox_fwd (l);
j = MSG_HANDLED;
}
break;
case KEY_PPAGE:
case ALT ('v'):
for (i = 0; (i < l->widget.lines - 1) && (l->pos > 0); i++)
{
listbox_back (l);
j = MSG_HANDLED;
}
break;
case KEY_DC:
case 'd':
if (l->deletable)
{
gboolean is_last = (l->pos + 1 >= l->count);
gboolean is_more = (l->top + l->widget.lines >= l->count);
listbox_remove_current (l);
if ((l->top > 0) && (is_last || is_more))
l->top--;
}
return MSG_HANDLED;
case (KEY_M_SHIFT | KEY_DC):
case 'D':
if (l->deletable && confirm_history_cleanup
/* TRANSLATORS: no need to translate 'DialogTitle', it's just a context prefix */
&& (query_dialog (Q_ ("DialogTitle|History cleanup"),
_("Do you want clean this history?"),
D_ERROR, 2, _("&Yes"), _("&No")) == 0))
{
listbox_remove_list (l);
j = MSG_HANDLED;
}
break;
default:
break;
}
return j;
command = lookup_keymap_command (listbox_map, key);
if (command == CK_Ignore_Key)
return MSG_NOT_HANDLED;
return listbox_execute_cmd (l, command);
}
static inline void
@ -2800,6 +2783,9 @@ listbox_callback (Widget * w, widget_msg_t msg, int parm)
}
return ret_code;
case WIDGET_COMMAND:
return listbox_execute_cmd (l, parm);
case WIDGET_CURSOR:
widget_move (&l->widget, l->cursor_y, 0);
h->callback (h, w, DLG_ACTION, l->pos, NULL);