Page 1 of 1

wxFileDialog in wxCrafter

Posted: Sat Sep 14, 2013 2:05 am
by musictreeAstro
I'd like to implement a simple wxFileDialog in wxCrafter where the user can go to File | New and be greeted with a dialog where they can choose to open a file. It would be nice to see Common Dialogs in wxCrafter if they aren't already there. How do others handle this type of event?

I could create a dialog and put a wxFilePickerCtrl in it, but I was hoping there was a faster way.

Re: wxFileDialog in wxCrafter

Posted: Sat Sep 14, 2013 9:40 am
by eranif
musictreeAstro wrote:I'd like to implement a simple wxFileDialog in wxCrafter where the user can go to File | New and be greeted with a dialog where they can choose to open a file. It would be nice to see Common Dialogs in wxCrafter if they aren't already there. How do others handle this type of event?

I could create a dialog and put a wxFilePickerCtrl in it, but I was hoping there was a faster way.
I never had to design such a dialog before since wxWidgets provide you with a simpler way:

In your frame class, at the OnFileNew handler, add this code:

Code: Select all

#include <wx/filedlg.h>
...

void MyFrame::OnFileNew( wxCommandEvent& event )
{
	wxUnusedVar(event);
	wxString new_path = ::wxFileSelector(_("Select a file:"));
	if ( new_path.IsEmpty() ) {
		// do something with the file
	}
}
See this for full description:
http://docs.wxwidgets.org/2.9.5/group__ ... 86b01928bf

Eran

Re: wxFileDialog in wxCrafter

Posted: Sat Sep 14, 2013 11:24 pm
by musictreeAstro
Thanks! That's exactly what I was looking for. I'm new to wxWidgets (and designing GUIs) and hadn't come across wxFileSelector yet.

Forrest