From 5753840f548f808b533d197f1f69022c4b788357 Mon Sep 17 00:00:00 2001 From: phibr0 Date: Tue, 19 Jul 2022 11:05:42 +0200 Subject: [PATCH] Handle removed commands in the settings --- locale/de.json | 3 +- locale/en.json | 3 +- manifest.json | 4 +- package.json | 2 +- src/manager/commands/menuManager.ts | 12 ++---- src/manager/commands/pageHeaderManager.ts | 3 ++ src/styles.scss | 8 +++- src/ui/components/commandComponent.tsx | 47 ++++++++++++++++++++++- 8 files changed, 65 insertions(+), 17 deletions(-) diff --git a/locale/de.json b/locale/de.json index 755bd5d..ce21d8f 100755 --- a/locale/de.json +++ b/locale/de.json @@ -62,5 +62,6 @@ "Donate": "Spenden", "Share feedback, issues, and ideas with our feedback form.": "Teile Feedback, Probleme und Ideen mit unserem Feedback Formular!", "Consider donating to support development.": "Spende um die Entwicklung zu unterstützen.", - "Save": "Speichern" + "Save": "Speichern", + "This Command is not available on this device.": "Dieser Befehl ist auf diesem Gerät nicht verfügbar." } diff --git a/locale/en.json b/locale/en.json index a88544e..41ce514 100755 --- a/locale/en.json +++ b/locale/en.json @@ -62,5 +62,6 @@ "Donate": "Donate", "Share feedback, issues, and ideas with our feedback form.": "Share feedback, issues, and ideas with our feedback form.", "Consider donating to support development.": "Consider donating to support development.", - "Save": "Save" + "Save": "Save", + "This Command is not available on this device.": "This Command is not available on this device." } diff --git a/manifest.json b/manifest.json index ea7b8ed..68fa702 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "cmdr", "name": "Commander", - "version": "0.0.17", - "minAppVersion": "0.12.0", + "version": "0.0.18", + "minAppVersion": "0.15.0", "description": "Customize your workspace by adding commands /everywhere/.", "author": "jsmorabito & phibr0", "authorUrl": "https://github.com/phibr0", diff --git a/package.json b/package.json index 2ba813b..be2bea7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cmdr", - "version": "0.0.17", + "version": "0.0.18", "description": "Customize your workspace by adding commands /everywhere/.", "main": "main.js", "scripts": { diff --git a/src/manager/commands/menuManager.ts b/src/manager/commands/menuManager.ts index bb964f6..51a4f84 100644 --- a/src/manager/commands/menuManager.ts +++ b/src/manager/commands/menuManager.ts @@ -147,16 +147,14 @@ export class EditorMenuCommandManager extends Base { public applyEditorMenuCommands(plugin: CommanderPlugin) { return async (menu: Menu, editor: Editor, view: MarkdownView): Promise => { - this.addCommandAddButton(plugin, menu, plugin.settings.editorMenu); + //this.addCommandAddButton(plugin, menu, plugin.settings.editorMenu); for (const cmdPair of plugin.settings.editorMenu) { const command = getCommandFromId(cmdPair.id); //Command has been removed - if (command === null) { - plugin.settings.editorMenu.remove(cmdPair); - await plugin.saveSettings(); - return; + if (!command) { + continue; } //Use the check callbacks accordingly if ((command.checkCallback && !command.checkCallback(true)) @@ -182,9 +180,7 @@ export class FileMenuCommandManager extends Base { //Command has been removed if (!command) { - plugin.settings.editorMenu.remove(cmdPair); - await plugin.saveSettings(); - return; + continue; } //Check for all checkedCallbacks diff --git a/src/manager/commands/pageHeaderManager.ts b/src/manager/commands/pageHeaderManager.ts index 66945ba..8349d43 100644 --- a/src/manager/commands/pageHeaderManager.ts +++ b/src/manager/commands/pageHeaderManager.ts @@ -137,6 +137,9 @@ export default class PageHeaderManager extends CommandManagerBase { private addButtonsToLeaf(leaf: WorkspaceLeaf): void { const viewActions = leaf.containerEl.getElementsByClassName('view-actions')[0]; + + if (!viewActions) return; + for (const pair of this.pairs) { if (!viewActions.getElementsByClassName( `view-action cmdr-page-header ${pair.id}` diff --git a/src/styles.scss b/src/styles.scss index 321fdfd..d13666e 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -38,7 +38,7 @@ .cmdr-menu-more-options { position: absolute; - right: 10px; + right: 0; padding-top: 2px; } @@ -205,7 +205,7 @@ .cmdr-setting-header { margin-bottom: 24px; overflow-y: hidden; - overflow-x: overlay; + overflow-x: auto; .cmdr-setting-tab-group { display: flex; @@ -345,3 +345,7 @@ margin: 0; } } + +.cmdr-icon.clickable-icon.mod-warning { + cursor: default; +} diff --git a/src/ui/components/commandComponent.tsx b/src/ui/components/commandComponent.tsx index 3fb924e..01b2cb6 100644 --- a/src/ui/components/commandComponent.tsx +++ b/src/ui/components/commandComponent.tsx @@ -1,4 +1,4 @@ -import { Platform } from "obsidian"; +import { Notice, Platform } from "obsidian"; import { Fragment, h } from "preact"; import t from "src/l10n"; import { CommandIconPair } from "src/types"; @@ -30,7 +30,50 @@ export default function CommandComponent({ const cmd = getCommandFromId(pair.id); if (!cmd) { // !TODO - return Command removed (todo); + return + {Platform.isDesktop &&
+ +
+
+ {pair.name} +
+
+ {t("This Command is not available on this device.")} +
+
+
+ +
+
} + {Platform.isMobile &&
{ new Notice(t("This Command is not available on this device.")); }}> + + + + + + + + {pair.name} + +
} +
; } const owningPluginID = cmd.id.split(":").first(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion