From 5fd611c2ff6c993ed8d85b6028771904e62a8628 Mon Sep 17 00:00:00 2001 From: Gordon Date: Tue, 30 Mar 2021 00:53:12 +0100 Subject: [PATCH] Allow css override for custom board styles --- ext-src/KanbnBoardPanel.ts | 30 +++++++++++++++++++++--------- ext-src/extension.ts | 6 +++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ext-src/KanbnBoardPanel.ts b/ext-src/KanbnBoardPanel.ts index aa260b8..cf51b45 100644 --- a/ext-src/KanbnBoardPanel.ts +++ b/ext-src/KanbnBoardPanel.ts @@ -8,11 +8,13 @@ export default class KanbnBoardPanel { private readonly _panel: vscode.WebviewPanel; private readonly _extensionPath: string; + private readonly _workspacePath: string; private readonly _kanbn: typeof import('@basementuniverse/kanbn/src/main'); private _disposables: vscode.Disposable[] = []; public static createOrShow( extensionPath: string, + workspacePath: string, kanbn: typeof import('@basementuniverse/kanbn/src/main') ) { const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined; @@ -23,6 +25,7 @@ export default class KanbnBoardPanel { } else { KanbnBoardPanel.currentPanel = new KanbnBoardPanel( extensionPath, + workspacePath, column || vscode.ViewColumn.One, kanbn ); @@ -42,33 +45,43 @@ export default class KanbnBoardPanel { index, tasks: (await KanbnBoardPanel.currentPanel._kanbn.loadAllTrackedTasks(index)).map( task => KanbnBoardPanel.currentPanel!._kanbn.hydrateTask(index, task) - ) + ), + startedColumns: index.options.startedColumns ?? [], + completedColumns: index.options.completedColumns ?? [] }); } } private constructor( extensionPath: string, + workspacePath: string, column: vscode.ViewColumn, kanbn: typeof import('@basementuniverse/kanbn/src/main') ) { this._extensionPath = extensionPath; + this._workspacePath = workspacePath; this._kanbn = kanbn; // Create and show a new webview panel - this._panel = vscode.window.createWebviewPanel(KanbnBoardPanel.viewType, "Kanbn Board", column, { + this._panel = vscode.window.createWebviewPanel(KanbnBoardPanel.viewType, 'Kanbn Board', column, { // Enable javascript in the webview enableScripts: true, // Retain state even when hidden retainContextWhenHidden: true, - // Restrict the webview to only loading content from our extension's `media` directory. + // Restrict the webview to only loading content from allowed paths localResourceRoots: [ - vscode.Uri.file(path.join(this._extensionPath, 'build')) + vscode.Uri.file(path.join(this._extensionPath, 'build')), + vscode.Uri.file(path.join(this._workspacePath, '.kanbn')) ] }); + // Set the webview's title to the kanbn project name + this._kanbn.getIndex().then(index => { + this._panel.title = index.name; + }); + // Set the webview's initial html content this._panel.webview.html = this._getHtmlForWebview(); @@ -104,11 +117,6 @@ export default class KanbnBoardPanel { // return; - // Rename a task - case 'kanbn.rename': - // - return; - // Delete a task case 'kanbn.delete': // @@ -140,6 +148,9 @@ export default class KanbnBoardPanel { const styleUri = vscode.Uri .file(path.join(this._extensionPath, 'build', mainStyle)) .with({ scheme: 'vscode-resource' }); + const customStyleUri = vscode.Uri + .file(path.join(this._workspacePath, '.kanbn', 'board.css')) + .with({ scheme: 'vscode-resource' }); // Use a nonce to whitelist which scripts can be run const nonce = getNonce(); @@ -152,6 +163,7 @@ export default class KanbnBoardPanel { Kanbn Board + diff --git a/ext-src/extension.ts b/ext-src/extension.ts index 1c3dbbe..787f240 100644 --- a/ext-src/extension.ts +++ b/ext-src/extension.ts @@ -62,7 +62,11 @@ export async function activate(context: vscode.ExtensionContext) { // If kanbn is initialised, view the kanbn board if (await kanbn.initialised()) { - KanbnBoardPanel.createOrShow(context.extensionPath, kanbn); + KanbnBoardPanel.createOrShow( + context.extensionPath, + vscode.workspace.workspaceFolders[0].uri.fsPath, + kanbn + ); KanbnBoardPanel.update(); } else { vscode.window.showErrorMessage('You need to initialise kanbn before viewing the kanbn board.');