1
1

Removed hardcoded hotkeys in dialog.c Replaced keymap's initialization from main.c into setup.c

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

Collect keybind-related variables in src/keybind.[ch] files.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Ilia Maslakov 2010-05-06 19:19:02 +00:00
родитель aeb03dad69
Коммит 823387a793
18 изменённых файлов: 215 добавлений и 142 удалений

Просмотреть файл

@ -359,6 +359,15 @@ HelpPrevLink = alt-tab
HelpNextNode = n
HelpPrevNode = p
[dialog]
DialogOK = enter
DialogCancel = f10; esc; ctrl-g
DialogPrevItem = left; up
DialogNextItem = right; down
DialogHelp = f1
DialogSuspend = ctrl-z
DialogRefresh = ctrl-l
[diffviewer]
DiffDisplaySymbols = alt-s; s
DiffDisplayNumbers = alt-n; l

Просмотреть файл

@ -363,6 +363,15 @@ HelpPrevLink = alt-tab
HelpNextNode = n
HelpPrevNode = p
[dialog]
DialogOK = enter
DialogCancel = f10; esc; ctrl-g
DialogPrevItem = left; up
DialogNextItem = right; down
DialogHelp = f1
DialogSuspend = ctrl-z
DialogRefresh = ctrl-l
[diffviewer]
DiffDisplaySymbols = alt-s; s
DiffDisplayNumbers = alt-n; l

Просмотреть файл

@ -219,6 +219,15 @@
#define CK_StartExtMap1 2021
#define CK_StartExtMap2 2022
/* Dialog */
#define CK_DialogOK 3001
#define CK_DialogCancel 3002
#define CK_DialogPrevItem 3003
#define CK_DialogNextItem 3004
#define CK_DialogHelp 3005
#define CK_DialogSuspend 3006
#define CK_DialogRefresh 3007
/* text fields*/
#define CK_InputBol 4001
#define CK_InputEol 4002

Просмотреть файл

@ -41,6 +41,8 @@
#include "dialog.h"
#include "layout.h"
#include "execute.h" /* suspend_cmd() */
#include "cmddef.h"
#include "keybind.h"
#include "main.h" /* fast_refresh */
#include "setup.h" /* mouse_close_dialog */
@ -609,43 +611,8 @@ dlg_stop (Dlg_head * h)
}
static void
dialog_handle_key (Dlg_head * h, int d_key)
refresh_cmd (void)
{
if (is_abort_char (d_key))
{
h->ret_value = B_CANCEL;
dlg_stop (h);
return;
}
switch (d_key)
{
case '\n':
case KEY_ENTER:
h->ret_value = B_ENTER;
dlg_stop (h);
break;
case KEY_LEFT:
case KEY_UP:
dlg_one_up (h);
break;
case KEY_RIGHT:
case KEY_DOWN:
dlg_one_down (h);
break;
case KEY_F (1):
interactive_display (NULL, h->help_ctx);
do_refresh ();
break;
case XCTRL ('z'):
suspend_cmd ();
/* Fall through */
case XCTRL ('l'):
#ifdef HAVE_SLANG
tty_touch_screen ();
mc_refresh ();
@ -654,11 +621,55 @@ dialog_handle_key (Dlg_head * h, int d_key)
clr_scr ();
repaint_screen ();
#endif /* HAVE_SLANG */
break;
}
default:
static cb_ret_t
dlg_execute_cmd (Dlg_head * h, unsigned long command)
{
cb_ret_t ret = MSG_HANDLED;
switch (command)
{
case CK_DialogOK:
h->ret_value = B_ENTER;
dlg_stop (h);
break;
case CK_DialogCancel:
h->ret_value = B_CANCEL;
dlg_stop (h);
break;
case CK_DialogPrevItem:
dlg_one_up (h);
break;
case CK_DialogNextItem:
dlg_one_down (h);
break;
case CK_DialogHelp:
interactive_display (NULL, h->help_ctx);
do_refresh ();
break;
case CK_DialogSuspend:
suspend_cmd ();
refresh_cmd ();
break;
case CK_DialogRefresh:
refresh_cmd ();
break;
default:
ret = MSG_NOT_HANDLED;
}
return ret;
}
static cb_ret_t
dlg_handle_key (Dlg_head * h, int d_key)
{
unsigned long command;
command = lookup_keymap_command (dialog_map, d_key);
if ((command == CK_Ignore_Key) || (dlg_execute_cmd (h, command) == MSG_NOT_HANDLED))
return MSG_NOT_HANDLED;
else
return MSG_HANDLED;
}
static cb_ret_t
@ -756,7 +767,7 @@ dlg_key_event (Dlg_head * h, int d_key)
handled = h->callback (h, NULL, DLG_UNHANDLED_KEY, d_key, NULL);
if (handled == MSG_NOT_HANDLED)
dialog_handle_key (h, d_key);
handled = dlg_handle_key (h, d_key);
h->callback (h, NULL, DLG_POST_KEY, d_key, NULL);
}
@ -849,9 +860,9 @@ dlg_process_event (Dlg_head * h, int key, Gpm_Event * event)
if (key == EV_NONE)
{
if (tty_got_interrupt ())
key = XCTRL ('g');
else
return;
dlg_execute_cmd (h, CK_DialogCancel);
return;
}
if (key == EV_MOUSE)

Просмотреть файл

@ -58,8 +58,6 @@
/*** global variables ****************************************************************************/
const global_keymap_t *diff_map;
/*** file scope macro definitions ****************************************************************/
#define g_array_foreach(a, TP, cbf) \

Просмотреть файл

@ -33,10 +33,7 @@
#include <stdio.h>
#include "lib/search.h" /* mc_search_type_t */
#include "src/dialog.h" /* cb_ret_t */
#include "src/keybind.h" /* global_keymap_t */
#include "src/editor/edit.h"
#define SEARCH_DIALOG_OPTION_NO_SCANF (1 << 0)
@ -318,9 +315,6 @@ extern edit_search_options_t edit_search_options;
extern int edit_stack_iterator;
extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
extern const global_keymap_t *editor_map;
extern const global_keymap_t *editor_x_map;
extern int option_line_state_width;
typedef enum

Просмотреть файл

@ -10,7 +10,6 @@
#include "lib/search.h" /* mc_search_t */
#include "edit-impl.h"
#include "src/keybind.h"
#define MAX_MACRO_LENGTH 1024
#define N_LINE_CACHES 32

Просмотреть файл

@ -57,6 +57,7 @@
#include "src/main.h" /* source_codepage */
#include "src/learn.h" /* learn_keys */
#include "src/cmddef.h"
#include "src/keybind.h"
#include "edit-impl.h"
#include "editlock.h"
@ -122,9 +123,6 @@ const char VERTICAL_MAGIC[] = { '\1', '\1', '\1', '\1', '\n' };
* fin.
*/
const global_keymap_t *editor_map;
const global_keymap_t *editor_x_map;
static void user_menu (WEdit * edit);
int

Просмотреть файл

@ -51,6 +51,7 @@
#include "src/widget.h" /* ButtonBar */
#include "src/menu.h" /* menubar_new() */
#include "src/cmddef.h"
#include "src/keybind.h"
int column_highlighting = 0;

Просмотреть файл

@ -67,8 +67,6 @@
#include "help.h"
#include "main.h"
const global_keymap_t *help_map;
#define MAXLINKNAME 80
#define HISTORY_SIZE 20
#define HELP_WINDOW_WIDTH min(80, COLS - 16)

Просмотреть файл

@ -44,6 +44,38 @@
#include "wtools.h"
#include "keybind.h"
#ifdef USE_INTERNAL_EDIT
GArray *editor_keymap = NULL;
GArray *editor_x_keymap = NULL;
const global_keymap_t *editor_map;
const global_keymap_t *editor_x_map;
#endif
GArray *main_keymap = NULL;
GArray *main_x_keymap = NULL;
GArray *viewer_keymap = NULL;
GArray *viewer_hex_keymap = NULL;
GArray *panel_keymap = NULL;
GArray *input_keymap = NULL;
GArray *tree_keymap = NULL;
GArray *help_keymap = NULL;
GArray *dialog_keymap = NULL;
#ifdef USE_DIFF_VIEW
GArray *diff_keymap = NULL;
const global_keymap_t *diff_map;
#endif
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 *tree_map;
const global_keymap_t *help_map;
const global_keymap_t *dialog_map;
static name_keymap_t command_names[] = {
#ifdef USE_INTERNAL_EDIT
{ "EditNoCommand", CK_Ignore_Key },
@ -447,6 +479,14 @@ static name_keymap_t command_names[] = {
{ "ShowCommandLine", CK_ShowCommandLine },
{ "SelectCodepage", CK_SelectCodepage },
/* dialog */
{ "DialogOK", CK_DialogOK },
{ "DialogCancel", CK_DialogCancel },
{ "DialogPrevItem", CK_DialogPrevItem },
{ "DialogNextItem", CK_DialogNextItem },
{ "DialogHelp", CK_DialogHelp },
{ "DialogSuspend", CK_DialogSuspend },
{ "DialogRefresh", CK_DialogRefresh },
/* diff viewer */
{ "DiffDisplaySymbols", CK_DiffDisplaySymbols},
@ -739,6 +779,23 @@ const global_keymap_t default_editor_x_keymap[] = {
};
#endif /* USE_INTERNAL_EDIT */
/* dialog */
const global_keymap_t default_dialog_keymap[] = {
{ '\n', CK_DialogOK, "Enter" },
{ KEY_ENTER, CK_DialogOK, "Enter" },
{ ESC_CHAR, CK_DialogCancel, "Esc" },
{ XCTRL('g'), CK_DialogCancel, "C-g" },
{ KEY_F (10), CK_DialogCancel, "F10" },
{ KEY_LEFT, CK_DialogPrevItem, "Left" },
{ KEY_UP, CK_DialogPrevItem, "Up" },
{ KEY_RIGHT, CK_DialogNextItem, "Right" },
{ KEY_DOWN, CK_DialogNextItem, "Down" },
{ KEY_F(1), CK_DialogHelp, "F1" },
{ XCTRL('z'), CK_DialogSuspend, "C-z" },
{ XCTRL('l'), CK_DialogRefresh, "C-l" },
{ 0, CK_Ignore_Key, "" }
};
/* tree */
const global_keymap_t default_tree_keymap[] = {
{ KEY_F (1), CK_TreeHelp, "F1"},

Просмотреть файл

@ -29,6 +29,38 @@ unsigned long lookup_action (const char *name);
const char *lookup_keymap_shortcut (const global_keymap_t *keymap, unsigned long action);
unsigned long lookup_keymap_command (const global_keymap_t *keymap, long key);
#ifdef USE_INTERNAL_EDIT
extern GArray *editor_keymap;
extern GArray *editor_x_keymap;
extern const global_keymap_t *editor_map;
extern const global_keymap_t *editor_x_map;
#endif
extern GArray *viewer_keymap;
extern GArray *viewer_hex_keymap;
extern GArray *main_keymap;
extern GArray *main_x_keymap;
extern GArray *panel_keymap;
extern GArray *input_keymap;
extern GArray *tree_keymap;
extern GArray *help_keymap;
extern GArray *dialog_keymap;
#ifdef USE_DIFF_VIEW
extern GArray *diff_keymap;
#endif
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 *tree_map;
extern const global_keymap_t *help_map;
extern const global_keymap_t *dialog_map;
#ifdef USE_DIFF_VIEW
extern const global_keymap_t *diff_map;
#endif
/* viewer/actions_cmd.c */
extern const global_keymap_t default_viewer_keymap[];
extern const global_keymap_t default_viewer_hex_keymap[];
@ -55,8 +87,11 @@ extern const global_keymap_t default_tree_keymap[];
/* help.c */
extern const global_keymap_t default_help_keymap[];
/* dialog.c */
extern const global_keymap_t default_dialog_keymap[];
#ifdef USE_DIFF_VIEW
/* yview.c */
/* ydiff.c */
extern const global_keymap_t default_diff_keymap[];
#endif

Просмотреть файл

@ -107,7 +107,7 @@
#ifdef HAVE_CHARSET
#include "charsets.h"
#endif
#endif /* HAVE_CHARSET */
#include "keybind.h" /* type global_keymap_t */
@ -300,24 +300,6 @@ mc_main_error_quark (void)
return g_quark_from_static_string (PACKAGE);
}
#ifdef USE_INTERNAL_EDIT
GArray *editor_keymap = NULL;
GArray *editor_x_keymap = NULL;
#endif
GArray *viewer_keymap = NULL;
GArray *viewer_hex_keymap = NULL;
GArray *main_keymap = NULL;
GArray *main_x_keymap = NULL;
GArray *panel_keymap = NULL;
GArray *input_keymap = NULL;
GArray *tree_keymap = NULL;
GArray *help_keymap = NULL;
#ifdef USE_DIFF_VIEW
GArray *diff_keymap = NULL;
#endif
const global_keymap_t *main_map;
const global_keymap_t *main_x_map;
/* Save current stat of directories to avoid reloading the panels */
/* when no modifications have taken place */
void
@ -1968,36 +1950,6 @@ do_nc (void)
/* start check display_codepage and source_codepage */
check_codeset ();
main_map = default_main_map;
if (main_keymap && main_keymap->len > 0)
main_map = (global_keymap_t *) main_keymap->data;
main_x_map = default_main_x_map;
if (main_x_keymap && main_x_keymap->len > 0)
main_x_map = (global_keymap_t *) main_x_keymap->data;
panel_map = default_panel_keymap;
if (panel_keymap && panel_keymap->len > 0)
panel_map = (global_keymap_t *) panel_keymap->data;
input_map = default_input_keymap;
if (input_keymap && input_keymap->len > 0)
input_map = (global_keymap_t *) input_keymap->data;
tree_map = default_tree_keymap;
if (tree_keymap && tree_keymap->len > 0)
tree_map = (global_keymap_t *) tree_keymap->data;
help_map = default_help_keymap;
if (help_keymap && help_keymap->len > 0)
help_map = (global_keymap_t *) help_keymap->data;
#ifdef USE_DIFF_VIEW
diff_map = default_diff_keymap;
if (diff_keymap && diff_keymap->len > 0)
diff_map = (global_keymap_t *) diff_keymap->data;
#endif
/* Check if we were invoked as an editor or file viewer */
if (mc_run_mode != MC_RUN_FULL)
mc_maybe_editor_or_viewer ();
@ -2325,6 +2277,11 @@ main (int argc, char *argv[])
load_setup ();
/* Removing this from the X code let's us type C-c */
load_key_defs ();
load_keymap_defs ();
tty_init_colors (mc_args__disable_colors, mc_args__force_colors);
isInitialized = mc_skin_init (&error);
@ -2356,11 +2313,6 @@ main (int argc, char *argv[])
#endif /* HAVE_SUBSHELL_SUPPORT */
/* Removing this from the X code let's us type C-c */
load_key_defs ();
load_keymap_defs ();
/* Also done after init_subshell, to save any shell init file messages */
if (console_flag)
handle_console (CONSOLE_SAVE);

Просмотреть файл

@ -109,31 +109,6 @@ extern int is_right; /* If the selected menu was the right */
#define MENU_PANEL_IDX (is_right ? 1 : 0)
#define SELECTED_IS_PANEL (get_display_type (is_right ? 1 : 0) == view_listing)
#ifdef USE_INTERNAL_EDIT
extern GArray *editor_keymap;
extern GArray *editor_x_keymap;
#endif
extern GArray *viewer_keymap;
extern GArray *viewer_hex_keymap;
extern GArray *main_keymap;
extern GArray *main_x_keymap;
extern GArray *panel_keymap;
extern GArray *input_keymap;
extern GArray *tree_keymap;
extern GArray *help_keymap;
#ifdef USE_DIFF_VIEW
extern GArray *diff_keymap;
#endif
extern const global_keymap_t *panel_map;
extern const global_keymap_t *input_map;
extern const global_keymap_t *tree_map;
extern const global_keymap_t *help_map;
#ifdef USE_DIFF_VIEW
extern const global_keymap_t *diff_map;
#endif
#ifdef HAVE_SUBSHELL_SUPPORT
void do_update_prompt (void);
int load_prompt (int fd, void *unused);

Просмотреть файл

@ -119,8 +119,6 @@ int filetype_mode = 1;
/* The hook list for the select file function */
Hook *select_file_hook = 0;
const global_keymap_t *panel_map;
static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
static int panel_event (Gpm_Event * event, void *);
static void paint_frame (WPanel * panel);

Просмотреть файл

@ -1082,12 +1082,44 @@ load_keymap_defs (void)
help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("help", help_keymap, mc_global_keymap);
dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("dialog", dialog_keymap, mc_global_keymap);
#ifdef USE_DIFF_VIEW
diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("diffviewer", diff_keymap, mc_global_keymap);
#endif
mc_config_deinit (mc_global_keymap);
}
main_map = default_main_map;
if (main_keymap && main_keymap->len > 0)
main_map = (global_keymap_t *) main_keymap->data;
main_x_map = default_main_x_map;
if (main_x_keymap && main_x_keymap->len > 0)
main_x_map = (global_keymap_t *) main_x_keymap->data;
panel_map = default_panel_keymap;
if (panel_keymap && panel_keymap->len > 0)
panel_map = (global_keymap_t *) panel_keymap->data;
input_map = default_input_keymap;
if (input_keymap && input_keymap->len > 0)
input_map = (global_keymap_t *) input_keymap->data;
tree_map = default_tree_keymap;
if (tree_keymap && tree_keymap->len > 0)
tree_map = (global_keymap_t *) tree_keymap->data;
help_map = default_help_keymap;
if (help_keymap && help_keymap->len > 0)
help_map = (global_keymap_t *) help_keymap->data;
dialog_map = default_dialog_keymap;
if (dialog_keymap && dialog_keymap->len > 0)
dialog_map = (global_keymap_t *) dialog_keymap->data;
}
void
@ -1115,6 +1147,8 @@ free_keymap_defs (void)
g_array_free (tree_keymap, TRUE);
if (help_keymap != NULL)
g_array_free (help_keymap, TRUE);
if (dialog_keymap != NULL)
g_array_free (dialog_keymap, TRUE);
#ifdef USE_DIFF_VIEW
if (diff_keymap != NULL)
g_array_free (diff_keymap, TRUE);

Просмотреть файл

@ -68,8 +68,6 @@
#include "tree.h"
#include "filegui.h"
const global_keymap_t *tree_map;
#define tlines(t) (t->is_panel ? t->widget.lines - 2 - (show_mini_info ? 2 : 0) : t->widget.lines)
/* Use the color of the parent widget for the unselected entries */

Просмотреть файл

@ -61,8 +61,6 @@
#include "panel.h" /* current_panel */
#include "main.h" /* confirm_history_cleanup */
const global_keymap_t *input_map;
static void
widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey)
{