Add "New Tab" menu item

This commit is contained in:
1024jp 2016-08-12 19:29:24 +09:00
parent 1a61b573ed
commit 0eeb0a44a9
7 changed files with 71 additions and 4 deletions

View File

@ -7,6 +7,7 @@ develop
### New Features
- Support window tabbing on macOS Sierra.
- Display recent used syntax styles at the top of the toolbar syntax style popup list.
- Add indivisual “Block Comment”, “Inline Comment” and “Uncomment” actions in Text menu unlike the “Comment Selection” action changes its behavior intelligently.

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11185.3" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11191" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11185.3"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11191"/>
</dependencies>
<scenes>
<!--Application-->
@ -71,6 +71,16 @@
<action selector="newDocument:" target="Ady-hI-5gd" id="82J-OW-zaP"/>
</connections>
</menuItem>
<menuItem title="New Tab" keyEquivalent="t" id="WCp-4v-OPR">
<connections>
<action selector="newDocumentAsTab:" target="Ady-hI-5gd" id="S8W-T4-6Jr"/>
<binding destination="Voe-Tx-rLC" name="hidden" keyPath="supportsWindowTabbing" id="oPe-r3-ZV7">
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
</dictionary>
</binding>
</connections>
</menuItem>
<menuItem title="Open…" keyEquivalent="o" id="72">
<connections>
<action selector="openDocument:" target="Ady-hI-5gd" id="hxD-kB-kqu"/>
@ -415,7 +425,8 @@
<menuItem isSeparatorItem="YES" id="748">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
<menuItem title="Set Editors Opacity…" keyEquivalent="T" id="367">
<menuItem title="Set Editors Opacity…" id="367">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showOpacityPanel:" target="Ady-hI-5gd" id="Mop-i1-1f6"/>
</connections>
@ -478,7 +489,8 @@
<menuItem title="Font" id="410">
<menu key="submenu" title="Font" systemMenu="font" id="418">
<items>
<menuItem title="Show Fonts" keyEquivalent="t" id="424">
<menuItem title="Show Fonts" id="424">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontFontPanel:" target="1Vq-aI-bgB" id="ClI-kR-koM"/>
</connections>

View File

@ -112,6 +112,8 @@ final class AppDelegate: NSResponder, NSApplicationDelegate {
private var didFinishLaunching = false
private lazy var acknowledgementsWindowController = WebDocumentWindowController(documentName: "Acknowledgements")!
private dynamic let supportsWindowTabbing: Bool
@IBOutlet private weak var encodingsMenu: NSMenu?
@IBOutlet private weak var syntaxStylesMenu: NSMenu?
@IBOutlet private weak var themesMenu: NSMenu?
@ -123,6 +125,13 @@ final class AppDelegate: NSResponder, NSApplicationDelegate {
override init() {
// add tab window
if #available(macOS 10.12, *) {
self.supportsWindowTabbing = true
} else {
self.supportsWindowTabbing = false
}
// register default setting values
var defaults: [String: AnyObject] = [:]
for (key, value) in DefaultSettings {

View File

@ -164,6 +164,21 @@ final class DocumentController: NSDocumentController {
}
/// return enability of actions
override func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
guard let action = item.action else { return false }
if #available(OSX 10.12, *) {
if action == #selector(newDocumentAsTab) {
return self.currentDocument != nil
}
}
return true
}
// MARK: Public Methods
@ -191,6 +206,30 @@ final class DocumentController: NSDocumentController {
}
/// open a new document as tab in the existing frontmost window
@available(macOS 10.12, *)
@IBAction func newDocumentAsTab(_ sender: AnyObject?) {
guard let frontmostWindow = self.currentDocument?.windowControllers.first?.window else {
return self.newDocument(sender)
}
let document: NSDocument
do {
document = try self.openUntitledDocumentAndDisplay(false)
} catch let error {
self.presentError(error)
return
}
document.makeWindowControllers()
guard let documentWindow = document.windowControllers.first?.window else { return }
frontmostWindow.addTabbedWindow(documentWindow, ordered: .above)
document.showWindows() // bring to the frontmost
}
// MARK: Private Methods

View File

@ -73,6 +73,8 @@
/* Class = "NSMenuItem"; title = "New"; ObjectID = "82"; */
"82.title" = "Neu";
/* Class = "NSMenuItem"; title = "New Tab"; ObjectID = "WCp-4v-OPR"; */
"WCp-4v-OPR.title" = "Neues Tab";
/* Class = "NSMenuItem"; title = "Open…"; ObjectID = "72"; */
"72.title" = "Öffnen …";
/* Class = "NSMenuItem"; title = "Open Hidden…"; ObjectID = "688"; */

View File

@ -73,6 +73,8 @@
/* Class = "NSMenuItem"; title = "New"; ObjectID = "82"; */
"82.title" = "新規";
/* Class = "NSMenuItem"; title = "New Tab"; ObjectID = "WCp-4v-OPR"; */
"WCp-4v-OPR.title" = "新規タブ";
/* Class = "NSMenuItem"; title = "Open…"; ObjectID = "72"; */
"72.title" = "開く...";
/* Class = "NSMenuItem"; title = "Open Hidden…"; ObjectID = "688"; */

View File

@ -74,6 +74,8 @@
/* Class = "NSMenuItem"; title = "New"; ObjectID = "82"; */
"82.title" = "新建";
/* Class = "NSMenuItem"; title = "New Tab"; ObjectID = "WCp-4v-OPR"; */
"WCp-4v-OPR.title" = "New Tab";
/* Class = "NSMenuItem"; title = "Open…"; ObjectID = "72"; */
"72.title" = "打开…";
/* Class = "NSMenuItem"; title = "Open Hidden…"; ObjectID = "688"; */