From 3988ff6b1e819860435f185deb1bb2873c31decb Mon Sep 17 00:00:00 2001 From: NomarCub Date: Tue, 16 Jul 2024 23:18:36 +0200 Subject: [PATCH 1/5] "reveal-in-navigation-tree" menu item --- src/helpers.ts | 2 ++ src/main.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/helpers.ts b/src/helpers.ts index f66bf39..aa081e6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -130,6 +130,7 @@ type menuType = "open-in-default-app" | "show-in-explorer" | "reveal-in-navigation" | + "reveal-in-navigation-tree" | "open-pdf"; export function setMenuItem(item: MenuItem, type: "copy-to-clipboard", imageSource: string | Promise): MenuItem; @@ -144,6 +145,7 @@ export function setMenuItem(item: MenuItem, type: menuType, imageSource?: string title: "plugins.open-with-default-app.action-show-in-folder" + (Platform.isMacOS ? "-mac" : "") }, "reveal-in-navigation": { section: "system", icon: "folder", title: "plugins.file-explorer.action-reveal-file" }, + "reveal-in-navigation-tree": { section: "system", icon: "folder", title: "Reveal in File Tree Alternative" }, "open-pdf": { section: "system", icon: "arrow-up-right", title: "plugins.open-with-default-app.action-open-file" } }; if (type === "copy-to-clipboard" && imageSource) { diff --git a/src/main.ts b/src/main.ts index 1ba132c..b2bf7bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -301,6 +301,20 @@ export default class CopyUrlInPreview extends Plugin { this.app.internalPlugins.getEnabledPluginById("file-explorer")?.revealInFolder(file); }) ); + // see: https://github.com/ozntel/file-tree-alternative + if (this.app.plugins.enabledPlugins.has("file-tree-alternative")) { + menu.addItem(item => setMenuItem(item, "reveal-in-navigation-tree") + .onClick(() => { + const file = this.app.vault.getFileByPath(relativePath); + if (!file) { + console.warn(`getFileByPath returned null for ${relativePath}`); + return; + } + window.dispatchEvent(new CustomEvent( + "fta-reveal-file", { detail: { file: file } })); + }) + ); + } } } menu.addItem(item => setMenuItem(item, "copy-to-clipboard", image)); From 41a0d1ef12c9894ffc730961801a276a57419583 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 17 Jul 2024 07:21:43 +0200 Subject: [PATCH 2/5] add `Reveal file in navigation menu item` setting, enabled by default --- src/main.ts | 22 ++++++++++++---------- src/settings.ts | 11 +++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index b2bf7bc..ac01fb0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -291,16 +291,18 @@ export default class CopyUrlInPreview extends Plugin { menu.addItem(item => setMenuItem(item, "show-in-explorer") .onClick(() => { this.app.showInFolder(relativePath); }) ); - menu.addItem(item => setMenuItem(item, "reveal-in-navigation") - .onClick(() => { - const file = this.app.vault.getFileByPath(relativePath); - if (!file) { - console.warn(`getFileByPath returned null for ${relativePath}`); - return; - } - this.app.internalPlugins.getEnabledPluginById("file-explorer")?.revealInFolder(file); - }) - ); + if (this.settings.revealInNavigation) { + menu.addItem(item => setMenuItem(item, "reveal-in-navigation") + .onClick(() => { + const file = this.app.vault.getFileByPath(relativePath); + if (!file) { + console.warn(`getFileByPath returned null for ${relativePath}`); + return; + } + this.app.internalPlugins.getEnabledPluginById("file-explorer")?.revealInFolder(file); + }) + ); + } // see: https://github.com/ozntel/file-tree-alternative if (this.app.plugins.enabledPlugins.has("file-tree-alternative")) { menu.addItem(item => setMenuItem(item, "reveal-in-navigation-tree") diff --git a/src/settings.ts b/src/settings.ts index 53f391f..964c33d 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -4,12 +4,14 @@ import { App, PluginSettingTab, Setting } from "obsidian"; export interface CopyUrlInPreviewSettings { pdfMenu: boolean; middleClickNewTab: boolean; + revealInNavigation: boolean; enableDefaultOnCanvas: boolean; } export const DEFAULT_SETTINGS: CopyUrlInPreviewSettings = { pdfMenu: false, middleClickNewTab: true, + revealInNavigation: true, enableDefaultOnCanvas: false }; @@ -40,6 +42,15 @@ export class CopyUrlInPreviewSettingTab extends PluginSettingTab { void this.plugin.saveSettings(); }); }); + new Setting(containerEl) + .setName("Reveal file in navigation menu item") + .setDesc("You might want to disable this if you use a plugin for replacing default Obsidian file navigation. This plugin supports File Tree Alternative by displaying a reveal menu item for it if installed.") + .addToggle(toggle => { + toggle.setValue(this.plugin.settings.revealInNavigation).onChange(value => { + this.plugin.settings.revealInNavigation = value; + void this.plugin.saveSettings(); + }); + }); new Setting(containerEl) .setName("Enable regular context menu on canvas") .setDesc("The regular context menu sometimes duplicates the context menu on the canvas, so it's disabled there by default.\n" From 8b52160139f944429b18402a155d0b6cdf07d629 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 17 Jul 2024 08:21:47 +0200 Subject: [PATCH 3/5] bump version to 1.9 --- manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 869c7bb..bc669d8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "copy-url-in-preview", "name": "Image Context Menus", - "version": "1.8.0", + "version": "1.9.0", "minAppVersion": "1.5.7", "description": "Copy to clipboard, Open in default app, Show in system explorer, Reveal file in navigation, Open in new tab context menus for images. Also has an pen PDF externally context menu.", "author": "NomarCub", diff --git a/package-lock.json b/package-lock.json index cce9188..0d2c084 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "copy-url-in-preview", - "version": "1.8.0", + "version": "1.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "copy-url-in-preview", - "version": "1.8.0", + "version": "1.9.0", "license": "MIT", "devDependencies": { "@stylistic/eslint-plugin": "^2.2.2", diff --git a/package.json b/package.json index 8d0aa03..3c49e66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "copy-url-in-preview", - "version": "1.8.0", + "version": "1.9.0", "description": "Copy Image, Copy URL and Open PDF externally context menu in reading view (formerly preview mode) for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { From d32a588d22444d22a0365a4536094159f92ef5f6 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 17 Jul 2024 08:23:58 +0200 Subject: [PATCH 4/5] add `Reveal in File Tree Alternative` context menu item to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0be4e64..b277c33 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ This plugin provides the following context menus for images in [Obsidian](https: - Open in default app - Show in system explorer - Reveal file in navigation + - Reveal in [File Tree Alternative](https://github.com/ozntel/file-tree-alternative) - Open in new tab - also available through middle mouse button click From fe5dde2231044979dfd87df02947d61e13c3cd2a Mon Sep 17 00:00:00 2001 From: NomarCub Date: Thu, 25 Jul 2024 12:17:30 +0200 Subject: [PATCH 5/5] bump obsidian dependency and manifest minAppVersion to 1.6.6 --- manifest.json | 2 +- package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/manifest.json b/manifest.json index bc669d8..71cac92 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "id": "copy-url-in-preview", "name": "Image Context Menus", "version": "1.9.0", - "minAppVersion": "1.5.7", + "minAppVersion": "1.6.6", "description": "Copy to clipboard, Open in default app, Show in system explorer, Reveal file in navigation, Open in new tab context menus for images. Also has an pen PDF externally context menu.", "author": "NomarCub", "authorUrl": "https://github.com/NomarCub", diff --git a/package-lock.json b/package-lock.json index 0d2c084..dacfdaa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "esbuild": "0.21.5", "eslint": "^8.57.0", "i18next": "^23.11.5", - "obsidian": "~1.5.7-1", + "obsidian": "~1.6.6", "obsidian-typings": "^1.1.6", "tslib": "2.6.3", "typescript": "5.5.2" @@ -1935,9 +1935,9 @@ "dev": true }, "node_modules/obsidian": { - "version": "1.5.7-1", - "resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.5.7-1.tgz", - "integrity": "sha512-T5ZRuQ1FnfXqEoakTTHVDYvzUEEoT8zSPnQCW31PVgYwG4D4tZCQfKHN2hTz1ifnCe8upvwa6mBTAP2WUA5Vng==", + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.6.6.tgz", + "integrity": "sha512-GZHzeOiwmw/wBjB5JwrsxAZBLqxGQmqtEKSvJJvT0LtTcqeOFnV8jv0ZK5kO7hBb44WxJc+LdS7mZgLXbb+qXQ==", "dev": true, "dependencies": { "@types/codemirror": "5.60.8", diff --git a/package.json b/package.json index 3c49e66..c1e5406 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "esbuild": "0.21.5", "eslint": "^8.57.0", "i18next": "^23.11.5", - "obsidian": "~1.5.7-1", + "obsidian": "~1.6.6", "obsidian-typings": "^1.1.6", "tslib": "2.6.3", "typescript": "5.5.2"