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 » Community » Newbie corner » using a file chooser (dir chooser??) to get a dir and not a file
using a file chooser (dir chooser??) to get a dir and not a file [message #32742] Sun, 05 June 2011 11:41 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
How do you choose a directory rather than a file?
I have been using this code to choose a file:
    FileSel fn; 
    void OpenAction() {
		fn.AllFilesType();
		String filename = fn;

		fn <<= Nvl(r_d, recent_dir);
		if(fn.ExecuteOpen()){ // file chooser 
			workdirField<<=Value(fn);
			r_d = fn;
			recent_dir = ~fn;
		}
//    	work.Run(THISBACK(Work));
    }


How can this be done to select a directory?

Is all I want to do is display the path and use that like:
cd C:\0-Neil\FAA\2011\Sectionals

I could parse the String filename but that would require a user to pick a file in that directory rather than just pick a directory. In some apps a directory can be chosen instead of a file.

Is there something built into U++ that can just select a directory??

[Updated on: Sun, 05 June 2011 13:20]

Report message to a moderator

Re: using a file chooser (dir chooser??) to get a dir and not a file [message #32745 is a reply to message #32742] Sun, 05 June 2011 18:34 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Neil,

Quick look into the documentation would reveal to you, that FileSel has method ExecuteSelectDir() Wink It does exactly what you ask for...

Honza
Re: using a file chooser (dir chooser??) to get a dir and not a file [message #32749 is a reply to message #32745] Mon, 06 June 2011 03:24 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Honza

I saw that but it gives no example code of how that is used.

Ecxuse me but I am not sharp enough to decipher this into usable code:
Quote:

bool ExecuteSelectDir(const char *title = NULL)
Executes directory selection dialog. title can specify alternate caption of dialog. If user selects a file to open, returns true.


It looks like it returns a bool of true only if a specified ("file name") exists and not actually choosing a directory

I did a search in the forum for "ExecuteSelectDir" and found threads like this:
http://www.ultimatepp.org/forum/index.php?t=msg&goto=314 13&&srch=ExecuteSelectDir#msg_31413
which had posts that included code like this:
FileSel fs;
fs.ActiveDir("C:/Test");
		
if (!fs.executeselectdir("Ouvrir à partir de ..."))
	return;

String selectedFolder = ~fs;


Trying code similar this there were errors like "it doesn't take 0 parameters".

After searching and trying for several hours I posted for help.

In Java it can be done with this"
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);


Do you have a U++ code example or a link to code I could try?

[Updated on: Mon, 06 June 2011 05:48]

Report message to a moderator

Re: using a file chooser (dir chooser??) to get a dir and not a file [message #32752 is a reply to message #32749] Mon, 06 June 2011 08:17 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

The usage of ExecuteSelectDir() is very similar to ExecuteOpen(). Following code is taken from examples/CompDir, I just added few comments.
void DlgCompareDir::DoBrowse(Ctrl *field)    // field is EditString or similar Ctrl
{
	FileSel fsel;
	fsel.AllFilesType();
	static String recent_dir;                  // variable to store last opened directory
	fsel <<= Nvl((String)~*field, recent_dir); //before opening, we pre-set the dialog to the value in field, fallback to recent_dir if there is Null
	if(fsel.ExecuteSelectDir())                //open the dialog to select directory
		*field <<= recent_dir = ~fsel;     // assign the selected directory 'recent_dir' and also fill it into 'field' Ctrl
}


BTW: I just found there is even simpler way to do this, although not as versatile:
String mydir = SelectDirectory();


Honza
Re: using a file chooser (dir chooser??) to get a dir and not a file [message #32753 is a reply to message #32752] Mon, 06 June 2011 08:42 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Honza

That should be a big help.
Re: using a file chooser (dir chooser??) to get a dir and not a file [message #32755 is a reply to message #32753] Mon, 06 June 2011 10:10 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks again Honza

After doing a search in the upp directory for "SelectDirectory" and looking at the code in:
C:\upp\uppsrc\CtrlLib\FileSelUtil.cpp

A very basic use can be done with just this:
	void SelDir() {workdirField <<= SelectDirectory();}


Works great!
Previous Topic: reading & writing a file
Next Topic: Restricting GridCtrl Selection to just One row
Goto Forum:
  


Current Time: Sun Apr 28 17:39:46 CEST 2024

Total time taken to generate the page: 0.90694 seconds