Skip to content

Commit

Permalink
feat: show config preview on click, not automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Aug 29, 2023
1 parent 28d0814 commit c76908a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
-->

# Changelog
## __WORK IN PROGRESS__
* Opening the preview is now done manually

## 0.0.12 (2023-04-11)
* Fix: avoid overlapping the config preview with the active editor

Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
"activationEvents": [
"onLanguage:jsonc"
],
"contributes": {
"commands": [
{
"command": "configEditor.open",
"title": "Open Z-Wave JS Config Editor",
"icon": "$(open-preview)"
}
],
"menus": {
"editor/title": [
{
"when": "configEditor.hasConfigDocument",
"command": "configEditor.open",
"group": "navigation"
}
]
}
},
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "npm run package",
Expand Down
11 changes: 2 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { enableConfigDocumentCache } from "./configDocument";
import { registerDiagnosticsProvider } from "./diagnostics/provider";
import { registerPreviewProvider } from "./interactivePreview/provider";
import { My } from "./my";
import { PreviewPanel } from "./panels/Preview";
import { registerShowPreviewCommand } from "./panels/showPreviewCommand";

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand All @@ -33,14 +33,6 @@ export function activate(context: vscode.ExtensionContext): void {
const my = new My(workspace, context, ls);
enableConfigDocumentCache(my);

context.subscriptions.push(
my.onConfigDocumentChanged(async (change) => {
if (change.current) {
await PreviewPanel.render(context.extensionUri);
}
}),
);

context.subscriptions.push(
registerCompletions(my),
registerHover(my),
Expand All @@ -49,6 +41,7 @@ export function activate(context: vscode.ExtensionContext): void {
registerReferences(my),
registerDiagnosticsProvider(my),
...registerPreviewProvider(my),
...registerShowPreviewCommand(my),
...registerImportOverrides(my),
);
}
Expand Down
28 changes: 28 additions & 0 deletions src/panels/showPreviewCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as vscode from "vscode";
import { My } from "../my";
import { PreviewPanel } from "./Preview";

export function registerShowPreviewCommand(my: My): vscode.Disposable[] {
const showPanel = () => PreviewPanel.render(my.context.extensionUri);

return [
vscode.commands.registerCommand("configEditor.open", async () => {
// Render the preview on click
if (my.configDocument) await showPanel();
}),

my.onConfigDocumentChanged(async (change) => {
// Show/hide the preview button
await vscode.commands.executeCommand(
"setContext",
"configEditor.hasConfigDocument",
!!change.current,
);

// Update open previews, but don't automatically open a new one
if (change.current && PreviewPanel.currentPanel) {
await showPanel();
}
}),
];
}

0 comments on commit c76908a

Please sign in to comment.