Skip to content

Commit d2fbb71

Browse files
authored
Merge pull request #43 from NomarCub/reveal-in-file-tree
Reveal in file tree alternative
2 parents 8408b9b + fe5dde2 commit d2fbb71

7 files changed

+50
-20
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This plugin provides the following context menus for images in [Obsidian](https:
55
- Open in default app
66
- Show in system explorer
77
- Reveal file in navigation
8+
- Reveal in [File Tree Alternative](https://github.com/ozntel/file-tree-alternative)
89
- Open in new tab
910
- also available through middle mouse button click
1011

manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "copy-url-in-preview",
33
"name": "Image Context Menus",
4-
"version": "1.8.0",
5-
"minAppVersion": "1.5.7",
4+
"version": "1.9.0",
5+
"minAppVersion": "1.6.6",
66
"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.",
77
"author": "NomarCub",
88
"authorUrl": "https://github.com/NomarCub",

package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copy-url-in-preview",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"description": "Copy Image, Copy URL and Open PDF externally context menu in reading view (formerly preview mode) for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {
@@ -20,7 +20,7 @@
2020
"esbuild": "0.21.5",
2121
"eslint": "^8.57.0",
2222
"i18next": "^23.11.5",
23-
"obsidian": "~1.5.7-1",
23+
"obsidian": "~1.6.6",
2424
"obsidian-typings": "^1.1.6",
2525
"tslib": "2.6.3",
2626
"typescript": "5.5.2"

src/helpers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ type menuType =
130130
"open-in-default-app" |
131131
"show-in-explorer" |
132132
"reveal-in-navigation" |
133+
"reveal-in-navigation-tree" |
133134
"open-pdf";
134135

135136
export function setMenuItem(item: MenuItem, type: "copy-to-clipboard", imageSource: string | Promise<ArrayBuffer>): MenuItem;
@@ -144,6 +145,7 @@ export function setMenuItem(item: MenuItem, type: menuType, imageSource?: string
144145
title: "plugins.open-with-default-app.action-show-in-folder" + (Platform.isMacOS ? "-mac" : "")
145146
},
146147
"reveal-in-navigation": { section: "system", icon: "folder", title: "plugins.file-explorer.action-reveal-file" },
148+
"reveal-in-navigation-tree": { section: "system", icon: "folder", title: "Reveal in File Tree Alternative" },
147149
"open-pdf": { section: "system", icon: "arrow-up-right", title: "plugins.open-with-default-app.action-open-file" }
148150
};
149151
if (type === "copy-to-clipboard" && imageSource) {

src/main.ts

+26-10
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,32 @@ export default class CopyUrlInPreview extends Plugin {
291291
menu.addItem(item => setMenuItem(item, "show-in-explorer")
292292
.onClick(() => { this.app.showInFolder(relativePath); })
293293
);
294-
menu.addItem(item => setMenuItem(item, "reveal-in-navigation")
295-
.onClick(() => {
296-
const file = this.app.vault.getFileByPath(relativePath);
297-
if (!file) {
298-
console.warn(`getFileByPath returned null for ${relativePath}`);
299-
return;
300-
}
301-
this.app.internalPlugins.getEnabledPluginById("file-explorer")?.revealInFolder(file);
302-
})
303-
);
294+
if (this.settings.revealInNavigation) {
295+
menu.addItem(item => setMenuItem(item, "reveal-in-navigation")
296+
.onClick(() => {
297+
const file = this.app.vault.getFileByPath(relativePath);
298+
if (!file) {
299+
console.warn(`getFileByPath returned null for ${relativePath}`);
300+
return;
301+
}
302+
this.app.internalPlugins.getEnabledPluginById("file-explorer")?.revealInFolder(file);
303+
})
304+
);
305+
}
306+
// see: https://github.com/ozntel/file-tree-alternative
307+
if (this.app.plugins.enabledPlugins.has("file-tree-alternative")) {
308+
menu.addItem(item => setMenuItem(item, "reveal-in-navigation-tree")
309+
.onClick(() => {
310+
const file = this.app.vault.getFileByPath(relativePath);
311+
if (!file) {
312+
console.warn(`getFileByPath returned null for ${relativePath}`);
313+
return;
314+
}
315+
window.dispatchEvent(new CustomEvent(
316+
"fta-reveal-file", { detail: { file: file } }));
317+
})
318+
);
319+
}
304320
}
305321
}
306322
menu.addItem(item => setMenuItem(item, "copy-to-clipboard", image));

src/settings.ts

+11
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { App, PluginSettingTab, Setting } from "obsidian";
44
export interface CopyUrlInPreviewSettings {
55
pdfMenu: boolean;
66
middleClickNewTab: boolean;
7+
revealInNavigation: boolean;
78
enableDefaultOnCanvas: boolean;
89
}
910

1011
export const DEFAULT_SETTINGS: CopyUrlInPreviewSettings = {
1112
pdfMenu: false,
1213
middleClickNewTab: true,
14+
revealInNavigation: true,
1315
enableDefaultOnCanvas: false
1416
};
1517

@@ -40,6 +42,15 @@ export class CopyUrlInPreviewSettingTab extends PluginSettingTab {
4042
void this.plugin.saveSettings();
4143
});
4244
});
45+
new Setting(containerEl)
46+
.setName("Reveal file in navigation menu item")
47+
.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.")
48+
.addToggle(toggle => {
49+
toggle.setValue(this.plugin.settings.revealInNavigation).onChange(value => {
50+
this.plugin.settings.revealInNavigation = value;
51+
void this.plugin.saveSettings();
52+
});
53+
});
4354
new Setting(containerEl)
4455
.setName("Enable regular context menu on canvas")
4556
.setDesc("The regular context menu sometimes duplicates the context menu on the canvas, so it's disabled there by default.\n"

0 commit comments

Comments
 (0)