Просмотр исходного кода

Ticket #2733 (a simple list of recently edited files)

    Based on patch by Filip Sefrna <fsefrna@gmail.com>
    added action 'EditorHistory' for call history dialog.

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
Ilia Maslakov 13 лет назад
Родитель
Сommit
3e7b2c49dc
6 измененных файлов с 61 добавлено и 0 удалено
  1. 1 0
      lib/keybind.c
  2. 1 0
      lib/keybind.h
  3. 1 0
      misc/mc.default.keymap
  4. 1 0
      misc/mc.emacs.keymap
  5. 56 0
      src/filemanager/midnight.c
  6. 1 0
      src/keybind-defaults.c

+ 1 - 0
lib/keybind.c

@@ -94,6 +94,7 @@ static name_keymap_t command_names[] = {
 #ifdef HAVE_CHARSET
     {"SelectCodepage", CK_SelectCodepage},
 #endif
+    {"EditorViewerHistory", CK_EditorViewerHistory},
     {"History", CK_History},
     {"HistoryNext", CK_HistoryNext},
     {"HistoryPrev", CK_HistoryPrev},

+ 1 - 0
lib/keybind.h

@@ -85,6 +85,7 @@ enum
     CK_EditNew,
     CK_Shell,
     CK_SelectCodepage,
+    CK_EditorViewerHistory,
     CK_History,
     CK_HistoryNext,
     CK_HistoryPrev,

+ 1 - 0
misc/mc.default.keymap

@@ -54,6 +54,7 @@ ScreenList = alt-prime
 # ConnectFtp =
 # ConnectSmb =
 # Undelete =
+EditorViewerHistory = alt-shift-e
 ExtendedKeyMap = ctrl-x
 
 [main:xmap]

+ 1 - 0
misc/mc.emacs.keymap

@@ -54,6 +54,7 @@ ScreenList = alt-prime
 # ConnectFtp =
 # ConnectSmb =
 # Undelete =
+EditorViewerHistory = alt-shift-e
 ExtendedKeyMap = ctrl-x
 
 [main:xmap]

+ 56 - 0
src/filemanager/midnight.c

@@ -61,6 +61,7 @@
 #include "src/setup.h"          /* variables */
 #include "src/learn.h"          /* learn_keys() */
 #include "src/keybind-defaults.h"
+#include "lib/fileloc.h"        /* MC_FILEPOS_FILE */
 #include "lib/keybind.h"
 #include "lib/event.h"
 
@@ -289,6 +290,10 @@ create_command_menu (void)
     entries = g_list_prepend (entries, menu_entry_create (_("Show directory s&izes"), CK_DirSize));
     entries = g_list_prepend (entries, menu_separator_create ());
     entries = g_list_prepend (entries, menu_entry_create (_("Command &history"), CK_History));
+    entries =
+        g_list_prepend (entries,
+                        menu_entry_create (_("Viewed/edited files hi&story"),
+                                           CK_EditorViewerHistory));
     entries = g_list_prepend (entries, menu_entry_create (_("Di&rectory hotlist"), CK_HotList));
 #ifdef ENABLE_VFS
     entries = g_list_prepend (entries, menu_entry_create (_("&Active VFS list"), CK_VfsList));
@@ -1000,6 +1005,54 @@ mc_maybe_editor_or_viewer (void)
 
 /* --------------------------------------------------------------------------------------------- */
 
+static void
+show_editor_history_list (void)
+{
+    char *fn;
+    FILE *f;
+    char buf[MC_MAXPATHLEN + 100];
+    GList *file_list = NULL;
+    char *s;
+    WPanel *panel = current_panel;
+
+    /* open file with positions */
+    fn = mc_config_get_full_path (MC_FILEPOS_FILE);
+    f = fopen (fn, "r");
+    g_free (fn);
+    if (f == NULL)
+        return;
+
+    while (fgets (buf, sizeof (buf), f) != NULL)
+    {
+        s = strrchr (buf, ' ');
+        if (s != NULL)
+            s = g_strndup (buf, s - buf);
+        else
+            s = g_strdup (buf);
+
+        file_list = g_list_prepend (file_list, s);
+    }
+    fclose (f);
+
+    file_list = g_list_last (file_list);
+    s = history_show (&file_list, WIDGET (panel));
+
+    if (s != NULL)
+    {
+        vfs_path_t *s_vpath;
+
+        s_vpath = vfs_path_from_str (s);
+        g_free (s);
+        do_edit_at_line (s_vpath, use_internal_edit, 0);
+        vfs_path_free (s_vpath);
+    }
+
+    file_list = g_list_first (file_list);
+    g_list_free_full (file_list, (GDestroyNotify) g_free);
+}
+
+/* --------------------------------------------------------------------------------------------- */
+
 static gboolean
 quit_cmd_internal (int quiet)
 {
@@ -1374,6 +1427,9 @@ midnight_execute_cmd (Widget * sender, long command)
     case CK_ViewFile:
         view_file_cmd ();
         break;
+    case CK_EditorViewerHistory:
+        show_editor_history_list ();
+        break;
     case CK_Cancel:
         /* don't close panels due to SIGINT */
         break;

+ 1 - 0
src/keybind-defaults.c

@@ -99,6 +99,7 @@ static const global_keymap_ini_t default_main_keymap[] = {
     {"MenuLastSelected", "f19"},
     {"QuitQuiet", "f20"},
     {"History", "alt-h"},
+    {"EditorViewerHistory", "alt-shift-e"},
     {"DirSize", "ctrl-space"},
     /* Copy useful information to the command line */
     {"PutCurrentPath", "alt-a"},