When you have a game open in GD and go to File > Close project, you get a confirmation popup stating that unsaved changes will be lost.
However, if you have a game open and go to File > Open, or File > Create a new project, and proceed through the various popups to open or create a game, you never get the same confirmation popup regarding unsaved changes being lost. This could result in data loss...
For prevent this can we see if the project as be saved before (what function can we use ?) ?
If the project is already saved we display nothing, and if save is not we alert the user ?
That would be ideal in all situations (creating a new project, opening an existing project and closing the current project).
For prevent this can we see if the project as be saved before (what function can we use ?) ?
If the project is already saved we display nothing, and if save is not we alert the user ?
That's the ideal solution.
There is no magic function to do it. Any change has to be saved in a flag "isDirty" in the editor to indicate that the project has some changes that are pending save.
The simplest workaround would be to alert the user when he clicks on "Create a new project" (like it happens with "Close project") but that wouldn't be ideal nor long-term solution 馃
Towards the ideal one, I would suggest implementing a more abstract/global state management between SceneEditor and the rest of the components (ElectronMainMenu for example) so we can have a unsavedChanges state. A tool for that would be Redux and even if I see it as a package dependency, I am not able to find any used instance of it, therefore I do not know if Redux is a desired solution for the Editor.
@4ian What do you think? I could start working on it, setting up a redux store and a "first form" of unsaved changes checking.
The simplest workaround would be to alert the user when he clicks on "Create a new project" (like it happens with "Close project") but that wouldn't be ideal nor long-term solution 馃
I think that would actually be a perfectly ideal long term solution for reducing the risk of people create new project/opening another one and losing their changes. :)
@4ian What do you think? I could start working on it, setting up a redux store and a "first form" of unsaved changes checking.
For the ideal solution, I'm all for doing the work of adding a dirty bit to the project or some state in the React components.
But I don't want to introduce Redux or a global state management in GDevelop. Mainly because as the name implies they are "global" - and nothing in GDevelop must be global. Any component must be able to work by itself - without relying on a store - just by having the proper props being passed. This is a very explicit approach and make navigating in the codebase as easy as looking at the props and searching for component names.
You may argue "sure, but a function to set a dirty flag to true will be used a lot, we should be able to avoid passing it as a prop everywhere". In this exceptional case, it's true that it would be a pain in which case we can use... React contexts :) They are great at doing exactly this: making something accessible without having to pass a prop everywhere - but still be explicit when you need it.
So in short: the ideal solution would be a dirty flag that is set whenever anything is changed - which can be provided thanks to a React context. Probably MainFrame should be responsible for this.
Thank you for your comments!
I will check it out and work on submitting the ideal solution.