From 2fcdc1f63424c99daba7e0253510d58126385771 Mon Sep 17 00:00:00 2001 From: Cory Thompson Date: Thu, 4 Jul 2024 21:32:46 +1000 Subject: [PATCH] feat: add ribbon icon #575 --- src/main.ts | 6 ++++++ src/quickAddSettingsTab.ts | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main.ts b/src/main.ts index 9f3ba14..63f6d4e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -95,6 +95,12 @@ export default class QuickAdd extends Plugin { log.register(new ConsoleErrorLogger()).register(new GuiLogger(this)); + if (this.settings.enableRibbonIcon) { + this.addRibbonIcon("file-plus", "QuickAdd", () => { + ChoiceSuggester.Open(this, this.settings.choices); + }); + } + this.addSettingTab(new QuickAddSettingsTab(this.app, this)); this.app.workspace.onLayoutReady(() => diff --git a/src/quickAddSettingsTab.ts b/src/quickAddSettingsTab.ts index bf5a393..b3c8e09 100644 --- a/src/quickAddSettingsTab.ts +++ b/src/quickAddSettingsTab.ts @@ -22,6 +22,7 @@ export interface QuickAddSettings { * Users _can_ still use User Scripts to do so by executing arbitrary JavaScript, but that is not something the plugin controls. */ disableOnlineFeatures: boolean; + enableRibbonIcon: boolean; ai: { defaultModel: Model["name"] | "Ask me"; defaultSystemPrompt: string; @@ -48,6 +49,7 @@ export const DEFAULT_SETTINGS: QuickAddSettings = { announceUpdates: true, version: "0.0.0", disableOnlineFeatures: true, + enableRibbonIcon: false, ai: { defaultModel: "Ask me", defaultSystemPrompt: `As an AI assistant within Obsidian, your primary goal is to help users manage their ideas and knowledge more effectively. Format your responses using Markdown syntax. Please use the [[Obsidian]] link format. You can write aliases for the links by writing [[Obsidian|the alias after the pipe symbol]]. To use mathematical notation, use LaTeX syntax. LaTeX syntax for larger equations should be on separate lines, surrounded with double dollar signs ($$). You can also inline math expressions by wrapping it in $ symbols. For example, use $$w_{ij}^{\text{new}}:=w_{ij}^{\text{current}}+\eta\cdot\delta_j\cdot x_{ij}$$ on a separate line, but you can write "($\eta$ = learning rate, $\delta_j$ = error term, $x_{ij}$ = input)" inline.`, @@ -84,6 +86,7 @@ export class QuickAddSettingsTab extends PluginSettingTab { this.addTemplateFolderPathSetting(); this.addAnnounceUpdatesSetting(); this.addDisableOnlineFeaturesSetting(); + this.addEnableRibbonIconSetting(); } addAnnounceUpdatesSetting() { @@ -194,4 +197,21 @@ export class QuickAddSettingsTab extends PluginSettingTab { }) ); } + + private addEnableRibbonIconSetting() { + new Setting(this.containerEl) + .setName("Show icon in sidebar") + .setDesc("Add QuickAdd icon to the sidebar ribbon. Requires a reload.") + .addToggle((toggle) => { + toggle + .setValue(settingsStore.getState().enableRibbonIcon) + .onChange((value:boolean) => { + settingsStore.setState({ + enableRibbonIcon: value, + }); + + this.display(); + }) + }); + } }