mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-17 13:02:42 +00:00
macos: use direct parameters for object-targeting commands
Change split, focus, close, activate window, select tab, close tab, and close window commands to accept their target object as a direct parameter instead of a named parameter. This produces natural AppleScript syntax: activate window (window 1) close tab (tab 1 of window 1) split (terminal 1) direction right instead of the awkward redundant form: activate window window (window 1) close tab tab (tab 1 of window 1) split terminal (terminal 1) direction right The implementation moves command logic from NSScriptCommand subclasses into responds-to handler methods on ScriptTerminal, ScriptWindow, and ScriptTab, which is the standard Cocoa Scripting pattern for commands whose direct parameter is an application class.
This commit is contained in:
@@ -174,6 +174,42 @@ final class ScriptWindow: NSObject {
|
||||
return controllers.first
|
||||
}
|
||||
|
||||
/// Handler for `activate window <window>`.
|
||||
@objc(handleActivateWindowCommand:)
|
||||
func handleActivateWindow(_ command: NSScriptCommand) -> Any? {
|
||||
guard NSApp.validateScript(command: command) else { return nil }
|
||||
|
||||
guard let windowContainer = preferredParentWindow else {
|
||||
command.scriptErrorNumber = errAEEventFailed
|
||||
command.scriptErrorString = "Window is no longer available."
|
||||
return nil
|
||||
}
|
||||
|
||||
windowContainer.makeKeyAndOrderFront(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Handler for `close window <window>`.
|
||||
@objc(handleCloseWindowCommand:)
|
||||
func handleCloseWindow(_ command: NSScriptCommand) -> Any? {
|
||||
guard NSApp.validateScript(command: command) else { return nil }
|
||||
|
||||
if let managedTerminalController = preferredController as? TerminalController {
|
||||
managedTerminalController.closeWindowImmediately()
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let windowContainer = preferredParentWindow else {
|
||||
command.scriptErrorNumber = errAEEventFailed
|
||||
command.scriptErrorString = "Window is no longer available."
|
||||
return nil
|
||||
}
|
||||
|
||||
windowContainer.close()
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Provides Cocoa scripting with a canonical "path" back to this object.
|
||||
///
|
||||
/// Without this, Cocoa can return data but cannot reliably build object
|
||||
|
||||
Reference in New Issue
Block a user