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'
|
import * as FileLoader from './file-loader'
|
||||||
|
|
||||||
export default class OmnisearchPlugin extends Plugin {
|
export default class OmnisearchPlugin extends Plugin {
|
||||||
|
private ribbonButton?: HTMLElement
|
||||||
|
|
||||||
async onload(): Promise<void> {
|
async onload(): Promise<void> {
|
||||||
await cleanOldCacheFiles()
|
await cleanOldCacheFiles()
|
||||||
await loadSettings(this)
|
await loadSettings(this)
|
||||||
@@ -88,10 +90,16 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addRibbonButton(): void {
|
addRibbonButton(): void {
|
||||||
this.addRibbonIcon('search', 'Omnisearch', _evt => {
|
this.ribbonButton = this.addRibbonIcon('search', 'Omnisearch', _evt => {
|
||||||
new OmnisearchVaultModal(app).open()
|
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)
|
new Setting(containerEl)
|
||||||
.setName('Show ribbon button')
|
.setName('Show ribbon button')
|
||||||
.setDesc(
|
.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 =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.ribbonIcon).onChange(async v => {
|
toggle.setValue(settings.ribbonIcon).onChange(async v => {
|
||||||
@@ -208,6 +208,8 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
await saveSettings(this.plugin)
|
await saveSettings(this.plugin)
|
||||||
if (v) {
|
if (v) {
|
||||||
this.plugin.addRibbonButton()
|
this.plugin.addRibbonButton()
|
||||||
|
} else {
|
||||||
|
this.plugin.removeRibbonButton()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user