NSDocument, setFileURL:

  • Hi all,

    I've run into a bit of snag using NSDocument. In my implementation,
    I'm editing remote files by downloading them locally, doing the edits,
    and then uploading to overwrite the changes.  The document's fileURL
    is the URL to the local copy of the file.

    This works well with NSDocument (albeit a few leaps in the paradigm
    because some stuff is remote), but the issue I've run into is that
    when the user renames a file remotely, I need to reflect that rename
    locally as well. When I receive notice of the path change, I call
    setFileURL: on the document, informing of it of the new path. The next
    time the user goes to save the document, it pops up a window informing
    the user that the document has been renamed, confirming the details.
    In my implementation, this is certainly not what I want. I require no
    user interaction for this rename --- they requested in the first
    place, remotely.

    Any suggestions?

    -Brian.
  • Hi,

    It seems no one has responded to this, which is typically a good
    indicator that it's an odd problem. And with an odd problem, comes an
    odd solution.

    I'm typically (read: almost always) against using class-dump, using
    private/undocumented methods, etc., but as far as I can tell
    NSDocument is doing its job, and there is no public way of preventing
    it from doing so, which would be necessary in this case. That being
    said:

    class-dump reveals a method, "_resetMoveAndRenameSensing", which,
    unsurprisingly, resets exactly what I need to. A quick subclass of
    setFileURL: in my NSDocument subclass allows me to do have setFileURL:
    do exactly what I need.

    - (void)setFileURL:(NSURL *)absoluteURL
    {
    [super setFileURL:absoluteURL];

    if ([super respondsToSelector:@selector(_resetMoveAndRenameSensing)])
    {
      [super performSelector:@selector(_resetMoveAndRenameSensing)];
    }
    }

    Best,
    Brian Amerige
    <brian...>
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today