[WIP] - Implement option to toggle auto save
Description
Added an option to toggle autosave.
Related Issue
- #603
Checklist
- [x] I read and understood the contributing guide as well as the code of conduct
- [x] My changes generate no new warnings
- [x] My code builds and runs on my machine
- [x] I documented my code
- [ ] Review requested
Screenshots
@lilingxi01 I just tested it. It looks like auto save toggle works for a single code file, just not for full projects. I will work on fixing that.
I might need some help here, anyone familiar with NSDocument? I can't figure out why I'm unable to toggle autosave for workspace documents. Autosave still works when autosavesDrafts is set to false, but documentation says setting that to false will disable autosave.
@jevonmao You might have better luck getting help in our Discord #help channel.
I might need some help here, anyone familiar with
NSDocument? I can't figure out why I'm unable to toggle autosave for workspace documents. Autosave still works whenautosavesDraftsis set to false, but documentation says setting that to false will disable autosave.
Hi @jevonmao According to https://developer.apple.com/documentation/appkit/nsdocument/
class var autosavesDrafts: Bool{ get } A Boolean value that indicates whether the document subclass supports autosaving of drafts.
This is a get only property, so unusable to stop autosaving.
Maybe the best option is to use a custom delegate and override the write functions, and decide in those functions if you want to write (autosave) or not. (see: https://developer.apple.com/documentation/appkit/nsdocument )
e.g.
func write(to: URL, ofType: String, for: NSDocument.SaveOperationType, originalContentsURL: URL?) Writes the contents of the document to a file or file package located by a URL.
func save(to: URL, ofType: String, for: NSDocument.SaveOperationType, delegate: Any?, didSave: Selector?, contextInfo: UnsafeMutableRawPointer?) Saves the contents of the document to a file or file package located by a URL, that is formatted to a specified type, for a particular kind of save operation.
func save(to: URL, ofType: String, for: NSDocument.SaveOperationType, completionHandler: (Error?) -> Void) Saves the contents of the document to a file or file package located by a URL, that is formatted to a specified type, for a particular kind of save operation, and invokes the passed-in completion handler.
And using https://developer.apple.com/documentation/appkit/nsdocument/saveoperationtype you can see if it is an auto save action.
Hope this helps you.
Any updates on this?
@jevonmao Do you have any updates on this?
This PR is getting stale. Please resubmit a new PR if you ever finish this.