From 9ebc4552c05eeedc46cc41803669e69928271a86 Mon Sep 17 00:00:00 2001 From: maksarsanjeev Date: Sat, 10 Oct 2026 01:48:12 +0300 Subject: [PATCH] Open panels above the notch; chat paperclip and in-chat file drop - NSOpenPanel opened from BroV appeared under the notch (BroV floats above the menu bar): presentAboveNotch shows it one level higher, non-modally. Used by the terminal paperclip, the chat paperclip and the chat folder picker in Settings. - Chat: paperclip next to the input attaches a file; dropping a file over the open chat attaches it directly instead of the shelf animation. Co-Authored-By: Claude Opus 5.5 --- NotchBuddy/Sources/App/AppState.swift | 2 ++ .../Sources/App/IslandViewContent.swift | 21 +++++++++++++++++++ .../Sources/App/IslandWindowController.swift | 11 +++++++--- NotchBuddy/Sources/App/SettingsView.swift | 3 ++- NotchBuddy/Sources/App/Tabs.swift | 19 +++++++++++++++-- 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/NotchBuddy/Sources/App/AppState.swift b/NotchBuddy/Sources/App/AppState.swift index 65a8df1..829a158 100644 --- a/NotchBuddy/Sources/App/AppState.swift +++ b/NotchBuddy/Sources/App/AppState.swift @@ -259,6 +259,8 @@ final class AppState: ObservableObject { // Context for prompt (window attach / file) @Published var promptContext: PromptContext? = nil + /// The chat is open in the notch: a dropped file attaches to it instead of the shelf. + var chatOnScreen: Bool { view == .prompt && mode == .expanded } // Dropped file (set during upload flow) @Published var droppedFile: DroppedFile? = nil diff --git a/NotchBuddy/Sources/App/IslandViewContent.swift b/NotchBuddy/Sources/App/IslandViewContent.swift index 404cacc..3a9b531 100644 --- a/NotchBuddy/Sources/App/IslandViewContent.swift +++ b/NotchBuddy/Sources/App/IslandViewContent.swift @@ -1253,6 +1253,14 @@ struct PromptView: View { .padding(.horizontal, 10) HStack(spacing: 8) { + Button(action: attachFile) { + Image(systemName: "paperclip") + .font(.system(size: 12, weight: .semibold)) + .foregroundColor(Color(hex: state.promptContext == nil ? "#8E939C" : "#D97757")) + } + .buttonStyle(.plain) + .help("Прикрепить файл (или перетащи его в чат)") + TextField(state.chatHistory.isEmpty ? "Спроси что угодно…" : "Продолжить…", text: $text) .textFieldStyle(.plain) .font(.system(size: 13)) @@ -1303,6 +1311,19 @@ struct PromptView: View { } } + private func attachFile() { + let panel = NSOpenPanel() + panel.canChooseFiles = true + panel.canChooseDirectories = false + panel.allowsMultipleSelection = false + panel.prompt = "Прикрепить" + panel.presentAboveNotch { urls in + guard let url = urls.first else { return } + state.promptContext = .file(name: url.lastPathComponent, fileURL: url) + focused = true + } + } + private func sendMessage() { let query = text.trimmingCharacters(in: .whitespacesAndNewlines) guard !query.isEmpty else { return } diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swift index 3e71900..0f66661 100644 --- a/NotchBuddy/Sources/App/IslandWindowController.swift +++ b/NotchBuddy/Sources/App/IslandWindowController.swift @@ -110,8 +110,8 @@ final class IslandWindowController: NSWindowController { dropView.autoresizingMask = [.width, .height] dropView.onDragEntered = { [weak self] loc in Task { @MainActor in - // Over an open terminal the file goes into its command line, not the shelf. - if TerminalStore.shared.activeTab != nil { return } + // Over an open terminal or chat the file goes there, not to the shelf. + if TerminalStore.shared.activeTab != nil || AppState.shared.chatOnScreen { return } let iLoc = self?.windowToIsland(loc) ?? CGPoint(x: 320, y: 88) AppState.shared.fileDragOver = true // enterZone sets isActive=true BEFORE hookExpand triggers re-render, @@ -123,7 +123,7 @@ final class IslandWindowController: NSWindowController { } dropView.onDragUpdated = { [weak self] loc in Task { @MainActor in - if TerminalStore.shared.activeTab != nil { return } + if TerminalStore.shared.activeTab != nil || AppState.shared.chatOnScreen { return } let iLoc = self?.windowToIsland(loc) ?? CGPoint(x: 320, y: 88) UploadSequenceEngine.shared.updateCursor(x: iLoc.x, y: iLoc.y) } @@ -142,6 +142,11 @@ final class IslandWindowController: NSWindowController { TerminalStore.shared.insertPaths(urls, into: tab) return } + if AppState.shared.chatOnScreen, let url = urls.first { + AppState.shared.promptContext = .file(name: url.lastPathComponent, fileURL: url) + SoundEngine.shared.play("pop") + return + } await FileDropHandler.handle(urls: urls, state: AppState.shared) } } diff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swift index fc8d65a..adf7cfd 100644 --- a/NotchBuddy/Sources/App/SettingsView.swift +++ b/NotchBuddy/Sources/App/SettingsView.swift @@ -635,7 +635,8 @@ struct SettingsView: View { panel.canChooseDirectories = true panel.canChooseFiles = false panel.allowsMultipleSelection = false - if panel.runModal() == .OK, let url = panel.url { + panel.presentAboveNotch { urls in + guard let url = urls.first else { return } state.chatWorkingDirectory = url.path ChatTabs.shared.cli(for: state.activeTabId).newConversation() } diff --git a/NotchBuddy/Sources/App/Tabs.swift b/NotchBuddy/Sources/App/Tabs.swift index ee79705..2831118 100644 --- a/NotchBuddy/Sources/App/Tabs.swift +++ b/NotchBuddy/Sources/App/Tabs.swift @@ -86,6 +86,22 @@ final class ChatTabs { } } +// MARK: - Open panel above the notch + +extension NSOpenPanel { + /// BroV floats above the menu bar, so a regular open panel would appear underneath + /// it. Shown non-modally one level above the notch (runModal resets the level). + func presentAboveNotch(_ done: @escaping @MainActor ([URL]) -> Void) { + level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.mainMenuWindow)) + 5) + NSApp.activate(ignoringOtherApps: true) + begin { response in + let urls = response == .OK ? self.urls : [] + MainActor.assumeIsolated { if !urls.isEmpty { done(urls) } } + } + orderFrontRegardless() + } +} + // MARK: - Terminals @MainActor @@ -155,8 +171,7 @@ final class TerminalStore: NSObject, LocalProcessTerminalViewDelegate { panel.allowsMultipleSelection = true panel.prompt = "Вставить" panel.message = "Пути выбранных файлов появятся в терминале" - NSApp.activate(ignoringOtherApps: true) - if panel.runModal() == .OK { insertPaths(panel.urls, into: id) } + panel.presentAboveNotch { [weak self] urls in self?.insertPaths(urls, into: id) } } static func shellEscaped(_ path: String) -> String {