Skip to content

Commit

Permalink
fix #50479
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed May 31, 2018
1 parent 6d06a25 commit 8954271
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
21 changes: 18 additions & 3 deletions src/vs/base/browser/ui/progressbar/progressbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,31 @@ export class ProgressBar {
}

/**
* Tells the progress bar that an amount of work has been completed.
* Tells the progress bar that an increment of work has been completed.
*/
public worked(value: number): ProgressBar {
assert.ok(!isNaN(this.totalWork), 'Total work not set');
value = Number(value);
assert.ok(!isNaN(value), 'Value is not a number');
value = Math.max(1, value);

return this.doSetWorked(this.workedVal + value);
}

/**
* Tells the progress bar the total amount of work that has been completed.
*/
public setWorked(value: number): ProgressBar {
value = Number(value);
assert.ok(!isNaN(value), 'Value is not a number');
value = Math.max(1, value);

this.workedVal += value;
return this.doSetWorked(value);
}

private doSetWorked(value: number): ProgressBar {
assert.ok(!isNaN(this.totalWork), 'Total work not set');

this.workedVal = value;
this.workedVal = Math.min(this.totalWork, this.workedVal);

if (this.element.hasClass(css_infinite)) {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/base/test/browser/progressBar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ suite('ProgressBar', () => {
assert(bar.infinite());
assert(bar.total(100));
assert(bar.worked(50));
assert(bar.worked(50));
assert(bar.setWorked(70));
assert(bar.worked(30));
assert(bar.done());

bar.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class NotificationTemplateRenderer {
}

if (typeof state.worked === 'number') {
this.template.progress.worked(state.worked).show();
this.template.progress.setWorked(state.worked).show();
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/common/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ export class NotificationViewItemProgress implements INotificationViewItemProgre
}

public worked(value: number): void {
this._state.worked = value;
if (typeof this._state.worked === 'number') {
this._state.worked += value;
} else {
this._state.worked = value;
}

this._state.infinite = void 0;
this._state.done = void 0;
Expand Down

0 comments on commit 8954271

Please sign in to comment.