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 diff --git a/manifest.json b/manifest.json index 869c7bb..71cac92 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "copy-url-in-preview", "name": "Image Context Menus", - "version": "1.8.0", - "minAppVersion": "1.5.7", + "version": "1.9.0", + "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 cce9188..dacfdaa 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", @@ -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 8d0aa03..c1e5406 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": { @@ -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" 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..ac01fb0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -291,16 +291,32 @@ 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") + .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)); 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"