Rename "Un-zoom" to "Reset Zoom" and add tooltips

This commit is contained in:
Pete Schaffner
2024-02-25 12:40:43 +01:00
parent 447310425d
commit 55621c214c
2 changed files with 29 additions and 25 deletions

View File

@@ -52,8 +52,8 @@ class TerminalToolbar: NSToolbar, NSToolbarDelegate {
item.maxSize = NSSize(width: 1024, height: self.titleTextField.intrinsicContentSize.height)
item.isEnabled = true
case .unZoom:
item = NSToolbarItem(itemIdentifier: .unZoom)
case .resetZoom:
item = NSToolbarItem(itemIdentifier: .resetZoom)
let view = NSView(frame: NSRect(x: 0, y: 0, width: 20, height: 20))
view.translatesAutoresizingMaskIntoConstraints = false
@@ -67,6 +67,8 @@ class TerminalToolbar: NSToolbar, NSToolbarDelegate {
button.contentTintColor = .controlAccentColor
button.state = .on
button.imageScaling = .scaleProportionallyUpOrDown
button.allowsExpansionToolTips = true
button.toolTip = "Reset Zoom"
view.addSubview(button)
item.view = view
@@ -78,7 +80,7 @@ class TerminalToolbar: NSToolbar, NSToolbarDelegate {
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.titleText, .flexibleSpace, .space, .unZoom]
return [.titleText, .flexibleSpace, .space, .resetZoom]
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
@@ -87,9 +89,9 @@ class TerminalToolbar: NSToolbar, NSToolbarDelegate {
// built-in spacers plus the un-zoom button item seems to exactly match the space
// on the left that's reserved for the window buttons.
if hasTitle {
return [.titleText, .flexibleSpace, .space, .space, .unZoom]
return [.titleText, .flexibleSpace, .space, .space, .resetZoom]
} else {
return [.flexibleSpace, .unZoom]
return [.flexibleSpace, .resetZoom]
}
}
}
@@ -111,6 +113,6 @@ fileprivate class CenteredDynamicLabel: NSTextField {
}
extension NSToolbarItem.Identifier {
static let unZoom = NSToolbarItem.Identifier("UnZoom")
static let resetZoom = NSToolbarItem.Identifier("ResetZoom")
static let titleText = NSToolbarItem.Identifier("TitleText")
}

View File

@@ -15,14 +15,14 @@ class TerminalWindow: NSWindow {
}
}
private var unZoomToolbarButton: NSButton? {
guard let button = toolbar?.items.first(where: { $0.itemIdentifier == .unZoom })?.view?.subviews.first as? NSButton
private var resetZoomToolbarButton: NSButton? {
guard let button = toolbar?.items.first(where: { $0.itemIdentifier == .resetZoom })?.view?.subviews.first as? NSButton
else { return nil }
return button
}
private let unZoomTabButton: NSButton = {
private let resetZoomTabButton: NSButton = {
let button = NSButton()
button.target = nil
button.action = #selector(TerminalController.splitZoom(_:))
@@ -30,6 +30,8 @@ class TerminalWindow: NSWindow {
button.widthAnchor.constraint(equalToConstant: 20).isActive = true
button.heightAnchor.constraint(equalToConstant: 20).isActive = true
button.isBordered = false
button.allowsExpansionToolTips = true
button.toolTip = "Reset Zoom"
button.contentTintColor = .controlAccentColor
button.state = .on
button.image = NSImage(systemSymbolName: "arrow.down.right.and.arrow.up.left.square.fill", accessibilityDescription: nil)!
@@ -48,10 +50,10 @@ class TerminalWindow: NSWindow {
private lazy var bindings = [
observe(\.surfaceIsZoomed, options: [.initial, .new]) { [weak self] window, _ in
guard let unZoomToolbarButton = self?.unZoomToolbarButton, let tabGroup = self?.tabGroup else { return }
guard let resetZoomToolbarButton = self?.resetZoomToolbarButton, let tabGroup = self?.tabGroup else { return }
self?.unZoomTabButton.isHidden = !window.surfaceIsZoomed
self?.updateUnZoomToolbarButtonVisibility()
self?.resetZoomTabButton.isHidden = !window.surfaceIsZoomed
self?.updateResetZoomToolbarButtonVisibility()
},
observe(\.keyEquivalent, options: [.initial, .new]) { [weak self] window, _ in
@@ -88,7 +90,7 @@ class TerminalWindow: NSWindow {
}
// Create the tab accessory view that houses the key-equivalent label and optional un-zoom button
let stackView = NSStackView(views: [keyEquivalentLabel, unZoomTabButton])
let stackView = NSStackView(views: [keyEquivalentLabel, resetZoomTabButton])
stackView.setHuggingPriority(.defaultHigh, for: .horizontal)
stackView.spacing = 3
tab.accessoryView = stackView
@@ -114,24 +116,24 @@ class TerminalWindow: NSWindow {
super.becomeKey()
updateNewTabButtonOpacity()
unZoomTabButton.isEnabled = true
unZoomTabButton.contentTintColor = .controlAccentColor
unZoomToolbarButton?.contentTintColor = .controlAccentColor
resetZoomTabButton.isEnabled = true
resetZoomTabButton.contentTintColor = .controlAccentColor
resetZoomToolbarButton?.contentTintColor = .controlAccentColor
}
override func resignKey() {
super.resignKey()
updateNewTabButtonOpacity()
unZoomTabButton.isEnabled = false
unZoomTabButton.contentTintColor = .labelColor
unZoomToolbarButton?.contentTintColor = .tertiaryLabelColor
resetZoomTabButton.isEnabled = false
resetZoomTabButton.contentTintColor = .labelColor
resetZoomToolbarButton?.contentTintColor = .tertiaryLabelColor
}
override func update() {
super.update()
updateUnZoomToolbarButtonVisibility()
updateResetZoomToolbarButtonVisibility()
titlebarSeparatorStyle = tabbedWindows != nil && !titlebarTabs ? .line : .none
@@ -202,13 +204,13 @@ class TerminalWindow: NSWindow {
newTabButtonImageView.alphaValue = isKeyWindow ? 1 : 0.5
}
private func updateUnZoomToolbarButtonVisibility() {
guard let unZoomToolbarButton = unZoomToolbarButton, let tabGroup else { return }
private func updateResetZoomToolbarButtonVisibility() {
guard let resetZoomToolbarButton = resetZoomToolbarButton, let tabGroup else { return }
if tabGroup.isTabBarVisible {
unZoomToolbarButton.isHidden = true
resetZoomToolbarButton.isHidden = true
} else {
unZoomToolbarButton.isHidden = !surfaceIsZoomed
resetZoomToolbarButton.isHidden = !surfaceIsZoomed
}
}
@@ -222,7 +224,7 @@ class TerminalWindow: NSWindow {
toolbar = terminalToolbar
toolbarStyle = .unifiedCompact
updateUnZoomToolbarButtonVisibility()
updateResetZoomToolbarButtonVisibility()
}
// MARK: - Titlebar Tabs