CodeEdit icon indicating copy to clipboard operation
CodeEdit copied to clipboard

[WIP] - Implement option to toggle auto save

Open jevonmao opened this issue 3 years ago • 6 comments

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

Screen Shot 2022-05-18 at 5 13 19 PM

jevonmao avatar May 19 '22 00:05 jevonmao

@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.

jevonmao avatar May 20 '22 21:05 jevonmao

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 avatar May 20 '22 21:05 jevonmao

@jevonmao You might have better luck getting help in our Discord #help channel.

austincondiff avatar May 25 '22 05:05 austincondiff

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.

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.

0xWDG avatar May 25 '22 09:05 0xWDG

Any updates on this?

lukepistrol avatar Jun 10 '22 15:06 lukepistrol

@jevonmao Do you have any updates on this?

0xWDG avatar Jun 22 '22 14:06 0xWDG

This PR is getting stale. Please resubmit a new PR if you ever finish this.

austincondiff avatar Aug 20 '22 03:08 austincondiff