1

In a document-based application, any change in a document is signalled by a

[self updateChangeCount: NSChangeDone];

At any time, when debugging, the [document isEdited] returns TRUE, as far as the document has been edited. The doc's window displays "Modified" besides the document's name. When I quit application, my app delegate reviews all opened documents, and check whether they've been edited or not, using this loop:

NSUInteger needsSaving = 0;
while (count--) {
    NSWindow *window = [windows objectAtIndex:count];
    Document *document = [Document documentForWindow:window];
    if (document && [document isDocumentEdited]) needsSaving++;
}

It appears that for any document —modified or not— the [document isDocumentEdited]; always returns FALSE! So that the review change/save process cannot be called. If I check the [window isDocumentEdited], it also returns FALSE despite the fact that "Modified" is written in the title bar of the window.

When the applications quits, the changes are eventually saved (automatically) but without informing the user. This is a very disturbing behaviour!

Any idea of what could explain that the isDocumentEdited boolean is reset to FALSE somewhere before entering this process?

I checked all the code to see if there wasn't any [self updateChangeCount: NSChangeCleared] that could be run somewhere, but it's not the case. I can circumvent the problem using a custom updateChange counting system in my Document subclass, but I would rather use the built-in process.

Using Xcode 10 under Mojave, with a 10.12 target

Denis
  • 775
  • 7
  • 22
  • When, in which method, do you check? – Willeke Nov 16 '18 at 17:03
  • in the applicationShouldTerminate: of the application delegate – Denis Nov 16 '18 at 17:27
  • I noticed that when a change is made in a document, all document windows get the "Modified" entry near window title, even for non modified documents – Denis Nov 16 '18 at 18:00
  • How do you create the documents, window controllers and windows? How is undo implemented? – Willeke Nov 16 '18 at 23:58
  • documents, window controllers and windows are created using IB (new in file menu, the rest created using makeWindowController). I disabled all undo operations to be sure that the undo system is not involved in the problem! I set up a turn around, using a self created flag, and the problem is solved in my app. But I would rather use the built-in system than circumvent it! – Denis Nov 17 '18 at 01:18

1 Answers1

1

isDocumentEdited is documented as a "value that indicates whether the document has unsaved changes". The behaviour might be happening if autosavesInPlace is enabled. There won't be unsaved changes at application quit.

ahooper
  • 46
  • 1
  • 5