Ticket #4204: EditFileGlobUpstr.patch

File EditFileGlobUpstr.patch, 3.8 KB (added by psprint, 3 years ago)
  • src/editor/edit-impl.h

    From 73a62e10fdc5f205fdcbc5bb825281ef79a3f68a Mon Sep 17 00:00:00 2001
    From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
    Date: Wed, 17 Feb 2021 10:38:06 -0600
    Subject: Support for glob patterns in open file dialog
    
    ---
     src/editor/edit-impl.h  |  2 +-
     src/editor/editcmd.c    | 43 +++++++++++++++++++++++++++++++++--------
     src/editor/editwidget.c |  2 +-
     3 files changed, 37 insertions(+), 10 deletions(-)
    
    diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h
    index 3ad04dbea..efae19de9 100644
    a b WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols, 
    185185                  const vfs_path_t * filename_vpath, long line); 
    186186gboolean edit_clean (WEdit * edit); 
    187187gboolean edit_ok_to_exit (WEdit * edit); 
    188 gboolean edit_load_cmd (WDialog * h); 
     188gboolean edit_load_cmd (WDialog * h, const void *data); 
    189189gboolean edit_load_file_from_history (WDialog * h); 
    190190gboolean edit_load_syntax_file (WDialog * h); 
    191191gboolean edit_load_menu_file (WDialog * h); 
  • src/editor/editcmd.c

    diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
    index 0d2caa923..a55810f30 100644
    a b  
    4444#include <errno.h> 
    4545#include <sys/stat.h> 
    4646#include <stdlib.h> 
     47#include <glob.h> 
    4748 
    4849#include "lib/global.h" 
    4950#include "lib/tty/tty.h" 
    edit_save_confirm_cmd (WEdit * edit) 
    20632064  */ 
    20642065 
    20652066gboolean 
    2066 edit_load_cmd (WDialog * h) 
     2067edit_load_cmd (WDialog * h, const void *data) 
    20672068{ 
    20682069    char *exp; 
    20692070    gboolean ret = TRUE;        /* possible cancel */ 
    20702071 
    2071     exp = input_expand_dialog (_("Load"), _("Enter file name:"), 
    2072                                MC_HISTORY_EDIT_LOAD, INPUT_LAST_TEXT, 
    2073                                INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD); 
     2072    if (data != NULL) 
     2073        exp = g_strdup ((char *) data); 
     2074    else 
     2075        exp = input_expand_dialog (_("Load"), _("Enter file name:"), 
     2076                                   MC_HISTORY_EDIT_LOAD, INPUT_LAST_TEXT, 
     2077                                   INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD); 
    20742078 
    20752079    if (exp != NULL && *exp != '\0') 
    20762080    { 
    2077         vfs_path_t *exp_vpath; 
     2081        if (g_strstr_len (exp, -1, "*") || g_strstr_len (exp, -1, "?") 
     2082            || g_strstr_len (exp, -1, "[")) 
     2083        { 
     2084            int gret; 
     2085            gsize idx; 
     2086            glob_t globbuf = { 0 }; 
     2087            gret = glob (exp, GLOB_MARK | GLOB_BRACE | GLOB_NOMAGIC | GLOB_TILDE | GLOB_TILDE_CHECK, 
     2088                         NULL, &globbuf); 
     2089            if (gret != 0) 
     2090                message (D_ERROR, _("Problem opening files"), 
     2091                         _("Pattern `%s` did not match any files"), exp); 
    20782092 
    2079         exp_vpath = vfs_path_from_str (exp); 
    2080         ret = edit_load_file_from_filename (h, exp_vpath); 
    2081         vfs_path_free (exp_vpath); 
     2093            /* Are any results returned? */ 
     2094            for (idx = 0; idx < globbuf.gl_pathc; idx++) 
     2095                if (globbuf.gl_pathv != NULL && globbuf.gl_pathv[idx] != NULL) 
     2096                    edit_load_cmd (h, globbuf.gl_pathv[idx]); 
     2097 
     2098            if (globbuf.gl_pathc > 0) 
     2099                globfree (&globbuf); 
     2100        } 
     2101        else 
     2102        { 
     2103            vfs_path_t *exp_vpath; 
     2104 
     2105            exp_vpath = vfs_path_from_str (exp); 
     2106            ret = edit_load_file_from_filename (h, exp_vpath); 
     2107            vfs_path_free (exp_vpath); 
     2108        } 
    20822109    } 
    20832110 
    20842111    g_free (exp); 
  • src/editor/editwidget.c

    diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c
    index 18ac00e66..10ceaff83 100644
    a b edit_dialog_command_execute (WDialog * h, long command) 
    391391        edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0); 
    392392        break; 
    393393    case CK_EditFile: 
    394         edit_load_cmd (h); 
     394        edit_load_cmd (h, NULL); 
    395395        break; 
    396396    case CK_History: 
    397397        edit_load_file_from_history (h);