title: Use NSPanel for user input. Not opening up again
body: <p>I want to display a 'NSPanel' for the user to input a name for a new folder. Why a NSPanel? Because it looks awesome! It hosts one TextField and one PushButton to confirm the name. It shall also close the window when clicked. </p>
  
  <p><a href="https://i.stack.imgur.com/d7cP9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d7cP9.png" alt="enter image description here"></a></p>
  
  <p>It displays when the "add" button gets clicked in my menu. It also closes when the "done" button gets clicked in the <code>NSPanel</code>. But when I click "add" again it doesn't show up anymore. That also occurs when I close it via the normal "close button" in the title bar. So it is not explicitly related to the "done"-PushButton. I also tested implementing <code>func windowWillClose(notification: NSNotification)</code> which also doesn't get triggered in either cases. What could be the problem? Also, does it somehow need to be a "new" window every time? Or am I using this correctly for user input? I mean it just gets instantiated once and then "shown" and "unshown" or am I wrong?</p>
  
  <p>So I did a new Cocoa-Class - Subclass of <code>NSWindowController</code> - and let xCode create a .xib for that also. In that .xib I "designed" the <code>NSPanel</code>. I ticked <code>visible at launch</code> without that the window wouldn't appear when the menu button gets clicked. I also hooked up an <code>IBOutlet</code> for the <code>NSPanel</code>in my Cocoa Class. My Class at the moment looks like this:</p>
  
  <pre><code>import Cocoa
  
  class NamingHUD: NSWindowController, NSWindowDelegate {
      @IBOutlet var insertNameWindow: NSPanel!
      @IBOutlet weak var nameTextField: NSTextField!
      override var windowNibName : String! {
          return "NamingHUD"
      }
      override func windowDidLoad() {
          super.windowDidLoad()
  
          insertNameWindow.center()
          insertNameWindow.makeKeyAndOrderFront(nil)
          NSApp.activateIgnoringOtherApps(true)
      }
      @IBAction func userSetName(sender: NSButton) {
          print("Close button clicked")
          insertNameWindow.close()
      }
  }
  </code></pre>
  
  <p>In my Main Class I declared it as a variable like this: </p>
  
  <pre><code>var namingHUD:NamingHUD!
  </code></pre>
  
  <p>and then in <code>override func awakeFromNib()</code> as: </p>
  
  <pre><code>namingHUD = NamingHUD()
  </code></pre>
  
  <p>as well as in a click handler like: </p>
  
  <pre><code> @IBAction func addClicked(sender: NSMenuItem) {
          namingHUD.showWindow(nil)
      }
  </code></pre>
  
  <p>Now. When I click and <code>addClicked()</code> gets called the window shows up as expected. Fine! I enter a name and hit the "done" button and it closes the window properly. Also Fine! But when I click again, say to add another folder, the window doesn't show up anymore. I also created a Preferences Window the exact same way. But with a Window instead of a NSPanel inside. That totally works as it should.</p>
  
  <p>So I clearly confused something or forget something. What could it be? I openly admit that it is the first time I am working with any kind of window outside of following a tutorial. So I clearly didn't grasp the whole concept of it. I read up about windows in Apples Developer Guide and it kinda makes sense. But... well, doesn't work at the moment. Am I "misusing" the <code>NSPanel</code>? Shouldn't be the case as it inherits from <code>NSWindow</code> or?</p>