wxFileDialog in wxCrafter

Post here wxCrafter related issues / features / bugs
musictreeAstro
CodeLite Curious
Posts: 7
Joined: Sat Sep 14, 2013 1:50 am
Genuine User: Yes
IDE Question: C++
Contact:

wxFileDialog in wxCrafter

Post 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.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: wxFileDialog in wxCrafter

Post 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
Make sure you have read the HOW TO POST thread
musictreeAstro
CodeLite Curious
Posts: 7
Joined: Sat Sep 14, 2013 1:50 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: wxFileDialog in wxCrafter

Post 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
Post Reply