From 09ad0f6b7b5da204aae153cb36721fe78a1e3de7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Oct 2023 22:06:55 -0700 Subject: [PATCH] macos: attach various menu items to first responder, terminal Fixes #758 --- macos/Sources/AppDelegate.swift | 83 ------------------- .../Terminal/TerminalController.swift | 80 ++++++++++++++++++ macos/Sources/MainMenu.xib | 30 +++---- 3 files changed, 95 insertions(+), 98 deletions(-) diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index 9fcd9ee5e..edda1eaba 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -236,11 +236,6 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp return terminalManager.focusedSurface?.surface } - private func splitMoveFocus(direction: Ghostty.SplitFocusDirection) { - guard let surface = focusedSurface() else { return } - ghostty.splitMoveFocus(surface: surface, direction: direction) - } - //MARK: - GhosttyAppStateDelegate func configDidReload(_ state: Ghostty.AppState) { @@ -311,86 +306,8 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp NSApp.activate(ignoringOtherApps: true) } - @IBAction func closeWindow(_ sender: Any) { - guard let currentWindow = NSApp.keyWindow else { return } - currentWindow.close() - } - - @IBAction func close(_ sender: Any) { - guard let surface = focusedSurface() else { - self.closeWindow(self) - return - } - - ghostty.requestClose(surface: surface) - } - - @IBAction func splitHorizontally(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_RIGHT) - } - - @IBAction func splitVertically(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DOWN) - } - - @IBAction func splitZoom(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.splitToggleZoom(surface: surface) - } - - @IBAction func splitMoveFocusPrevious(_ sender: Any) { - splitMoveFocus(direction: .previous) - } - - @IBAction func splitMoveFocusNext(_ sender: Any) { - splitMoveFocus(direction: .next) - } - - @IBAction func splitMoveFocusAbove(_ sender: Any) { - splitMoveFocus(direction: .top) - } - - @IBAction func splitMoveFocusBelow(_ sender: Any) { - splitMoveFocus(direction: .bottom) - } - - @IBAction func splitMoveFocusLeft(_ sender: Any) { - splitMoveFocus(direction: .left) - } - - @IBAction func splitMoveFocusRight(_ sender: Any) { - splitMoveFocus(direction: .right) - } - @IBAction func showHelp(_ sender: Any) { guard let url = URL(string: "https://github.com/mitchellh/ghostty") else { return } NSWorkspace.shared.open(url) } - - @IBAction func toggleFullScreen(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.toggleFullscreen(surface: surface) - } - - @IBAction func increaseFontSize(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.changeFontSize(surface: surface, .increase(1)) - } - - @IBAction func decreaseFontSize(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.changeFontSize(surface: surface, .decrease(1)) - } - - @IBAction func resetFontSize(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.changeFontSize(surface: surface, .reset) - } - - @IBAction func toggleTerminalInspector(_ sender: Any) { - guard let surface = focusedSurface() else { return } - ghostty.toggleTerminalInspector(surface: surface) - } } diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 4115692f5..8c1cd2b2c 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -150,6 +150,86 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele self.window?.contentView = nil } + //MARK: - First Responder + + @IBAction func close(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.requestClose(surface: surface) + } + + @IBAction func closeWindow(_ sender: Any) { + self.window?.performClose(sender) + } + + @IBAction func splitHorizontally(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_RIGHT) + } + + @IBAction func splitVertically(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DOWN) + } + + @IBAction func splitZoom(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.splitToggleZoom(surface: surface) + } + + @IBAction func splitMoveFocusPrevious(_ sender: Any) { + splitMoveFocus(direction: .previous) + } + + @IBAction func splitMoveFocusNext(_ sender: Any) { + splitMoveFocus(direction: .next) + } + + @IBAction func splitMoveFocusAbove(_ sender: Any) { + splitMoveFocus(direction: .top) + } + + @IBAction func splitMoveFocusBelow(_ sender: Any) { + splitMoveFocus(direction: .bottom) + } + + @IBAction func splitMoveFocusLeft(_ sender: Any) { + splitMoveFocus(direction: .left) + } + + @IBAction func splitMoveFocusRight(_ sender: Any) { + splitMoveFocus(direction: .right) + } + + private func splitMoveFocus(direction: Ghostty.SplitFocusDirection) { + guard let surface = focusedSurface?.surface else { return } + ghostty.splitMoveFocus(surface: surface, direction: direction) + } + + @IBAction func toggleFullScreen(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.toggleFullscreen(surface: surface) + } + + @IBAction func increaseFontSize(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.changeFontSize(surface: surface, .increase(1)) + } + + @IBAction func decreaseFontSize(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.changeFontSize(surface: surface, .decrease(1)) + } + + @IBAction func resetFontSize(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.changeFontSize(surface: surface, .reset) + } + + @IBAction func toggleTerminalInspector(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.toggleTerminalInspector(surface: surface) + } + //MARK: - TerminalViewDelegate func focusedSurfaceDidChange(to: Ghostty.SurfaceView?) { diff --git a/macos/Sources/MainMenu.xib b/macos/Sources/MainMenu.xib index 910430b95..1bb51de68 100644 --- a/macos/Sources/MainMenu.xib +++ b/macos/Sources/MainMenu.xib @@ -107,26 +107,26 @@ - + - + - + - + @@ -139,26 +139,26 @@ - + - + - + - + @@ -216,19 +216,19 @@ - + - + - + @@ -238,25 +238,25 @@ - + - + - + - +