From 4694e6026815c41f29b97233091455c6fcc7ffc8 Mon Sep 17 00:00:00 2001 From: idanl Date: Wed, 2 Oct 2024 19:06:38 +0300 Subject: [PATCH] adding new settings --- main.ts | 78 +++++++++++++++++++++++++++++++++++++++------------ manifest.json | 2 +- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/main.ts b/main.ts index abe9914..aae4a16 100644 --- a/main.ts +++ b/main.ts @@ -36,8 +36,8 @@ export default class RedirectPlugin extends Plugin { await this.loadSettings(); this.app.workspace.on("active-leaf-change", (leaf) => { - console.log(leaf); - // this.test(); + console.log("active-leaf-change: ", leaf); + this.test(); }); // This adds a settings tab so the user can configure various aspects of the plugin @@ -66,17 +66,19 @@ export default class RedirectPlugin extends Plugin { .match(linkTextRegex) ?.at(1); - console.log("redirectTargetText: ", targetNoteName); + console.log("redirectTargetNote: ", targetNoteName); if (targetNoteName) { const targetNotePath = this.app.metadataCache.getFirstLinkpathDest( - getLinkpath(targetNoteName as string), + getLinkpath(targetNoteName), "" ); console.log("targetNotePath: ", targetNotePath); this.app.workspace.openLinkText( targetNoteName || "", targetNotePath?.path as string + // true, + // { active: true } ); } else { console.log("no redirect found"); @@ -97,21 +99,21 @@ export default class RedirectPlugin extends Plugin { await this.saveData(this.settings); } - getTargetFile(): TFile | null { - // const currentFile = this.app.workspace.getActiveFile(); - const targetFile = this.app.vault.getFileByPath("_redirects/js.md"); - console.log(targetFile); + // getTargetFile(): TFile | null { + // // const currentFile = this.app.workspace.getActiveFile(); + // const targetFile = this.app.vault.getFileByPath("_redirects/js.md"); + // console.log(targetFile); - this.app.workspace.openLinkText( - targetFile?.name as string, - targetFile?.path as string, - false, - { - active: false, - } - ); - return targetFile; - } + // this.app.workspace.openLinkText( + // targetFile?.name as string, + // targetFile?.path as string, + // false, + // { + // active: false, + // } + // ); + // return targetFile; + // } } class RedirectSettingsTab extends PluginSettingTab { @@ -142,5 +144,45 @@ class RedirectSettingsTab extends PluginSettingTab { } }); }); + + new Setting(containerEl) + .setName("Open target note in new tab.") + .setDesc("Whether to open the target note in a new tab.") + .addToggle((toggle) => { + toggle.setValue(true); + // toggle.setTooltip(""); + toggle.onChange((value) => { + console.log(value); + if (value) { + console.log("Yes, open target note in new tab."); + // show the next setting: a toggle whether to automatically change view to the new tab + } else { + console.log("No, open target note in same tab."); + // hide the next setting: a toggle whether to automatically change view to the new tab. Also make sure to DISABLE THE DEPENDENT OPTION - whether to switch to the new tab + } + }); + }); + // .clear(); // Clears (ie removes) whatever the setting instance contains (in this case, the toggle switch) + + new Setting(containerEl) + .setName("Switch view to new tab.") + .setDesc( + "When the target note opens in a new tab, whether to switch view to the new tab." + ) + .addToggle((toggle) => { + toggle.setValue(true); + // toggle.setTooltip(""); + toggle.onChange((value) => { + console.log(value); + if (value) { + console.log("Yes, switch to new tab."); + // show the next setting: a toggle whether to automatically change view to the new tab + } else { + console.log("No, switch to new tab."); + // hide the next setting: a toggle whether to automatically change view to the new tab + } + }); + }); + // .clear(); // Clears (ie removes) whatever the setting instance contains (in this case, the toggle switch) } } diff --git a/manifest.json b/manifest.json index 0b2ac36..35e91eb 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "id": "synonyms-plugin", - "name": "obsidian-synonyms-plugin", + "name": "obsidian-redirect-plugin", "version": "1.0.0", "minAppVersion": "0.15.0", "description": "This plugin allows you to redirect multiple references to a single note.",