mirror of
https://github.com/martindampier/draw-steel-retainer.git
synced 2026-07-22 05:44:15 +00:00
View
This commit is contained in:
parent
632a5635e5
commit
dbdd96d66d
3 changed files with 63 additions and 3 deletions
29
lib/Views/InitiativeTrackerView.ts
Normal file
29
lib/Views/InitiativeTrackerView.ts
Normal 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.
|
||||
}
|
||||
}
|
||||
32
lib/main.ts
32
lib/main.ts
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
"ES5",
|
||||
"ES6",
|
||||
"ES7"
|
||||
]
|
||||
],
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
"**/*.ts",
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue