Fixed ribbon button not disappearing
This commit is contained in:
10
src/main.ts
10
src/main.ts
@@ -13,6 +13,8 @@ import * as NotesIndex from './notes-index'
|
||||
import * as FileLoader from './file-loader'
|
||||
|
||||
export default class OmnisearchPlugin extends Plugin {
|
||||
private ribbonButton?: HTMLElement
|
||||
|
||||
async onload(): Promise<void> {
|
||||
await cleanOldCacheFiles()
|
||||
await loadSettings(this)
|
||||
@@ -88,10 +90,16 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
}
|
||||
|
||||
addRibbonButton(): void {
|
||||
this.addRibbonIcon('search', 'Omnisearch', _evt => {
|
||||
this.ribbonButton = this.addRibbonIcon('search', 'Omnisearch', _evt => {
|
||||
new OmnisearchVaultModal(app).open()
|
||||
})
|
||||
}
|
||||
|
||||
removeRibbonButton(): void {
|
||||
if (this.ribbonButton) {
|
||||
this.ribbonButton.parentNode?.removeChild(this.ribbonButton)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -200,7 +200,7 @@ export class SettingsTab extends PluginSettingTab {
|
||||
new Setting(containerEl)
|
||||
.setName('Show ribbon button')
|
||||
.setDesc(
|
||||
'Add a button on the sidebar to open the Vault search modal. Needs a restart to remove the button.'
|
||||
'Add a button on the sidebar to open the Vault search modal.'
|
||||
)
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.ribbonIcon).onChange(async v => {
|
||||
@@ -208,6 +208,8 @@ export class SettingsTab extends PluginSettingTab {
|
||||
await saveSettings(this.plugin)
|
||||
if (v) {
|
||||
this.plugin.addRibbonButton()
|
||||
} else {
|
||||
this.plugin.removeRibbonButton()
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user