1

In macOS 10.12 there is a new tab bar that is added to NSWindows for NSDocument apps. You can prevent the toolbar from appearing (see How do I disable the Show Tab Bar menu option in Sierra apps?). But how to remove the "+" button for adding new Windows?

Community
  • 1
  • 1
Henrik
  • 3,908
  • 27
  • 48

4 Answers4

7

According to the AppKit release notes, returning false for responding newWindowForTab(_:) action message in a NSDocumentController subclass disables "+" button in the tab bar.

override func responds(to aSelector: Selector!) -> Bool {

    if #available(OSX 10.12, *) {
        if aSelector == #selector(NSResponder.newWindowForTab(_:)) {
            return false
        }
    }

    return super.responds(to: aSelector)
}

See "New Button" section in the AppKit Release Notes for macOS 10.12.

Dalzhim
  • 1,970
  • 1
  • 17
  • 34
1024jp
  • 2,058
  • 1
  • 16
  • 25
1

Depends of your Application functionality you may subclass NSDocumentController and return empty array for documentClassNames property.

class MyDocumentController: NSDocumentController {

   override var documentClassNames: [String] {
      return [] // This will disable "+" plus button in NSWindow tab bar.
   }
}

Here is a documentation of the documentClassNames property:

documentClassNames
An array of strings representing the custom document classes supported by this app.

The items in the array are NSString objects, each of which represents the name of a document subclasses supported by the app. The document class names are derived from the app’s Info.plist. You can override this property and use it to return the names of document classes that are dynamically loaded from plugins.

Source

And here is explanation how documentClassNames property affects NSWindow tab bar plus button appearance:

New Button

The plus button will be shown if newWindowForTab: is implemented in the responder chain. NSDocumentController informally implements newWindowForTab:, but only returns YES from respondsToSelector: for this selector if the self.documentClassNames.count > 0 and if the app has a default new document type. In other words, it only responds to it if NSDocument has at least one registered document class name which can be edited.

Source

Vlad
  • 6,402
  • 1
  • 60
  • 74
-1

Just set ‘Tabbing Mode’ to Disallowed in Interface Builder for your NSWindow.

Screenshot of Interface Builder with Tabbing Mode set to Disallowed for a Window

Aral Balkan
  • 5,981
  • 3
  • 21
  • 24
-1

Change this

@IBAction override func newWindowForTab(_ sender: Any?) {}

into this

@IBAction func myButton(_ sender: Any?) {}

This will hide the plus button. The tabbing still works