File changed by other application after saving

  • Hi,

    After saving my untitled file successfully, if I then try to save
    again, the following alert pops up:

    "This document’s file has been changed by another application since
    you opened or saved it."

    ...with the option to save or not save.

    The app is an NSDocument based app whose documents are packages. It
    uses the "Open" dialog to open both its native file format and to open
    PDF documents. To open documents my NSDocument subclass overrides
    readFromURL:ofType:error: which opens PDF documents in the following
    way:

    -uses the passed in pathname as the location from which to read the
    PDF document.
    -sets up any dependencies
    -sets file type to the app's native file type
    -sets file URL to nil
    -issues [self updateChangeCount:NSChangeDone] so that the user can
    save the file. (After all, effectively an untitled file was created
    into which a PDF was automatically imported, which is a change, and
    the user definitely needs to be able to save the file in native format
    without having to resort to Save As)

    The saving is done by
    saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo
    : which detaches a drawingThread to save the file, since saving tends
    to be a rather expensive process. The saving routine does the following:

    -It checks if the directory already exists at the specified saving
    path. If not it creates it. So within the domain of the issue a
    directory is create here.
    -It saves whatever it needs to save (or update) within the save
    directory.
    -If the document's fileURL is nil or not equal to the save path it
    sets the fileURL to the new path.
    -It sets the document's change count to NSChangeCleared.

    At this point an untitled document has been created and the PDF
    document has been successfully imported. The document can now be
    operated upon. When I issue the save command again I get the error
    message quoted above. But no other app _has_ changed the file. I must
    be missing something, but what?

    -António

    ----------------------------------------------------
    There is a world of difference between
    searching for happiness and choosing
    to be happy.
    ----------------------------------------------------
  • On Dec 18, 2007, at 12:49 PM, Antonio Nunes wrote:

    > The saving is done by
    > saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo
    > : which detaches a drawingThread to save the file, since saving
    > tends to be a rather expensive process. The saving routine does the
    > following:
    >
    > -It checks if the directory already exists at the specified saving
    > path. If not it creates it. So within the domain of the issue a
    > directory is create here.
    > -It saves whatever it needs to save (or update) within the save
    > directory.
    > -If the document's fileURL is nil or not equal to the save path it
    > sets the fileURL to the new path.
    > -It sets the document's change count to NSChangeCleared.

    I now discovered what causes the "file changed by other application"
    alert to come up: it's the 3rd step listed bove. Setting the file URL
    after saving. However: if I don't do that then my document remains
    untitled, and won't point to the newly saved file.

    Perhaps I better restate the question:
    I need to save documents separately from the main thread so as to keep
    the UI responsive. What is the correct/recommended way to go about that?

    -António

    -----------------------------------------------------------
    Don't believe everything you think
    -----------------------------------------------------------
previous month december 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