3

I am doing a simple document based application. I've implemented readFromData and dataOfType function. Creating a newDocument and saveDocument are working. However, the question is how to set up save notification when user clicks Close. I add some data in my application and when I click close, it just directly close. There is no save notification. I think it was supposed to have it in document based application.

I tried windowWillClose:(NSNotification*)a, having an alertsheet. The alert comes and window closes immediately.

What I am missing?

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140

2 Answers2

2

Use NSDocument -updateChangeCount: method to track changes in your document. Like :

// add some data to theDocument
[theDocument updateChangeCount:NSChangeDone];

But just read the documentation, you may not need to update change count yourself, if you use default document undo manager.

Cheers

Emmanuel
  • 2,897
  • 1
  • 14
  • 15
1

Implement this kind of logic, and you will be done.

- (BOOL)isDocumentEdited{
        if (somethingGotChanged){
            return YES;
        }
        else{
            return NO;
        }
        //or return somethingGotChanged; //*** make somethingGotChanged BOOL
    }

Here, somethingGotChanged is a flag, which you have to set based on you editing on the data.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140