Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Sephiroth on November 27, 2023, 12:36:00 am

Title: Using a file dialog with wxSmith?
Post by: Sephiroth on November 27, 2023, 12:36:00 am
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?
Title: Re: Using a file dialog with wxSmith?
Post by: Commaster on November 27, 2023, 07:47:11 am
I hope this helps https://docs.wxwidgets.org/3.2/classwx_file_dialog.html
Title: Re: Using a file dialog with wxSmith?
Post by: Miguel Gimenez on November 27, 2023, 09:23:20 am
wxSmith creates an object called FileDialog1, you can change the name. Use something like this in your menu event:
Code
  FileDialog1->SetDirectory(initialDirectory);
  if (FileDialog1->ShowModal() == wxID_OK)
    OpenFile(FileDialog1->GetPath());
EDIT: Fixed object name
Title: Re: Using a file dialog with wxSmith?
Post by: Sephiroth on November 27, 2023, 06:34:04 pm
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.
Title: Re: Using a file dialog with wxSmith?
Post by: Miguel Gimenez on November 27, 2023, 06:40:21 pm
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).