macos: simplify terminal controller a bunch
parent
1073e89a0d
commit
c83bf1de75
|
|
@ -54,16 +54,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
|||
/// The configuration derived from the Ghostty config so we don't need to rely on references.
|
||||
private(set) var derivedConfig: DerivedConfig
|
||||
|
||||
/// The accent color that should be rendered for this tab.
|
||||
var tabColor: TerminalTabColor = .none {
|
||||
didSet {
|
||||
guard tabColor != oldValue else { return }
|
||||
if let terminalWindow = window as? TerminalWindow {
|
||||
terminalWindow.display(tabColor: tabColor)
|
||||
}
|
||||
window?.invalidateRestorableState()
|
||||
}
|
||||
}
|
||||
|
||||
/// The notification cancellable for focused surface property changes.
|
||||
private var surfaceAppearanceCancellables: Set<AnyCancellable> = []
|
||||
|
|
@ -870,12 +860,14 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
|||
with undoState: UndoState
|
||||
) {
|
||||
self.init(ghostty, withSurfaceTree: undoState.surfaceTree)
|
||||
self.tabColor = undoState.tabColor
|
||||
|
||||
// Show the window and restore its frame
|
||||
showWindow(nil)
|
||||
if let window {
|
||||
window.setFrame(undoState.frame, display: true)
|
||||
if let terminalWindow = window as? TerminalWindow {
|
||||
terminalWindow.tabColor = undoState.tabColor
|
||||
}
|
||||
|
||||
// If we have a tab group and index, restore the tab to its original position
|
||||
if let tabGroup = undoState.tabGroup,
|
||||
|
|
@ -912,7 +904,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
|||
focusedSurface: focusedSurface?.id,
|
||||
tabIndex: window.tabGroup?.windows.firstIndex(of: window),
|
||||
tabGroup: window.tabGroup,
|
||||
tabColor: tabColor)
|
||||
tabColor: (window as? TerminalWindow)?.tabColor ?? .none)
|
||||
}
|
||||
|
||||
//MARK: - NSWindowController
|
||||
|
|
@ -954,9 +946,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
|||
delegate: self,
|
||||
))
|
||||
|
||||
if let terminalWindow = window as? TerminalWindow {
|
||||
terminalWindow.display(tabColor: tabColor)
|
||||
}
|
||||
// If we have a default size, we want to apply it.
|
||||
if let defaultSize {
|
||||
switch (defaultSize) {
|
||||
|
|
@ -1195,11 +1184,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func setTabColor(_ color: TerminalTabColor) {
|
||||
tabColor = color
|
||||
}
|
||||
|
||||
@IBAction func returnToDefaultSize(_ sender: Any?) {
|
||||
guard let window, let defaultSize else { return }
|
||||
defaultSize.apply(to: window)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class TerminalRestorableState: Codable {
|
|||
self.focusedSurface = controller.focusedSurface?.id.uuidString
|
||||
self.surfaceTree = controller.surfaceTree
|
||||
self.effectiveFullscreenMode = controller.fullscreenStyle?.fullscreenMode
|
||||
self.tabColor = controller.tabColor
|
||||
self.tabColor = (controller.window as? TerminalWindow)?.tabColor ?? .none
|
||||
}
|
||||
|
||||
init?(coder aDecoder: NSCoder) {
|
||||
|
|
@ -97,7 +97,8 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration {
|
|||
return
|
||||
}
|
||||
|
||||
c.tabColor = state.tabColor
|
||||
// Restore our tab color
|
||||
(window as? TerminalWindow)?.tabColor = state.tabColor
|
||||
|
||||
// Setup our restored state on the controller
|
||||
// Find the focused surface in surfaceTree
|
||||
|
|
|
|||
|
|
@ -46,8 +46,13 @@ class TerminalWindow: NSWindow {
|
|||
windowController as? TerminalController
|
||||
}
|
||||
|
||||
func display(tabColor: TerminalTabColor) {
|
||||
tabColorSelection = tabColor
|
||||
var tabColor: TerminalTabColor {
|
||||
get { tabColorSelection }
|
||||
set {
|
||||
guard tabColorSelection != newValue else { return }
|
||||
tabColorSelection = newValue
|
||||
invalidateRestorableState()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: NSWindow Overrides
|
||||
|
|
@ -756,7 +761,7 @@ extension TerminalWindow {
|
|||
paletteItem.view = makeTabColorPaletteView(
|
||||
selectedColor: tabColorSelection
|
||||
) { [weak target] color in
|
||||
target?.setTabColor(color)
|
||||
(target?.window as? TerminalWindow)?.tabColor = color
|
||||
}
|
||||
menu.addItem(paletteItem)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue