- *.archify-decision files: id (unique, words), title, status, date, elements, diagrams, supersedes, and prose; parsed, merged and link-checked in the model index; diagnostics on the file - diagrams point at decisions with decisions: [...] on the diagram, nodes and edges; stripped before Archify, unknown ids reported, completion, hover and go-to-definition for the ids and for elements/diagrams/ supersedes in decision files - Decisions panel on the main.archify page; Decisions rail panel under a diagram (hover lights up the node or connection); decisions on element cards and in the element dialog; decision view for the file, with a lost-model note outside a model - Archify | New Decision… command and template; editor schemas; the three New Model examples carry decisions; docs, changelog, 0.8.0
64 lines
2.9 KiB
TypeScript
64 lines
2.9 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { isDecisionFile } from '../model/decisions';
|
|
import { isRegistryFile } from '../model/format';
|
|
import { isArchifyFile } from '../sources/detect';
|
|
import { DIAGRAM_EDITOR_VIEW_TYPE } from '../views/diagramView';
|
|
import { REGISTRY_VIEW_TYPE } from '../views/registryView';
|
|
import { DECISION_VIEW_TYPE } from '../views/decisionView';
|
|
import { CommandContext, isHtmlUri, openHtmlViewer, sourceUri } from './context';
|
|
|
|
export function viewCommands(ctx: CommandContext): vscode.Disposable[] {
|
|
return [
|
|
vscode.commands.registerCommand('archify.showPreview', (arg?: unknown) => {
|
|
const uri = sourceUri(ctx, arg);
|
|
if (!uri) return;
|
|
if (isHtmlUri(uri)) return openHtmlViewer(uri);
|
|
if (isRegistryFile(uri.path)) return vscode.commands.executeCommand('vscode.openWith', uri, REGISTRY_VIEW_TYPE);
|
|
if (isDecisionFile(uri.path)) return vscode.commands.executeCommand('vscode.openWith', uri, DECISION_VIEW_TYPE);
|
|
if (isArchifyFile(uri.path)) return vscode.commands.executeCommand('vscode.openWith', uri, DIAGRAM_EDITOR_VIEW_TYPE);
|
|
ctx.views.show(uri, vscode.window.activeTextEditor?.viewColumn ?? vscode.ViewColumn.Active);
|
|
}),
|
|
|
|
vscode.commands.registerCommand('archify.showPreviewToSide', (arg?: unknown) => {
|
|
const uri = sourceUri(ctx, arg);
|
|
if (!uri) return;
|
|
if (isHtmlUri(uri)) return openHtmlViewer(uri, vscode.ViewColumn.Beside);
|
|
if (isArchifyFile(uri.path)) {
|
|
return vscode.commands.executeCommand('vscode.openWith', uri, DIAGRAM_EDITOR_VIEW_TYPE, {
|
|
viewColumn: vscode.ViewColumn.Beside,
|
|
preserveFocus: true,
|
|
});
|
|
}
|
|
ctx.views.show(uri, vscode.ViewColumn.Beside, true);
|
|
}),
|
|
|
|
vscode.commands.registerCommand('archify.openHtmlViewer', (arg?: unknown) => {
|
|
const uri = sourceUri(ctx, arg);
|
|
if (uri) return openHtmlViewer(uri);
|
|
}),
|
|
|
|
vscode.commands.registerCommand('archify.refreshPreview', () => ctx.views.activePreview?.update(true)),
|
|
|
|
vscode.commands.registerCommand('archify.showSource', async () => {
|
|
const preview = ctx.views.activePreview;
|
|
if (preview?.isEditor) {
|
|
// The diagram is the editor; open the YAML text beside it.
|
|
await vscode.commands.executeCommand('vscode.openWith', preview.uri, 'default', vscode.ViewColumn.Beside);
|
|
return;
|
|
}
|
|
if (preview) {
|
|
const column = preview.panel.viewColumn === vscode.ViewColumn.One ? vscode.ViewColumn.Two : vscode.ViewColumn.One;
|
|
await vscode.window.showTextDocument(preview.uri, { viewColumn: column });
|
|
return;
|
|
}
|
|
const page = ctx.registry.activeUri ?? ctx.decision.activeUri;
|
|
if (page) {
|
|
await vscode.commands.executeCommand('vscode.openWith', page, 'default', vscode.ViewColumn.Beside);
|
|
return;
|
|
}
|
|
const html = ctx.htmlViewer.activeUri;
|
|
if (html) await vscode.commands.executeCommand('vscode.openWith', html, 'default');
|
|
}),
|
|
];
|
|
}
|