Skip to content

Commit 8954271

Browse files
author
Benjamin Pasero
committed
1 parent 6d06a25 commit 8954271

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/vs/base/browser/ui/progressbar/progressbar.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,31 @@ export class ProgressBar {
164164
}
165165

166166
/**
167-
* Tells the progress bar that an amount of work has been completed.
167+
* Tells the progress bar that an increment of work has been completed.
168168
*/
169169
public worked(value: number): ProgressBar {
170-
assert.ok(!isNaN(this.totalWork), 'Total work not set');
170+
value = Number(value);
171+
assert.ok(!isNaN(value), 'Value is not a number');
172+
value = Math.max(1, value);
173+
174+
return this.doSetWorked(this.workedVal + value);
175+
}
171176

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

176-
this.workedVal += value;
185+
return this.doSetWorked(value);
186+
}
187+
188+
private doSetWorked(value: number): ProgressBar {
189+
assert.ok(!isNaN(this.totalWork), 'Total work not set');
190+
191+
this.workedVal = value;
177192
this.workedVal = Math.min(this.totalWork, this.workedVal);
178193

179194
if (this.element.hasClass(css_infinite)) {

src/vs/base/test/browser/progressBar.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ suite('ProgressBar', () => {
2424
assert(bar.infinite());
2525
assert(bar.total(100));
2626
assert(bar.worked(50));
27-
assert(bar.worked(50));
27+
assert(bar.setWorked(70));
28+
assert(bar.worked(30));
2829
assert(bar.done());
2930

3031
bar.dispose();

src/vs/workbench/browser/parts/notifications/notificationsViewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export class NotificationTemplateRenderer {
474474
}
475475

476476
if (typeof state.worked === 'number') {
477-
this.template.progress.worked(state.worked).show();
477+
this.template.progress.setWorked(state.worked).show();
478478
}
479479
}
480480

src/vs/workbench/common/notifications.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ export class NotificationViewItemProgress implements INotificationViewItemProgre
314314
}
315315

316316
public worked(value: number): void {
317-
this._state.worked = value;
317+
if (typeof this._state.worked === 'number') {
318+
this._state.worked += value;
319+
} else {
320+
this._state.worked = value;
321+
}
318322

319323
this._state.infinite = void 0;
320324
this._state.done = void 0;

0 commit comments

Comments
 (0)