Skip to content

Commit

Permalink
Menu API changes for Obsidian 0.15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby committed Jun 26, 2022
1 parent b7c9dc0 commit bcfad29
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
21 changes: 14 additions & 7 deletions main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quick-explorer",
"name": "Quick Explorer",
"version": "0.1.26",
"version": "0.1.27",
"description": "Perform file explorer operations (and see your current file path) from the title bar, using the mouse or keyboard",
"minAppVersion": "0.14.5",
"isDesktopOnly": true
Expand Down
6 changes: 6 additions & 0 deletions src/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {Menu, App, MenuItem, debounce, Keymap, Scope} from "obsidian";
import {around} from "monkey-around";

declare module "obsidian" {
interface Component {
_loaded: boolean
}
interface Menu {
app: App
dom: HTMLDivElement
Expand All @@ -12,6 +15,8 @@ declare module "obsidian" {
selected: number
onArrowDown(e: KeyboardEvent): false
onArrowUp(e: KeyboardEvent): false

sort?(): void
}

export namespace Keymap {
Expand Down Expand Up @@ -92,6 +97,7 @@ export class PopupMenu extends Menu {
const i = new MenuItem(this);
this.items.push(i);
cb(i);
if (this._loaded && this.sort) this.sort();
return this;
}

Expand Down
10 changes: 9 additions & 1 deletion src/quick-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ declare module "obsidian" {
registerHoverLinkSource(source: string, info: {display: string, defaultMod?: boolean}): void
unregisterHoverLinkSource(source: string): void
}
interface Menu {
sections: string[]
}
interface MenuItem {
setSection?(section: string): this
}
}

export default class QE extends Plugin {
Expand Down Expand Up @@ -37,11 +43,13 @@ export default class QE extends Plugin {
if (source !== "quick-explorer") menu.addItem(i => {
i.setIcon("folder").setTitle("Show in Quick Explorer").onClick(e => { this.explorers.forWindow()?.browseFile(file); });
item = i;
item.setSection?.("view");
})
if (item) {
const revealFile = i18next.t(`plugins.file-explorer.action-reveal-file`);
const idx = menu.items.findIndex(i => i.titleEl.textContent === revealFile);
(menu.dom as HTMLElement).insertBefore(item.dom, menu.items[idx+1].dom);
// Remove this once 0.15.3+ is required
if (!menu.sections) (menu.dom as HTMLElement).insertBefore(item.dom, menu.items[idx+1].dom);
menu.items.remove(item);
menu.items.splice(idx+1, 0, item);
}
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"0.1.26": "0.14.5",
"0.1.27": "0.14.5",
"0.1.23": "0.14.2",
"0.1.19": "0.13.23",
"0.1.9": "0.12.12",
Expand Down

0 comments on commit bcfad29

Please sign in to comment.