Permalink
Browse files

Add toggle pip button in touch bar.

[Locaization change]
Update zh-Hans & zh-Hant localizations
Need a better icon to better fit touch bar size.
Ref: #1900
  • Loading branch information...
alejx committed Feb 9, 2019
1 parent 6212933 commit fcbb05768c199c51e95cc9bcec93055868babf09
@@ -273,3 +273,4 @@
"touchbar.seek" = "Seek";
"touchbar.time" = "Time Position";
"touchbar.remainingTime" = "Remaining Time";
"touchbar.toggle_pip" = "Toggle Picture-in-Picture";
@@ -35,7 +35,7 @@ fileprivate extension NSTouchBarItem.Identifier {
static let next = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.next")
static let prev = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.prev")
static let exitFullScr = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.exitFullScr")

static let togglePIP = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.togglePIP")
}

// Image name, tag, custom label
@@ -63,13 +63,12 @@ class TouchBarSupport: NSObject, NSTouchBarDelegate {
touchBar.delegate = self
touchBar.customizationIdentifier = .windowBar
touchBar.defaultItemIdentifiers = [.playPause, .time, .slider, .remainingTime]
touchBar.customizationAllowedItemIdentifiers = [.playPause, .slider, .volumeUp, .volumeDown, .rewind, .fastForward, .time, .remainingTime, .ahead15Sec, .ahead30Sec, .back15Sec, .back30Sec, .next, .prev, .fixedSpaceLarge]
touchBar.customizationAllowedItemIdentifiers = [.playPause, .slider, .volumeUp, .volumeDown, .rewind, .fastForward, .time, .remainingTime, .ahead15Sec, .ahead30Sec, .back15Sec, .back30Sec, .next, .prev, .togglePIP, .fixedSpaceLarge]
return touchBar
}()

weak var touchBarPlaySlider: TouchBarPlaySlider?
weak var touchBarPlayPauseBtn: NSButton?
weak var touchBarExitFullScr: NSButton?
var touchBarPosLabels: [DurationDisplayTextField] = []
var touchBarPosLabelWidthLayout: NSLayoutConstraint?
/** The current/remaining time label in Touch Bar. */
@@ -151,7 +150,13 @@ class TouchBarSupport: NSObject, NSTouchBarDelegate {
case .exitFullScr:
let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(image: NSImage(named: NSImage.touchBarExitFullScreenTemplateName)!, target: self, action: #selector(self.touchBarExitFullScrAction(_:)))
self.touchBarExitFullScr = item.view as? NSButton
return item

case .togglePIP:
let item = NSCustomTouchBarItem(identifier: identifier)
// FIXME: we might need a better icon for this
item.view = NSButton(image: Bundle.main.image(forResource: "pip")!, target: self, action: #selector(self.touchBarTogglePIP(_:)))
item.customizationLabel = NSLocalizedString("touchbar.toggle_pip", comment: "Toggle PIP")
return item

default:
@@ -198,6 +203,10 @@ class TouchBarSupport: NSObject, NSTouchBarDelegate {
player.mainWindow.toggleWindowFullScreen()
}

@objc func touchBarTogglePIP(_ sender: NSButton) {
player.mainWindow.menuTogglePIP(.dummy)
}

private func buttonTouchBarItem(withIdentifier identifier: NSTouchBarItem.Identifier, imageName: NSImage.Name, tag: Int, customLabel: String, action: Selector) -> NSCustomTouchBarItem {
let item = NSCustomTouchBarItem(identifier: identifier)
let button = NSButton(image: NSImage(named: imageName)!, target: self, action: action)
@@ -217,4 +217,5 @@
"touchbar.rewind" = "快退";
"touchbar.seek" = "进度条";
"touchbar.time" = "播放进度";
"touchbar.toggle_pip" = "切换「画中画」模式";
"track.none" = "<无>";
@@ -217,4 +217,5 @@
"touchbar.rewind" = "快退";
"touchbar.seek" = "進度列";
"touchbar.time" = "播放進度";
"touchbar.toggle_pip" = "切換「畫中畫」模式";
"track.none" = "<無>";

0 comments on commit fcbb057

Please sign in to comment.