Jump to content

VFileSelect: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


==Synopsis==
==Synopsis==
;Header:
;Header: <tt><v/vfilesel.h></tt>
: <tt><v/vfilesel.h></tt>
;Class name: vFileSelect
;Class name:
;Hierarchy: vModalDialog ->vFileSelect
: vFileSelect
;Hierarchy:
: vModalDialog ->vFileSelect


==Description==
==Description==
Line 13: Line 10:


==Methods==
==Methods==
vFileSelect(vBaseWindow* win)
;vFileSelect(vBaseWindow* win)
 
;vFileSelect(vApp* app):The <tt>vFileSelect</tt> constructor requires a pointer to a <tt>vBaseWindow</tt>, which includes all '''''V''''' windows and dialogs, or a pointer to the <tt>vApp</tt> object. You will usually pass the <tt>this</tt> to the constructor.
vFileSelect(vApp* app)
;int FileSelect(const char* prompt, char* filename, const int maxLen, char** filterList, int& filterIndex)
 
;int FileSelectSave(const char* prompt, char* filename, const int maxLen, char** filterList, int& filterIndex):You provide a <tt>prompt</tt> for the user, such as ''Open File''. The user then uses the dialog to select or set a file name. <tt>FileSelect</tt> returns <tt>True</tt> if the user picked the OK button, and <tt>False</tt> if they used the Cancel button.
The <tt>vFileSelect</tt> constructor requires a pointer to a <tt>vBaseWindow</tt>, which includes all '''''V''''' windows and dialogs, or a pointer to the <tt>vApp</tt> object. You will usually pass the <tt>this</tt> to the constructor.
:The filename will be filled in to the <tt>filename</tt> buffer of maximum length <tt>maxLen</tt>. The full path of the file will be included with the file name.
 
:You can also provide a list of filter patterns to filter file extensions. If you don't provide a filter list, the default filter of ''*'' will be used. Each item in the filter list can include a list of file extensions separated by blanks. You can provide several filtering options. The first filter in the list will be the default. Only leading ''*'' wild cards are supported.
int FileSelect(const char* prompt, char* filename, const int maxLen,
:The <tt>filterIndex</tt> reference parameter is used to track which filter the user selected. After <tt>FileSelect</tt> returns, <tt>filterIndex</tt> will be set to the index of the filter list that the user last selected. For the best interface, you should remember this value for the next time you call <tt>FileSelect</tt> with the same filter list so that the user selected filter will be preserved.
                char** filterList, int& filterIndex)
:You should use <tt>FileSelect</tt> to open a new or existing file. If the user is being asked to save a file (usually after picking a ''Save As'' menu choice), use the <tt>FileSelectSave</tt> method. On some platforms, there will be no difference between these two methods (X, for example). On other platforms (Windows, for example), different underlying system provided file dialogs are used. To your program, there will be no difference in functionality.
 
int FileSelectSave(const char* prompt, char* filename, const int maxLen,
                    char** filterList, int& filterIndex)
 
You provide a <tt>prompt</tt> for the user, such as ''Open File''. The user then uses the dialog to select or set a file name. <tt>FileSelect</tt> returns <tt>True</tt> if the user picked the OK button, and <tt>False</tt> if they used the Cancel button.
 
The filename will be filled in to the <tt>filename</tt> buffer of maximum length <tt>maxLen</tt>. The full path of the file will be included with the file name.
 
You can also provide a list of filter patterns to filter file extensions. If you don't provide a filter list, the default filter of ''*'' will be used. Each item in the filter list can include a list of file extensions separated by blanks. You can provide several filtering options. The first filter in the list will be the default. Only leading ''*'' wild cards are supported.
 
The <tt>filterIndex</tt> reference parameter is used to track which filter the user selected. After <tt>FileSelect</tt> returns, <tt>filterIndex</tt> will be set to the index of the filter list that the user last selected. For the best interface, you should remember this value for the next time you call <tt>FileSelect</tt> with the same filter list so that the user selected filter will be preserved.
 
You should use <tt>FileSelect</tt> to open a new or existing file. If the user is being asked to save a file (usually after picking a ''Save As'' menu choice), use the <tt>FileSelectSave</tt> method. On some platforms, there will be no difference between these two methods (X, for example). On other platforms (Windows, for example), different underlying system provided file dialogs are used. To your program, there will be no difference in functionality.


===Example===
===Example===

Latest revision as of 22:15, 9 April 2020

A utility class to select or set a file name.

Synopsis

Header
<v/vfilesel.h>
Class name
vFileSelect
Hierarchy
vModalDialog ->vFileSelect

Description

This utility class provides a dialog interface for selecting filenames. It can be used either to select an input file name, or verify or change an output file name. This utility does not open or alter files - it simply constructs a legal file name for use in opening a file.

Methods

vFileSelect(vBaseWindow* win)
vFileSelect(vApp* app)
The vFileSelect constructor requires a pointer to a vBaseWindow, which includes all V windows and dialogs, or a pointer to the vApp object. You will usually pass the this to the constructor.
int FileSelect(const char* prompt, char* filename, const int maxLen, char** filterList, int& filterIndex)
int FileSelectSave(const char* prompt, char* filename, const int maxLen, char** filterList, int& filterIndex)
You provide a prompt for the user, such as Open File. The user then uses the dialog to select or set a file name. FileSelect returns True if the user picked the OK button, and False if they used the Cancel button.
The filename will be filled in to the filename buffer of maximum length maxLen. The full path of the file will be included with the file name.
You can also provide a list of filter patterns to filter file extensions. If you don't provide a filter list, the default filter of * will be used. Each item in the filter list can include a list of file extensions separated by blanks. You can provide several filtering options. The first filter in the list will be the default. Only leading * wild cards are supported.
The filterIndex reference parameter is used to track which filter the user selected. After FileSelect returns, filterIndex will be set to the index of the filter list that the user last selected. For the best interface, you should remember this value for the next time you call FileSelect with the same filter list so that the user selected filter will be preserved.
You should use FileSelect to open a new or existing file. If the user is being asked to save a file (usually after picking a Save As menu choice), use the FileSelectSave method. On some platforms, there will be no difference between these two methods (X, for example). On other platforms (Windows, for example), different underlying system provided file dialogs are used. To your program, there will be no difference in functionality.

Example

The following is a simple example of using vFileSelect.

    static char* filter[] =     // define a filter list
      {
        "*",                    // all files
        "*.txt",                // .txt files
        "*.c *.cpp *.h",        // C sources
        0
      };
    static int filterIndex = 0;    // to track filter picked
    char name[100];

    vFileSelect fsel(this);     // instantiate

    int oans = fsel.FileSelect("Open file",name,99,filter,filterIndex);

    vNoticeDialog fsnote(this); // make an instance

    if (oans && *name)
        (void)fsnote.Notice(name);
    else
        (void)fsnote.Notice("No file name input.");