Browse Source

added a new action "Record and Repeat commands", added menu entry (Record/Repeat actions) for this.

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

some fixes

Signed-off-by: Slava Zanko <slavazanko@gmail.com>

and one more fix

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Ilia Maslakov 14 years ago
parent
commit
83177cfc16
9 changed files with 59 additions and 20 deletions
  1. 1 0
      lib/keybind.c
  2. 13 10
      lib/keybind.h
  3. 2 0
      misc/mc.keymap.default
  4. 2 0
      misc/mc.keymap.emacs
  5. 2 0
      src/editor/edit-impl.h
  6. 19 5
      src/editor/edit.c
  7. 18 5
      src/editor/editcmd.c
  8. 1 0
      src/editor/editmenu.c
  9. 1 0
      src/history.h

+ 1 - 0
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},

+ 13 - 10
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

+ 2 - 0
misc/mc.keymap.default

@@ -160,6 +160,8 @@ EditFindDefinition = alt-enter
 EditLoadPrevFile = alt-minus
 EditLoadNextFile = alt-plus
 
+EditBeginEndRepeat =
+
 SelectCodepage = alt-e
 
 [viewer]

+ 2 - 0
misc/mc.keymap.emacs

@@ -157,6 +157,8 @@ EditFindDefinition = alt-enter
 EditLoadPrevFile = alt-minus
 EditLoadNextFile = alt-plus
 
+EditBeginEndRepeat =
+
 SelectCodepage = alt-e
 
 EditExtMode = ctrl-x

+ 2 - 0
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);
 

+ 19 - 5
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;

+ 18 - 5
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

+ 1 - 0
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)));

+ 1 - 0
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"