mirror of
https://github.com/mara-li/obsidian-my-thesaurus.git
synced 2026-07-22 05:38:22 +00:00
chore: add and delete main function
This commit is contained in:
parent
5eeeca1763
commit
1a2da7ab2a
4 changed files with 18 additions and 101 deletions
|
|
@ -1,9 +1,11 @@
|
|||
|
||||
|
||||
export interface <%= data.interfaceName %>Settings {
|
||||
mySetting: string;
|
||||
export interface MyThesaurusSettings {
|
||||
thesaurusPath: string;
|
||||
excludedPath: string[];
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: <%= data.interfaceName %>Settings = {
|
||||
mySetting: "default"
|
||||
export const DEFAULT_SETTINGS: MyThesaurusSettings = {
|
||||
thesaurusPath: "",
|
||||
excludedPath: []
|
||||
};
|
||||
|
|
|
|||
73
src/main.ts
73
src/main.ts
|
|
@ -1,13 +1,12 @@
|
|||
import { type Editor, MarkdownView, Notice, Plugin, Modal } from "obsidian";
|
||||
import { Plugin } from "obsidian";
|
||||
import { resources, translationLanguage } from "./i18n";
|
||||
import i18next from "i18next";
|
||||
|
||||
import { <%= data.interfaceName %>SettingTab } from "./settings";
|
||||
import { <%= data.interfaceName%>Modal } from "./modals";
|
||||
import { <%= data.interfaceName%>Settings, DEFAULT_SETTINGS } from "./interfaces";
|
||||
import { MyThesaurusSettingTab } from "./settings";
|
||||
import { MyThesaurusSettings, DEFAULT_SETTINGS } from "./interfaces";
|
||||
|
||||
export default class <%= data.interfaceName %> extends Plugin {
|
||||
settings!: <%= data.interfaceName %>Settings;
|
||||
export default class MyThesaurus extends Plugin {
|
||||
settings!: MyThesaurusSettings;
|
||||
|
||||
async onload() {
|
||||
console.log(`[${this.manifest.name}] Loaded`)
|
||||
|
|
@ -20,66 +19,8 @@ export default class <%= data.interfaceName %> extends Plugin {
|
|||
returnNull: false,
|
||||
returnEmptyString: false,
|
||||
});
|
||||
// This creates an icon in the left ribbon.
|
||||
const ribbonIconEl = this.addRibbonIcon("dice", "Sample Plugin", (_evt: MouseEvent) => {
|
||||
// Called when the user clicks the icon.
|
||||
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 <%= data.interfaceName%>Modal(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|MarkdownFileInfo) => {
|
||||
console.log(editor.getSelection());
|
||||
editor.replaceSelection("Sample Editor Command");
|
||||
}
|
||||
});
|
||||
// This adds a complex command that can check whether the current state of the app allows execution of the command
|
||||
this.addCommand({
|
||||
id: "open-sample-modal-complex",
|
||||
name: "Open sample modal (complex)",
|
||||
checkCallback: (checking: boolean) => {
|
||||
// Conditions to check
|
||||
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
if (markdownView) {
|
||||
// If checking is true, we're simply "checking" if the command can be run.
|
||||
// If checking is false, then we want to actually perform the operation.
|
||||
if (!checking) {
|
||||
new <%= DataTransferItem={}.name%>Modal(this.app).open();
|
||||
}
|
||||
|
||||
// This command will only show up in Command Palette when the check function returns true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// This adds a settings tab so the user can configure various aspects of the plugin
|
||||
this.addSettingTab(new <%= data.interfaceName %>SettingTab(this.app, this));
|
||||
|
||||
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
|
||||
// Using this function will automatically remove the event listener when this plugin is disabled.
|
||||
this.registerDomEvent(document, "click", (evt: MouseEvent) => {
|
||||
console.log("click", evt);
|
||||
});
|
||||
|
||||
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
|
||||
this.registerInterval(window.setInterval(() => console.log("setInterval"), 5 * 60 * 1000));
|
||||
this.addSettingTab(new MyThesaurusSettingTab(this.app, this));
|
||||
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
import { type App, Modal } from "obsidian";
|
||||
|
||||
export class <%= data.interfaceName%>Modal extends Modal {
|
||||
constructor(app: App) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
const {contentEl} = this;
|
||||
contentEl.setText("Woah!");
|
||||
}
|
||||
|
||||
onClose() {
|
||||
const {contentEl} = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import { type App, PluginSettingTab, Setting } from "obsidian";
|
||||
import <%= data.interfaceName %> from "./main";
|
||||
import MyThesaurus from "./main";
|
||||
|
||||
export class <%= data.interfaceName %>SettingTab extends PluginSettingTab {
|
||||
plugin: <%= data.interfaceName %>;
|
||||
export class MyThesaurusSettingTab extends PluginSettingTab {
|
||||
plugin: MyThesaurus;
|
||||
|
||||
constructor(app: App, plugin: <%= data.interfaceName %>) {
|
||||
constructor(app: App, plugin: MyThesaurus) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
|
@ -14,15 +14,6 @@ export class <%= data.interfaceName %>SettingTab extends PluginSettingTab {
|
|||
|
||||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Setting #1")
|
||||
.setDesc("It's a secret")
|
||||
.addText(text => text
|
||||
.setPlaceholder("Enter your secret")
|
||||
.setValue(this.plugin.settings.mySetting)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.mySetting = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue