(event: MouseEvent, file: TFile, plugin: TaskNotesPlugin)
| 109 | } |
| 110 | |
| 111 | function showFileContextMenu(event: MouseEvent, file: TFile, plugin: TaskNotesPlugin): void { |
| 112 | const menu = new Menu(); |
| 113 | |
| 114 | let populated = false; |
| 115 | try { |
| 116 | plugin.app.workspace.trigger("file-menu", menu, file, "tasknotes-bases-view"); |
| 117 | populated = ((menu as MenuWithItems).items?.length ?? 0) > 0; |
| 118 | } catch { |
| 119 | populated = false; |
| 120 | } |
| 121 | |
| 122 | if (!populated) { |
| 123 | menu.addItem((item) => { |
| 124 | item.setTitle("Open"); |
| 125 | item.setIcon("file-text"); |
| 126 | item.onClick(() => { |
| 127 | void plugin.app.workspace.getLeaf(false).openFile(file); |
| 128 | }); |
| 129 | }); |
| 130 | menu.addItem((item) => { |
| 131 | item.setTitle("Open in new tab"); |
| 132 | item.setIcon("external-link"); |
| 133 | item.onClick(() => { |
| 134 | void plugin.app.workspace.openLinkText(file.path, "", true); |
| 135 | }); |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | menu.showAtMouseEvent(event); |
| 140 | } |
no test coverage detected