I create an rfd::FileDialog object, and then clone it to load from / save to a file. Using it to load works fine. Using it to save, if I enter a new filename to save to, it works fine. But if I select an existing file, and then hit the save button, the file name is highlighted, but then everything seems to hang. Am I misunderstanding rfd::FileDialog.save_file()?
what operating system are you using? are you seeing some confirmation/warning dialog popping up, saying something along the lines about "are you sure you want to overwrite existing file"? this is the typical behavior of the save file dialog on most desktop platforms.
I am running the program on Windows (which is also where I am doing the development). Using iced for UI. Using rfd for a file dialog. If it is trying to pop up an alert, that alert must be hiding behind the file selection dialog, which I can't move once I have tried to select a file to replace. (I have code, if I can get that far, which will first move the existing file.)
Yours,
Joel
if you didn't see the popup, there are two possibilities:
the alert did pop up, but it was hidden under other windows or dialogs. if so, try use keyboard shortcut to focus it or move it;
the alert didn't pop up for some reason, if so, maybe it's something to do with the modal dialog blocking the main event loop, or something similar.
since you mentioned iced, are you calling save_file() in the main thread, e.g. from the iced message handler? I'm not a Windows expert, but is it possible to open the save file dialog from another thread? or maybe you can somehow integrate the file dialog with the main iced event loop?
I am calling the rfd FileDialog save_file method from my iced update method. I am not using any asynch / threading in any part of the program, and using the synchronous rfd method. If there are keyboard shortcuts to get to or clear an alert, I have no idea what they are. And I can't very well expect someone else using the program to know them.
Thank you for the pointer to the example. I would prefer not to use the aynch methods since during the load or save, I don't want the user doing anything else. Is there something intrinsic in the save_file that makes it advantageous to use the asynch methods? (I do need to learn the various asynch techniques. I just don't want to burden this program with that. If there is some important advantage to asynch file interaction, I can od it.)
Yours,
Joel
The sync methods essentially block the GUI thread, so they won't work. At least when I tried the sync methods on Linux, I'd get a pop up saying that the window has become unresponsive and would I like to close it.
You can set a flag in your app state when the file dialog is open (like in the example I linked), and you can use that flag to conditionally disable interaction with the rest of the app. If you want to literally block everything, you can stack an opaque widget on top of your UI to block interactions.
Edit: the modal example implements a modal using those widgets, whereby background interaction is blocked whilst a modal is open. You can also use a semi-transluscent black container on top of the UI to give the effect of dimming it.
To clarify, the async-ness of the file dialog is not being used for the benefit of the user to allow them to do stuff whilst the file dialog is open, but it's used in order to not block the GUI itself.
If I understand, the problem is that the save_file dialog is trying to ask something, but because I used the synch approach, it can't display it's dialog? Even though those dialog messages apparently won't bo through my update method? If that is so, how do I block all of my activities while allowing the asynch to complete properly. I don't want to go through all of my update branches and add checks for an active background operation.
Thanks.
I'm not 100% sure what is going wrong in your specific case; I haven't tried it myself on Windows and the sync API is not the one to use.
As far as I have understood the issue, the two examples I linked show exactly how to use rfd and how to conditionally display a message whilst blocking interaction with the rest of your app (I.e. a modal that you can display whilst the file dialog is open).
Edit: sorry I keep editing, so you may have missed that I added a link to the modal example above
I had read your reply before you added the modal. I am not sure how I use that modal approach with rfd. I am also not sure I understand how modal works, except that I think it displays the content without enabling any interaction. I have multiple view methods (one primary, which calls the others based on the state. Constructing an opaque version of them seems tricky. I suppose that I could jus tuse the async and hope things are fast enough that the user can't make a mess. But that seems a bad design.
I do wish that something (rfd? iced? Had a warning about using synchronous rfd with iced.