fl_native_file_chooser utility

7 views
Skip to first unread message

anmol....@gmail.com

unread,
Sep 27, 2021, 8:39:39 AM9/27/21
to fltk.general
This would be a useful addition to fltk.

char *fl_native_file_chooser(const char *message,const char *pat,const char *fname,int relative=0) {

    static char   retname[FL_PATH_MAX];           // Returned filename

    char *tmpstr = NULL;

    

    Fl_Native_File_Chooser *fnfc = new Fl_Native_File_Chooser;

    fnfc->title(message);

    fnfc->type(Fl_Native_File_Chooser::BROWSE_FILE);

    fnfc->filter(pat);

    if (!fname || !*fname) fname = ".";

   fnfc->preset_file(fname);

    // Show native chooser

    switch ( fnfc->show() ) {

        case -1: 

            break;  // ERROR

        case  1: 

            break;  // CANCEL

        default: 

            tmpstr = (char *)fnfc->filename();

            break;  // FILE CHOSEN

    }

    

    if (tmpstr && relative) {

        fl_filename_relative(retname, sizeof(retname), (char *)fnfc->filename());

        return retname;

    }

    return tmpstr;

}

Reply all
Reply to author
Forward
0 new messages