112 lines
2.4 KiB
TypeScript
112 lines
2.4 KiB
TypeScript
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
|
|
|
interface FileHiderSettings {
|
|
ribbonIcon: boolean;
|
|
};
|
|
|
|
const DEFAULT_SETTINGS: FileHiderSettings = {
|
|
ribbonIcon: false,
|
|
};
|
|
|
|
export default class FileHider extends Plugin {
|
|
settings: FileHiderSettings;
|
|
|
|
async onload() {
|
|
await this.loadSettings();
|
|
|
|
// This creates an icon in the left ribbon.
|
|
|
|
const ribbonIconEl = this.addRibbonIcon('dice', 'Toggle Hiding', (evt: MouseEvent) => {
|
|
new Notice('This is a notice!');
|
|
});
|
|
// Perform additional things with the ribbon
|
|
ribbonIconEl.addClass('my-plugin-ribbon-class');
|
|
|
|
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
|
|
const statusBarItemEl = this.addStatusBarItem();
|
|
statusBarItemEl.setText('Status Bar Text');
|
|
|
|
// This adds a simple command that can be triggered anywhere
|
|
this.addCommand({
|
|
id: 'open-sample-modal-simple',
|
|
name: 'Open sample modal (simple)',
|
|
callback: () => {
|
|
new FilesModal(this.app).open();
|
|
}
|
|
});
|
|
// This adds an editor command that can perform some operation on the current editor instance
|
|
this.addCommand({
|
|
id: 'sample-editor-command',
|
|
name: 'Sample editor command',
|
|
editorCallback: (editor: Editor, view: MarkdownView) => {
|
|
console.log(editor.getSelection());
|
|
editor.replaceSelection('Sample Editor Command');
|
|
}
|
|
});
|
|
|
|
this.addSettingTab(new FileHiderSettingsTab(this.app, this));
|
|
}
|
|
|
|
onunload() {
|
|
|
|
}
|
|
|
|
async loadSettings() {
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
|
}
|
|
|
|
async saveSettings() {
|
|
await this.saveData(this.settings);
|
|
|
|
// Remove/Add the ribbon icon if the user wants it
|
|
}
|
|
}
|
|
|
|
class FilesModal extends Modal {
|
|
constructor(app: App) {
|
|
super(app);
|
|
}
|
|
|
|
onOpen() {
|
|
const {contentEl} = this;
|
|
contentEl.setText('Woah!');
|
|
}
|
|
|
|
onClose() {
|
|
const {contentEl} = this;
|
|
contentEl.empty();
|
|
}
|
|
};
|
|
|
|
class DirectoryModal extends Modal {
|
|
constructor(app: App) {
|
|
super(app);
|
|
}
|
|
|
|
onOpen() {
|
|
const {contentEl} = this;
|
|
contentEl.setText('Woah!');
|
|
}
|
|
|
|
onClose() {
|
|
const {contentEl} = this;
|
|
contentEl.empty();
|
|
}
|
|
}
|
|
|
|
class FileHiderSettingsTab extends PluginSettingTab {
|
|
plugin: FileHider;
|
|
|
|
constructor(app: App, plugin: FileHider) {
|
|
super(app, plugin);
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
display(): void {
|
|
const {containerEl} = this;
|
|
|
|
containerEl.empty();
|
|
|
|
containerEl.createEl('h2', {text: 'Settings for my awesome plugin.'});
|
|
}
|
|
}
|