Skip to content

Commit 9e6e3dc

Browse files
committed
first draft of outline provider
1 parent 9920027 commit 9e6e3dc

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from 'vscode';
2+
3+
export class DesignerOutlineProvider implements vscode.CustomEditorOutlineProvider {
4+
private readonly _onDidChangeOutline = new vscode.EventEmitter<void>();
5+
readonly onDidChangeOutline = this._onDidChangeOutline.event;
6+
7+
private readonly _onDidChangeActiveItem = new vscode.EventEmitter<string | undefined>();
8+
readonly onDidChangeActiveItem = this._onDidChangeActiveItem.event;
9+
10+
private _items: vscode.CustomEditorOutlineItem[] = [];
11+
private _webview: vscode.Webview | undefined;
12+
13+
setWebview(webview: vscode.Webview): void {
14+
this._webview = webview;
15+
}
16+
17+
updateItems(items: vscode.CustomEditorOutlineItem[]): void {
18+
this._items = items;
19+
this._onDidChangeOutline.fire();
20+
}
21+
22+
setActive(itemId: string | undefined): void {
23+
this._onDidChangeActiveItem.fire(itemId);
24+
}
25+
26+
provideOutline(_token: vscode.CancellationToken): vscode.CustomEditorOutlineItem[] {
27+
return this._items;
28+
}
29+
30+
revealItem(itemId: string): void {
31+
this._webview?.postMessage({ type: 'reveal', id: itemId });
32+
}
33+
}

src/vscode/DesignerTextEditor.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import { DesignerOutlineProvider } from './DesignerOutlineProvider.js';
23

34
export function getNonce() {
45
let text = '';
@@ -11,19 +12,21 @@ export function getNonce() {
1112

1213
export class DesignerTextEditor implements vscode.CustomTextEditorProvider {
1314

14-
public static register(context: vscode.ExtensionContext): vscode.Disposable {
15-
const provider = new DesignerTextEditor(context);
15+
public static register(context: vscode.ExtensionContext): vscode.Disposable[] {
16+
let outlineProvider = new DesignerOutlineProvider();
17+
const provider = new DesignerTextEditor(context, outlineProvider);
1618
const providerRegistration = vscode.window.registerCustomEditorProvider(DesignerTextEditor.viewType, provider, {
1719
webviewOptions: {
1820
retainContextWhenHidden: true
1921
}
2022
});
21-
return providerRegistration;
23+
const outlineRegistration = vscode.window.registerCustomEditorOutlineProvider('designer.visualEditor', outlineProvider)
24+
return [providerRegistration, outlineRegistration];
2225
}
2326

2427
private static readonly viewType = 'designer.designerTextEditor';
2528

26-
constructor(private readonly context: vscode.ExtensionContext) { }
29+
constructor(private readonly context: vscode.ExtensionContext, private readonly outline: DesignerOutlineProvider) { }
2730

2831
public async addCustomElementsJsons(webviewPanel: vscode.WebviewPanel) {
2932
//TODO:
@@ -141,6 +144,32 @@ export class DesignerTextEditor implements vscode.CustomTextEditorProvider {
141144
return;
142145
}
143146
});
147+
148+
this.outline.setWebview(webviewPanel.webview);
149+
150+
// Provide some initial outline items
151+
this.outline.updateItems([
152+
{
153+
id: 'root',
154+
label: 'Canvas',
155+
icon: new vscode.ThemeIcon('layout'),
156+
contextValue: 'canvas',
157+
children: [
158+
{
159+
id: 'btn-1',
160+
label: 'Button',
161+
icon: new vscode.ThemeIcon('symbol-event'),
162+
contextValue: 'widget',
163+
},
164+
{
165+
id: 'input-1',
166+
label: 'Text Input',
167+
icon: new vscode.ThemeIcon('symbol-field'),
168+
contextValue: 'widget',
169+
},
170+
],
171+
},
172+
]);
144173
}
145174

146175
/**

src/vscode/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DesignerTextEditor } from './DesignerTextEditor.js';
44
export function activate(context: vscode.ExtensionContext) {
55
//context.subscriptions.push(
66
// vscode.window.registerWebviewViewProvider(ColorsViewProvider.viewType, provider));
7-
context.subscriptions.push(DesignerTextEditor.register(context));
7+
context.subscriptions.push(...DesignerTextEditor.register(context));
88

99
vscode.commands.registerCommand('designer.openInDesignerTextEditor', (uri: vscode.Uri) => {
1010
vscode.commands.executeCommand('vscode.openWith', uri, 'designer.designerTextEditor');

0 commit comments

Comments
 (0)