Gitea-VSCode/src/extension.ts

42 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-04-09 14:37:58 +02:00
import * as vscode from 'vscode';
import { showIssueHTML } from './template.html';
import { Issue } from './issue';
2020-08-16 20:26:14 +02:00
import { IssueProvider } from './issueProvider';
2019-04-09 14:37:58 +02:00
2020-08-16 20:26:14 +02:00
export function showIssueInWebPanel(issue: Issue) {
const panel = vscode.window.createWebviewPanel('issue', issue.label, vscode.ViewColumn.Active, {});
panel.webview.html = showIssueHTML(issue);
2020-08-16 20:26:14 +02:00
return panel;
}
export function activate(context: vscode.ExtensionContext) {
// Array of issues; This is used to determine whether a issue is already open
// in a tab or not.
let openIssues: Array<Issue> = [];
const openIssuesProvider = new IssueProvider("open");
const closedIssuesProvider = new IssueProvider("closed");
vscode.window.registerTreeDataProvider('open-issues', openIssuesProvider);
vscode.window.registerTreeDataProvider('closed-issues', closedIssuesProvider);
vscode.commands.registerCommand('giteaIssues.openIssue', (issue: Issue) => {
const issueOpenable = openIssues.find((c) => c.issueId === issue.issueId) === undefined;
if (issueOpenable) {
const panel = showIssueInWebPanel(issue);
openIssues.push(issue);
panel.onDidDispose((event) => {
openIssues.splice(openIssues.indexOf(issue), 1);
});
2019-06-14 13:22:17 +02:00
}
});
2020-08-16 20:26:14 +02:00
vscode.commands.registerCommand('giteaIssues.refreshIssues', () => {
openIssuesProvider.refresh();
closedIssuesProvider.refresh();
});
2019-04-09 14:37:58 +02:00
}
export function deactivate() {}