import Cocoa import UniformTypeIdentifiers class SettingsWindow: NSWindowController { private var databasePathField: NSTextField? private var mountPointField: NSTextField? convenience init() { let window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 400, height: 200), styleMask: [.titled, .closable, .miniaturizable], backing: .buffered, defer: false ) window.title = "MarkBaseFS Settings" window.center() self.init(window: window) setupUI() } private func setupUI() { guard let window = window else { return } let contentView = NSView(frame: window.contentRect(forFrameRect: window.frame)) let databaseLabel = NSTextField(frame: NSRect(x: 20, y: 150, width: 100, height: 24)) databaseLabel.stringValue = "Database Path:" databaseLabel.isEditable = false databaseLabel.isBezeled = false databaseLabel.drawsBackground = false contentView.addSubview(databaseLabel) databasePathField = NSTextField(frame: NSRect(x: 120, y: 150, width: 200, height: 24)) databasePathField?.stringValue = DatabaseConfig().getCurrentDatabasePath() contentView.addSubview(databasePathField!) let browseButton = NSButton(frame: NSRect(x: 330, y: 150, width: 50, height: 24)) browseButton.title = "Browse" browseButton.bezelStyle = .rounded browseButton.target = self browseButton.action = #selector(browseDatabase) contentView.addSubview(browseButton) let mountLabel = NSTextField(frame: NSRect(x: 20, y: 100, width: 100, height: 24)) mountLabel.stringValue = "Mount Point:" mountLabel.isEditable = false mountLabel.isBezeled = false mountLabel.drawsBackground = false contentView.addSubview(mountLabel) mountPointField = NSTextField(frame: NSRect(x: 120, y: 100, width: 260, height: 24)) mountPointField?.stringValue = "/Volumes/MarkBase_warren" contentView.addSubview(mountPointField!) let applyButton = NSButton(frame: NSRect(x: 200, y: 20, width: 80, height: 24)) applyButton.title = "Apply" applyButton.bezelStyle = .rounded applyButton.target = self applyButton.action = #selector(applySettings) contentView.addSubview(applyButton) let cancelButton = NSButton(frame: NSRect(x: 300, y: 20, width: 80, height: 24)) cancelButton.title = "Cancel" cancelButton.bezelStyle = .rounded cancelButton.target = self cancelButton.action = #selector(cancelSettings) contentView.addSubview(cancelButton) window.contentView = contentView } @objc func browseDatabase() { let openPanel = NSOpenPanel() if let sqliteType = UTType(filenameExtension: "sqlite") { openPanel.allowedContentTypes = [sqliteType] } openPanel.allowsMultipleSelection = false if openPanel.runModal() == .OK { if let url = openPanel.url { databasePathField?.stringValue = url.path } } } @objc func applySettings() { print("Settings applied") close() } @objc func cancelSettings() { print("Settings cancelled") close() } }