From 823387a7937e3cfc570ae955a7f5cf445f71bae9 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Thu, 6 May 2010 19:19:02 +0000 Subject: [PATCH] Removed hardcoded hotkeys in dialog.c Replaced keymap's initialization from main.c into setup.c Signed-off-by: Ilia Maslakov Collect keybind-related variables in src/keybind.[ch] files. Signed-off-by: Andrew Borodin --- misc/mc.keymap.default | 9 +++++ misc/mc.keymap.emacs | 9 +++++ src/cmddef.h | 9 +++++ src/dialog.c | 85 +++++++++++++++++++++++++++--------------------- src/diffviewer/ydiff.c | 2 -- src/editor/edit-impl.h | 6 ---- src/editor/edit-widget.h | 1 - src/editor/edit.c | 4 +-- src/editor/editwidget.c | 1 + src/help.c | 2 -- src/keybind.c | 57 ++++++++++++++++++++++++++++++++ src/keybind.h | 37 ++++++++++++++++++++- src/main.c | 60 ++++------------------------------ src/main.h | 25 -------------- src/screen.c | 2 -- src/setup.c | 34 +++++++++++++++++++ src/tree.c | 2 -- src/widget.c | 2 -- 18 files changed, 210 insertions(+), 137 deletions(-) diff --git a/misc/mc.keymap.default b/misc/mc.keymap.default index 18dc9155d..0869d41f1 100644 --- a/misc/mc.keymap.default +++ b/misc/mc.keymap.default @@ -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 diff --git a/misc/mc.keymap.emacs b/misc/mc.keymap.emacs index 43f810ec9..2a7cb4ed3 100644 --- a/misc/mc.keymap.emacs +++ b/misc/mc.keymap.emacs @@ -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 diff --git a/src/cmddef.h b/src/cmddef.h index 2885e88d1..67abf24c3 100644 --- a/src/cmddef.h +++ b/src/cmddef.h @@ -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 diff --git a/src/dialog.c b/src/dialog.c index 313f7929a..96b687c3b 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -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,56 +611,65 @@ 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; - } +#ifdef HAVE_SLANG + tty_touch_screen (); + mc_refresh (); +#else + /* Use this if the refreshes fail */ + clr_scr (); + repaint_screen (); +#endif /* HAVE_SLANG */ +} - switch (d_key) +static cb_ret_t +dlg_execute_cmd (Dlg_head * h, unsigned long command) +{ + cb_ret_t ret = MSG_HANDLED; + switch (command) { - case '\n': - case KEY_ENTER: + case CK_DialogOK: h->ret_value = B_ENTER; dlg_stop (h); break; - - case KEY_LEFT: - case KEY_UP: + case CK_DialogCancel: + h->ret_value = B_CANCEL; + dlg_stop (h); + break; + case CK_DialogPrevItem: dlg_one_up (h); break; - - case KEY_RIGHT: - case KEY_DOWN: + case CK_DialogNextItem: dlg_one_down (h); break; - - case KEY_F (1): + case CK_DialogHelp: interactive_display (NULL, h->help_ctx); do_refresh (); break; - - case XCTRL ('z'): + case CK_DialogSuspend: suspend_cmd (); - /* Fall through */ - - case XCTRL ('l'): -#ifdef HAVE_SLANG - tty_touch_screen (); - mc_refresh (); -#else - /* Use this if the refreshes fail */ - clr_scr (); - repaint_screen (); -#endif /* HAVE_SLANG */ + refresh_cmd (); break; - - default: + 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) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 7874382da..2c50c07ee 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -58,8 +58,6 @@ /*** global variables ****************************************************************************/ -const global_keymap_t *diff_map; - /*** file scope macro definitions ****************************************************************/ #define g_array_foreach(a, TP, cbf) \ diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 72b570b62..1949f1fc7 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -33,10 +33,7 @@ #include #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 diff --git a/src/editor/edit-widget.h b/src/editor/edit-widget.h index 0e452374a..c51b15d2c 100644 --- a/src/editor/edit-widget.h +++ b/src/editor/edit-widget.h @@ -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 diff --git a/src/editor/edit.c b/src/editor/edit.c index d7fa462b8..7109d1a33 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -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 diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 0407ada0c..57aa2fda6 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -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; diff --git a/src/help.c b/src/help.c index df5fd1409..9cf025cc1 100644 --- a/src/help.c +++ b/src/help.c @@ -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) diff --git a/src/keybind.c b/src/keybind.c index 9e2895f23..c9a32fd6b 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -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"}, diff --git a/src/keybind.h b/src/keybind.h index 96991c6d6..6c599149c 100644 --- a/src/keybind.h +++ b/src/keybind.h @@ -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 diff --git a/src/main.c b/src/main.c index d09d3eadf..962e71f04 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/main.h b/src/main.h index 63aab2461..c33696549 100644 --- a/src/main.h +++ b/src/main.h @@ -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); diff --git a/src/screen.c b/src/screen.c index 22cc7127d..8237b5e6f 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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); diff --git a/src/setup.c b/src/setup.c index 556af5747..75f6cade3 100644 --- a/src/setup.c +++ b/src/setup.c @@ -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); diff --git a/src/tree.c b/src/tree.c index 7df35eacb..8dacd48ec 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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 */ diff --git a/src/widget.c b/src/widget.c index 0b6497330..10656e732 100644 --- a/src/widget.c +++ b/src/widget.c @@ -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) { -- 2.11.4.GIT