diff --git a/src/diffviewer/Makefile.am b/src/diffviewer/Makefile.am index ecb97da8d..1a95b7833 100644 --- a/src/diffviewer/Makefile.am +++ b/src/diffviewer/Makefile.am @@ -4,6 +4,7 @@ libdiffviewer_la_SOURCES = \ events.c \ execute.c execute.h \ internal.h \ + keymaps.c \ options.c options.h \ search.c \ tools.c \ diff --git a/src/diffviewer/events.c b/src/diffviewer/events.c index 5dcad7b33..16f65d549 100644 --- a/src/diffviewer/events.c +++ b/src/diffviewer/events.c @@ -529,7 +529,8 @@ mc_diffviewer_cmd_quit (event_info_t * event_info, gpointer data, GError ** erro (void) event_info; (void) error; - dview->view_quit = 1; + dview->view_quit = TRUE; + dlg_stop (WIDGET (data)->owner); return TRUE; } diff --git a/src/diffviewer/internal.h b/src/diffviewer/internal.h index f8dfd37c7..5784f938f 100644 --- a/src/diffviewer/internal.h +++ b/src/diffviewer/internal.h @@ -90,7 +90,7 @@ typedef struct WDiff int ndiff; /* number of hunks */ DSRC dsrc; /* data source: memory or temporary file */ - int view_quit:1; /* Quit flag */ + gboolean view_quit; /* Quit flag */ int height; int half1; @@ -140,6 +140,7 @@ typedef struct WDiff /*** declarations of public functions ************************************************************/ void mc_diffviewer_init_events (GError ** error); +void mc_diffviewer_init_keymaps (GError ** error); /* search.c */ gboolean mc_diffviewer_cmd_search (event_info_t * event_info, gpointer data, GError ** error); diff --git a/src/diffviewer/keymaps.c b/src/diffviewer/keymaps.c new file mode 100644 index 000000000..dadda7d93 --- /dev/null +++ b/src/diffviewer/keymaps.c @@ -0,0 +1,163 @@ +/* + Default values for keymapping engine + + Copyright (C) 2009-2014 + Free Software Foundation, Inc. + + Written by: + Vitja Makarov, 2005 + Ilia Maslakov , 2009, 2010 + Andrew Borodin , 2010, 2011 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include + +#include "lib/global.h" +#include "lib/widget.h" /* dialog_map, input_map, listbox_map */ +#include "lib/keymap.h" + +#include "src/keybind-defaults.h" +#include "internal.h" + +/*** global variables ****************************************************************************/ + +GArray *diff_keymap = NULL; + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/* default keymaps in ini (key=value) format */ + +/*** file scope variables ************************************************************************/ + +/* diff viewer */ +static const default_keymap_ini_t default_diff_keymap[] = { + {"ShowSymbols", "alt-s; s"}, + {"ShowNumbers", "alt-n; l"}, + {"SplitFull", "f"}, + {"SplitEqual", "equal"}, + {"SplitMore", "gt"}, + {"SplitLess", "lt"}, + {"Tab2", "2"}, + {"Tab3", "3"}, + {"Tab4", "4"}, + {"Tab8", "8"}, + {"Swap", "ctrl-u"}, + {"Redo", "ctrl-r"}, + {"HunkNext", "n; enter; space"}, + {"HunkPrev", "p; backspace"}, + {"Goto", "g; shift-g"}, + {"Save", "f2"}, + {"Edit", "f4"}, + {"EditOther", "f14"}, + {"Merge", "f5"}, + {"MergeOther", "f15"}, + {"Search", "f7"}, + {"SearchContinue", "f17"}, + {"Options", "f9"}, + {"Top", "ctrl-home"}, + {"Bottom", "ctrl-end"}, + {"Down", "down"}, + {"Up", "up"}, + {"LeftQuick", "ctrl-left"}, + {"RightQuick", "ctrl-right"}, + {"Left", "left"}, + {"Right", "right"}, + {"PageDown", "pgdn"}, + {"PageUp", "pgup"}, + {"Home", "home"}, + {"End", "end"}, + {"Quit", "f10; q; shift-q; esc"}, +#ifdef HAVE_CHARSET + {"SelectCodepage", "alt-e"}, +#endif + {"Shell", "ctrl-o"}, + {NULL, NULL} +}; + + +static const mc_keymap_event_init_group_t mc_keymap_event_diffview[] = { + {"ShowSymbols", MCEVENT_GROUP_DIFFVIEWER, "show_symbols"}, + {"ShowNumbers", MCEVENT_GROUP_DIFFVIEWER, "show_numbers"}, + {"SplitFull", MCEVENT_GROUP_DIFFVIEWER, "split_full"}, + {"SplitEqual", MCEVENT_GROUP_DIFFVIEWER, "split_equal"}, + {"SplitMore", MCEVENT_GROUP_DIFFVIEWER, "split_more"}, + {"SplitLess", MCEVENT_GROUP_DIFFVIEWER, "split_less"}, + {"Tab2", MCEVENT_GROUP_DIFFVIEWER, "tab_size_2"}, + {"Tab3", MCEVENT_GROUP_DIFFVIEWER, "tab_size_3"}, + {"Tab4", MCEVENT_GROUP_DIFFVIEWER, "tab_size_4"}, + {"Tab8", MCEVENT_GROUP_DIFFVIEWER, "tab_size_8"}, + {"Swap", MCEVENT_GROUP_DIFFVIEWER, "swap"}, + {"Redo", MCEVENT_GROUP_DIFFVIEWER, "redo"}, + {"HunkNext", MCEVENT_GROUP_DIFFVIEWER, "hunk_next"}, + {"HunkPrev", MCEVENT_GROUP_DIFFVIEWER, "hunk_prev"}, + {"Goto", MCEVENT_GROUP_DIFFVIEWER, "goto_line"}, + {"Save", MCEVENT_GROUP_DIFFVIEWER, "save_changes"}, + {"Edit", MCEVENT_GROUP_DIFFVIEWER, "edit_current"}, + {"EditOther", MCEVENT_GROUP_DIFFVIEWER, "edit_other"}, + {"Merge", MCEVENT_GROUP_DIFFVIEWER, "merge_from_left_to_right"}, + {"MergeOther", MCEVENT_GROUP_DIFFVIEWER, "merge_from_right_to_left"}, + {"Search", MCEVENT_GROUP_DIFFVIEWER, "search"}, + {"SearchContinue", MCEVENT_GROUP_DIFFVIEWER, "continue_search"}, + {"Options", MCEVENT_GROUP_DIFFVIEWER, "options_show_dialog"}, + {"Top", MCEVENT_GROUP_DIFFVIEWER, "goto_top"}, + {"Bottom", MCEVENT_GROUP_DIFFVIEWER, "goto_bottom"}, + {"Down", MCEVENT_GROUP_DIFFVIEWER, "goto_down"}, + {"Up", MCEVENT_GROUP_DIFFVIEWER, "goto_up"}, + {"LeftQuick", MCEVENT_GROUP_DIFFVIEWER, "goto_left_quick"}, + {"RightQuick", MCEVENT_GROUP_DIFFVIEWER, "goto_right_quick"}, + {"Left", MCEVENT_GROUP_DIFFVIEWER, "goto_left"}, + {"Right", MCEVENT_GROUP_DIFFVIEWER, "goto_right"}, + {"PageDown", MCEVENT_GROUP_DIFFVIEWER, "goto_page_down"}, + {"PageUp", MCEVENT_GROUP_DIFFVIEWER, "goto_page_up"}, + {"Home", MCEVENT_GROUP_DIFFVIEWER, "goto_start_of_line"}, + {"Quit", MCEVENT_GROUP_DIFFVIEWER, "quit"}, +#ifdef HAVE_CHARSET + {"SelectCodepage", MCEVENT_GROUP_DIFFVIEWER, "select_encoding_show_dialog"}, +#endif + {"Shell", MCEVENT_GROUP_FILEMANAGER, "view_other"}, + {NULL, NULL, NULL} +}; + + +static const mc_keymap_event_init_t mc_keymap_event_defaults[] = { + {KEYMAP_SECTION_DIFFVIEWER, mc_keymap_event_diffview}, + {NULL, NULL} +}; + + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +void +mc_diffviewer_init_keymaps (GError ** error) +{ + mc_core_keybind_mass_init (KEYMAP_SECTION_DIFFVIEWER, default_diff_keymap, FALSE, error); + mc_keymap_mass_bind_event (mc_keymap_event_defaults, error); +} diff --git a/src/diffviewer/tools.c b/src/diffviewer/tools.c index abab30849..ad7cd150c 100644 --- a/src/diffviewer/tools.c +++ b/src/diffviewer/tools.c @@ -1585,6 +1585,9 @@ mc_diffviewer_update (WDiff * dview) int width2; int last; + if (dview->view_quit) + return; + last = dview->a[DIFF_LEFT]->len - 1; if (dview->skip_rows > last) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index ba43e61d8..8a6f23eb2 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -44,6 +44,7 @@ #include "lib/charsets.h" #endif #include "lib/event.h" /* mc_event_raise() */ +#include "lib/keymap.h" #include "src/filemanager/cmd.h" /* edit_file_at_line(), view_other_cmd() */ #include "src/filemanager/panel.h" @@ -149,7 +150,7 @@ dview_init (WDiff * dview, const char *args, const char *file1, const char *file dview->ndiff = ndiff; - dview->view_quit = 0; + dview->view_quit = FALSE; dview->bias = 0; dview->new_frame = 1; @@ -192,13 +193,13 @@ dview_labels (WDiff * dview) h = d->owner; b = find_buttonbar (h); - buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, d); - buttonbar_set_label (b, 2, Q_ ("ButtonBar|Save"), diff_map, d); - buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), diff_map, d); - buttonbar_set_label (b, 5, Q_ ("ButtonBar|Merge"), diff_map, d); - buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), diff_map, d); - buttonbar_set_label (b, 9, Q_ ("ButtonBar|Options"), diff_map, d); - buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), diff_map, d); + buttonbar_init_button (b, 1, Q_ ("ButtonBar|Help"), KEYMAP_SECTION_DIFFVIEWER, d); + buttonbar_init_button (b, 2, Q_ ("ButtonBar|Save"), KEYMAP_SECTION_DIFFVIEWER, d); + buttonbar_init_button (b, 4, Q_ ("ButtonBar|Edit"), KEYMAP_SECTION_DIFFVIEWER, d); + buttonbar_init_button (b, 5, Q_ ("ButtonBar|Merge"), KEYMAP_SECTION_DIFFVIEWER, d); + buttonbar_init_button (b, 7, Q_ ("ButtonBar|Search"), KEYMAP_SECTION_DIFFVIEWER, d); + buttonbar_init_button (b, 9, Q_ ("ButtonBar|Options"), KEYMAP_SECTION_DIFFVIEWER, d); + buttonbar_init_button (b, 10, Q_ ("ButtonBar|Quit"), KEYMAP_SECTION_DIFFVIEWER, d); } /* --------------------------------------------------------------------------------------------- */ @@ -279,160 +280,26 @@ dview_ok_to_exit (WDiff * dview) } /* --------------------------------------------------------------------------------------------- */ - -static cb_ret_t -dview_execute_cmd (WDiff * dview, unsigned long command) -{ - cb_ret_t res = MSG_NOT_HANDLED; - const char *event_name = NULL; - const char *event_group_name = MCEVENT_GROUP_DIFFVIEWER; - - switch (command) - { - case CK_ShowSymbols: - event_name = "show_symbols"; - break; - case CK_ShowNumbers: - event_name = "show_numbers"; - break; - case CK_SplitFull: - event_name = "split_full"; - break; - case CK_SplitEqual: - event_name = "split_equal"; - break; - case CK_SplitMore: - event_name = "split_more"; - break; - case CK_SplitLess: - event_name = "split_less"; - break; - case CK_Tab2: - event_name = "tab_size_2"; - break; - case CK_Tab3: - event_name = "tab_size_3"; - break; - case CK_Tab4: - event_name = "tab_size_4"; - break; - case CK_Tab8: - event_name = "tab_size_8"; - break; - case CK_Swap: - event_name = "swap"; - break; - case CK_Redo: - event_name = "redo"; - break; - case CK_HunkNext: - event_name = "hunk_next"; - break; - case CK_HunkPrev: - event_name = "hunk_prev"; - break; - case CK_Goto: - event_name = "goto_line"; - break; - case CK_Edit: - event_name = "edit_current"; - break; - case CK_Merge: - event_name = "merge_from_left_to_right"; - break; - case CK_MergeOther: - event_name = "merge_from_right_to_left"; - break; - case CK_EditOther: - event_name = "edit_other"; - break; - case CK_Search: - event_name = "search"; - break; - case CK_SearchContinue: - event_name = "continue_search"; - break; - case CK_Top: - event_name = "goto_top"; - break; - case CK_Bottom: - event_name = "goto_bottom"; - break; - case CK_Up: - event_name = "goto_up"; - break; - case CK_Down: - event_name = "goto_down"; - break; - case CK_PageDown: - event_name = "goto_page_down"; - break; - case CK_PageUp: - event_name = "goto_page_up"; - break; - case CK_Left: - event_name = "goto_left"; - break; - case CK_Right: - event_name = "goto_right"; - break; - case CK_LeftQuick: - event_name = "goto_left_quick"; - break; - case CK_RightQuick: - event_name = "goto_right_quick"; - break; - case CK_Home: - event_name = "goto_start_of_line"; - break; - case CK_Shell: - event_group_name = MCEVENT_GROUP_FILEMANAGER; - event_name = "view_other"; - res = MSG_HANDLED; - break; - case CK_Quit: - event_name = "quit"; - break; - case CK_Save: - event_name = "save_changes"; - break; - case CK_Options: - event_name = "options_show_dialog"; - break; -#ifdef HAVE_CHARSET - case CK_SelectCodepage: - event_name = "select_encoding_show_dialog"; - break; -#endif - case CK_Cancel: - /* don't close diffviewer due to SIGINT */ - break; - default:; - } - - if (event_name != NULL && mc_event_raise (event_group_name, event_name, dview, NULL, NULL)) - res = MSG_HANDLED; - - return res; -} - /* --------------------------------------------------------------------------------------------- */ static cb_ret_t -dview_handle_key (WDiff * dview, int key) +dview_handle_key (WDiff * dview, int key, GError ** error) { - unsigned long command; + cb_ret_t ret_value = MSG_NOT_HANDLED; + event_return_t ret; #ifdef HAVE_CHARSET key = convert_from_input_c (key); #endif - command = keybind_lookup_keymap_command (diff_map, key); - if ((command != CK_IgnoreKey) && (dview_execute_cmd (dview, command) == MSG_HANDLED)) - return MSG_HANDLED; + ret.b = TRUE; - /* Key not used */ - return MSG_NOT_HANDLED; + if (mc_keymap_process_group (KEYMAP_SECTION_DIFFVIEWER, key, (void *) dview, &ret, error)) + ret_value = (ret.b) ? MSG_HANDLED : MSG_NOT_HANDLED; + + mc_diffviewer_update (dview); + + return ret_value; } /* --------------------------------------------------------------------------------------------- */ @@ -441,8 +308,6 @@ static cb_ret_t dview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WDiff *dview = (WDiff *) w; - WDialog *h = w->owner; - cb_ret_t i; switch (msg) { @@ -458,20 +323,7 @@ dview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d return MSG_HANDLED; case MSG_KEY: - i = dview_handle_key (dview, parm); - if (dview->view_quit) - dlg_stop (h); - else - mc_diffviewer_update (dview); - return i; - - case MSG_ACTION: - i = dview_execute_cmd (dview, parm); - if (dview->view_quit) - dlg_stop (h); - else - mc_diffviewer_update (dview); - return i; + return dview_handle_key (dview, parm, NULL); case MSG_DESTROY: mc_event_raise (MCEVENT_GROUP_DIFFVIEWER, "options_save", dview, NULL, NULL); @@ -514,21 +366,6 @@ dview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, dview_adjust_size (h); return MSG_HANDLED; - case MSG_ACTION: - /* shortcut */ - if (sender == NULL) - return dview_execute_cmd (NULL, parm); - /* message from buttonbar */ - if (sender == WIDGET (find_buttonbar (h))) - { - if (data != NULL) - return send_message (data, NULL, MSG_ACTION, parm, NULL); - - dview = (WDiff *) find_widget_type (h, dview_callback); - return dview_execute_cmd (dview, parm); - } - return MSG_NOT_HANDLED; - case MSG_VALIDATE: dview = (WDiff *) find_widget_type (h, dview_callback); h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ @@ -696,6 +533,7 @@ void mc_diffviewer_init (GError ** error) { mc_diffviewer_init_events (error); + mc_diffviewer_init_keymaps (error); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c index 34cb8da0f..af5b4037e 100644 --- a/src/keybind-defaults.c +++ b/src/keybind-defaults.c @@ -29,9 +29,11 @@ #include "lib/global.h" #include "lib/widget.h" /* dialog_map, input_map, listbox_map */ +#include "lib/keymap.h" #include "keybind-defaults.h" + /*** global variables ****************************************************************************/ GArray *main_keymap = NULL; @@ -48,9 +50,6 @@ GArray *editor_x_keymap = NULL; #endif GArray *viewer_keymap = NULL; GArray *viewer_hex_keymap = NULL; -#ifdef USE_DIFF_VIEW -GArray *diff_keymap = NULL; -#endif const global_keymap_t *main_map = NULL; const global_keymap_t *main_x_map = NULL; @@ -64,25 +63,17 @@ const global_keymap_t *editor_x_map = NULL; #endif const global_keymap_t *viewer_map = NULL; const global_keymap_t *viewer_hex_map = NULL; -#ifdef USE_DIFF_VIEW -const global_keymap_t *diff_map = NULL; -#endif /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ /* default keymaps in ini (key=value) format */ -typedef struct global_keymap_ini_t -{ - const char *key; - const char *value; -} global_keymap_ini_t; /*** file scope variables ************************************************************************/ /* midnight */ -static const global_keymap_ini_t default_main_keymap[] = { +static const default_keymap_ini_t default_main_keymap[] = { {"Help", "f1"}, {"UserMenu", "f2"}, {"View", "f3"}, @@ -133,7 +124,7 @@ static const global_keymap_ini_t default_main_keymap[] = { {NULL, NULL} }; -static const global_keymap_ini_t default_main_x_keymap[] = { +static const default_keymap_ini_t default_main_x_keymap[] = { {"CompareDirs", "d"}, #ifdef USE_DIFF_VIEW {"CompareFiles", "ctrl-d"}, @@ -164,7 +155,7 @@ static const global_keymap_ini_t default_main_x_keymap[] = { }; /* panel */ -static const global_keymap_ini_t default_panel_keymap[] = { +static const default_keymap_ini_t default_panel_keymap[] = { {"PanelOtherCd", "alt-o"}, {"PanelOtherCdLink", "alt-l"}, {"CopySingle", "f15"}, @@ -204,7 +195,7 @@ static const global_keymap_ini_t default_panel_keymap[] = { }; /* dialog */ -static const global_keymap_ini_t default_dialog_keymap[] = { +static const default_keymap_ini_t default_dialog_keymap[] = { {"Ok", "enter"}, {"Cancel", "f10; esc; ctrl-g"}, {"Up", "up; left"}, @@ -223,7 +214,7 @@ static const global_keymap_ini_t default_dialog_keymap[] = { }; /* input line */ -static const global_keymap_ini_t default_input_keymap[] = { +static const default_keymap_ini_t default_input_keymap[] = { /* Motion */ {"Home", "ctrl-a; alt-lt; home; a1"}, {"End", "ctrl-e; alt-gt; end; c1"}, @@ -258,7 +249,7 @@ static const global_keymap_ini_t default_input_keymap[] = { }; /* listbox */ -static const global_keymap_ini_t default_listbox_keymap[] = { +static const default_keymap_ini_t default_listbox_keymap[] = { {"Up", "up; ctrl-p"}, {"Down", "down; ctrl-n"}, {"Top", "home; alt-lt; a1"}, @@ -271,7 +262,7 @@ static const global_keymap_ini_t default_listbox_keymap[] = { }; /* tree */ -static const global_keymap_ini_t default_tree_keymap[] = { +static const default_keymap_ini_t default_tree_keymap[] = { {"Help = f1"}, {"Rescan = f2; ctrl-r"}, {"Forget = f3"}, @@ -296,7 +287,7 @@ static const global_keymap_ini_t default_tree_keymap[] = { }; /* help */ -static const global_keymap_ini_t default_help_keymap[] = { +static const default_keymap_ini_t default_help_keymap[] = { {"Help", "f1"}, {"Index", "f2; c"}, {"Back", "f3; left; l"}, @@ -318,7 +309,7 @@ static const global_keymap_ini_t default_help_keymap[] = { }; #ifdef USE_INTERNAL_EDIT -static const global_keymap_ini_t default_editor_keymap[] = { +static const default_keymap_ini_t default_editor_keymap[] = { {"Enter", "enter"}, {"Return", "shift-enter; ctrl-enter; ctrl-shift-enter"}, /* useful for pasting multiline text */ {"Tab", "tab; shift-tab; ctrl-tab; ctrl-shift-tab"}, /* ditto */ @@ -423,13 +414,13 @@ static const global_keymap_ini_t default_editor_keymap[] = { }; /* emacs keyboard layout emulation */ -static const global_keymap_ini_t default_editor_x_keymap[] = { +static const default_keymap_ini_t default_editor_x_keymap[] = { {NULL, NULL} }; #endif /* USE_INTERNAL_EDIT */ /* viewer */ -static const global_keymap_ini_t default_viewer_keymap[] = { +static const default_keymap_ini_t default_viewer_keymap[] = { {"Help", "f1"}, {"WrapMode", "f2"}, {"Quit", "f3; f10; q; esc"}, @@ -470,7 +461,7 @@ static const global_keymap_ini_t default_viewer_keymap[] = { }; /* hex viewer */ -static const global_keymap_ini_t default_viewer_hex_keymap[] = { +static const default_keymap_ini_t default_viewer_hex_keymap[] = { {"Help", "f1"}, {"HexEditMode", "f2"}, {"Quit", "f3; f10; q; esc"}, @@ -503,53 +494,10 @@ static const global_keymap_ini_t default_viewer_hex_keymap[] = { {NULL, NULL} }; -#ifdef USE_DIFF_VIEW -/* diff viewer */ -static const global_keymap_ini_t default_diff_keymap[] = { - {"ShowSymbols", "alt-s; s"}, - {"ShowNumbers", "alt-n; l"}, - {"SplitFull", "f"}, - {"SplitEqual", "equal"}, - {"SplitMore", "gt"}, - {"SplitLess", "lt"}, - {"Tab2", "2"}, - {"Tab3", "3"}, - {"Tab4", "4"}, - {"Tab8", "8"}, - {"Swap", "ctrl-u"}, - {"Redo", "ctrl-r"}, - {"HunkNext", "n; enter; space"}, - {"HunkPrev", "p; backspace"}, - {"Goto", "g; shift-g"}, - {"Save", "f2"}, - {"Edit", "f4"}, - {"EditOther", "f14"}, - {"Merge", "f5"}, - {"MergeOther", "f15"}, - {"Search", "f7"}, - {"SearchContinue", "f17"}, - {"Options", "f9"}, - {"Top", "ctrl-home"}, - {"Bottom", "ctrl-end"}, - {"Down", "down"}, - {"Up", "up"}, - {"LeftQuick", "ctrl-left"}, - {"RightQuick", "ctrl-right"}, - {"Left", "left"}, - {"Right", "right"}, - {"PageDown", "pgdn"}, - {"PageUp", "pgup"}, - {"Home", "home"}, - {"End", "end"}, - {"Help", "f1"}, - {"Quit", "f10; q; shift-q; esc"}, -#ifdef HAVE_CHARSET - {"SelectCodepage", "alt-e"}, -#endif - {"Shell", "ctrl-o"}, +static const mc_keymap_event_init_t mc_keymap_event_defaults[] = { {NULL, NULL} }; -#endif + /*** file scope macro definitions ****************************************************************/ @@ -562,7 +510,7 @@ static const global_keymap_ini_t default_diff_keymap[] = { static void create_default_keymap_section (mc_config_t * keymap, const char *section, - const global_keymap_ini_t * k) + const default_keymap_ini_t * k) { size_t i; @@ -574,8 +522,20 @@ create_default_keymap_section (mc_config_t * keymap, const char *section, /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ +void +mc_core_keybind_mass_init (const char *keymap_group, const default_keymap_ini_t * k, + gboolean isDeleteOld, GError ** error) +{ + size_t i; + + for (i = 0; k[i].key != NULL; i++) + mc_keymap_bind_keycode (keymap_group, k[i].key, k[i].value, isDeleteOld, error); +} + +/* --------------------------------------------------------------------------------------------- */ + mc_config_t * -create_default_keymap (void) +create_default_keymap (GError ** error) { mc_config_t *keymap; @@ -595,9 +555,10 @@ create_default_keymap (void) #endif create_default_keymap_section (keymap, KEYMAP_SECTION_VIEWER, default_viewer_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_VIEWER_HEX, default_viewer_hex_keymap); -#ifdef USE_DIFF_VIEW - create_default_keymap_section (keymap, KEYMAP_SECTION_DIFFVIEWER, default_diff_keymap); -#endif + + mc_keymap_mass_bind_event (mc_keymap_event_defaults, error); return keymap; } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/keybind-defaults.h b/src/keybind-defaults.h index 7b569c67e..5951100b5 100644 --- a/src/keybind-defaults.h +++ b/src/keybind-defaults.h @@ -11,6 +11,12 @@ /*** structures declarations (and typedefs of structures)*****************************************/ +typedef struct global_keymap_ini_t +{ + const char *key; + const char *value; +} default_keymap_ini_t; + /*** global variables defined in .c file *********************************************************/ extern GArray *main_keymap; @@ -27,9 +33,6 @@ extern GArray *editor_x_keymap; #endif extern GArray *viewer_keymap; extern GArray *viewer_hex_keymap; -#ifdef USE_DIFF_VIEW -extern GArray *diff_keymap; -#endif extern const global_keymap_t *main_map; @@ -44,13 +47,12 @@ extern const global_keymap_t *editor_x_map; #endif extern const global_keymap_t *viewer_map; extern const global_keymap_t *viewer_hex_map; -#ifdef USE_DIFF_VIEW -extern const global_keymap_t *diff_map; -#endif /*** declarations of public functions ************************************************************/ -mc_config_t *create_default_keymap (void); +mc_config_t *create_default_keymap (GError ** error); +void mc_core_keybind_mass_init (const char *keymap_group, const default_keymap_ini_t * k, + gboolean isDeleteOld, GError ** error); /*** inline functions ****************************************************************************/ diff --git a/src/main.c b/src/main.c index de54c36b8..7e711ceb5 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,7 @@ #include "lib/global.h" #include "lib/event.h" +#include "lib/keymap.h" #include "lib/tty/tty.h" #include "lib/tty/key.h" /* For init_key() */ #include "lib/tty/mouse.h" /* init_mouse() */ @@ -291,6 +292,12 @@ main (int argc, char *argv[]) goto startup_exit_falure; } + if (!mc_keymap_init (&mcerror)) + { + mc_event_deinit (NULL); + goto startup_exit_falure; + } + vfs_init (); vfs_plugins_init (); @@ -366,7 +373,7 @@ main (int argc, char *argv[]) /* Removing this from the X code let's us type C-c */ load_key_defs (); - load_keymap_defs (!mc_args__nokeymap); + load_keymap_defs (!mc_args__nokeymap, &mcerror); macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t)); @@ -434,6 +441,7 @@ main (int argc, char *argv[]) tty_shutdown (); done_setup (); + mc_keymap_deinit (&mcerror); if (mc_global.tty.console_flag != '\0' && (quit & SUBSHELL_EXIT) == 0) handle_console (CONSOLE_RESTORE); diff --git a/src/setup.c b/src/setup.c index 88ad6f6d1..98e23ba58 100644 --- a/src/setup.c +++ b/src/setup.c @@ -33,6 +33,7 @@ #include #include "lib/global.h" +#include "lib/keymap.h" #include "lib/tty/tty.h" #include "lib/tty/key.h" @@ -721,7 +722,7 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) char *fname, *fname2; /* 0) Create default keymap */ - keymap_config = create_default_keymap (); + keymap_config = create_default_keymap (NULL); if (!load_from_file) return keymap_config; @@ -1234,7 +1235,7 @@ load_anon_passwd (void) /* --------------------------------------------------------------------------------------------- */ void -load_keymap_defs (gboolean load_from_file) +load_keymap_defs (gboolean load_from_file, GError ** error) { /* * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user @@ -1246,6 +1247,30 @@ load_keymap_defs (gboolean load_from_file) if (mc_global_keymap != NULL) { + char **keymap_sections, **section_name; + + keymap_sections = mc_config_get_groups (mc_global_keymap, NULL); + + for (section_name = keymap_sections; *section_name != NULL; section_name++) + { + char **keymap_names, **param_name; + + keymap_names = mc_config_get_keys (mc_global_keymap, *section_name, NULL); + for (param_name = keymap_names; *param_name != NULL; param_name++) + { + char *value; + + value = + mc_config_get_string_raw (mc_global_keymap, *section_name, *param_name, NULL); + + if (value != NULL) + mc_keymap_bind_keycode (*section_name, *param_name, value, TRUE, error); + } + g_strfreev (keymap_names); + } + g_strfreev (keymap_sections); + + main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap); main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); @@ -1281,11 +1306,6 @@ load_keymap_defs (gboolean load_from_file) viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap); -#ifdef USE_DIFF_VIEW - diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); - load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap); -#endif - mc_config_deinit (mc_global_keymap); } @@ -1303,9 +1323,6 @@ load_keymap_defs (gboolean load_from_file) #endif viewer_map = (global_keymap_t *) viewer_keymap->data; viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data; -#ifdef USE_DIFF_VIEW - diff_map = (global_keymap_t *) diff_keymap->data; -#endif } /* --------------------------------------------------------------------------------------------- */ @@ -1339,10 +1356,6 @@ free_keymap_defs (void) g_array_free (viewer_keymap, TRUE); if (viewer_hex_keymap != NULL) g_array_free (viewer_hex_keymap, TRUE); -#ifdef USE_DIFF_VIEW - if (diff_keymap != NULL) - g_array_free (diff_keymap, TRUE); -#endif } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/setup.h b/src/setup.h index ea4cbff85..c6f0a5347 100644 --- a/src/setup.h +++ b/src/setup.h @@ -150,7 +150,7 @@ void load_key_defs (void); char *load_anon_passwd (void); #endif /* ENABLE_VFS_FTP */ -void load_keymap_defs (gboolean load_from_file); +void load_keymap_defs (gboolean load_from_file, GError ** error); void free_keymap_defs (void); void panel_load_setup (WPanel * panel, const char *section);