2

Is there a way I can I know if a document is locked or not? (I mean the string that appears in the title bar of a document based app in Cocoa, see picture)

I've been trying with -[NSDocument isInViewingMode] but it always returns NO :( and been reading this thread without much success so far ...

enter image description here

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
nacho4d
  • 43,720
  • 45
  • 157
  • 240
  • What do you plan to do next with this information? – Mike Abdullah Jun 25 '12 at 23:39
  • I want to make a custom window and I need to know this to show this info correctly :) – nacho4d Jun 26 '12 at 01:50
  • 1
    [See this post about how to implement document.isLocked for earlier versions of OS X than 10.8.][1] [1]: http://stackoverflow.com/questions/12059241/nsdocument-islocked-implementation-for-10-7 – Yoav Aug 22 '12 at 19:15

1 Answers1

2

To my understanding, there are three cases to check for:

  • The doc has been locked by the user, which can be retrieved from the URL or file manager
  • The location of the document isn't writable: perhaps it's a read-only file system, or the user doesn't have permission
  • the doc is old enough that the system thinks the user probably doesn't actually want to edit it

The first two you have to check for yourself. But the latter can be achieved by calling -checkAutosavingSafetyAndReturnError:

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75