Home » U++ Library support » FileSel&FileList, Path » How to open a FileSelect widget and select a file?
Re: How to open a FileSelect widget and select a file? [message #2715 is a reply to message #2697] |
Sat, 22 April 2006 15:35 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
forlano wrote on Fri, 21 April 2006 22:59 |
1. What have I done? (I do not understand the logic of the first operation... FileSel& UWordFs()...
2. How can I get the selected file, the directory in which it resides, and set a filter? (For example I want to show in the dialog only the file *.txt and *.qtf)
|
I've investigated the source code of TheIDE and after many experiments I can answer to question 2.
// open a file
void OpenFileSelect()
{ // FileSelector fs;
String fn;
FileSel fs;
fs.Type( "Files (text, cpp)", "*.txt;*.cpp").DefaultExt("bmp").ExecuteOpen();
fn = ~fs; // fn contains the file name
if( fn != Null) PromptOK(NFormat(t_("opening file [* \1%s\1]. Continue?"), fn));
else PromptOK( "no file :-(");
}
I noticed that if I use
FileSelector fs;
instead of
FileSel fs;
appear the filedialog of Windows. I couldn't find the equivalent one for the directory.
// choose a directory
void ChooseDirectory()
{ String directory;
FileSel fs;
fs.ExecuteSelectDir();
directory = ~fs;
if ( directory != Null) PromptOK(NFormat(t_("Selected [* \1%s\1] directory"), directory));
else PromptOK( "no directory selected");
}
//Save as dialog
void SaveAsDialog()
{ String filename;
FileSel fs;
fs.Type( "File bitmap", "").DefaultExt("bmp").ExecuteSaveAs("Save as...");
filename= ~fs;
if ( filename!= Null) PromptOK(NFormat(t_("Selected [* \1%s\1] as filename"), filename));
else PromptOK( "no filename selected");
}
These code snippet are very common in an application. I think they should appear in the documentation very soon to show how it is easy to work with such dialog.
Luigi
[Updated on: Sat, 22 April 2006 21:31] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 04 14:07:39 CEST 2024
Total time taken to generate the page: 0.02836 seconds
|