This commit is contained in:
MartinDampier 2025-02-10 21:12:13 -06:00
parent 632a5635e5
commit dbdd96d66d
3 changed files with 63 additions and 3 deletions

View file

@ -0,0 +1,29 @@
import { ItemView, WorkspaceLeaf } from 'obsidian';
export const VIEW_TYPE_EXAMPLE = 'example-view';
export class ExampleView extends ItemView {
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
getViewType() {
return VIEW_TYPE_EXAMPLE;
}
getDisplayText() {
return 'Example view';
}
async onOpen() {
const container = this.containerEl.children[1];
container.empty();
container.createEl('h2', { text: 'Example view' });
//container.createEl('br');
container.createEl('h4', { text: 'Example view' });
}
async onClose() {
// Nothing to clean up.
}
}

View file

@ -1,5 +1,5 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { ExampleView, VIEW_TYPE_EXAMPLE } from './Views/InitiativeTrackerView';
// Remember to rename these classes and interfaces!
interface MyPluginSettings {
@ -16,6 +16,16 @@ export default class ForbiddenLandsCharacterSheet extends Plugin {
async onload() {
await this.loadSettings();
this.registerView(
VIEW_TYPE_EXAMPLE,
(leaf) => new ExampleView(leaf)
);
this.addRibbonIcon('dice', 'Activate view', () => {
this.activateView();
});
// This creates an icon in the left ribbon.
const CharacterRibbon = this.addRibbonIcon('book', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon.
@ -87,6 +97,26 @@ export default class ForbiddenLandsCharacterSheet extends Plugin {
}
async activateView() {
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);
await leaf.setViewState({ type: VIEW_TYPE_EXAMPLE, active: true });
}
// "Reveal" the leaf in case it is in a collapsed sidebar
workspace.revealLeaf(leaf);
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

View file

@ -16,9 +16,10 @@
"ES5",
"ES6",
"ES7"
]
],
},
"include": [
"**/*.ts"
"**/*.ts",
"lib"
]
}