Skip to content

Commit

Permalink
Option to open tasks to the side on click board click
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Bachmann committed Jan 8, 2025
1 parent 9bae18d commit 09483e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
19 changes: 15 additions & 4 deletions ext-src/KanbnBoardPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export default class KanbnBoardPanel {
if (this._panel == null) {
await this.setUpPanel()
}

this.reveal()
}

private reveal (): void {
this._panel?.reveal(this.column)
}

Expand All @@ -49,10 +54,10 @@ export default class KanbnBoardPanel {
}
}

public showTaskPanel (taskId: string | null, column: string | null = null): void {
public showTaskPanel (taskId: string | null, column: string | null = null, openToSide: boolean = false): void {
let panel: KanbnTaskPanel
if (taskId == null || !this.openedTaskPanels.has(taskId)) {
panel = new KanbnTaskPanel(this._extensionPath, this._workspacePath, this._kanbn, this._kanbnFolderName, taskId ?? Symbol('prelim-task-id'), column, this.openedTaskPanels)
panel = new KanbnTaskPanel(this._extensionPath, this._workspacePath, this._kanbn, this._kanbnFolderName, taskId ?? Symbol('prelim-task-id'), column, openToSide, this.openedTaskPanels)
this.openedTaskPanels.set(panel.getTaskId(), panel)
} else {
panel = this.openedTaskPanels.get(taskId) as KanbnTaskPanel
Expand Down Expand Up @@ -133,6 +138,8 @@ export default class KanbnBoardPanel {
// Handle messages from the webview
this._panel.webview.onDidReceiveMessage(
async (message) => {
this.reveal()

switch (message.command) {
// Display error message
case 'error':
Expand All @@ -146,7 +153,7 @@ export default class KanbnBoardPanel {

// Open an already existing task in the editor
case 'kanbn.task':
this.showTaskPanel(message.taskId, message.columnName)
this.showTaskPanel(message.taskId, message.columnName, this.isOpenTaskToSide())
return

// Move a task
Expand All @@ -164,7 +171,7 @@ export default class KanbnBoardPanel {

// Open a webview for a new task (with no ID)
case 'kanbn.addTask':
this.showTaskPanel(null, message.columnName)
this.showTaskPanel(null, message.columnName, this.isOpenTaskToSide())
return

// Sort a column
Expand Down Expand Up @@ -281,6 +288,10 @@ export default class KanbnBoardPanel {
this._kanbnBurndownPanel = kanbnBurndownPanel
}

private isOpenTaskToSide (): boolean | undefined {
return vscode.workspace.getConfiguration('kanbn').get<boolean>('openBoardTasksToSide')
}

private _getHtmlForWebview (): string {
const mainScript = path.join('static', 'index.js')
const mainStyle = path.join('static', 'index.css')
Expand Down
7 changes: 4 additions & 3 deletions ext-src/KanbnTaskPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ export default class KanbnTaskPanel {
kanbnFolderName: string,
taskId: string | symbol,
defaultColumn: string | null,
openToSide: boolean,
taskCache: Map<string | symbol, KanbnTaskPanel>
) {
const column = vscode.window.activeTextEditor?.viewColumn ?? vscode.ViewColumn.One
const column = openToSide ? vscode.ViewColumn.Beside : vscode.window.activeTextEditor?.viewColumn
this._extensionPath = extensionPath
this._workspacePath = workspacePath
this._kanbn = kanbn
Expand Down Expand Up @@ -224,8 +225,8 @@ export default class KanbnTaskPanel {
)
}

private createWebviewPanel (column: vscode.ViewColumn): vscode.WebviewPanel {
return vscode.window.createWebviewPanel(KanbnTaskPanel.viewType, 'New task', column, {
private createWebviewPanel (column?: vscode.ViewColumn): vscode.WebviewPanel {
return vscode.window.createWebviewPanel(KanbnTaskPanel.viewType, 'New task', column as any, {
// Enable javascript in the webview
enableScripts: true,

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"type": "string",
"default": "vscode.markdown.preview.editor",
"description": "Set the editor to be used when opening task source files."
},
"kanbn.openBoardTasksToSide": {
"type": "boolean",
"default": false,
"description": "Opens tasks clicked on the board to an editor to the right."
}
}
}
Expand Down Expand Up @@ -208,4 +213,4 @@
"not ie <= 11",
"not op_mini all"
]
}
}

0 comments on commit 09483e9

Please sign in to comment.