Skip to content

Commit

Permalink
Merge pull request #43 from NomarCub/reveal-in-file-tree
Browse files Browse the repository at this point in the history
Reveal in file tree alternative
  • Loading branch information
NomarCub authored Jul 25, 2024
2 parents 8408b9b + fe5dde2 commit d2fbb71
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayBuffer>): MenuItem;
Expand All @@ -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) {
Expand Down
36 changes: 26 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
11 changes: 11 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d2fbb71

Please sign in to comment.