0

I've built a document-based app in Swift for MacOS. Hit Cmd-N (New File) N times, and N document windows are created (and cascaded). So far so good.

So I added a floating Palette window (and WindowController and ViewController, all in the storyboard), and wired up a menu command to call the AppDelegate to build it and show it, which works the first time. I marked it with the .floating window level, and that seems to work too.

But Cmd-N is now causing new copies of the palette window, rather than the frontmost document window underneath the palette window, to be created. The new palette windows are cascaded too, even though my palette window controller is setting the cascade property to false. And being floating, they show up behind the original floating palette window, which apparently takes precedence.

When the palette window shows up, it is the active window. If one clicks on a background Document window, it becomes active, and then Cmd-N works as expected.

What's the best way to direct the Cmd-N event towards making a new document? All this is happening under the hood without any code I've implemented, so where does one get one's hooks into it all?

selbie
  • 100,020
  • 15
  • 103
  • 173
jsbox
  • 304
  • 2
  • 11
  • Your documents should be managed by an `NSDocumentController` and document windows should be owned by `NSDocuments` – Scott Thompson Nov 06 '21 at 00:23
  • Post a [mre] please. – Willeke Nov 06 '21 at 10:16
  • There is no code to post. It's a question about the correct way to manage a floating palette. When it shows up the first time, it is made the frontmost window, and the document window underneath it is deactivated. So the system implements the New File command by duplicating a palette window (wrong!). But if one clicks on the document window underneath the palette window, the document stays behind (correct), it activates, and then New File works correctly. My question is ... What is the "right way" to avoid forcing the user to click on the document window after opening a floating palette? – jsbox Nov 08 '21 at 21:13
  • How can we reproduce the issue? I tried but Command-N always creates a document window, even when the palette window is the active frontmost window. Is it possible to reproduce the issue in a small test project? – Willeke Nov 09 '21 at 15:07

0 Answers0