gaphor / gaphor

Gaphor is the simple modeling tool
https://gaphor.org
1.87k stars 200 forks source link

Add Automatic Save to a Temporary File #2831

Closed alkis05 closed 4 months ago

alkis05 commented 11 months ago

Is your feature request related to a problem?

App crashed and lost a lot of work

Describe the solution you'd like

Of course I could save often, but it wouldn't heart to have a temporary file saved, say, after changing a diagram or something. This could be loaded in case the program closes for some reason before saving. At least offer the option for that. Like there is on text editors and many other tools.

Describe alternatives you've considered

Just remember to save often.

Additional context

Add any other context or screenshots about the feature request here.

amolenaar commented 11 months ago

I've been thinking about this before.

It's a bit hard to do a full save operation: that will take a while for big projects.

Maybe it's an idea to build an event log and register all events that modify the model? We already do that for the undo functionality. If Gaphor crashes, we can replay the event log.

The only uncertainty is what happens if the event log cannot be fully replayed? Should it replay up to the point where it errors?

amolenaar commented 5 months ago

I've been implementing a little service in Gaphor that records all (model) changes.

Doing this adds hardly any overhead and all changes (in case of a crash or abrupt termination of Gaphor) can be replayed (it's re-using undo functionality to some extents).

The idea is that a user doesn't loose any work in case of a failure.

I see three approaches at this point:

  1. On application startup, show to-be recovered sessions in the Greeter window and allow users to recover them, or delete them
  2. When a model is loaded, any unsaved changes are automatically applied.
  3. The application instantly opens with all user sessions, as if nothing happened.

For case 1 I created some screenshots.

image

NB. A delete button is missing on the "recover" rows.

I'm not sure if the difference between Recently Opened and Recover Models is clear. Maybe add them all to Recently Opened and add a note (with unsaved changes) ?

image

@danyeaw What do you think?

danyeaw commented 5 months ago

Hey @amolenaar, I really like your idea to integrate this with the current greeter! You also told me that you thought this might be getting too complex.

Since recovering from a crash should hopefully not be a frequent event, and because users should almost always want what they were working on back, what if we directly open the restored window?

danyeaw commented 4 months ago

@all-contributors please add @alkis05 for idea

allcontributors[bot] commented 4 months ago

@danyeaw

I've put up a pull request to add @alkis05! :tada:

danyeaw commented 4 months ago

Thanks @alkis05 for the enhancement request!

@amolenaar did a fantastic job implementing automatic recovery of unsaved changes, and it will be out in the next feature release soon.