From 83177cfc16855aab6de144cdeba42b34266e7bcc Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Mon, 24 Jan 2011 18:55:00 +0300 Subject: [PATCH] added a new action "Record and Repeat commands", added menu entry (Record/Repeat actions) for this. Signed-off-by: Ilia Maslakov some fixes Signed-off-by: Slava Zanko and one more fix Signed-off-by: Andrew Borodin --- lib/keybind.c | 1 + lib/keybind.h | 23 +++++++++++++---------- misc/mc.keymap.default | 2 ++ misc/mc.keymap.emacs | 2 ++ src/editor/edit-impl.h | 2 ++ src/editor/edit.c | 24 +++++++++++++++++++----- src/editor/editcmd.c | 23 ++++++++++++++++++----- src/editor/editmenu.c | 1 + src/history.h | 1 + 9 files changed, 59 insertions(+), 20 deletions(-) diff --git a/lib/keybind.c b/lib/keybind.c index 2d064e2b6..5b7c6a5b5 100644 --- a/lib/keybind.c +++ b/lib/keybind.c @@ -134,6 +134,7 @@ static name_keymap_t command_names[] = { {"EditUserMenu", CK_User_Menu}, {"EditBeginRecordMacro", CK_Begin_Record_Macro}, {"EditEndRecordMacro", CK_End_Record_Macro}, + {"EditBeginEndRepeat", CK_Begin_End_Repeat}, {"EditDeleteMacro", CK_Delete_Macro}, {"EditToggleBookmark", CK_Toggle_Bookmark}, {"EditFlushBookmarks", CK_Flush_Bookmarks}, diff --git a/lib/keybind.h b/lib/keybind.h index 90b0d41f9..20bf4244a 100644 --- a/lib/keybind.h +++ b/lib/keybind.h @@ -189,19 +189,22 @@ #define CK_Paragraph_Down_Alt_Highlight 671 /* X clipboard operations */ -#define CK_XStore 701 -#define CK_XCut 702 -#define CK_XPaste 703 -#define CK_Selection_History 704 +#define CK_XStore 701 +#define CK_XCut 702 +#define CK_XPaste 703 +#define CK_Selection_History 704 -#define CK_Shell 801 +#define CK_Shell 801 /* C-x or similar */ -#define CK_Ext_Mode 820 - -#define CK_Insert_Literal 851 -#define CK_Execute_Macro 852 -#define CK_Begin_End_Macro 853 +#define CK_Ext_Mode 820 + +#define CK_Insert_Literal 851 +#define CK_Execute_Macro 852 +#define CK_Begin_End_Macro 853 +#define CK_Begin_End_Repeat 854 +#define CK_Begin_Record_Repeat 855 +#define CK_End_Record_Repeat 856 /* help */ #define CK_HelpHelp 1001 diff --git a/misc/mc.keymap.default b/misc/mc.keymap.default index 356fa5cda..e0f3374ab 100644 --- a/misc/mc.keymap.default +++ b/misc/mc.keymap.default @@ -160,6 +160,8 @@ EditFindDefinition = alt-enter EditLoadPrevFile = alt-minus EditLoadNextFile = alt-plus +EditBeginEndRepeat = + SelectCodepage = alt-e [viewer] diff --git a/misc/mc.keymap.emacs b/misc/mc.keymap.emacs index 0d357ce3e..53c1d231a 100644 --- a/misc/mc.keymap.emacs +++ b/misc/mc.keymap.emacs @@ -157,6 +157,8 @@ EditFindDefinition = alt-enter EditLoadPrevFile = alt-minus EditLoadNextFile = alt-plus +EditBeginEndRepeat = + SelectCodepage = alt-e EditExtMode = ctrl-x diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 809272885..5b49e316c 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -308,6 +308,7 @@ void edit_help_cmd (WEdit * edit); int edit_store_macro_cmd (WEdit * edit); gboolean edit_load_macro_cmd (WEdit * edit); void edit_delete_macro_cmd (WEdit * edit); +gboolean edit_repeat_macro_cmd (WEdit * edit); int edit_copy_to_X_buf_cmd (WEdit * edit); int edit_cut_to_X_buf_cmd (WEdit * edit); @@ -318,6 +319,7 @@ void edit_insert_literal_cmd (WEdit * edit); void edit_execute_macro_cmd (WEdit * edit); gboolean edit_execute_macro (WEdit * edit, int hotkey); void edit_begin_end_macro_cmd (WEdit * edit); +void edit_begin_end_repeat_cmd (WEdit * edit); void edit_paste_from_history (WEdit * edit); diff --git a/src/editor/edit.c b/src/editor/edit.c index 5d49e93f2..84b1e3813 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -3379,18 +3379,29 @@ edit_find_bracket (WEdit * edit) void edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_insertion) { - if (command == CK_Begin_Record_Macro || (command == CK_Begin_End_Macro && macro_index < 0)) + if (command == CK_Begin_Record_Macro || command == CK_Begin_Record_Repeat + || (macro_index < 0 && (command == CK_Begin_End_Macro || command == CK_Begin_End_Repeat))) { macro_index = 0; edit->force |= REDRAW_CHAR_ONLY | REDRAW_LINE; return; } - if ((command == CK_End_Record_Macro || command == CK_Begin_End_Macro) && macro_index != -1) + if (macro_index != -1) { edit->force |= REDRAW_COMPLETELY; - edit_store_macro_cmd (edit); - macro_index = -1; - return; + if (command == CK_End_Record_Macro || command == CK_Begin_End_Macro) + { + edit_store_macro_cmd (edit); + macro_index = -1; + return; + } + else if (command == CK_End_Record_Repeat || command == CK_Begin_End_Repeat) + { + edit_repeat_macro_cmd (edit); + macro_index = -1; + return; + } + } if (macro_index >= 0 && macro_index < MAX_MACRO_LENGTH - 1) @@ -4117,6 +4128,9 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) case CK_Begin_End_Macro: edit_begin_end_macro_cmd (edit); break; + case CK_Begin_End_Repeat: + edit_begin_end_repeat_cmd (edit); + break; case CK_Ext_Mode: edit->extmod = 1; break; diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 14c9af622..e763b4b40 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1590,7 +1590,7 @@ edit_store_macro_cmd (WEdit * edit) return TRUE; } -/* --------------------------------------------------------------------------------------------- */ + /* --------------------------------------------------------------------------------------------- */ gboolean edit_repeat_macro_cmd (WEdit * edit) @@ -1600,7 +1600,7 @@ edit_repeat_macro_cmd (WEdit * edit) long count_repeat; char *error = NULL; - f = input_dialog (_("Repeat last commands"), _("Repeat times:"), NULL, "1"); + f = input_dialog (_("Repeat last commands"), _("Repeat times:"), MC_HISTORY_EDIT_REPEAT, NULL); if (f == NULL || *f == '\0') { g_free (f); @@ -1609,7 +1609,7 @@ edit_repeat_macro_cmd (WEdit * edit) count_repeat = strtol (f, &error, 0); - if (error != NULL) + if (*error != '\0') { g_free (f); return FALSE; @@ -1618,8 +1618,8 @@ edit_repeat_macro_cmd (WEdit * edit) g_free (f); edit_push_undo_action (edit, KEY_PRESS + edit->start_display); - edit->force |= REDRAW_PAGE; + for (j = 0; j < count_repeat; j++) for (i = 0; i < macro_index; i++) edit_execute_cmd (edit, record_macro_buf[i].action, record_macro_buf[i].ch); @@ -3155,13 +3155,26 @@ void edit_begin_end_macro_cmd (WEdit * edit) { /* edit is a pointer to the widget */ - if (edit) + if (edit != NULL) { unsigned long command = macro_index < 0 ? CK_Begin_Record_Macro : CK_End_Record_Macro; edit_execute_key_command (edit, command, -1); } } + /* --------------------------------------------------------------------------------------------- */ + +void +edit_begin_end_repeat_cmd (WEdit * edit) +{ + /* edit is a pointer to the widget */ + if (edit != NULL) + { + unsigned long command = macro_index < 0 ? CK_Begin_Record_Repeat : CK_End_Record_Repeat; + edit_execute_key_command (edit, command, -1); + } +} + /* --------------------------------------------------------------------------------------------- */ int diff --git a/src/editor/editmenu.c b/src/editor/editmenu.c index bc2c4aa25..58d8e4d6e 100644 --- a/src/editor/editmenu.c +++ b/src/editor/editmenu.c @@ -170,6 +170,7 @@ create_command_menu (void) g_list_append (entries, menu_entry_create (_("&Start/Stop record macro"), CK_Begin_End_Macro)); entries = g_list_append (entries, menu_entry_create (_("Delete macr&o..."), CK_Delete_Macro)); + entries = g_list_append (entries, menu_entry_create (_("Record/Repeat &actions"), CK_Begin_End_Repeat)); entries = g_list_append (entries, menu_separator_create ()); entries = g_list_append (entries, menu_entry_create (_("'ispell' s&pell check"), CK_Pipe_Block (1))); diff --git a/src/history.h b/src/history.h index 370ce925e..d032942cc 100644 --- a/src/history.h +++ b/src/history.h @@ -16,6 +16,7 @@ #define MC_HISTORY_EDIT_GOTO_LINE "mc.edit.goto-line" #define MC_HISTORY_EDIT_SORT "mc.edit.sort" #define MC_HISTORY_EDIT_PASTE_EXTCMD "mc.edit.paste-extcmd" +#define MC_HISTORY_EDIT_REPEAT "mc.edit.repeat-action" #define MC_HISTORY_FM_VIEW_FILE "mc.fm.view-file" #define MC_HISTORY_FM_MKDIR "mc.fm.mkdir" -- 2.11.4.GIT