Re: quick view and user defined view



Hello coders,

I have attached my patch to current cvs version of mc in which the Quickview panel honours actions defined in the extension file. While this patch works for me (and my current needs) I consider it rather ugly code and it further complicates the code in ext.c, which should IMO be cleaned up or better completely refactored. But I currently don't have time and patience to do so.

I solved the problem by defining an additional property "action" for the functions in ext.c which will then call the appropriate function depending if the result of exec_regex is designated for the fullscreen viewer or the quickview. I would rather like that the functions in ext.c don't call the viewer functions directly, but rather just prepare the file to be viewed (by applying a cmd if defined) and then return the constructed cmd shell script. As all functions dealing with quickview and fullscreenview already have the capabilty of dealing with a "cmd" argument that would be a cleaner solution. However I did not go this path, because I don't know of the subtle interactions ext.c does with mc's VFS code, that's why I made this ugly hack.

--
---> doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org
Index: src/cmd.c
===================================================================
RCS file: /cvsroot/mc/mc/src/cmd.c,v
retrieving revision 1.159
diff -u -r1.159 cmd.c
--- src/cmd.c   27 May 2005 03:35:15 -0000      1.159
+++ src/cmd.c   29 Jun 2005 12:39:52 -0000
@@ -121,7 +120,7 @@
        else
            strcpy (view_entry, "View");
 
-       if (regex_command (filename, view_entry, &move_dir) == 0) {
+       if (regex_command (filename, view_entry, &move_dir, 0) == 0) {
            view (0, filename, &move_dir, start_line);
            repaint_screen ();
        }
@@ -290,7 +289,7 @@
 void
 edit_cmd (void)
 {
-    if (regex_command (selection (current_panel)->fname, "Edit", 0) == 0)
+    if (regex_command (selection (current_panel)->fname, "Edit", 0, 0) == 0)
        do_edit (selection (current_panel)->fname);
 }
 
Index: src/ext.c
===================================================================
RCS file: /cvsroot/mc/mc/src/ext.c,v
retrieving revision 1.77
diff -u -r1.77 ext.c
--- src/ext.c   28 Jun 2005 13:55:33 -0000      1.77
+++ src/ext.c   29 Jun 2005 12:39:52 -0000
@@ -57,9 +57,14 @@
 
 typedef char *(*quote_func_t) (const char *name, int quote_percent);
 
+enum {
+  EXEC_VIEW,
+  EXEC_QUICKVIEW
+};
+
 static void
 exec_extension (const char *filename, const char *data, int *move_dir,
-               int start_line)
+               int start_line, int action, void *private)
 {
     char *file_name;
     int cmd_file_fd;
@@ -235,10 +240,28 @@
         * into view
         */
        if (written_nonspace) {
-           view (cmd, filename, move_dir, start_line);
+         switch (action)
+           {
+           default:
+           case EXEC_VIEW:
+             view (cmd, filename, move_dir, start_line);
+             break;
+           case EXEC_QUICKVIEW:
+             view_load (private, cmd, filename, start_line);
+             break;
+           }
            unlink (file_name);
        } else {
-           view (0, filename, move_dir, start_line);
+         switch (action)
+           {
+           default:
+           case EXEC_VIEW:
+             view (0, filename, move_dir, start_line);
+             break;
+           case EXEC_QUICKVIEW:
+             view_load (private, 0, filename, start_line);
+             break;
+           }
        }
        if (changed_hex_mode && !altered_hex_mode)
            default_hex_mode = def_hex_mode;
@@ -413,25 +436,37 @@
  * if the value for %d exists, then the viewer is started up at that line number.
  */
 int
-regex_command (const char *filename, const char *action, int *move_dir)
+regex_command (const char *filename, const char *action, int *move_dir, void *private)
 {
     char *p, *q, *r, c;
-    int file_len = strlen (filename);
+    int file_len;
     int found = 0;
     int error_flag = 0;
     int ret = 0;
     struct stat mystat;
-    int view_at_line_number;
+    int view_at_line_number = 0;
     char *include_target;
     int include_target_len;
     int have_type = 0;         /* Flag used by regex_check_type() */
+    int quickview = 0;
+    int execaction = EXEC_VIEW;
+
+    if(!filename || !action)
+      return -1;
+
+    file_len = strlen (filename);
+
+    if (!strncmp(action, "Quickview", 9))
+      {
+       quickview=1;
+       action = "View";
+       execaction = EXEC_QUICKVIEW;
+      }
 
     /* Check for the special View:%d parameter */
     if (strncmp (action, "View:", 5) == 0) {
        view_at_line_number = atoi (action + 5);
        action = "View";
-    } else {
-       view_at_line_number = 0;
     }
 
     if (data == NULL) {
@@ -592,7 +627,7 @@
                            char *filename_copy = g_strdup (filename);
 
                            exec_extension (filename_copy, r + 1, move_dir,
-                                           view_at_line_number);
+                                           view_at_line_number, execaction, private);
                            g_free (filename_copy);
 
                            ret = 1;
Index: src/ext.h
===================================================================
RCS file: /cvsroot/mc/mc/src/ext.h,v
retrieving revision 1.19
diff -u -r1.19 ext.h
--- src/ext.h   3 Dec 2004 19:17:47 -0000       1.19
+++ src/ext.h   29 Jun 2005 12:39:52 -0000
@@ -1,7 +1,7 @@
 #ifndef MC_EXT_H
 #define MC_EXT_H
 
-int regex_command (const char *filename, const char *action, int *move_dir);
+int regex_command (const char *filename, const char *action, int *move_dir, void *private);
 
 /* Call it after the user has edited the mc.ext file,
  * to flush the cached mc.ext file
Index: src/layout.c
===================================================================
RCS file: /cvsroot/mc/mc/src/layout.c,v
retrieving revision 1.93
diff -u -r1.93 layout.c
--- src/layout.c        14 Jun 2005 13:02:31 -0000      1.93
+++ src/layout.c        29 Jun 2005 12:39:52 -0000
@@ -965,7 +965,11 @@
        else
            file_name = "";
        
-       view_load ((WView *) new_widget, 0, file_name, 0);
+       {
+         int move_dir=0;
+         if(regex_command (file_name, "Quickview", &move_dir, new_widget) < 1)
+           view_load ((WView *) new_widget, 0, file_name, 0);
+       }
        break;
     }
     panels [num].type = type;
Index: src/screen.c
===================================================================
RCS file: /cvsroot/mc/mc/src/screen.c,v
retrieving revision 1.214
diff -u -r1.214 screen.c
--- src/screen.c        27 May 2005 03:35:15 -0000      1.214
+++ src/screen.c        29 Jun 2005 12:39:54 -0000
@@ -1962,7 +1962,7 @@
     }
 
     /* Try associated command */
-    if (regex_command (fe->fname, "Open", 0) != 0)
+    if (regex_command (fe->fname, "Open", 0, 0) != 0)
        return 1;
 
     /* Check if the file is executable */
Index: src/view.c
===================================================================
RCS file: /cvsroot/mc/mc/src/view.c,v
retrieving revision 1.279
diff -u -r1.279 view.c
--- src/view.c  28 Jun 2005 13:21:42 -0000      1.279
+++ src/view.c  29 Jun 2005 12:39:54 -0000
@@ -3187,6 +3187,7 @@
 {
     WView *view = (WView *) v;
     WPanel *panel;
+    int move_dir=0;
 
     /* If the user is busy typing, wait until he finishes to update the
        screen */
@@ -3205,7 +3206,8 @@
     else
        return;
 
-    view_load (view, 0, panel->dir.list[panel->selected].fname, 0);
+    if(regex_command (panel->dir.list[panel->selected].fname, "Quickview", &move_dir, view) < 1)
+      view_load (view, 0, panel->dir.list[panel->selected].fname, 0);
     display (view);
     view_status (view);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]