mirror of
https://github.com/decaf-dev/obsidian-vault-explorer.git
synced 2026-07-22 10:10:31 +00:00
feat: add command to open view
This commit is contained in:
parent
8f58abbaca
commit
84ddcaaaa2
1 changed files with 22 additions and 10 deletions
32
src/main.ts
32
src/main.ts
|
|
@ -46,16 +46,15 @@ export default class VaultExplorerPlugin extends Plugin {
|
|||
);
|
||||
|
||||
this.addRibbonIcon("compass", "Open vault explorer", async () => {
|
||||
const leaves = this.app.workspace.getLeavesOfType(VAULT_EXPLORER_VIEW);
|
||||
if (leaves.length !== 0) {
|
||||
const leaf = leaves[0];
|
||||
this.app.workspace.revealLeaf(leaf);
|
||||
} else {
|
||||
this.app.workspace.getLeaf().setViewState({
|
||||
type: VAULT_EXPLORER_VIEW,
|
||||
active: true,
|
||||
});
|
||||
}
|
||||
this.openVaultExplorerView();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "open",
|
||||
name: "Open vault explorer view",
|
||||
callback: async () => {
|
||||
this.openVaultExplorerView();
|
||||
},
|
||||
});
|
||||
|
||||
this.registerEvents();
|
||||
|
|
@ -276,4 +275,17 @@ export default class VaultExplorerPlugin extends Plugin {
|
|||
Logger.debug({ fileName: "main.ts", functionName: "saveSettings", message: "saving settings" }, this.settings);
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
|
||||
private openVaultExplorerView() {
|
||||
const leaves = this.app.workspace.getLeavesOfType(VAULT_EXPLORER_VIEW);
|
||||
if (leaves.length !== 0) {
|
||||
const leaf = leaves[0];
|
||||
this.app.workspace.revealLeaf(leaf);
|
||||
} else {
|
||||
this.app.workspace.getLeaf().setViewState({
|
||||
type: VAULT_EXPLORER_VIEW,
|
||||
active: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue