Skip to content

Commit

Permalink
Refactor extension
Browse files Browse the repository at this point in the history
  • Loading branch information
svipas committed Feb 13, 2020
1 parent 3af792e commit 2999f75
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
20 changes: 10 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as vscode from 'vscode';
import { ExtensionCommand } from './extension-command';
import { message } from './message';
import { progressBadge } from './progress-badge';
import { Message } from './message';
import { ProgressBadge } from './progress-badge';

export function activate(context: vscode.ExtensionContext) {
const messageKeys = Object.keys(message);

context.subscriptions.push(
vscode.commands.registerCommand(ExtensionCommand.SHOW_INFORMATION_MESSAGE, () => message.showInfo()),
vscode.commands.registerCommand(ExtensionCommand.SHOW_WARNING_MESSAGE, () => message.showWarn()),
vscode.commands.registerCommand(ExtensionCommand.SHOW_ERROR_MESSAGE, () => message.showError()),
vscode.commands.registerCommand(ExtensionCommand.SHOW_INFORMATION_MESSAGE, () => Message.info()),
vscode.commands.registerCommand(ExtensionCommand.SHOW_WARNING_MESSAGE, () => Message.warn()),
vscode.commands.registerCommand(ExtensionCommand.SHOW_ERROR_MESSAGE, () => Message.error()),
vscode.commands.registerCommand(ExtensionCommand.SHOW_ALL_MESSAGES, () => {
messageKeys.forEach(key => message[key]());
Message.info();
Message.warn();
Message.error();
}),
vscode.commands.registerCommand(ExtensionCommand.START_PROGRESS_BADGE, () => progressBadge.start()),
vscode.commands.registerCommand(ExtensionCommand.STOP_PROGRESS_BADGE, () => progressBadge.stop())
vscode.commands.registerCommand(ExtensionCommand.START_PROGRESS_BADGE, () => ProgressBadge.start()),
vscode.commands.registerCommand(ExtensionCommand.STOP_PROGRESS_BADGE, () => ProgressBadge.stop())
);
}

Expand Down
24 changes: 12 additions & 12 deletions src/message.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as vscode from 'vscode';

function showInfo() {
vscode.window.showInformationMessage('Information message.', { title: 'Yes' }, { title: 'No' });
export class Message {
static info() {
vscode.window.showInformationMessage('Information message.', { title: 'Yes' }, { title: 'No' });
}

static warn() {
vscode.window.showWarningMessage('Warning message.', { title: 'Yes' }, { title: 'No' });
}

static error() {
vscode.window.showErrorMessage('Error message.', { title: 'Yes' }, { title: 'No' });
}
}

function showWarn() {
vscode.window.showWarningMessage('Warning message.', { title: 'Yes' }, { title: 'No' });
}

function showError() {
vscode.window.showErrorMessage('Error message.', { title: 'Yes' }, { title: 'No' });
}

export const message = { showInfo, showWarn, showError };
40 changes: 20 additions & 20 deletions src/progress-badge.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as vscode from 'vscode';

let resolveFn: () => void;
export class ProgressBadge {
private static resolveFn?: () => void;

function start() {
if (resolveFn) {
vscode.window.showWarningMessage('Progress Badge is already visible in Source Control!');
return;
static start() {
if (this.resolveFn) {
vscode.window.showWarningMessage('Progress Badge is already visible in Source Control!');
return;
}

vscode.window.withProgress({ location: vscode.ProgressLocation.SourceControl }, () => {
vscode.window.showInformationMessage('Progress Badge is visible in Source Control.');
return new Promise(resolve => (this.resolveFn = resolve));
});
}

vscode.window.withProgress({ location: vscode.ProgressLocation.SourceControl }, () => {
vscode.window.showInformationMessage('Progress Badge is visible in Source Control.');
return new Promise(resolve => (resolveFn = resolve));
});
}
static stop() {
if (!this.resolveFn) {
vscode.window.showWarningMessage('Progress Badge is already stopped!');
return;
}

function stop() {
if (!resolveFn) {
vscode.window.showWarningMessage('Progress Badge is already stopped!');
return;
this.resolveFn();
this.resolveFn = undefined;
vscode.window.showInformationMessage('Progress Badge is stopped.');
}

resolveFn();
resolveFn = undefined;
vscode.window.showInformationMessage('Progress Badge is stopped.');
}

export const progressBadge = { start, stop };

0 comments on commit 2999f75

Please sign in to comment.