Branchwell

Jotley / app / macOS / Views / NotesListView+Commands.swift

1import SwiftUI
2import AppKit
3
4extension NotesListView {
5 var canCreateNewNote: Bool {
6 !viewModel.recorder.isRecording && !viewModel.isTranscriptionPaused &&
7 !viewModel.recorder.isBusy && !viewModel.operationInProgress && !LocalAppModel.shared.busy
8 }
9
10 var activeRecordingNote: Note? {
11 viewModel.activeRecordingNote
12 }
13
14 func focusMainWindow() {
15 if let appDelegate = NSApp.delegate as? JotleyAppDelegate {
16 appDelegate.bringMainWindowToFrontAndEnsureSingle()
17 } else {
18 NSApp.activate(ignoringOtherApps: true)
19 }
20 }
21
22 func handleDeleteCommand() {
23 // Keep standard delete behavior when user is editing text fields/editors.
24 if NSApp.keyWindow?.firstResponder is NSTextView {
25 return
26 }
27
28 guard !viewModel.selectedNoteIDs.isEmpty else { return }
29 Task { @MainActor in await viewModel.deleteSelectedNotes(fetchedNotes: notes) }
30 }
31}