0

I have an application, which is primarily for presenting documents but can under certain circumstances also change the presented document. That's why my app isn't a real document based app.

Nevertheless I want to display the "— Edited" additive to my window title, when the document has been edited and the changes weren't saved yet.

Therefore I have to methods in my AppDelegate

@objc func didEditDocument(_ notification: Notification) {
    myMainWindow.windowController?.setDocumentEdited(true)
}


@objc func didSaveDocument(_ notification: Notification) {
    myMainWindow.windowController?.setDocumentEdited(false)
}

I was expecting my window title to change from MyWindow to MyWindow — Edited after calling .setDocumentEdited(true), but that didn't happen. But the dot in the red close button changes. What am I doing wrong?

Codey
  • 1,131
  • 2
  • 15
  • 34

1 Answers1

1

What am I doing wrong

Nothing. When you rejected the NSDocument architecture, you rejected the automatic "Edited" title change along with a lot of other automatic crunchy goodness. Nothing wrong with that, but then you can't complain when the crunchy goodness is missing. If you want the title changed, you'll have to change it yourself.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Ok but I thought it would be wrong to use the document based app, since my app is only for displaying one document at a time? I thought when you use a document based app, you need to be able to display multiple document windows? – Codey May 15 '20 at 18:11
  • And how come that the close button changes? Is that something that is provided but the window title is not? – Codey May 15 '20 at 18:14
  • Yeah, you're just passing thru the undo manager, which is a separate mechanism (which the NSDocument architecture uses too). – matt May 15 '20 at 18:21
  • Ok, I think all of that is too overkill for my purpose. I will stick to you suggestion to change the window title myself. Thanks for you help! – Codey May 15 '20 at 18:23
  • OK you've asked a more penetrating question, which is, should you be using the document architecture? I kind of think yes. If you can open and save documents, even if it's only one at a time, I think that's the document architecture and then you can tweak it to make it impossible to open more than one at once...? – matt May 15 '20 at 18:23
  • That way you get the Recent Documents menu etc. Ability to rename documents from menu bar too I think... – matt May 15 '20 at 18:23
  • The more than one option isn't needed for my app, because you can only present one document at a time :) I've already implemented the recent documents menu myself. But if I wanted to add document based to my existing project, can you recommend a good starting point/tutorial how to do that. I only know the option to choose when creating a new project – Codey May 15 '20 at 18:25