mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 17:26:09 +03:00
macos: add tab index labels
This commit is contained in:

committed by
Mitchell Hashimoto

parent
752aa11930
commit
59ba6fac2b
@ -1,6 +1,6 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class PrimaryWindowController: NSWindowController {
|
class PrimaryWindowController: NSWindowController, NSWindowDelegate {
|
||||||
// This is used to programmatically control tabs.
|
// This is used to programmatically control tabs.
|
||||||
weak var windowManager: PrimaryWindowManager?
|
weak var windowManager: PrimaryWindowManager?
|
||||||
|
|
||||||
@ -21,4 +21,12 @@ class PrimaryWindowController: NSWindowController {
|
|||||||
window.contentView = nil
|
window.contentView = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func windowDidBecomeKey(_ notification: Notification) {
|
||||||
|
self.windowManager?.indexTabs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func windowWillClose(_ notification: Notification) {
|
||||||
|
self.windowManager?.indexTabs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ class PrimaryWindowManager {
|
|||||||
|
|
||||||
let managed = ManagedWindow(windowController: windowController, window: window, closePublisher: pubClose)
|
let managed = ManagedWindow(windowController: windowController, window: window, closePublisher: pubClose)
|
||||||
managedWindows.append(managed)
|
managedWindows.append(managed)
|
||||||
|
window.delegate = windowController
|
||||||
|
|
||||||
return managed
|
return managed
|
||||||
}
|
}
|
||||||
@ -178,4 +179,21 @@ class PrimaryWindowManager {
|
|||||||
Self.lastCascadePoint = NSPoint(x: frame.minX, y: frame.maxY)
|
Self.lastCascadePoint = NSPoint(x: frame.minX, y: frame.maxY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the accessory view of the first 9 tabs. This is called when the
|
||||||
|
/// key window changes and when a window is closed.
|
||||||
|
func indexTabs() {
|
||||||
|
if let windows = self.mainWindow?.tabbedWindows {
|
||||||
|
for (index, window) in windows.enumerated().prefix(9) {
|
||||||
|
let string = " ⌘\(index + 1) "
|
||||||
|
let attributes: [NSAttributedString.Key: Any] = [
|
||||||
|
.font: NSFont.labelFont(ofSize: 0),
|
||||||
|
.foregroundColor: window.isKeyWindow ? NSColor.labelColor : NSColor.secondaryLabelColor,
|
||||||
|
]
|
||||||
|
let attributedString = NSAttributedString(string: string, attributes: attributes)
|
||||||
|
let text = NSTextField(labelWithAttributedString: attributedString)
|
||||||
|
window.tab.accessoryView = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user