Fix mode switch after CK_FileNext/CK_FilePrev.
authorAndrew Borodin <aborodin@vmail.ru>
Sun, 24 Mar 2013 12:14:33 +0000 (24 16:14 +0400)
committerAndrew Borodin <aborodin@vmail.ru>
Fri, 5 Apr 2013 15:16:41 +0000 (5 19:16 +0400)
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
src/filemanager/ext.c
src/viewer/actions_cmd.c
src/viewer/internal.h

index c57f841..d897910 100644 (file)
@@ -356,8 +356,6 @@ exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath,
     int def_hex_mode = mcview_default_hex_mode, changed_hex_mode = 0;
     int def_nroff_flag = mcview_default_nroff_flag, changed_nroff_flag = 0;
 
-    (void) target;
-
     mcview_altered_hex_mode = 0;
     mcview_altered_nroff_flag = 0;
     if (def_hex_mode != mcview_default_hex_mode)
@@ -365,7 +363,16 @@ exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath,
     if (def_nroff_flag != mcview_default_nroff_flag)
         changed_nroff_flag = 1;
 
-    mcview_viewer (cmd, filename_vpath, start_line);
+    if (target == NULL)
+        mcview_viewer (cmd, filename_vpath, start_line);
+    else
+    {
+        char *file_name;
+
+        file_name = vfs_path_to_str (filename_vpath);
+        mcview_load ((mcview_t *) target, cmd, file_name, start_line);
+        g_free (file_name);
+    }
 
     if (changed_hex_mode && !mcview_altered_hex_mode)
         mcview_default_hex_mode = def_hex_mode;
index 51e65e5..5024542 100644 (file)
@@ -63,6 +63,7 @@
 #include "src/filemanager/layout.h"
 #include "src/filemanager/cmd.h"
 #include "src/filemanager/midnight.h"   /* current_panel */
+#include "src/filemanager/ext.h"        /* regex_command_for() */
 
 #include "src/history.h"
 #include "src/execute.h"
 
 /*** file scope variables ************************************************************************/
 
+/* --------------------------------------------------------------------------------------------- */
 /*** file scope functions ************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
 
+static void
+mcview_remove_ext_script (mcview_t * view)
+{
+    if (view->ext_script != NULL)
+    {
+        mc_unlink (view->ext_script);
+        vfs_path_free (view->ext_script);
+        view->ext_script = NULL;
+    }
+}
+
+/* --------------------------------------------------------------------------------------------- */
+
 /* Both views */
 static void
 mcview_search (mcview_t * view)
@@ -320,7 +335,7 @@ mcview_load_next_prev (mcview_t * view, int direction)
     dir_list *dir;
     int *dir_count, *dir_idx;
     vfs_path_t *vfile;
-    char *file;
+    vfs_path_t *ext_script = NULL;
 
     mcview_load_next_prev_init (view);
     mcview_scan_for_file (view, direction);
@@ -333,15 +348,22 @@ mcview_load_next_prev (mcview_t * view, int direction)
     view->dir_count = NULL;
     view->dir_idx = NULL;
     vfile = vfs_path_append_new (view->workdir_vpath, dir->list[*dir_idx].fname, (char *) NULL);
-    file = vfs_path_to_str (vfile);
-    vfs_path_free (vfile);
     mcview_done (view);
+    mcview_remove_ext_script (view);
     mcview_init (view);
-    mcview_load (view, NULL, file, 0);
-    g_free (file);
+    if (regex_command_for (view, vfile, "View", &ext_script) == 0)
+    {
+        char *file;
+
+        file = vfs_path_to_str (vfile);
+        mcview_load (view, NULL, file, 0);
+        g_free (file);
+    }
+    vfs_path_free (vfile);
     view->dir = dir;
     view->dir_count = dir_count;
     view->dir_idx = dir_idx;
+    view->ext_script = ext_script;
 
     view->dpy_bbar_dirty = FALSE;       /* FIXME */
     view->dirty++;
@@ -622,6 +644,7 @@ mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *
                 mcview_ok_to_quit (view);
         }
         mcview_done (view);
+        mcview_remove_ext_script (view);
         return MSG_HANDLED;
 
     default:
index dddc3ac..a94d8fd 100644 (file)
@@ -188,6 +188,7 @@ struct mcview_struct
                                  * Pointer is used here as reference to WPanel::count */
     int *dir_idx;               /* Index of current file in dir structure.
                                  * Pointer is used here as reference to WPanel::count */
+    vfs_path_t *ext_script;     /* Temporary script file created by regex_command_for() */
 };
 
 typedef struct mcview_nroff_struct