Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » FileSel&FileList, Path » How to open a FileSelect widget and select a file?
How to open a FileSelect widget and select a file? [message #2697] Fri, 21 April 2006 22:59 Go to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Now it is time to read the data from a file (and later save them). So the first step is to select one.

Spying in the available code I've found in UWord package some useful code. I copied, without understand, in VegaMain.h
FileSel& UWordFs()
{
	static FileSel fs;
	return fs;
}

and then created the following method:
void VegaMain::OpenTournament()
{
	FileSel& fs = UWordFs();
	fs.ExecuteOpen();
}

that with my great satisfaction open a fileselect widget. Now I've 2 questions:

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 think when I need to save a file the operations to select a filename are the same.

Thank you,
Luigi

[Updated on: Fri, 21 April 2006 23:01]

Report message to a moderator

Re: How to open a FileSelect widget and select a file? [message #2700 is a reply to message #2697] Sat, 22 April 2006 00:45 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
just a clue for the beginning:
	AFs().Type("vec files", "*.vec")
	         .AllFilesType()
	         .DefaultExt("vec");
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 Go to previous message
forlano is currently offline  forlano
Messages: 1182
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

Next Topic: How to determine the file type selected in a FileSel widget? [SOLVED]
Goto Forum:
  


Current Time: Fri Mar 29 00:07:00 CET 2024

Total time taken to generate the page: 0.01139 seconds