(
event: MouseEvent,
taskPath: string,
plugin: TaskNotesPlugin,
targetDate: Date,
options: { promoteOccurrenceControls?: boolean } = {}
)
| 64 | * Show context menu for task card. |
| 65 | */ |
| 66 | export async function showTaskContextMenu( |
| 67 | event: MouseEvent, |
| 68 | taskPath: string, |
| 69 | plugin: TaskNotesPlugin, |
| 70 | targetDate: Date, |
| 71 | options: { promoteOccurrenceControls?: boolean } = {} |
| 72 | ): Promise<void> { |
| 73 | const file = plugin.app.vault.getAbstractFileByPath(taskPath); |
| 74 | const showFileMenuFallback = () => { |
| 75 | if (file instanceof TFile) { |
| 76 | showFileContextMenu(event, file, plugin); |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | try { |
| 81 | const task = await plugin.cacheManager.getTaskInfo(taskPath); |
| 82 | if (!task) { |
| 83 | showFileMenuFallback(); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | const contextMenu = new TaskContextMenu({ |
| 88 | task, |
| 89 | plugin, |
| 90 | targetDate, |
| 91 | promoteOccurrenceControls: options.promoteOccurrenceControls, |
| 92 | onUpdate: () => { |
| 93 | plugin.app.workspace.trigger("tasknotes:refresh-views"); |
| 94 | }, |
| 95 | }); |
| 96 | |
| 97 | contextMenu.show(event); |
| 98 | } catch (error) { |
| 99 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 100 | getTaskCardContextMenuLogger(plugin).error("Error creating context menu", { |
| 101 | category: "internal", |
| 102 | operation: "create-context-menu", |
| 103 | details: { taskPath, errorMessage }, |
| 104 | error, |
| 105 | }); |
| 106 | new Notice(`Failed to create context menu: ${errorMessage}`); |
| 107 | showFileMenuFallback(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | function showFileContextMenu(event: MouseEvent, file: TFile, plugin: TaskNotesPlugin): void { |
| 112 | const menu = new Menu(); |
no test coverage detected