From b232c55843f0c5157a46bf697c61bc047530cb4c Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 20 Apr 2022 11:19:23 +0200 Subject: [PATCH] Fix for mode switch --- CHANGELOG.md | 5 +++++ package.json | 2 +- src/constants/context.ts | 2 ++ src/services/ModeSwitch.ts | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db4a2d42..497d8ac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 🎨 Enhancements - [#263](https://github.com/estruyf/vscode-front-matter/issues/263): WYSIWYG string field option +- [#308](https://github.com/estruyf/vscode-front-matter/issues/308): New `File` field - [#314](https://github.com/estruyf/vscode-front-matter/issues/314): New preview actions to open the page in the browser and refresh the preview - [#322](https://github.com/estruyf/vscode-front-matter/issues/322): Show parent folder name when file is an index page (`index.md` / `_index.md`) @@ -12,6 +13,10 @@ - [#316](https://github.com/estruyf/vscode-front-matter/issues/316): Surpress file parsing errors when closing the dashboard +### 🐞 Fixes + +- Hide the view mode action from the Front Matter panel if no custom modes are defined + ## [7.1.2] - 2022-04-11 ### 🐞 Fixes diff --git a/package.json b/package.json index 9d6f5ff1..1b1592e9 100644 --- a/package.json +++ b/package.json @@ -1692,7 +1692,7 @@ { "command": "frontMatter.mode.switch", "group": "navigation@1", - "when": "view == frontMatter.explorer" + "when": "view == frontMatter.explorer && frontMatter:has:modes == true" }, { "command": "frontMatter.dashboard", diff --git a/src/constants/context.ts b/src/constants/context.ts index 8cb7dc25..007ddae4 100644 --- a/src/constants/context.ts +++ b/src/constants/context.ts @@ -9,6 +9,8 @@ export const CONTEXT = { backer: "frontMatter:backers:supporter", isValidFile: "frontMatter:file:isValid", + hasViewModes: "frontMatter:has:modes", + isSnippetsDashboardEnabled: "frontMatter:dashboard:snippets:enabled", isDataDashboardEnabled: "frontMatter:dashboard:data:enabled", }; \ No newline at end of file diff --git a/src/services/ModeSwitch.ts b/src/services/ModeSwitch.ts index 352740d4..b6a6675a 100644 --- a/src/services/ModeSwitch.ts +++ b/src/services/ModeSwitch.ts @@ -2,7 +2,7 @@ import { ModeListener } from './../listeners/general/ModeListener'; import { SETTING_GLOBAL_ACTIVE_MODE, SETTING_GLOBAL_MODES } from './../constants/settings'; import { commands, StatusBarAlignment, StatusBarItem, ThemeColor, window } from "vscode"; import { Settings } from "../helpers/SettingsHelper"; -import { COMMAND_NAME } from '../constants'; +import { COMMAND_NAME, CONTEXT } from '../constants'; import { Mode } from '../models'; @@ -36,9 +36,11 @@ export class ModeSwitch { const modes = Settings.get(SETTING_GLOBAL_MODES); if (!modes || modes.length === 0) { ModeSwitch.statusBarElm.hide(); + commands.executeCommand('setContext', CONTEXT.hasViewModes, false); return; } + commands.executeCommand('setContext', CONTEXT.hasViewModes, true); ModeSwitch.setText(); }