|
7 | 7 | FileSystemAdapter, |
8 | 8 | FuzzySuggestModal, |
9 | 9 | MarkdownRenderer, |
| 10 | + Menu, |
10 | 11 | Plugin, |
11 | 12 | PluginSettingTab, |
12 | 13 | sanitizeHTMLToDom, |
@@ -59,6 +60,7 @@ declare module "obsidian" { |
59 | 60 | config: { |
60 | 61 | theme?: "obsidian" | "moonstone"; |
61 | 62 | }; |
| 63 | + resolveFileUrl(path: string): TFile; |
62 | 64 | } |
63 | 65 | interface Plugin { |
64 | 66 | _loaded: boolean; |
@@ -317,7 +319,6 @@ class ImageWindowSettingTab extends PluginSettingTab { |
317 | 319 | await this.parent.saveSettings(); |
318 | 320 | }) |
319 | 321 | ); |
320 | | - |
321 | 322 | this.buildWindows(this.containerEl.createDiv()); |
322 | 323 | } |
323 | 324 | buildWindows(el: HTMLElement) { |
@@ -474,6 +475,42 @@ export default class ImageWindow extends Plugin { |
474 | 475 | }) |
475 | 476 | ); |
476 | 477 |
|
| 478 | + this.registerDomEvent(document, "contextmenu", (event: MouseEvent) => { |
| 479 | + const target = event.target as HTMLElement; |
| 480 | + if (target.localName !== "img") return; |
| 481 | + |
| 482 | + const imgPath = (target as HTMLImageElement).currentSrc; |
| 483 | + const file = this.app.vault.resolveFileUrl(imgPath); |
| 484 | + |
| 485 | + if (!(file instanceof TFile)) return; |
| 486 | + const menu = new Menu(); |
| 487 | + menu.addItem((item) => { |
| 488 | + item.setTitle("Open in new window") |
| 489 | + .setIcon("open-elsewhere-glyph") |
| 490 | + .onClick(async () => { |
| 491 | + this.defaultWindow.loadFile(file); |
| 492 | + }); |
| 493 | + }); |
| 494 | + |
| 495 | + for (const [name, record] of Object.entries( |
| 496 | + this.settings.windows |
| 497 | + )) { |
| 498 | + if (name === DEFAULT_WINDOW_NAME) continue; |
| 499 | + menu.addItem((item) => { |
| 500 | + item.setTitle(`Open in window '${name}'`) |
| 501 | + .setIcon("open-elsewhere-glyph") |
| 502 | + .onClick(async () => { |
| 503 | + const namedWindow = this.windows.get(record.id); |
| 504 | + if (namedWindow !== undefined) { |
| 505 | + namedWindow.loadFile(file); |
| 506 | + } |
| 507 | + }); |
| 508 | + }); |
| 509 | + } |
| 510 | + |
| 511 | + menu.showAtPosition({ x: event.pageX, y: event.pageY }); |
| 512 | + }); |
| 513 | + |
477 | 514 | this.addCommand({ |
478 | 515 | id: "open-image", |
479 | 516 | name: "Open image in new window", |
|
0 commit comments