From 739dffe274af7b7a14295ddc93d2049670ead1e7 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Sat, 11 Nov 2023 13:27:07 -0800 Subject: [PATCH] Enhancement: Better content type creation for Astro #704 --- l10n/bundle.l10n.json | 1 + src/dashboardWebView/DashboardMessage.ts | 1 + .../components/Steps/StepsToGetStarted.tsx | 9 +++++++- src/listeners/dashboard/DashboardListener.ts | 22 ++++++++++++++++++- src/localization/localization.enum.ts | 4 ++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index b94f2cf4..90052cfb 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -669,6 +669,7 @@ "helpers.taxonomyHelper.move.progress.title": "{0}: Moving \"{1}\" from {2} to \"${3}\".", "helpers.taxonomyHelper.move.success": "Move completed.", + "listeners.dashboard.dashboardListener.openConfig.notification": "Open the \"frontmatter.json\" file if you want to review the configuration.", "listeners.dashboard.dashboardListener.pinItem.noPath.error": "No path provided.", "listeners.dashboard.dashboardListener.pinItem.coundNotPin.error": "Could not pin item.", "listeners.dashboard.dashboardListener.pinItem.coundNotUnPin.error": "Could not unpin item.", diff --git a/src/dashboardWebView/DashboardMessage.ts b/src/dashboardWebView/DashboardMessage.ts index 043e0808..9c8a2f7a 100644 --- a/src/dashboardWebView/DashboardMessage.ts +++ b/src/dashboardWebView/DashboardMessage.ts @@ -4,6 +4,7 @@ export enum DashboardMessage { setPageViewType = 'setPageViewType', getMode = 'getMode', showWarning = 'showWarning', + openConfig = 'openConfig', // Project switching switchProject = 'switchProject', diff --git a/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx b/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx index 8e2bd9d0..3ace08a2 100644 --- a/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx +++ b/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx @@ -55,6 +55,10 @@ export const StepsToGetStarted: React.FunctionComponent }); } + const showNotification = () => { + Messenger.send(DashboardMessage.openConfig); + }; + const reload = () => { const crntState: any = Messenger.getState() || {}; @@ -260,7 +264,10 @@ export const StepsToGetStarted: React.FunctionComponent : Status.NotStarted, onClick: settings.initialized && settings.contentFolders && settings.contentFolders.length > 0 - ? reload + ? () => { + showNotification(); + reload(); + } : undefined } ] diff --git a/src/listeners/dashboard/DashboardListener.ts b/src/listeners/dashboard/DashboardListener.ts index 21870a40..754bc22f 100644 --- a/src/listeners/dashboard/DashboardListener.ts +++ b/src/listeners/dashboard/DashboardListener.ts @@ -2,12 +2,14 @@ import { Dashboard } from '../../commands/Dashboard'; import { ExtensionState } from '../../constants'; import { DashboardCommand } from '../../dashboardWebView/DashboardCommand'; import { DashboardMessage } from '../../dashboardWebView/DashboardMessage'; -import { Extension, Notifications } from '../../helpers'; +import { Extension, Notifications, Settings } from '../../helpers'; import { PostMessageData } from '../../models'; import { PinnedItems } from '../../services'; import { BaseListener } from './BaseListener'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../localization'; +import { Uri, commands } from 'vscode'; +import { existsAsync } from '../../utils'; export class DashboardListener extends BaseListener { /** @@ -29,6 +31,9 @@ export class DashboardListener extends BaseListener { case DashboardMessage.setPageViewType: Extension.getInstance().setState(ExtensionState.PagesView, msg.payload, 'workspace'); break; + case DashboardMessage.openConfig: + this.openConfig(); + break; case DashboardMessage.showWarning: Notifications.warning(msg.payload); break; @@ -44,6 +49,21 @@ export class DashboardListener extends BaseListener { } } + private static async openConfig() { + const answer = await Notifications.info( + l10n.t(LocalizationKey.listenersDashboardDashboardListenerOpenConfigNotification), + l10n.t(LocalizationKey.commonOpenSettings) + ); + + if (answer && answer === l10n.t(LocalizationKey.commonOpenSettings)) { + const configPath = await Settings.projectConfigPath(); + + if (configPath && (await existsAsync(configPath))) { + commands.executeCommand('vscode.open', Uri.file(configPath)); + } + } + } + /** * Get the pinned items * @param msg diff --git a/src/localization/localization.enum.ts b/src/localization/localization.enum.ts index 0130359e..d0f5a9b7 100644 --- a/src/localization/localization.enum.ts +++ b/src/localization/localization.enum.ts @@ -2200,6 +2200,10 @@ export enum LocalizationKey { * Move completed. */ helpersTaxonomyHelperMoveSuccess = 'helpers.taxonomyHelper.move.success', + /** + * Open the "frontmatter.json" file if you want to review the configuration. + */ + listenersDashboardDashboardListenerOpenConfigNotification = 'listeners.dashboard.dashboardListener.openConfig.notification', /** * No path provided. */