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 <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,8 @@ final class AppState: ObservableObject {
|
|||||||
|
|
||||||
// Context for prompt (window attach / file)
|
// Context for prompt (window attach / file)
|
||||||
@Published var promptContext: PromptContext? = nil
|
@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)
|
// Dropped file (set during upload flow)
|
||||||
@Published var droppedFile: DroppedFile? = nil
|
@Published var droppedFile: DroppedFile? = nil
|
||||||
|
|||||||
@@ -1253,6 +1253,14 @@ struct PromptView: View {
|
|||||||
.padding(.horizontal, 10)
|
.padding(.horizontal, 10)
|
||||||
|
|
||||||
HStack(spacing: 8) {
|
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)
|
TextField(state.chatHistory.isEmpty ? "Спроси что угодно…" : "Продолжить…", text: $text)
|
||||||
.textFieldStyle(.plain)
|
.textFieldStyle(.plain)
|
||||||
.font(.system(size: 13))
|
.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() {
|
private func sendMessage() {
|
||||||
let query = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
let query = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
guard !query.isEmpty else { return }
|
guard !query.isEmpty else { return }
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ final class IslandWindowController: NSWindowController {
|
|||||||
dropView.autoresizingMask = [.width, .height]
|
dropView.autoresizingMask = [.width, .height]
|
||||||
dropView.onDragEntered = { [weak self] loc in
|
dropView.onDragEntered = { [weak self] loc in
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
// Over an open terminal the file goes into its command line, not the shelf.
|
// Over an open terminal or chat the file goes there, not to the shelf.
|
||||||
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)
|
let iLoc = self?.windowToIsland(loc) ?? CGPoint(x: 320, y: 88)
|
||||||
AppState.shared.fileDragOver = true
|
AppState.shared.fileDragOver = true
|
||||||
// enterZone sets isActive=true BEFORE hookExpand triggers re-render,
|
// enterZone sets isActive=true BEFORE hookExpand triggers re-render,
|
||||||
@@ -123,7 +123,7 @@ final class IslandWindowController: NSWindowController {
|
|||||||
}
|
}
|
||||||
dropView.onDragUpdated = { [weak self] loc in
|
dropView.onDragUpdated = { [weak self] loc in
|
||||||
Task { @MainActor 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)
|
let iLoc = self?.windowToIsland(loc) ?? CGPoint(x: 320, y: 88)
|
||||||
UploadSequenceEngine.shared.updateCursor(x: iLoc.x, y: iLoc.y)
|
UploadSequenceEngine.shared.updateCursor(x: iLoc.x, y: iLoc.y)
|
||||||
}
|
}
|
||||||
@@ -142,6 +142,11 @@ final class IslandWindowController: NSWindowController {
|
|||||||
TerminalStore.shared.insertPaths(urls, into: tab)
|
TerminalStore.shared.insertPaths(urls, into: tab)
|
||||||
return
|
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)
|
await FileDropHandler.handle(urls: urls, state: AppState.shared)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -635,7 +635,8 @@ struct SettingsView: View {
|
|||||||
panel.canChooseDirectories = true
|
panel.canChooseDirectories = true
|
||||||
panel.canChooseFiles = false
|
panel.canChooseFiles = false
|
||||||
panel.allowsMultipleSelection = 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
|
state.chatWorkingDirectory = url.path
|
||||||
ChatTabs.shared.cli(for: state.activeTabId).newConversation()
|
ChatTabs.shared.cli(for: state.activeTabId).newConversation()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// MARK: - Terminals
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
@@ -155,8 +171,7 @@ final class TerminalStore: NSObject, LocalProcessTerminalViewDelegate {
|
|||||||
panel.allowsMultipleSelection = true
|
panel.allowsMultipleSelection = true
|
||||||
panel.prompt = "Вставить"
|
panel.prompt = "Вставить"
|
||||||
panel.message = "Пути выбранных файлов появятся в терминале"
|
panel.message = "Пути выбранных файлов появятся в терминале"
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
panel.presentAboveNotch { [weak self] urls in self?.insertPaths(urls, into: id) }
|
||||||
if panel.runModal() == .OK { insertPaths(panel.urls, into: id) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static func shellEscaped(_ path: String) -> String {
|
static func shellEscaped(_ path: String) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user