News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Using a file dialog with wxSmith?

Started by Sephiroth, November 27, 2023, 12:36:00 AM

Previous topic - Next topic

Sephiroth

I'm new to wxSmith so this is probably me missing something, but I need some guidance. I've got a basic app laid out and working, but now I need to be able to open and save files. In Windows (and X) I had an "OpenFileDialog" I could use. I assume wxWidgets has one of these but I am not sure how to find it. I've got a menu entry setup and functioning for bringing up said dialog, but where is it? How can I get an OFD to open a file so I can read or edit it?


Miguel Gimenez

#2
wxSmith creates an object called FileDialog1, you can change the name. Use something like this in your menu event:

  FileDialog1->SetDirectory(initialDirectory);
  if (FileDialog1->ShowModal() == wxID_OK)
    OpenFile(FileDialog1->GetPath());

EDIT: Fixed object name

Sephiroth

#3
I am not seeing "wxFileDialog" on the completion popup in CB, so I am not sure but I do not believe it is working for me. I saw the information linked by Commaster, but again, it does not appear to show up in the auto-complete list so I assumed it wasn't working and I was messing up. Will try regardless this afternoon. Thank you both!

*UPDATE*

I had a typo in the header and it was not including the wx/filedlg.h header. So it WAS me! Thanks for the help, I got it from here.

Miguel Gimenez

You said you are using wxsmith. Did you add a wxFileDialog to your frame/dialog?.

If you want to add one, open wxSmith, go to the Dialogs tab and select wxFilleDialog (the third from the left).