提交 a396179e 编写于 作者: B Benjamin Pasero

debt - notifications should talk about closing not disposal

上级 99b6b5d6
......@@ -7,7 +7,6 @@
import BaseSeverity from 'vs/base/common/severity';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IAction } from 'vs/base/common/actions';
import { Event, Emitter } from 'vs/base/common/event';
......@@ -89,12 +88,12 @@ export interface INotificationProgress {
done(): void;
}
export interface INotificationHandle extends IDisposable {
export interface INotificationHandle {
/**
* Will be fired once the notification is disposed.
* Will be fired once the notification is closed.
*/
readonly onDidDispose: Event<void>;
readonly onDidClose: Event<void>;
/**
* Allows to indicate progress on the notification even after the
......@@ -118,6 +117,11 @@ export interface INotificationHandle extends IDisposable {
* notification is already visible.
*/
updateActions(actions?: INotificationActions): void;
/**
* Hide the notification and remove it from the notification center.
*/
close(): void;
}
export interface IPromptChoice {
......@@ -199,18 +203,18 @@ export interface INotificationService {
export class NoOpNotification implements INotificationHandle {
readonly progress = new NoOpProgress();
private readonly _onDidDispose: Emitter<void> = new Emitter();
private readonly _onDidClose: Emitter<void> = new Emitter();
public get onDidDispose(): Event<void> {
return this._onDidDispose.event;
public get onDidClose(): Event<void> {
return this._onDidClose.event;
}
updateSeverity(severity: Severity): void { }
updateMessage(message: NotificationMessage): void { }
updateActions(actions?: INotificationActions): void { }
dispose(): void {
this._onDidDispose.dispose();
close(): void {
this._onDidClose.dispose();
}
}
......
......@@ -92,7 +92,7 @@ export class MainThreadMessageService implements MainThreadMessageServiceShape {
// if promise has not been resolved yet, now is the time to ensure a return value
// otherwise if already resolved it means the user clicked one of the buttons
once(messageHandle.onDidDispose)(() => {
once(messageHandle.onDidClose)(() => {
dispose(...primaryActions, ...secondaryActions);
resolve(undefined);
});
......
......@@ -559,7 +559,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
actions
});
once(handle.onDidDispose)(() => dispose(actions.primary));
once(handle.onDidClose)(() => dispose(actions.primary));
}
this.editorGroupsControl.updateProgress(position, ProgressState.DONE);
......
......@@ -289,9 +289,9 @@ export class NotificationsCenter extends Themable {
// Hide notifications center first
this.hide();
// Dispose all
// Close all
while (this.model.notifications.length) {
this.model.notifications[0].dispose();
this.model.notifications[0].close();
}
}
}
......
......@@ -115,7 +115,7 @@ export function registerNotificationCommands(center: INotificationsCenterControl
handler: (accessor, args?: any) => {
const notification = getNotificationFromContext(accessor.get(IListService), args);
if (notification) {
notification.dispose();
notification.close();
}
}
});
......
......@@ -168,8 +168,8 @@ export class NotificationsToasts extends Themable {
}
}));
// Remove when item gets disposed
once(item.onDidDispose)(() => {
// Remove when item gets closed
once(item.onDidClose)(() => {
this.removeToast(item);
});
......
......@@ -442,7 +442,7 @@ export class NotificationTemplateRenderer {
this.actionRunner.run(action, notification);
// Hide notification
notification.dispose();
notification.close();
}));
this.inputDisposeables.push(attachButtonStyler(button, this.themeService));
......
......@@ -44,21 +44,21 @@ export interface INotificationChangeEvent {
}
export class NotificationHandle implements INotificationHandle {
private readonly _onDidDispose: Emitter<void> = new Emitter();
private readonly _onDidClose: Emitter<void> = new Emitter();
constructor(private item: INotificationViewItem, private disposeItem: (item: INotificationViewItem) => void) {
constructor(private item: INotificationViewItem, private closeItem: (item: INotificationViewItem) => void) {
this.registerListeners();
}
private registerListeners(): void {
once(this.item.onDidDispose)(() => {
this._onDidDispose.fire();
this._onDidDispose.dispose();
once(this.item.onDidClose)(() => {
this._onDidClose.fire();
this._onDidClose.dispose();
});
}
public get onDidDispose(): Event<void> {
return this._onDidDispose.event;
public get onDidClose(): Event<void> {
return this._onDidClose.event;
}
public get progress(): INotificationProgress {
......@@ -77,9 +77,9 @@ export class NotificationHandle implements INotificationHandle {
this.item.updateActions(actions);
}
public dispose(): void {
this.disposeItem(this.item);
this._onDidDispose.dispose();
public close(): void {
this.closeItem(this.item);
this._onDidClose.dispose();
}
}
......@@ -117,7 +117,7 @@ export class NotificationsModel implements INotificationsModel {
// Deduplicate
const duplicate = this.findNotification(item);
if (duplicate) {
duplicate.dispose();
duplicate.close();
}
// Add to list as first entry
......@@ -127,15 +127,15 @@ export class NotificationsModel implements INotificationsModel {
this._onDidNotificationChange.fire({ item, index: 0, kind: NotificationChangeType.ADD });
// Wrap into handle
return new NotificationHandle(item, item => this.disposeItem(item));
return new NotificationHandle(item, item => this.closeItem(item));
}
private disposeItem(item: INotificationViewItem): void {
private closeItem(item: INotificationViewItem): void {
const liveItem = this.findNotification(item);
if (liveItem && liveItem !== item) {
liveItem.dispose(); // item could have been replaced with another one, make sure to dispose the live item
liveItem.close(); // item could have been replaced with another one, make sure to close the live item
} else {
item.dispose(); // otherwise just dispose the item that was passed in
item.close(); // otherwise just close the item that was passed in
}
}
......@@ -174,7 +174,7 @@ export class NotificationsModel implements INotificationsModel {
}
});
once(item.onDidDispose)(() => {
once(item.onDidClose)(() => {
itemExpansionChangeListener.dispose();
itemLabelChangeListener.dispose();
......@@ -204,7 +204,7 @@ export interface INotificationViewItem {
readonly canCollapse: boolean;
readonly onDidExpansionChange: Event<void>;
readonly onDidDispose: Event<void>;
readonly onDidClose: Event<void>;
readonly onDidLabelChange: Event<INotificationViewItemLabelChangeEvent>;
expand(): void;
......@@ -217,7 +217,7 @@ export interface INotificationViewItem {
updateMessage(message: NotificationMessage): void;
updateActions(actions?: INotificationActions): void;
dispose(): void;
close(): void;
equals(item: INotificationViewItem);
}
......@@ -359,7 +359,7 @@ export class NotificationViewItem implements INotificationViewItem {
private _progress: NotificationViewItemProgress;
private readonly _onDidExpansionChange: Emitter<void>;
private readonly _onDidDispose: Emitter<void>;
private readonly _onDidClose: Emitter<void>;
private readonly _onDidLabelChange: Emitter<INotificationViewItemLabelChangeEvent>;
public static create(notification: INotification): INotificationViewItem {
......@@ -435,8 +435,8 @@ export class NotificationViewItem implements INotificationViewItem {
this._onDidLabelChange = new Emitter<INotificationViewItemLabelChangeEvent>();
this.toDispose.push(this._onDidLabelChange);
this._onDidDispose = new Emitter<void>();
this.toDispose.push(this._onDidDispose);
this._onDidClose = new Emitter<void>();
this.toDispose.push(this._onDidClose);
}
private setActions(actions: INotificationActions): void {
......@@ -464,8 +464,8 @@ export class NotificationViewItem implements INotificationViewItem {
return this._onDidLabelChange.event;
}
public get onDidDispose(): Event<void> {
return this._onDidDispose.event;
public get onDidClose(): Event<void> {
return this._onDidClose.event;
}
public get canCollapse(): boolean {
......@@ -556,8 +556,8 @@ export class NotificationViewItem implements INotificationViewItem {
}
}
public dispose(): void {
this._onDidDispose.fire();
public close(): void {
this._onDidClose.fire();
this.toDispose = dispose(this.toDispose);
}
......
......@@ -102,7 +102,7 @@ export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContributi
private onFileSavedOrReverted(resource: URI): void {
const messageHandle = this.messages.get(resource);
if (messageHandle) {
messageHandle.dispose();
messageHandle.close();
this.messages.delete(resource);
}
}
......@@ -179,7 +179,7 @@ export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContributi
// Show message and keep function to hide in case the file gets saved/reverted
const handle = this.notificationService.notify({ severity: Severity.Error, message, actions });
once(handle.onDidDispose)(() => dispose(...actions.primary, ...actions.secondary));
once(handle.onDidClose)(() => dispose(...actions.primary, ...actions.secondary));
this.messages.set(model.getResource(), handle);
}
......@@ -193,7 +193,7 @@ export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContributi
const pendingResolveSaveConflictMessages: INotificationHandle[] = [];
function clearPendingResolveSaveConflictMessages(): void {
while (pendingResolveSaveConflictMessages.length > 0) {
pendingResolveSaveConflictMessages.pop().dispose();
pendingResolveSaveConflictMessages.pop().close();
}
}
......@@ -265,7 +265,7 @@ class ResolveSaveConflictAction extends Action {
actions.secondary.push(this.instantiationService.createInstance(DoNotShowResolveConflictLearnMoreAction));
const handle = this.notificationService.notify({ severity: Severity.Info, message: conflictEditorHelp, actions });
once(handle.onDidDispose)(() => dispose(...actions.primary, ...actions.secondary));
once(handle.onDidClose)(() => dispose(...actions.primary, ...actions.secondary));
pendingResolveSaveConflictMessages.push(handle);
});
}
......
......@@ -80,7 +80,7 @@ export class NotificationService implements INotificationService {
// Close notification unless we are told to keep open
if (!choice.keepOpen) {
handle.dispose();
handle.close();
}
return TPromise.as(void 0);
......@@ -96,7 +96,7 @@ export class NotificationService implements INotificationService {
// Show notification with actions
handle = this.notify({ severity, message, actions });
once(handle.onDidDispose)(() => {
once(handle.onDidClose)(() => {
// Cleanup when notification gets disposed
dispose(...actions.primary, ...actions.secondary);
......
......@@ -203,7 +203,7 @@ export class ProgressService2 implements IProgressService2 {
updateProgress(handle, increment);
once(handle.onDidDispose)(() => {
once(handle.onDidClose)(() => {
dispose(toDispose);
});
......@@ -247,7 +247,7 @@ export class ProgressService2 implements IProgressService2 {
// Show progress for at least 800ms and then hide once done or canceled
always(TPromise.join([TPromise.timeout(800), p]), () => {
if (handle) {
handle.dispose();
handle.close();
}
});
......
......@@ -96,11 +96,11 @@ suite('Notifications', () => {
assert.equal(called, 1);
called = 0;
item1.onDidDispose(() => {
item1.onDidClose(() => {
called++;
});
item1.dispose();
item1.close();
assert.equal(called, 1);
// Error with Action
......@@ -157,11 +157,11 @@ suite('Notifications', () => {
assert.equal(model.notifications.length, 3);
let called = 0;
item1Handle.onDidDispose(() => {
item1Handle.onDidClose(() => {
called++;
});
item1Handle.dispose();
item1Handle.close();
assert.equal(called, 1);
assert.equal(model.notifications.length, 2);
assert.equal(lastEvent.item.severity, item1.severity);
......@@ -176,7 +176,7 @@ suite('Notifications', () => {
assert.equal(lastEvent.index, 0);
assert.equal(lastEvent.kind, NotificationChangeType.ADD);
item2Handle.dispose();
item2Handle.close();
assert.equal(model.notifications.length, 1);
assert.equal(lastEvent.item.severity, item2Duplicate.severity);
assert.equal(lastEvent.item.message.value, item2Duplicate.message);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册