Add status bar functionality
This commit is contained in:
parent
fbe3dd7a7d
commit
40632935ee
@ -1,15 +1,13 @@
|
|||||||
import * as kanbn from '@basementuniverse/kanbn/src/main';
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import ReactPanel from './ReactPanel';
|
import ReactPanel from './ReactPanel';
|
||||||
|
|
||||||
let statusBarItem: vscode.StatusBarItem;
|
let statusBarItem: vscode.StatusBarItem;
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export async function activate(context: vscode.ExtensionContext) {
|
||||||
|
|
||||||
// Register a command to initialise kanbn in the current workspace. This command will be invoked when the status
|
// Register a command to initialise kanbn in the current workspace. This command will be invoked when the status
|
||||||
// bar item is clicked in a workspace where kanbn isn't already initialised.
|
// bar item is clicked in a workspace where kanbn isn't already initialised.
|
||||||
const initialiseCommandId = 'kanbn.init';
|
context.subscriptions.push(vscode.commands.registerCommand('kanbn.init', async () => {
|
||||||
context.subscriptions.push(vscode.commands.registerCommand(initialiseCommandId, async () => {
|
|
||||||
|
|
||||||
// If no workspace folder is opened, we can't initialise kanbn
|
// If no workspace folder is opened, we can't initialise kanbn
|
||||||
if (vscode.workspace.workspaceFolders === undefined) {
|
if (vscode.workspace.workspaceFolders === undefined) {
|
||||||
@ -17,49 +15,75 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, check if kanbn is already initialised in the current workspace
|
// Set the node process directory and import kanbn
|
||||||
console.log(kanbn.getMainFolder());
|
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
|
||||||
// Prints /home/gordon/.kanbn because presumably vscode runs extension code with process.cwd() as /home/<user>
|
const kanbn = await import('@basementuniverse/kanbn/src/main');
|
||||||
// TODO update kanbn to inject root (see const ROOT in kanbn/src/main.js) into every method that needs it...
|
|
||||||
|
|
||||||
// if (vscode.workspace.workspaceFolders !== undefined) {
|
// If kanbn is already initialised, get the project name
|
||||||
// const name = await vscode.window.showInputBox({
|
let projectName = '';
|
||||||
// value: '',
|
if (await kanbn.initialised()) {
|
||||||
// placeHolder: 'The project name.',
|
projectName = (await kanbn.getIndex()).name;
|
||||||
// validateInput: text => {
|
}
|
||||||
// return text.length < 1 ? 'The project name cannot be empty.' : null;
|
|
||||||
// }
|
// Prompt for a new project name
|
||||||
// });
|
const newProjectName = await vscode.window.showInputBox({
|
||||||
// if (name !== undefined) {
|
value: projectName,
|
||||||
// vscode.window.showInformationMessage(`creating with ${name}`);
|
placeHolder: 'The project name.',
|
||||||
// }
|
validateInput: text => {
|
||||||
// }
|
return text.length < 1 ? 'The project name cannot be empty.' : null;
|
||||||
// TODO initialise kanbn board
|
}
|
||||||
// updateStatusBarItem();
|
});
|
||||||
// console.log(kanbn);
|
|
||||||
// console.log(`kanbn initialised: ${await kanbn.initialised()}`);
|
// If the input prompt wasn't cancelled, initialise kanbn
|
||||||
|
if (newProjectName !== undefined) {
|
||||||
|
await kanbn.initialise({
|
||||||
|
name: newProjectName
|
||||||
|
});
|
||||||
|
vscode.window.showInformationMessage(`Initialised kanbn project '${newProjectName}'.`);
|
||||||
|
updateStatusBarItem(kanbn);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Register a command to open the kanbn board. This command will be invoked when the status bar item is clicked
|
// Register a command to open the kanbn board. This command will be invoked when the status bar item is clicked
|
||||||
// in a workspace where kanbn has already been initialised.
|
// in a workspace where kanbn has already been initialised.
|
||||||
const openBoardCommandId = 'kanbn.open';
|
context.subscriptions.push(vscode.commands.registerCommand('kanbn.board', async () => {
|
||||||
context.subscriptions.push(vscode.commands.registerCommand(openBoardCommandId, () => {
|
|
||||||
ReactPanel.createOrShow(context.extensionPath);
|
// If no workspace folder is opened, we can't open the kanbn board
|
||||||
|
if (vscode.workspace.workspaceFolders === undefined) {
|
||||||
|
vscode.window.showErrorMessage('You need to open a workspace before viewing the kanbn board.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the node process directory and import kanbn
|
||||||
|
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
|
||||||
|
const kanbn = await import('@basementuniverse/kanbn/src/main');
|
||||||
|
|
||||||
|
// If kanbn is initialised, view the kanbn board
|
||||||
|
if (await kanbn.initialised()) {
|
||||||
|
ReactPanel.createOrShow(context.extensionPath);
|
||||||
|
} else {
|
||||||
|
vscode.window.showErrorMessage('You need to initialise kanbn before viewing the kanbn board.');
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// If a workspace folder is open, add a status bar item and start watching for file changes
|
// If a workspace folder is open, add a status bar item and start watching for file changes
|
||||||
if (vscode.workspace.workspaceFolders !== undefined) {
|
if (vscode.workspace.workspaceFolders !== undefined) {
|
||||||
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
|
|
||||||
statusBarItem.command = openBoardCommandId;
|
|
||||||
context.subscriptions.push(statusBarItem);
|
|
||||||
updateStatusBarItem();
|
|
||||||
|
|
||||||
|
// Set the node process directory and import kanbn
|
||||||
|
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
|
||||||
|
const kanbn = await import('@basementuniverse/kanbn/src/main');
|
||||||
|
|
||||||
|
// Create status bar item
|
||||||
|
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
|
||||||
|
context.subscriptions.push(statusBarItem);
|
||||||
|
updateStatusBarItem(kanbn);
|
||||||
|
|
||||||
|
// Initialise file watcher
|
||||||
const uri = vscode.workspace.workspaceFolders[0].uri.fsPath;
|
const uri = vscode.workspace.workspaceFolders[0].uri.fsPath;
|
||||||
const fileWatcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(uri, '.kanbn/*'));
|
const fileWatcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(uri, '.kanbn/*'));
|
||||||
fileWatcher.onDidChange(e => {
|
fileWatcher.onDidChange(() => {
|
||||||
|
updateStatusBarItem(kanbn);
|
||||||
// TODO update kanbn board
|
// TODO update kanbn board
|
||||||
updateStatusBarItem();
|
|
||||||
console.log(e);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,10 +92,18 @@ export function deactivate(): void {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatusBarItem(): void {
|
async function updateStatusBarItem(kanbn: typeof import('@basementuniverse/kanbn/src/main')): Promise<void> {
|
||||||
if (statusBarItem === undefined) {
|
if (statusBarItem === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
statusBarItem.text = `$(project) Not initialised`;
|
const initialised = await kanbn.initialised();
|
||||||
|
const text = initialised ? await getStatusBarText(kanbn) : 'Not initialised';
|
||||||
|
statusBarItem.text = `$(project) ${text}`;
|
||||||
|
statusBarItem.command = initialised ? 'kanbn.board' : 'kanbn.init';
|
||||||
statusBarItem.show();
|
statusBarItem.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getStatusBarText(kanbn: typeof import('@basementuniverse/kanbn/src/main')): Promise<string> {
|
||||||
|
const status = await kanbn.status(true);
|
||||||
|
return Object.values(status.columnTasks).join(' / ');
|
||||||
|
}
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
},
|
},
|
||||||
"publisher": "basementuniverse",
|
"publisher": "basementuniverse",
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"onStartupFinished",
|
"onStartupFinished"
|
||||||
"onCommand:kanbn.open"
|
|
||||||
],
|
],
|
||||||
"main": "./build/ext-src/extension.js",
|
"main": "./build/ext-src/extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
@ -18,7 +17,7 @@
|
|||||||
"category": "Kanbn"
|
"category": "Kanbn"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "kanbn.open",
|
"command": "kanbn.board",
|
||||||
"title": "Open board",
|
"title": "Open board",
|
||||||
"category": "Kanbn"
|
"category": "Kanbn"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user