Re: Disabling menu items

2017-10-06 Thread Kevin Perry
This should be handled automatically by NSDocumentController’s implementation of -validateUserInterfaceItem: / -validateMenuItem:. Any chance you’re overriding either of those methods and returning YES for menu items you don’t own (instead of calling super)? > On Oct 6, 2017, at 4:13 PM, Shane

Re: Document drafts

2017-03-13 Thread Kevin Perry
Drafts are documents that have been autosaved in a user-visible location (i.e. the app’s iCloud container) and therefore aren’t typical “Untitled” documents from the programmer’s perspective as their fileURL property is not nil. However, they still behave like “Untitled” documents in that they w

Re: Intercept Save when closing NSDocument

2017-02-10 Thread Kevin Perry
NSSavePanelDelegate is probably the approach you want to take, with -[NSDocument prepareSavePanel:] being the most convenient means of inserting your delegate. > On Feb 10, 2017, at 9:41 AM, Quincey Morris > wrote: > > On Feb 10, 2017, at 08:12 , Trygve Inda wrote: >> >> I would like to dis

Re: Does "- replaceItemAtURL: withItemAtURL: backupItemName: options: resultingItemURL: error:" handle cross-volume moves?

2015-03-30 Thread Kevin Perry
> On Mar 30, 2015, at 5:17 PM, Daryle Walker wrote: > >> On Mar 30, 2015, at 7:59 PM, Kevin Perry > <mailto:kpe...@apple.com>> wrote: >> >> -replaceItemAtURL:… relies on the atomicity of the POSIX rename() function >> in order to safely do its ope

Re: Does "- replaceItemAtURL: withItemAtURL: backupItemName: options: resultingItemURL: error:" handle cross-volume moves?

2015-03-30 Thread Kevin Perry
Hi Daryle, -replaceItemAtURL:… relies on the atomicity of the POSIX rename() function in order to safely do its operation. Since rename() doesn’t work across volumes (returning EXDEV), the two URLs must be on the same volume. If you’re using a temporary directory with replaceItemAtURL:…, you wa

Re: NSUserDirectory returns nil

2014-09-25 Thread Kevin Perry
NSUserDirectory refers to the “Users” directory, which exists only in the “System” domain (“/Users"). The “User” domain is the home directory (“~”). The combination of NSUserDirectory and NSUserDomainMask results in a nonsensical and nonexistent path (“~/Users”) so it returns nil/empty instead.

Re: makeDocumentForURL:nil withContentsOfURL:fileURL causing deletion

2014-02-10 Thread Kevin Perry
Using -makeDocumentForURL:nil withContentsOfURL:non-nil was originally designed around the idea of reopening a document that was autosaved into ~/Library/Autosave Information after crash recovery or via the post-Lion "Restore" feature. When such documents are closed without saving, it is desired

Re: NSDocument and KVO compliance

2013-10-18 Thread Kevin Perry
If you wanted to try this, you should also override -updateChangeCountWithToken:forSaveOperation:, which is used to decrement change counts after saving. I expect this would get you 99% of the way, but as Seth said, don't expect it to be bulletproof. On Oct 18, 2013, at 11:49 AM, Seth Willits

Re: Correct usage of NSTextView and NSFindBar

2013-09-23 Thread Kevin Perry
> NSTextStorage instances, one for each file that's being managed, and swap >> those in and out by doing setTextView on the storage instance. So is this >> somehow bypassing the chain of notifications that tells NSTextFinder that >> the string changed? Any way

Re: Correct usage of NSTextView and NSFindBar

2013-09-20 Thread Kevin Perry
On Sep 20, 2013, at 10:00 AM, Martin Hewitson wrote: > Dear list, > > I have an editor app which presents a list of files that can be edited. > Selecting a file displays the text contents in an NSTextView subclass. On > 10.7 and later the app supports using the FindBar. Searching the current

Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file

2013-09-18 Thread Kevin Perry
lock. So in this case a > "File Access" block apparently can't be used. FYI: You can get help discovering the cause of hangs involving performSynchronousFileAccessUsingBlock (and performActivityWithSynchronousWaiting:usingBlock:) by doing 'po _NSDocumentSerializationInfo()&

Re: Unwanted presentedItemDidMoveToURL: for old file after using setFileURL: to specify a new file

2013-09-16 Thread Kevin Perry
Re-using a single NSDocument instance to represent several different files is certainly atypical… But, I suspect the problem here is that you're not using File Coordination when reading in the contents of the new file. By not doing that, you're not giving File Coordination the hint that it need

Re: Find bar in a text view

2013-08-15 Thread Kevin Perry
Sounds like a bug that you should report via Bug Reporter. But as a workaround, you should be able to call -[NSTextView setIncrementalSearchingEnabled:NO] when the subview gets collapsed (then obviously set it back to YES when the text view is uncollapsed, though you will lose search results in

Re: Temporarily disabling autosave

2013-04-25 Thread Kevin Perry
On Apr 25, 2013, at 10:05 AM, Quincey Morris wrote: >> I can't begin to count the number of times I've opened documents, edited >> them in some way, not intending to save those changes. Maybe I just needed >> to, say, find an image in a particular layer of some image editing app, so I >> hid

Re: Autosave directory settable?

2013-04-16 Thread Kevin Perry
That might work, though I would probably recommend overriding at -saveToURL:ofType:forSaveOperation:completionHandler: instead, and only modify the path if saveOperation == NSAutosaveElsewhereOperation. If you override at that level, setAutosavedContentsFileURL: will be invoked for you when the

Re: NSOpenPanel not showing iCloud

2013-04-03 Thread Kevin Perry
At the moment, the only open panel that gets the iCloud treatment is the one created by -[NSDocumentController openDocument:] or -[NSDocumentController beginOpenPanelWithCompletionHandler:]. -KP On Apr 3, 2013, at 8:29 PM, Kurt Sutter wrote: > Dear all > > We are trying to make our applicati

Re: Setting the position of new windows

2013-03-13 Thread Kevin Perry
I think you want to use -setShouldCascadeWindows:NO. On Mar 13, 2013, at 2:20 PM, Steve Mills wrote: > I've spent most of the day researching and coding this, but still don't have > it perfect. I need to position our new document windows so they aren't > covered by palettes that might be visib

Re: Getting file type from Save dlog

2013-01-30 Thread Kevin Perry
On Jan 30, 2013, at 1:27 PM, Steve Mills wrote: > On Jan 30, 2013, at 15:15:32, Kevin Perry > wrote: > >> On Jan 30, 2013, at 12:32 PM, Steve Mills wrote: >> >>> I finally got this all figured out. This is a mess. It's goofy that Apple >>> dec

Re: Getting file type from Save dlog

2013-01-30 Thread Kevin Perry
On Jan 30, 2013, at 12:32 PM, Steve Mills wrote: > On Jan 25, 2013, at 16:42:01, Kevin Perry wrote: > >> If you’re using your own accessory view instead of the built-in one >> (shouldRunSavePanelWithAccessoryView), you’re responsible for changing the >> value of file

Re: Getting file type from Save dlog

2013-01-25 Thread Kevin Perry
If you’re using your own accessory view instead of the built-in one (shouldRunSavePanelWithAccessoryView), you’re responsible for changing the value of fileTypeFromLastRunSavePanel. One way to do this is to make your NSDocument instance the target of the popup button’s action and change an inte

Re: NSMutableData and Pinned Memory buffers..

2012-12-13 Thread Kevin Perry
On Dec 13, 2012, at 4:24 PM, Greg Parker wrote: > On Dec 13, 2012, at 4:13 PM, Robert Monaghan wrote: >> I went ahead and created a really crude subclass of NSMutableData. It seems >> to work for my situation. >> Attached is the code, for posterity. (I am sure I won't be the only one >> worki

Re: NSMutableData and Pinned Memory buffers..

2012-12-13 Thread Kevin Perry
x27;t copy and throws an exception when something tries to change the length. That would violate the Liskov substitution principle though, so at the very least, you want to prevent any code that doesn't understand the fixed-length restriction from getting ahold of one of these objects. [kevi

Re: NSDocument -close called multiple times?

2012-09-21 Thread Kevin Perry
; > On 9/21/12 6:49 PM, Kevin Perry wrote: >> Oh dear. Forget you heard me mention anything about unpublished API. The >> lack of an "_" threw me off... >> >> Yes, you'll probably want to keep your own flag. >> >> -KP >> >> On Se

Re: NSDocument -close called multiple times?

2012-09-21 Thread Kevin Perry
n NSDocument > or NSWindowController, did you mean to say that I'll have to keep a flag > myself? > > Regards > Markus > > On 9/20/12 6:53 PM, Kevin Perry wrote: >> This is an known and unfortunate result of the current architecture of >> NSWindow, NS

Re: NSDocument -close called multiple times?

2012-09-20 Thread Kevin Perry
or -shouldCloseDocument is YES, then this will also -close the document." The best way around this at the moment is to first verify [self isClosed] == NO before calling super and doing your own work. [kevin perry]; On Sep 19, 2012, at 1:06 PM, Markus Spoettl wrote: > Why doe

Re: NSSplitView crash upon restore from 10.8 Versions Browser

2012-08-20 Thread Kevin Perry
Looks like the crash is happening while attempting to invoke -respondsToSelector:. Odds are that this is a message being sent to [self delegate], which looks like a deallocated object. Is it possible that the split view is outliving its delegate? Typically, when a delegate gets deallocated (or

Re: +underPageBackgroundColor

2012-08-06 Thread Kevin Perry
A stab in the dark: Have you tried running with OBJC_PRINT_REPLACED_METHODS set? There's a small chance that you have code in your app or a library that you're linking that replaces via category a method implementation internal to AppKit that +underPageBackgroundColor relies on. Also, it might

Re: Problem enumerating a directory

2012-07-27 Thread Kevin Perry
You should probably try -[NSFileManager enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:]. The errorHandler block will give you more detail about any errors that occur in the middle of the enumeration (and give you the ability to ignore them). -KP On Jul 27, 2012, at 9:44 AM, M

Re: NSDocument -canCloseDocumentWithDelegate::: not called when terminating

2012-07-23 Thread Kevin Perry
On Jul 23, 2012, at 10:51 AM, Markus Spoettl wrote: > On 7/23/12 6:22 PM, Kyle Sluder wrote: >> I don't have my crazy autosave flowchart handy, but I *think* you should be >> able to simply override -hasUnautosavedChanges to return YES if either super >> returns YES or if your preferences file

Re: NSDocument -canCloseDocumentWithDelegate::: not called when terminating

2012-07-23 Thread Kevin Perry
I can't really recommend an approach that essentially lies about the "dirty" state of a document. If you have something to write into the document bundle, then the document is dirty and it should be declared so with the available NSDocument APIs. If the existing APIs don't meet your needs for wh

Re: notification upon restoring a version

2012-06-25 Thread Kevin Perry
-revertToContentsOfURL:ofType:error: (once the version's contents are written in place over the existing file). [kevin perry]; On Jun 25, 2012, at 1:44 PM, qvacua wrote: > Hi, > > are there notifications or delegate methods of NSDocument (or > NSDocumentController) which are called when

Re: NSDocument autosave doesn't show as edited

2012-05-23 Thread Kevin Perry
On May 23, 2012, at 9:43 AM, Martin Hewitson wrote: >> It is indeed -updateChangeCount: that controls the 'Edited' state. You might >> try overriding with a call to super and setting a breakpoint or adding a log >> to make sure it's being called as expected (with NSChangeDone). That should >>

Re: NSDocument autosave doesn't show as edited

2012-05-23 Thread Kevin Perry
Does "Revert to Last Saved" become available after saving and editing? Which NSDocument methods are you overriding? It is indeed -updateChangeCount: that controls the 'Edited' state. You might try overriding with a call to super and setting a breakpoint or adding a log to make sure it's being c

Re: NSDocument app: combine multiple file contents to open one window instead of multiple windows

2012-04-06 Thread Kevin Perry
Unless I'm mistaken, I don't think Gilles is trying to create a "multi-document window" interface like Xcode or Preview. It sounds like he wants a single window with a single view (or set of related views) that simply displays the contents of multiple files in aggregate. If that understanding i

Re: NSTextFinder: endless loops asking for string at index that doesn't exist.

2012-03-28 Thread Kevin Perry
Eric, It's possible that NSTextFinder has a bug, in which case you should file a Radar with a sample app that reproduces the problem. Having that information, it may be possible to identify a workaround. However, first tell me—are you setting the endsWithSearchBoundary parameter to YES for the

Re: NSSplitView-like cursor "grabbing"

2012-03-26 Thread Kevin Perry
It overrides -[NSView hitTest:] to return self for clicks inside the draggable region. -KP On Mar 26, 2012, at 10:30 AM, Markus Spoettl wrote: > Hello all, > > does anyone know how to grab the cursor like NSSplitView does? It somehow > manages to know that the cursor is near a divider when

Re: can't get NSTextFinder to show the find panel

2012-03-23 Thread Kevin Perry
The public NSTextFinder API doesn't provide a way for you to access the old-style find panel. -KP On Mar 23, 2012, at 6:18 AM, Eric Slosser wrote: > I'm trying to use the NSTextFinder object on Lion, from an app whose base SDK > is Tiger. > > I've created an instance of NSTextFinder, called

Re: NSUndoManager w/ Document based app

2012-01-25 Thread Kevin Perry
Hi, If your document class returns YES for +autosavesInPlace (which it hopefully is!), then the dirty dot is no longer used. The dot used to suggest that what was in memory differed from what's currently on disk. With Lion's Autosave feature, the intent is to make it appear to the user that wh

Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)

2011-09-30 Thread Kevin Perry
On Sep 30, 2011, at 8:47 AM, Kevin Perry wrote: > On Sep 29, 2011, at 4:41 PM, Kyle Sluder wrote: > >> [...snip...] >> >> A general issue I have with asynchronous saving: what if the save >> operation fails? The user has now made additional changes, but their >

Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)

2011-09-30 Thread Kevin Perry
ve another question. > > On Thu, Sep 29, 2011 at 12:33 PM, Kevin Perry wrote: >> NSDocument's NSFilePresenter methods use >> performAsynchronousFileAccessUsingBlock: internally, so if something else >> current has file access, the NSFileCoordinator requests are indee

Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)

2011-09-29 Thread Kevin Perry
On Sep 29, 2011, at 12:00 PM, Kyle Sluder wrote: > On Thu, Sep 29, 2011 at 9:20 AM, Kevin Perry wrote: >> If it were to call the fileAccessCompletionHandler any earlier then it might >> be possible, for example, for -fileModificationDate to be invoked on the >&

Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)

2011-09-29 Thread Kevin Perry
The header documentation for -performSynchronousFileAccessUsingBlock: (which also applies to performAsynchronousFileAccessUsingBlock:) says: "this method's primary use is to wait for asynchronous saving, but in contrast with that method it is only for use to wait for the part of an asyn

Re: Duplicating an edited document in 10.7.1

2011-09-20 Thread Kevin Perry
There's a bug in NSDocument in that it doesn't protect itself against nil return values from -fileNameExtensionForType:saveOperation:. To work around, make sure you return a non-nil value from that method. -KP On Sep 20, 2011, at 2:49 AM, Gerriet M. Denkmann wrote: > In my toy editor I open an

Re: Odd error logged when coming back from 'Browse All Versions'

2011-08-24 Thread Kevin Perry
Hi Graham, Right now, Versions doesn't bring back the inspectors automatically, but it may do so in the future. For now, bringing them back manually is the right thing. As for the logging, it's a known OS bug, but is basically harmless. Thanks. On Aug 23, 2011, at 8:08 PM, Graham Cox wrote: >

Re: [SOLVED] Re: printDocument: hangs on Lion?

2011-08-23 Thread Kevin Perry
Whoops, found this too late. See my other reply about the actual cause of the deadlock though. Deprecation warnings are unfortunately only generated when calling a method, not when they are overridden. -KP On Aug 22, 2011, at 8:24 PM, Graham Cox wrote: > > On 23/08/2011, at 1:00 PM, Graham C

Re: printDocument: hangs on Lion?

2011-08-23 Thread Kevin Perry
Hi Graham, First of all, -printShowingPrintPanel: is deprecated. I believe if you were to stop overriding that method and use -printOperationWithSettings:error: and -runModalPrintOperation:delegate:didRunSelector:contextInfo: instead the problem would go away. Otherwise, you've found the crux

Re: printDocument: hangs on Lion?

2011-08-22 Thread Kevin Perry
Graham, This can happen if there is a previous call to -performActivityWithSynchronousWaiting:usingBlock: and the block never calls the completion handler. If you use that method anywhere, please make sure the completion handler always gets called. If you don't use the method directly, other m

Re: Telling Auto Save, "No, I'm busy now"

2011-08-08 Thread Kevin Perry
Ah, I did not foresee this. I really can't generally recommend calling -saveToURL:::error: instead of saveToURL:::completionHandler: because the latter does some important things that the former doesn't. Unfortunately, I think the problem you're seeing with the hang is insurmountable without ad

Re: Telling Auto Save, "No, I'm busy now"

2011-08-04 Thread Kevin Perry
What Ken said. Also, it might be more convenient to use NSBlockOperation or -addOperationWithBlock so the function parameters (including the completion handler) are all captured correctly for you automatically. It's a lot more convenient than stashing things in an NSDictionary. Finally, I miss

Re: Telling Auto Save, "No, I'm busy now"

2011-08-01 Thread Kevin Perry
AppKit-initiated autosaves generally happen for two main reasons: the autosave timer, and file coordination. These are both initiated with -autosaveWithImplicitCancellability:completionHandler:. The "implicitly cancelable" flag indicates whether it's appropriate for an NSDocument subclass to ca

Re: Space-efficient saving for Versions?

2011-07-28 Thread Kevin Perry
The Versions store will do this automatically. It can detect when blocks of a file have been duplicated and avoid storing those blocks on disk. On Jul 28, 2011, at 12:37 AM, Daniel Vollmer wrote: > Salutations, > > in my custom document package I'm always including a large-ish chunk of data >

Re: How to implement Autosaving, Browsing Versions, Reverting to Last Saved in Lion?

2011-07-26 Thread Kevin Perry
There is nothing that you are obviously doing wrong here. Please file a Radar with your test app attached. -KP On Jul 24, 2011, at 7:46 PM, Zorg wrote: > I'm having a difficult time figuring out how to implement these features > correctly in Lion. I've created a very simple NSDocument based te

Re: NSDocument: Read-only types and autosavesInPlace

2011-07-22 Thread Kevin Perry
On Jul 22, 2011, at 9:16 AM, Daniel Vollmer wrote: > Hello, > > I'm trying to add autosavesInPlace support to my NSDocument-based > Application. It supports a read-only type that is internally converted (as > suggested in > https://developer.apple.com/library/mac/documentation/Cocoa/Conceptua

Re: problem with dataWithContentsOfFile on Lion

2011-07-21 Thread Kevin Perry
Please check the NSData.h header and Foundation release notes for Lion. Because mapping files on non-local drives (which may be disconnected or removed at any moment, resulting in a crash if you attempt to access parts of the file that haven't been faulted in) is unsafe, NSData on Lion has chang

Re: Why do I have to initialize NSError ?

2011-03-08 Thread Kevin Perry
This is a bug in the framework. NSError-returning methods should not need to check the value of the dereferenced pointer before setting it. Please file a bug for this. -KP On Mar 8, 2011, at 7:22 AM, Gerriet M. Denkmann wrote: > I thought that NSError is just an output parameter, which is set

Re: NSView setAlphaValue question (Update still not working)

2010-12-17 Thread Kevin Perry
The reason why this isn't working in Leopard is simple: -setAlphaValue: for non-layer-backed views was not implemented until Snow Leopard. The documentation for -setAlphaValue: states: > Sending this message to a view that is not managing a Core Animation layer > causes an exception. I don't

Re: NSPathControl w/ popups and icons

2010-08-09 Thread Kevin Perry
NSPathControl doesn't map submenus in its menu to the individual NSPathComponentCells, so that's not going to work. This will probably require some heavy subclassing of at least NSPathComponentCell, and perhaps NSPathCell (if the layout isn't quite how you need it). You'll need to provide some

Re: Problems with NSPathControl

2010-07-12 Thread Kevin Perry
? > > Dave > > On Jul 12, 2010, at 2:45 PM, Dave DeLong wrote: > >> Fair enough; How can I retrieve which item was clicked? The sender of the >> action is the actual NSPathControl, and -clickedPathComponentCell:, which >> works on 10.6, returns nil on 10.5.

Re: Problems with NSPathControl

2010-07-12 Thread Kevin Perry
Dave, I believe what you're seeing is the intended behavior. There are cases where developers have not wanted the URL to change when an item in the pop-up menu is selected. Instead of doing this automatically and forcing developers to prevent or undo this behavior, NSPathControl instead expects

Re: Finding Application support folder without Cocoa or Carbon

2010-07-12 Thread Kevin Perry
You can use the C API in /usr/include/NSSystemDirectories.h. On Jul 12, 2010, at 1:17 PM, Alexander Cohen wrote: > Hello, > > I need to find the system Application Support folder without using either > Carbon or Cocoa, i can use CoreFoundation though. Is there a way to do this? > > thx > > AC

Re: NSFileManager 'attributesOfItemAtPath:error:' does not traverse a link?

2010-05-28 Thread Kevin Perry
That documentation is incorrect and is scheduled to be corrected. -attribtuesOfItemAtPath:error: will never automatically resolve symlinks, and that will never change. -Kevin Perry On May 28, 2010, at 8:17 AM, Charles Srstka wrote: > On May 28, 2010, at 10:01 AM, Tito Ciuro wrote: >

Re: "Operation could not be completed. No such file or directory"

2010-04-13 Thread Kevin Perry
It's referring to the source path. The documentation specifically states that no file should exist at the destination path. So, one can deduce that NSFileManager wouldn't report a "no such file" error if there was no file there, since that is what is expected. -Kevin On Apr 13, 2010, at 11:31

Re: Attempt to nest an NSCollectionView fails.

2010-03-24 Thread Kevin Perry
use an NSCollectionView. I was thinking the collection view would save me > some work. Appears to not be the case. > > Thanks for the assistance. > > Brian > > - Original Message - > From: "Kevin Perry" > To: "Brian Krisler" > Cc: cocoa-dev@lis

Re: Attempt to nest an NSCollectionView fails.

2010-03-23 Thread Kevin Perry
I'm not sure this is really a usage case that I'd expect to be well tested, since it seems a little out of the ordinary. Anyway, which approach are you using for your prototype view? Is the view in the same nib, or have you factored it out into a separate nib, using the fact that NSCollectionVi

Re: IsReadableFileAtPath

2010-03-01 Thread Kevin Perry
In general, this kind of check-then-do pattern opens the door for file system race conditions. The documentation for this method (and related methods) has a little more information about this in the "Note" section. Could you just try to copy the symlink and then deal with any errors that result