macos: support drag and drop with no windows

This commit is contained in:
Mitchell Hashimoto
2023-10-03 22:03:04 -07:00
parent d5299fec25
commit 6249621d71
3 changed files with 32 additions and 2 deletions

View File

@ -2,6 +2,21 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Folders</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.directory</string>
</array>
</dict>
</array>
<key>LSEnvironment</key>
<dict>
<key>GHOSTTY_MAC_APP</key>

View File

@ -138,6 +138,23 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp
return false
}
func application(_ sender: NSApplication, openFile filename: String) -> Bool {
AppDelegate.logger.warning("OPEN FILE=\(filename)")
// Build our config
var config = Ghostty.SurfaceConfiguration()
config.workingDirectory = filename
// If we don't have a window open through the window manager, we launch
// a new window.
guard let mainWindow = windowManager.mainWindow else {
windowManager.addNewWindow(withBaseConfig: config)
return true
}
return false
}
/// This is called for the dock right-click menu.
func applicationDockMenu(_ sender: NSApplication) -> NSMenu? {
return dockMenu

View File

@ -199,8 +199,6 @@ extension Ghostty {
init(from config: ghostty_surface_config_s) {
self.fontSize = config.font_size
self.workingDirectory = String.init(cString: config.working_directory, encoding: .utf8)
let blah = workingDirectory!
AppDelegate.logger.warning("OPEN from=\(blah)")
}
/// Returns the ghostty configuration for this surface configuration struct. The memory