From 62f3c368c9de227b5c80ea9ed572e4a5fc35b3ec Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 18 Nov 2010 10:43:23 +0200 Subject: [PATCH] Renamed keybind-related functions: * lookup_action -> keybind_lookup_action * lookup_keymap_shortcut -> keybind_lookup_keymap_shortcut * lookup_keymap_command -> keybind_lookup_keymap_command Signed-off-by: Slava Zanko --- lib/keybind/TODO.txt | 151 +++++++++++++++++++++++++++++ lib/keybind/keybind.c | 0 lib/keybind/keybind.h | 0 lib/keybind/keymap.c | 2 + lib/keybind/keymap.h | 0 lib/keybind/readme.txt | 16 ++++ lib/vfs/mc-vfs/fish/README.fish~HEAD | 178 +++++++++++++++++++++++++++++++++++ lib/widget/buttonbar.c | 2 +- lib/widget/dialog.c | 2 +- lib/widget/input.c | 4 +- lib/widget/listbox.c | 2 +- src/diffviewer/ydiff.c | 2 +- src/editor/editkeys.c | 6 +- src/editor/editwidget.c | 6 +- src/help.c | 2 +- src/keybind.c | 6 +- src/keybind.h | 6 +- src/main.c | 14 +-- src/setup.c | 4 +- src/viewer/actions_cmd.c | 4 +- 20 files changed, 377 insertions(+), 30 deletions(-) create mode 100644 lib/keybind/TODO.txt create mode 100644 lib/keybind/keybind.c create mode 100644 lib/keybind/keybind.h create mode 100644 lib/keybind/keymap.c create mode 100644 lib/keybind/keymap.h create mode 100644 lib/keybind/readme.txt create mode 100644 lib/vfs/mc-vfs/fish/README.fish~HEAD diff --git a/lib/keybind/TODO.txt b/lib/keybind/TODO.txt new file mode 100644 index 000000000..3e064ab10 --- /dev/null +++ b/lib/keybind/TODO.txt @@ -0,0 +1,151 @@ +/* + +== кеймапы работают как: == + +клавиша - название + +название вполне может быть Event! + + +mc.hotkeys + +[Группа] + действие=клавиша + + +Это должно быть преобразовано в Event как: + mcevent_add_cb ("Группа.действие", ...) + +при этом спец. группа 'mc.*'(и дочерние) должны быть проигнорированы в файле привязок + +главная группа [core] + +Инициализируется по дефолту. остальные группы описывают дополнительные назначения клавиш. + +Спец.случаи. Панель и командная строка. +[panel] + - тут кейбиндинги панели. +[panel-commandline] + - тут кейбиндинги комстроки. + +признак того, что необходимо включить или выключить "panel-commandline.*" - не пустая или пустая комстрока. +При непустой комстроке делаем просто mckeybind_push ("panel-commandline"), а как только строка очищается - +делаем mckeybind_pop(); + +То есть. выглядит всё так: +mckeybind_init("core"); // инициализируем некие базовые(одинаковые для всех) хоткеи. + +switch (args) + { + case 'editor': + mckeybind_push("editor"); + case 'viewer' + mckeybind_push("viewer"); + default: + mckeybind_push("panel"); + } + ... + if (cmd_active()) + mckeybind_push("panel-commandline"); + + ... + if (cmd_inactive()) + mckeybind_pop(); + + +== КЕЙБИНДИНГИ ПО УМОЛЧАНИЮ == +Должны содержать минимально необходимый для работы минимум. Если действие доступно через меню, +hardcoded-кейбиндинга быть не должно. + +=== как инициальзировать === +Ну... mckeybind_push("editor", g_hash_array *default(or NULL)) ? + + +== Хранение в памяти == +храним в памяти в виде "хоткей" -> "event". Чтобы после чтения с клавы был быстрый доступ к mcevent_raise('action') + +== Дубликаты хоткеев == +наверное, надо предупреждать. что в конфиге есть конфликт... +[group] +action1 = ctrl-v +action2 = ctrl-v + +в момент... гм. наверное. в момент mckeybind_push +ибо конфиг читаем целиком, но весь сразу не парсим... + +== "Многоэтажные" хоткеи == + +=== Дубликаты: === +action1 = ctrl-v +action2 = ctrl-v, w +Это ошибка. Выдать алерт. + +=== Нормальная обработка === +action1 = ctrl-v, q +action2 = ctrl-v, w +action3 = ctrl-v, e, 1 +action4 = ctrl-v, e, 2 + + +варианты использования. +mckeybind_push() должна добавить новые хоткеи к уже существующим (заменить существующие привязки клавиш). +mckeybind_pop() должна воостановить на предыдущее значение! + +При этом должна быть возможность как бы временно "скрыть" существующие привязки. Для многоэтажных хоткеев. + + +//При парсинге видим многоэтажный хоткей и сразу создаём Event вида "mc.hotkey.". +// где - это - или просто . +//mc_event_add_cb ("mc.hotkey.ctrl-v", ); +нет. Надо предусмотреть временное замещение всех действующих хоткеев на только хоткеи "второго эшелона". +то есть, из примера надо после нажатия ctrl-v задейтвовать: +{ + q -> action1 + w -> action2 + e -> !!!!!!! (ещё раз очищаем хоткеи и ждём 1 или 2 !!!) +} +После всего этого возвращаемся в обычный режим работы. + +делаем это созданием псевдогруппы привязок вида "mc.hotkey.". +где - это - или просто . +затем привязываем "ctrl-v" к спецкейбиндингу: + +ctrl-v -> "mc.hotkey.processMulti('ctrl-v')" + +привязывать к именам хоткеев нужно структуру вида: +{ + char *action; + char *param; /* для всех равен NULL, для многоэтажных равен названию группы хоткеев второго эшелона*/ +} + +при вызове этого Event начинаем искать группу хоткеев "mc.hotkey.ctrl-v" +находим и заменяем активные привязки на таблицу: + +{ + q -> action1 + w -> action2 + e -> mc.hotkey.processMulti('ctrl-v,e') +} + +NB: При парсинге файла привязок если встречаем мультихоткей, то ищем в списке групп - есть уже или нету. +"ctrl-v, e, 1" = ищем по группе "mc.hotkey.ctrl-v,e" +нашли - гуд. Добавляем. + + +== Порядок обработки файлов привязок == +традиционно: + 1) комстрока + 2) переменная окружения + 3) конфиг в дом.каталоге + 4) конфиг в /etc/mc + +*/ + + + + +init +deinit + +push +pop \ No newline at end of file diff --git a/lib/keybind/keybind.c b/lib/keybind/keybind.c new file mode 100644 index 000000000..e69de29bb diff --git a/lib/keybind/keybind.h b/lib/keybind/keybind.h new file mode 100644 index 000000000..e69de29bb diff --git a/lib/keybind/keymap.c b/lib/keybind/keymap.c new file mode 100644 index 000000000..139597f9c --- /dev/null +++ b/lib/keybind/keymap.c @@ -0,0 +1,2 @@ + + diff --git a/lib/keybind/keymap.h b/lib/keybind/keymap.h new file mode 100644 index 000000000..e69de29bb diff --git a/lib/keybind/readme.txt b/lib/keybind/readme.txt new file mode 100644 index 000000000..2375f8fd6 --- /dev/null +++ b/lib/keybind/readme.txt @@ -0,0 +1,16 @@ += Обработка хоткеев = + +Используются "карты хоткеев" (keybindings), которые содержат множество пар "хоткей - событие". +В зависимости от того, какой элемент интерфейса сейчас активирован. карты хоткеев могут дополняться или замещаться. +Должна быть возможность отмены текущей карты хоткеев и возврата на предыдущую карту. Это реализовывается стековой +моделью. + +Замещение карты хоткеев происходит при: + * работе модального диалога. Хоткеи основного интерфейса должны быть "спрятаны"; + * + +Дополнение происходит при: + * назначении клавиш быстрого доступа к опциям. В таком случае основная карта хоткеев дополняется хоткеями из + меток (labels) диалогов; + * + diff --git a/lib/vfs/mc-vfs/fish/README.fish~HEAD b/lib/vfs/mc-vfs/fish/README.fish~HEAD new file mode 100644 index 000000000..10b07770f --- /dev/null +++ b/lib/vfs/mc-vfs/fish/README.fish~HEAD @@ -0,0 +1,178 @@ + + FIles transferred over SHell protocol (V 0.0.2) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This protocol was designed for transferring files over a remote shell +connection (rsh and compatibles). It can be as well used for transfers over +rsh, and there may be other uses. + +Client sends requests of following form: + +#FISH_COMMAND +equivalent shell commands, +which may be multiline + +Only fish commands are defined here, shell equivalents are for your +information only and will probably vary from implementation to +implementation. Fish commands always have priority: server is +expected to execute fish command if it understands it. If it does not, +however, it can try the luck and execute shell command. + +Server's reply is multiline, but always ends with + +### 000 + +line. ### is prefix to mark this line, 000 is return code. Return +codes are superset to those used in ftp. + +There are few new exit codes defined: + +000 don't know; if there were no previous lines, this marks COMPLETE +success, if they were, it marks failure. + +001 don't know; if there were no previous lines, this marks +PRELIMinary success, if they were, it marks failure + + Connecting + ~~~~~~~~~~ +Client uses "echo FISH:;/bin/sh" as command executed on remote +machine. This should make it possible for server to distinguish FISH +connections from normal rsh/ssh. + + Commands + ~~~~~~~~ +#FISH +echo; start_fish_server; echo '### 200' + +This command is sent at the beginning. It marks that client wishes to +talk via FISH protocol. #VER command must follow. If server +understands FISH protocol, it has option to put FISH server somewhere +on system path and name it start_fish_server. + +#VER 0.0.2 <...> +echo '### 000' + +This command is the second one. It sends client version and extensions +to the server. Server should reply with protocol version to be used, +and list of extensions accepted. + +VER 0.0.0 +### 200 + +#PWD +pwd; echo '### 200' + +Server should reply with current directory (in form /abc/def/ghi) +followed by line indicating success. + +#LIST /directory +ls -lLa $1 | grep '^[^cbt]' | ( while read p x u g s m d y n; do echo "P$p $u.$g +S$s +d$m $d $y +:$n +"; done ) +ls -lLa $1 | grep '^[cb]' | ( while read p x u g a i m d y n; do echo "P$p $u.$g +E$a$i +dD$m $d $y +:$n +"; done ) +echo '### 200' + +This allows client to list directory or get status information about +single file. Output is in following form (any line except : +may be omitted): + +P . +S +d<3-letters month name> +D [.1234] +E, +: +L + + +Unix permissions are of form X--------- where X is type of +file. Currently, '-' means regular file, 'd' means directory, 'c', 'b' +means character and block device, 'l' means symbolic link, 'p' means +FIFO and 's' means socket. + +'d' has three fields: month (one of strings Jan Feb Mar Apr May Jun +Jul Aug Sep Oct Nov Dec), day of month, and third is either single +number indicating year, or HH:MM field (assume current year in such +case). As you've probably noticed, this is pretty broken; it is for +compatibility with ls listing. + +#RETR /some/name +ls -l /some/name | ( read a b c d x e; echo $x ); echo '### 100'; cat /some/name; echo '### 200' + +Server sends line with filesize on it, followed by line with ### 100 +indicating partial success, then it sends binary data (exactly +filesize bytes) and follows them with (with no preceding newline) ### +200. + +Note that there's no way to abort running RETR command - except +closing the connection. + +#STOR /file/name +> /file/name; echo '### 001'; ( dd bs=4096 count=; dd bs= count=1 ) 2>/dev/null | ( cat > %s; cat > /dev/null ); echo '### 200' + +This command is for storing /file/name, which is exactly size bytes +big. You probably think I went crazy. Well, I did not: that strange +cat > /dev/null has purpose to discard any extra data which was not +written to disk (due to for example out of space condition). + +[Why? Imagine uploading file with "rm -rf /" line in it.] + +#CWD /somewhere +cd /somewhere; echo '### 000' + +It is specified here, but I'm not sure how wise idea is to use this +one: it breaks stateless-ness of the protocol. + +Following commands should be rather self-explanatory: + +#CHMOD 1234 file +chmod 1234 file; echo '### 000' + +#DELE /some/path +rm -f /some/path; echo '### 000' + +#MKD /some/path +mkdir /some/path; echo '### 000' + +#RMD /some/path +rmdir /some/path; echo '### 000' + +#RENAME /path/a /path/b +mv /path/a /path/b; echo '### 000' + +#LINK /path/a /path/b +ln /path/a /path/b; echo '### 000' + +#SYMLINK /path/a /path/b +ln -s /path/a /path/b; echo '### 000' + +#CHOWN user /file/name +chown user /file/name; echo '### 000' + +#CHGRP group /file/name +chgrp group /file/name; echo '### 000' + +#READ /path/and/filename +cat /path/and/filename | ( dd bs=4096 count= > /dev/null; +dd bs= count=1 > /dev/null; +dd bs=4096 count=; +dd bs= count=1; ) + +Returns ### 200 on successful exit, ### 291 on successful exit when +reading ended at eof, ### 292 on successfull exit when reading did not +end at eof. + +#WRITE /path/and/filename + +Hmm, shall we define these ones if we know our client is not going to +use them? + + +That's all, folks! + pavel@ucw.cz diff --git a/lib/widget/buttonbar.c b/lib/widget/buttonbar.c index 5fddae6b4..83ec36bac 100644 --- a/lib/widget/buttonbar.c +++ b/lib/widget/buttonbar.c @@ -262,7 +262,7 @@ buttonbar_set_label (WButtonBar * bb, int idx, const char *text, unsigned long command = CK_Ignore_Key; if (keymap != NULL) - command = lookup_keymap_command (keymap, KEY_F (idx)); + command = keybind_lookup_keymap_command (keymap, KEY_F (idx)); if ((text == NULL) || (text[0] == '\0')) set_label_text (bb, idx, ""); diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 2d53d86be..c8d1c580a 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -306,7 +306,7 @@ static cb_ret_t dlg_handle_key (Dlg_head * h, int d_key) { unsigned long command; - command = lookup_keymap_command (dialog_map, d_key); + command = keybind_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 diff --git a/lib/widget/input.c b/lib/widget/input.c index a6e25de20..cbe63fab7 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -1131,7 +1131,7 @@ input_handle_char (WInput * in, int key) return v; } - command = lookup_keymap_command (input_map, key); + command = keybind_lookup_keymap_command (input_map, key); if (command == CK_Ignore_Key) { @@ -1166,7 +1166,7 @@ input_key_is_in_map (WInput * in, int key) { unsigned long command; - command = lookup_keymap_command (input_map, key); + command = keybind_lookup_keymap_command (input_map, key); if (command == CK_Ignore_Key) return 0; diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index d9ad42028..6c6b01257 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -305,7 +305,7 @@ listbox_key (WListbox * l, int key) return MSG_HANDLED; } - command = lookup_keymap_command (listbox_map, key); + command = keybind_lookup_keymap_command (listbox_map, key); if (command == CK_Ignore_Key) return MSG_NOT_HANDLED; return listbox_execute_cmd (l, command); diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 97dcabb46..d2187394b 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -3141,7 +3141,7 @@ dview_handle_key (WDiff * dview, int key) key = convert_from_input_c (key); - command = lookup_keymap_command (diff_map, key); + command = keybind_lookup_keymap_command (diff_map, key); if ((command != CK_Ignore_Key) && (dview_execute_cmd (dview, command) == MSG_HANDLED)) return MSG_HANDLED; diff --git a/src/editor/editkeys.c b/src/editor/editkeys.c index 18ee0047a..8eccbe61a 100644 --- a/src/editor/editkeys.c +++ b/src/editor/editkeys.c @@ -51,7 +51,7 @@ #include "editcmd_dialogs.h" #include "src/cmddef.h" /* list of commands */ -#include "src/keybind.h" /* lookup_keymap_command() */ +#include "src/keybind.h" /* keybind_lookup_keymap_command() */ #include "src/main.h" /* display_codepage */ /*** global variables ****************************************************************************/ @@ -186,10 +186,10 @@ edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch) if (edit->extmod) { edit->extmod = 0; - command = lookup_keymap_command (editor_x_map, x_key); + command = keybind_lookup_keymap_command (editor_x_map, x_key); } else - command = lookup_keymap_command (editor_map, x_key); + command = keybind_lookup_keymap_command (editor_map, x_key); if (command == CK_Ignore_Key) command = CK_Insert_Char; diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 05306dab9..206c40804 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -74,13 +74,13 @@ edit_get_shortcut (unsigned long command) const char *ext_map; const char *shortcut = NULL; - shortcut = lookup_keymap_shortcut (editor_map, command); + shortcut = keybind_lookup_keymap_shortcut (editor_map, command); if (shortcut != NULL) return g_strdup (shortcut); - ext_map = lookup_keymap_shortcut (editor_map, CK_Ext_Mode); + ext_map = keybind_lookup_keymap_shortcut (editor_map, CK_Ext_Mode); if (ext_map != NULL) - shortcut = lookup_keymap_shortcut (editor_x_map, command); + shortcut = keybind_lookup_keymap_shortcut (editor_x_map, command); if (shortcut != NULL) return g_strdup_printf ("%s %s", ext_map, shortcut); diff --git a/src/help.c b/src/help.c index b19524546..cd2aacec0 100644 --- a/src/help.c +++ b/src/help.c @@ -918,7 +918,7 @@ help_handle_key (Dlg_head * h, int c) { unsigned long command; - command = lookup_keymap_command (help_map, c); + command = keybind_lookup_keymap_command (help_map, c); if ((command == CK_Ignore_Key) || (help_execute_cmd (command) == MSG_NOT_HANDLED)) return MSG_NOT_HANDLED; diff --git a/src/keybind.c b/src/keybind.c index 5e41f638e..e946cd34a 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -1277,7 +1277,7 @@ keybind_cmd_bind (GArray * keymap, const char *keybind, unsigned long action) /* --------------------------------------------------------------------------------------------- */ unsigned long -lookup_action (const char *name) +keybind_lookup_action (const char *name) { const name_keymap_t key = { name, 0 }; name_keymap_t *res; @@ -1293,7 +1293,7 @@ lookup_action (const char *name) /* --------------------------------------------------------------------------------------------- */ const char * -lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action) +keybind_lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action) { size_t i; @@ -1307,7 +1307,7 @@ lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action) /* --------------------------------------------------------------------------------------------- */ unsigned long -lookup_keymap_command (const global_keymap_t * keymap, long key) +keybind_lookup_keymap_command (const global_keymap_t * keymap, long key) { size_t i; diff --git a/src/keybind.h b/src/keybind.h index 07307ca52..2010f8401 100644 --- a/src/keybind.h +++ b/src/keybind.h @@ -107,9 +107,9 @@ extern const global_keymap_t default_diff_keymap[]; /*** declarations of public functions ************************************************************/ void keybind_cmd_bind (GArray * keymap, const char *keybind, unsigned long action); -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); +unsigned long keybind_lookup_action (const char *name); +const char *keybind_lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action); +unsigned long keybind_lookup_keymap_command (const global_keymap_t * keymap, long key); /*** inline functions ****************************************************************************/ #endif /* MC__KEYBIND_H */ diff --git a/src/main.c b/src/main.c index 1544ab323..2ecd621d6 100644 --- a/src/main.c +++ b/src/main.c @@ -598,17 +598,17 @@ midnight_get_shortcut (unsigned long command) const char *ext_map; const char *shortcut = NULL; - shortcut = lookup_keymap_shortcut (main_map, command); + shortcut = keybind_lookup_keymap_shortcut (main_map, command); if (shortcut != NULL) return g_strdup (shortcut); - shortcut = lookup_keymap_shortcut (panel_map, command); + shortcut = keybind_lookup_keymap_shortcut (panel_map, command); if (shortcut != NULL) return g_strdup (shortcut); - ext_map = lookup_keymap_shortcut (main_map, CK_StartExtMap1); + ext_map = keybind_lookup_keymap_shortcut (main_map, CK_StartExtMap1); if (ext_map != NULL) - shortcut = lookup_keymap_shortcut (main_x_map, command); + shortcut = keybind_lookup_keymap_shortcut (main_x_map, command); if (shortcut != NULL) return g_strdup_printf ("%s %s", ext_map, shortcut); @@ -1392,7 +1392,7 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void if (ctl_x_map_enabled) { ctl_x_map_enabled = FALSE; - command = lookup_keymap_command (main_x_map, parm); + command = keybind_lookup_keymap_command (main_x_map, parm); if (command != CK_Ignore_Key) return midnight_execute_cmd (NULL, command); } @@ -1509,10 +1509,10 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void if (ctl_x_map_enabled) { ctl_x_map_enabled = FALSE; - command = lookup_keymap_command (main_x_map, parm); + command = keybind_lookup_keymap_command (main_x_map, parm); } else - command = lookup_keymap_command (main_map, parm); + command = keybind_lookup_keymap_command (main_map, parm); return (command == CK_Ignore_Key) ? MSG_NOT_HANDLED : midnight_execute_cmd (NULL, command); diff --git a/src/setup.c b/src/setup.c index 23d47b506..5f5cd647a 100644 --- a/src/setup.c +++ b/src/setup.c @@ -61,7 +61,7 @@ #include "layout.h" #include "cmd.h" #include "file.h" /* safe_delete */ -#include "keybind.h" /* lookup_action */ +#include "keybind.h" /* keybind_lookup_action */ #ifdef USE_INTERNAL_EDIT @@ -569,7 +569,7 @@ load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len); - action = lookup_action (*profile_keys); + action = keybind_lookup_action (*profile_keys); if (action > 0) { diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 4c6bba5b8..534481588 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -397,12 +397,12 @@ mcview_handle_key (mcview_t * view, int key) if (view->hexedit_mode && (mcview_handle_editkey (view, key) == MSG_HANDLED)) return MSG_HANDLED; - command = lookup_keymap_command (view->hex_map, key); + command = keybind_lookup_keymap_command (view->hex_map, key); if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED)) return MSG_HANDLED; } - command = lookup_keymap_command (view->plain_map, key); + command = keybind_lookup_keymap_command (view->plain_map, key); if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED)) return MSG_HANDLED; -- 2.11.4.GIT