mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-07-05 01:11:19 +02:00
feat: Add URI handler for command links from documentation #821
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
- [#467](https://github.com/estruyf/vscode-front-matter/issues/467): New `fmContentType` metadata field to link content type (fallback to the `type` field)
|
||||
- [#819](https://github.com/estruyf/vscode-front-matter/issues/819): Added new extensibility support for media scripts
|
||||
- [#821](https://github.com/estruyf/vscode-front-matter/issues/821): Added URI handler to support command links from the documentation
|
||||
- [#822](https://github.com/estruyf/vscode-front-matter/issues/822): Added docs to the panel & dashboard views
|
||||
- [#829](https://github.com/estruyf/vscode-front-matter/issues/829): UI extensibility is now generally available
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { commands } from 'vscode';
|
||||
import { COMMAND_NAME } from '../constants';
|
||||
import { TagType } from '../panelWebView/TagType';
|
||||
import { PanelProvider } from '../panelWebView/PanelProvider';
|
||||
|
||||
export class Taxonomy {
|
||||
/**
|
||||
* Registers the commands for the Article class.
|
||||
*
|
||||
* @param subscriptions - The array of subscriptions to register the commands with.
|
||||
*/
|
||||
public static async registerCommands(subscriptions: unknown[]) {
|
||||
const explorerSidebar = PanelProvider.getInstance();
|
||||
|
||||
if (explorerSidebar) {
|
||||
subscriptions.push(
|
||||
commands.registerCommand(COMMAND_NAME.insertTags, async () => {
|
||||
await commands.executeCommand('workbench.view.extension.frontmatter-explorer');
|
||||
await commands.executeCommand('workbench.action.focusSideBar');
|
||||
explorerSidebar.triggerInputFocus(TagType.tags);
|
||||
})
|
||||
);
|
||||
|
||||
subscriptions.push(
|
||||
commands.registerCommand(COMMAND_NAME.insertCategories, async () => {
|
||||
await commands.executeCommand('workbench.view.extension.frontmatter-explorer');
|
||||
await commands.executeCommand('workbench.action.focusSideBar');
|
||||
explorerSidebar.triggerInputFocus(TagType.categories);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,7 @@ export * from './Preview';
|
||||
export * from './Project';
|
||||
export * from './Settings';
|
||||
export * from './StatusListener';
|
||||
export * from './Taxonomy';
|
||||
export * from './Template';
|
||||
export * from './Wysiwyg';
|
||||
export * from './i18n';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const extensionName = 'frontMatter';
|
||||
export const EXTENSION_COMMAND_PREFIX = 'frontMatter';
|
||||
|
||||
export const EXTENSION_ID = 'eliostruyf.vscode-front-matter';
|
||||
export const EXTENSION_BETA_ID = 'eliostruyf.vscode-front-matter-beta';
|
||||
|
||||
export const getCommandName = (command: string) => {
|
||||
return `${extensionName}.${command}`;
|
||||
return `${EXTENSION_COMMAND_PREFIX}.${command}`;
|
||||
};
|
||||
|
||||
export const COMMAND_NAME = {
|
||||
|
||||
+12
-23
@@ -2,7 +2,6 @@ import { GitListener } from './listeners/general/GitListener';
|
||||
import * as vscode from 'vscode';
|
||||
import { COMMAND_NAME, CONTEXT, EXTENSION_NAME, TelemetryEvent } from './constants';
|
||||
import { MarkdownFoldingProvider } from './providers/MarkdownFoldingProvider';
|
||||
import { TagType } from './panelWebView/TagType';
|
||||
import { PanelProvider } from './panelWebView/PanelProvider';
|
||||
import {
|
||||
DashboardSettings,
|
||||
@@ -31,11 +30,13 @@ import {
|
||||
Article,
|
||||
Settings,
|
||||
StatusListener,
|
||||
Chatbot
|
||||
Chatbot,
|
||||
Taxonomy
|
||||
} from './commands';
|
||||
import { join } from 'path';
|
||||
import { Terminal } from './services';
|
||||
import { i18n } from './commands/i18n';
|
||||
import { UriHandler } from './providers/UriHandler';
|
||||
|
||||
let pageUpdateDebouncer: { (fnc: any, time: number): void };
|
||||
let editDebounce: { (fnc: any, time: number): void };
|
||||
@@ -54,6 +55,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
vscode.commands.executeCommand('setContext', CONTEXT.isDevelopment, true);
|
||||
}
|
||||
|
||||
// Sponsor check
|
||||
Backers.init(context).then(() => {});
|
||||
|
||||
// Make sure the EN language file is loaded
|
||||
@@ -118,32 +120,16 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
// Folding the front matter of markdown files
|
||||
MarkdownFoldingProvider.register();
|
||||
|
||||
const insertTags = vscode.commands.registerCommand(COMMAND_NAME.insertTags, async () => {
|
||||
await vscode.commands.executeCommand('workbench.view.extension.frontmatter-explorer');
|
||||
await vscode.commands.executeCommand('workbench.action.focusSideBar');
|
||||
explorerSidebar.triggerInputFocus(TagType.tags);
|
||||
});
|
||||
|
||||
const insertCategories = vscode.commands.registerCommand(
|
||||
COMMAND_NAME.insertCategories,
|
||||
async () => {
|
||||
await vscode.commands.executeCommand('workbench.view.extension.frontmatter-explorer');
|
||||
await vscode.commands.executeCommand('workbench.action.focusSideBar');
|
||||
explorerSidebar.triggerInputFocus(TagType.categories);
|
||||
}
|
||||
);
|
||||
// Register the taxonomy commands
|
||||
Taxonomy.registerCommands(subscriptions);
|
||||
|
||||
// Register all the article commands
|
||||
Article.registerCommands(subscriptions);
|
||||
|
||||
/**
|
||||
* Template creation
|
||||
*/
|
||||
// Template creation
|
||||
Template.registerCommands();
|
||||
|
||||
/**
|
||||
* Content creation
|
||||
*/
|
||||
// Content creation
|
||||
ContentType.registerCommands();
|
||||
Content.registerCommands();
|
||||
Folders.registerCommands();
|
||||
@@ -251,8 +237,11 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
// Cache commands
|
||||
Cache.registerCommands();
|
||||
|
||||
// Register the URI handler
|
||||
UriHandler.register();
|
||||
|
||||
// Subscribe all commands
|
||||
subscriptions.push(insertTags, PanelView, insertCategories, collapseAll, fmStatusBarItem);
|
||||
subscriptions.push(PanelView, collapseAll, fmStatusBarItem);
|
||||
|
||||
console.log(`𝖥𝗋𝗈𝗇𝗍 𝖬𝖺𝗍𝗍𝖾𝗋 𝖢𝖬𝖲 𝖺𝖼𝗍𝗂𝗏𝖺𝗍𝖾𝖽! 𝖱𝖾𝖺𝖽𝗒 𝗍𝗈 𝗌𝗍𝖺𝗋𝗍 𝗐𝗋𝗂𝗍𝗂𝗇𝗀... 👩💻🧑💻👨💻`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { commands, Uri, window } from 'vscode';
|
||||
import { EXTENSION_COMMAND_PREFIX } from '../constants';
|
||||
|
||||
export class UriHandler {
|
||||
/**
|
||||
* Register the URI handler
|
||||
*/
|
||||
public static register() {
|
||||
window.registerUriHandler({
|
||||
handleUri(uri: Uri) {
|
||||
const queryParams = new URLSearchParams(uri.query);
|
||||
if (!queryParams.has('command')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = queryParams.get('command');
|
||||
let args = queryParams.get('args');
|
||||
|
||||
if (!command || !command.startsWith(EXTENSION_COMMAND_PREFIX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args) {
|
||||
try {
|
||||
args = JSON.parse(args);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
}
|
||||
|
||||
commands.executeCommand(command, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user