diff --git a/CHANGELOG.md b/CHANGELOG.md index 91426c06..fef7a50d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ ### 🎨 Enhancements - Grouping and status tabs enhancements +- Removed the status bar item to toggle the draft field +- Added a FM status bar item to open the dashboard - [#570](https://github.com/estruyf/vscode-front-matter/issues/570): Clear empty values on content creation and editing - [#645](https://github.com/estruyf/vscode-front-matter/issues/645): French localization added (thanks to [ClΓ©ment Barbaza](https://github.com/cba85)) - [#649](https://github.com/estruyf/vscode-front-matter/issues/649): Parse optional variables from snippets diff --git a/assets/frontmatter.woff b/assets/frontmatter.woff new file mode 100644 index 00000000..46ae87e4 Binary files /dev/null and b/assets/frontmatter.woff differ diff --git a/package.json b/package.json index 2084d605..5a83e2a6 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,15 @@ ], "main": "./dist/extension.js", "contributes": { + "icons": { + "fm-logo": { + "description": "Front Matter icon", + "default": { + "fontPath": "assets/frontmatter.woff", + "fontCharacter": "\\e900" + } + } + }, "configurationDefaults": { "files.associations": { "**/frontmatter.json": "jsonc", diff --git a/src/commands/StatusListener.ts b/src/commands/StatusListener.ts index 12eb0b84..0ad6fc7c 100644 --- a/src/commands/StatusListener.ts +++ b/src/commands/StatusListener.ts @@ -24,18 +24,7 @@ export class StatusListener { * @param frontMatterSB * @param collection */ - public static async verify( - frontMatterSB: vscode.StatusBarItem, - collection: vscode.DiagnosticCollection - ) { - const draftMsg = 'in draft'; - const publishMsg = 'to publish'; - - const draft = ContentType.getDraftField(); - if (!draft || draft.type !== 'boolean') { - frontMatterSB.hide(); - } - + public static async verify(collection: vscode.DiagnosticCollection) { const editor = vscode.window.activeTextEditor; let document = editor?.document; @@ -54,17 +43,6 @@ export class StatusListener { ? ArticleHelper.getFrontMatter(editor) : await ArticleHelper.getFrontMatterByPath(document.uri.fsPath); - // Update the StatusBar based on the article draft state - if (article && typeof article.data['draft'] !== 'undefined') { - if (article.data['draft'] === true) { - frontMatterSB.text = `$(book) ${draftMsg}`; - frontMatterSB.show(); - } else if (article.data['draft'] === false) { - frontMatterSB.text = `$(book) ${publishMsg}`; - frontMatterSB.show(); - } - } - // Check SEO and required fields if (article && article.data) { collection.clear(); @@ -108,8 +86,6 @@ export class StatusListener { DataListener.pushMetadata(null); } } - - frontMatterSB.hide(); } /** diff --git a/src/constants/Extension.ts b/src/constants/Extension.ts index a46b4782..1111d40a 100644 --- a/src/constants/Extension.ts +++ b/src/constants/Extension.ts @@ -18,7 +18,6 @@ export const COMMAND_NAME = { setLastModifiedDate: getCommandName('setLastModifiedDate'), generateSlug: getCommandName('generateSlug'), createFromTemplate: getCommandName('createFromTemplate'), - toggleDraft: getCommandName('toggleDraft'), registerFolder: getCommandName('registerFolder'), unregisterFolder: getCommandName('unregisterFolder'), createContent: getCommandName('createContent'), diff --git a/src/extension.ts b/src/extension.ts index b7966c93..62aded6f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -37,8 +37,7 @@ import { } from './commands'; import { join } from 'path'; -let frontMatterStatusBar: vscode.StatusBarItem; -let statusDebouncer: { (fnc: any, time: number): void }; +let pageUpdateDebouncer: { (fnc: any, time: number): void }; let editDebounce: { (fnc: any, time: number): void }; let collection: vscode.DiagnosticCollection; @@ -190,12 +189,6 @@ export async function activate(context: vscode.ExtensionContext) { ) ); - const toggleDraftCommand = COMMAND_NAME.toggleDraft; - const toggleDraft = vscode.commands.registerCommand(toggleDraftCommand, async () => { - await Article.toggleDraft(); - triggerShowDraftStatus(`toggleDraft`); - }); - // Register project folders const registerFolder = vscode.commands.registerCommand( COMMAND_NAME.registerFolder, @@ -277,21 +270,27 @@ export async function activate(context: vscode.ExtensionContext) { SettingsHelper.startListening(); // Create the status bar - frontMatterStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100); - frontMatterStatusBar.command = toggleDraftCommand; - subscriptions.push(frontMatterStatusBar); - statusDebouncer = debounceCallback(); + let fmStatusBarItem = vscode.window.createStatusBarItem( + 'fm-statusBarItem', + vscode.StatusBarAlignment.Right, + -100 + ); + fmStatusBarItem.command = COMMAND_NAME.dashboard; + fmStatusBarItem.text = `$(fm-logo)`; + fmStatusBarItem.tooltip = `Front Matter CMS`; + fmStatusBarItem.show(); // Register listeners that make sure the status bar updates + pageUpdateDebouncer = debounceCallback(); subscriptions.push( vscode.window.onDidChangeActiveTextEditor(() => - triggerShowDraftStatus(`onDidChangeActiveTextEditor`) + triggerPageUpdate(`onDidChangeActiveTextEditor`) ) ); subscriptions.push( vscode.window.onDidChangeTextEditorSelection((e) => { if (e.kind === vscode.TextEditorSelectionChangeKind.Mouse) { - statusDebouncer(() => triggerShowDraftStatus(`onDidChangeTextEditorSelection`), 200); + pageUpdateDebouncer(() => triggerPageUpdate(`onDidChangeTextEditorSelection`), 200); } }) ); @@ -300,13 +299,13 @@ export async function activate(context: vscode.ExtensionContext) { const filePath = TextDocumentChangeEvent.document.uri.fsPath; if (filePath && !filePath.toLowerCase().startsWith(`extension-output`)) { MarkdownFoldingProvider.triggerHighlighting(); - statusDebouncer(() => triggerShowDraftStatus(`onDidChangeTextEditorSelection`), 200); + pageUpdateDebouncer(() => triggerPageUpdate(`onDidChangeTextEditorSelection`), 200); } }) ); // Automatically run the command - triggerShowDraftStatus(`triggerShowDraftStatus`); + triggerPageUpdate(`main`); // Listener for file edit changes subscriptions.push(vscode.workspace.onWillSaveTextDocument(handleAutoDateUpdate)); @@ -378,14 +377,14 @@ export async function activate(context: vscode.ExtensionContext) { generateSlug, createFromTemplate, createTemplate, - toggleDraft, registerFolder, unregisterFolder, createContent, createByContentType, createByTemplate, collapseAll, - createFolder + createFolder, + fmStatusBarItem ); console.log(`π–₯π—‹π—ˆπ—‡π— 𝖬𝖺𝗍𝗍𝖾𝗋 𝖒𝖬𝖲 𝖺𝖼𝗍𝗂𝗏𝖺𝗍𝖾𝖽! 𝖱𝖾𝖺𝖽𝗒 π—π—ˆ π—Œπ—π–Ίπ—‹π— 𝗐𝗋𝗂𝗍𝗂𝗇𝗀... πŸ‘©β€πŸ’»πŸ§‘β€πŸ’»πŸ‘¨β€πŸ’»`); @@ -397,9 +396,9 @@ const handleAutoDateUpdate = (e: vscode.TextDocumentWillSaveEvent) => { Article.autoUpdate(e); }; -const triggerShowDraftStatus = (location: string) => { +const triggerPageUpdate = (location: string) => { Logger.info(`Triggering draft status update: ${location}`); - statusDebouncer(() => { - StatusListener.verify(frontMatterStatusBar, collection); + pageUpdateDebouncer(() => { + StatusListener.verify(collection); }, 1000); };