Improve loads of fancy things in relation to the mouse pointer

This commit is contained in:
2026-10-07 13:02:52 +02:00
parent ed5a227c9d
commit a0b3ef9975
25 changed files with 334 additions and 89 deletions
+23 -9
View File
@@ -3,7 +3,8 @@ import Foundation
/// What was right-clicked.
public enum ContextTarget: Sendable, Equatable {
/// A line or selection in the editor; `code` is the selected text, if any.
case editor(reference: AgentReference, code: String?)
/// `showDiffLine` is the clicked line when it is marked and the file offers its Diff.
case editor(reference: AgentReference, code: String?, showDiffLine: Int? = nil)
case file(path: String)
case directory(path: String)
/// A git row; the row carries its own half, since one file can have two rows.
@@ -14,7 +15,7 @@ public enum ContextTarget: Sendable, Equatable {
public var path: String {
switch self {
case let .editor(reference, _): reference.path
case let .editor(reference, _, _): reference.path
case let .file(path), let .directory(path), let .gitRow(path, _): path
case .projectRoot, .terminal: ""
}
@@ -32,12 +33,16 @@ public enum ContextAction: Sendable, Equatable {
case stage(String)
case unstage(String)
case openDiff(String)
/// Opens the Diff of the open file at this line.
case showDiff(String, line: Int)
case discard(String)
case rename(String, isDirectory: Bool)
case revealInFinder(String)
case delete(String, isDirectory: Bool)
case copyTerminalSelection(TerminalKind)
case pasteIntoTerminal(TerminalKind)
/// Inserts `/bouwen <name>` into the agent composer for an ontwikkeling folder.
case bouwen(String)
/// Destructive items read in amber-deep.
public var isDestructive: Bool {
@@ -55,27 +60,28 @@ public enum ContextMenuEntry: Sendable, Equatable {
}
public enum ContextActions {
/// The header line of the menu: the reference, or `project/` for the root.
/// The header line of the menu: the path, or `project/` for the root; the editor, folders and terminals have none.
public static func header(for target: ContextTarget, projectName: String) -> String {
switch target {
case let .editor(reference, _): reference.description
case let .directory(path): path + "/"
case let .file(path), let .gitRow(path, _): path
case .projectRoot: projectName + "/"
case .terminal: ""
case .editor, .directory, .terminal: ""
}
}
/// Menu entries: every "Pass on …" item has its "Copy …" twin directly below.
public static func entries(for target: ContextTarget) -> [ContextMenuEntry] {
switch target {
case let .editor(reference, code):
case let .editor(reference, code, showDiffLine):
let ref = reference.description
let hasCode = !(code ?? "").isEmpty
let showDiff: [ContextMenuEntry] = showDiffLine.map {
[.separator, .action(.showDiff(reference.path, line: $0), label: "Show diff")]
} ?? []
return [
.action(.passOnReference(ref, code: hasCode ? code : nil), label: hasCode ? "Pass on selection" : "Pass on reference"),
.action(.copyReference(ref), label: "Copy reference"),
]
] + showDiff
case .projectRoot:
return [
.action(.newFile(inDirectory: ""), label: "New file"),
@@ -90,7 +96,8 @@ public enum ContextActions {
]
case let .directory(path):
let ref = path + "/"
return [
let bouwen: [ContextMenuEntry] = ontwikkelingName(path).map { [.action(.bouwen($0), label: "Bouwen"), .separator] } ?? []
return bouwen + [
.action(.passOnReference(ref, code: nil), label: "Pass on reference"),
.action(.copyReference(ref), label: "Copy reference"),
.separator,
@@ -114,6 +121,13 @@ public enum ContextActions {
}
}
/// The folder name of a direct child of `ontwikkelingen/`, except the `ontwikkeld` archive.
private static func ontwikkelingName(_ path: String) -> String? {
let parts = path.split(separator: "/", omittingEmptySubsequences: false)
guard parts.count == 2, parts[0] == "ontwikkelingen", !parts[1].isEmpty, parts[1] != "ontwikkeld" else { return nil }
return String(parts[1])
}
private static func fileHead(_ path: String) -> [ContextMenuEntry] {
let name = PathUtils.basename(path)
return [