mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 12:30:24 +00:00
Merge pull request #39 from devonthesofa/feature/status-pane-command
feat: open leaf for grouped status view
This commit is contained in:
commit
10ccf550dc
1 changed files with 46 additions and 1 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import { Plugin, Notice, TFile, App } from "obsidian";
|
||||
import { Plugin, Notice, TFile, App, WorkspaceLeaf } from "obsidian";
|
||||
import { NoteStatusService, BaseNoteStatusService } from "./noteStatusService";
|
||||
import settingsService from "./settingsService";
|
||||
import eventBus from "./eventBus";
|
||||
import { VIEW_TYPE_EXAMPLE } from "../integrations/views/grouped-status-view";
|
||||
|
||||
export class CommandsService {
|
||||
private plugin: Plugin;
|
||||
|
|
@ -227,6 +228,50 @@ export class CommandsService {
|
|||
},
|
||||
});
|
||||
this.registeredCommands.add("search-by-status");
|
||||
|
||||
// Open Status Pane command
|
||||
this.plugin.addCommand({
|
||||
id: "open-status-pane",
|
||||
name: "Open Status Pane",
|
||||
callback: async () => {
|
||||
await this.openStatusPane();
|
||||
},
|
||||
});
|
||||
this.registeredCommands.add("open-status-pane");
|
||||
}
|
||||
|
||||
private async openStatusPane(): Promise<void> {
|
||||
const { workspace } = this.app;
|
||||
|
||||
let leaf: WorkspaceLeaf | null = null;
|
||||
const leaves = workspace.getLeavesOfType(VIEW_TYPE_EXAMPLE);
|
||||
|
||||
if (leaves.length > 0) {
|
||||
// A leaf with our view already exists, use that
|
||||
leaf = leaves[0];
|
||||
} else {
|
||||
// Our view could not be found in the workspace, create a new leaf
|
||||
// in the right sidebar for it
|
||||
leaf = workspace.getRightLeaf(false);
|
||||
if (!leaf) {
|
||||
console.error(
|
||||
"getRightLeaf return null, unable to setup the view",
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
await leaf.setViewState({
|
||||
type: VIEW_TYPE_EXAMPLE,
|
||||
active: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// "Reveal" the leaf in case it is in a collapsed sidebar
|
||||
if (!leaf) {
|
||||
console.error("leaf not found, unable to activate the view");
|
||||
} else {
|
||||
workspace.revealLeaf(leaf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue