andy-stack_vaultkeeper-ai/Services/WorkSpaceService.ts
Andrew Beal 9cf8f1dbd7 refactor: move replaceCopy helper to Helpers module and add tag merge utilities
Move replaceCopy function from Copy enum to Helpers module to improve
separation of concerns. Add splitFrontmatter and mergeTagsIntoFrontmatter
utilities for YAML frontmatter manipulation. Remove unused Beautify prompt
and QuickActionsService. Add timeout support to Semaphore.wait(). Remove
unused Event.QuickActionsSettingsChanged. Update all imports across AI
classes, prompts, services, and tests.
2026-05-29 22:01:02 +01:00

46 lines
No EOL
1.7 KiB
TypeScript

import type VaultkeeperAIPlugin from "main";
import { Resolve } from "./DependencyService";
import { Services } from "./Services";
import { Notice, TFile, type WorkspaceLeaf } from "obsidian";
import type { FileSystemService } from "./FileSystemService";
export class WorkSpaceService {
private readonly plugin: VaultkeeperAIPlugin = Resolve<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin);
private readonly fileSystemService: FileSystemService = Resolve<FileSystemService>(Services.FileSystemService);
public async openNote(noteName: string) {
const file: TFile | null = this.plugin.app.metadataCache.getFirstLinkpathDest(noteName, "");
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
if (file) {
await leaf.openFile(file);
} else {
new Notice(`Failed to open note: "${noteName}"`);
}
}
public async openNoteByPath(path: string) {
const file = this.plugin.app.vault.getAbstractFileByPath(path);
if (file instanceof TFile) {
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
await leaf.openFile(file);
} else {
new Notice(`Failed to open note: "${path}"`);
}
}
public getActiveFile(allowAccessToPluginRoot: boolean = false): TFile | null {
const activeFile = this.plugin.app.workspace.getActiveFile();
if (!activeFile || this.fileSystemService.isExclusion(activeFile.path, allowAccessToPluginRoot)) {
return null;
}
return activeFile;
}
public getLeavesOfType(type: string): WorkspaceLeaf[] {
return this.plugin.app.workspace.getLeavesOfType(type);
}
}