提交 cd82bcb5 编写于 作者: M Matt Bierner

Make Action extend Disposable

This class already is an implicit IDisposable and a number of subclasses to it re-implement the Disposable logic
上级 025c005f
......@@ -48,9 +48,9 @@ export interface IActionChangeEvent {
radio?: boolean;
}
export class Action implements IAction {
export class Action extends Disposable implements IAction {
protected _onDidChange = new Emitter<IActionChangeEvent>();
protected _onDidChange = this._register(new Emitter<IActionChangeEvent>());
readonly onDidChange: Event<IActionChangeEvent> = this._onDidChange.event;
protected _id: string;
......@@ -63,6 +63,7 @@ export class Action implements IAction {
protected _actionCallback?: (event?: any) => Promise<any>;
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => Promise<any>) {
super();
this._id = id;
this._label = label;
this._cssClass = cssClass;
......@@ -171,10 +172,6 @@ export class Action implements IAction {
return Promise.resolve(true);
}
dispose() {
this._onDidChange.dispose();
}
}
export interface IRunEvent {
......
......@@ -83,15 +83,13 @@ export class NewFileAction extends Action {
static readonly ID = 'workbench.files.action.createFileFromExplorer';
static readonly LABEL = nls.localize('createNewFile', "New File");
private toDispose: IDisposable[] = [];
constructor(
@IExplorerService explorerService: IExplorerService,
@ICommandService private commandService: ICommandService
) {
super('explorer.newFile', NEW_FILE_LABEL);
this.class = 'explorer-action new-file';
this.toDispose.push(explorerService.onDidChangeEditable(e => {
this._register(explorerService.onDidChangeEditable(e => {
const elementIsBeingEdited = explorerService.isEditable(e);
this.enabled = !elementIsBeingEdited;
}));
......@@ -100,11 +98,6 @@ export class NewFileAction extends Action {
run(): Promise<any> {
return this.commandService.executeCommand(NEW_FILE_COMMAND_ID);
}
dispose(): void {
super.dispose();
dispose(this.toDispose);
}
}
/* New Folder */
......@@ -112,15 +105,13 @@ export class NewFolderAction extends Action {
static readonly ID = 'workbench.files.action.createFolderFromExplorer';
static readonly LABEL = nls.localize('createNewFolder', "New Folder");
private toDispose: IDisposable[] = [];
constructor(
@IExplorerService explorerService: IExplorerService,
@ICommandService private commandService: ICommandService
) {
super('explorer.newFolder', NEW_FOLDER_LABEL);
this.class = 'explorer-action new-folder';
this.toDispose.push(explorerService.onDidChangeEditable(e => {
this._register(explorerService.onDidChangeEditable(e => {
const elementIsBeingEdited = explorerService.isEditable(e);
this.enabled = !elementIsBeingEdited;
}));
......@@ -129,11 +120,6 @@ export class NewFolderAction extends Action {
run(): Promise<any> {
return this.commandService.executeCommand(NEW_FOLDER_COMMAND_ID);
}
dispose(): void {
super.dispose();
dispose(this.toDispose);
}
}
/* Create new file from anywhere: Open untitled */
......@@ -508,7 +494,6 @@ export class ToggleAutoSaveAction extends Action {
}
export abstract class BaseSaveAllAction extends Action {
private toDispose: IDisposable[];
private lastIsDirty: boolean;
constructor(
......@@ -521,7 +506,6 @@ export abstract class BaseSaveAllAction extends Action {
) {
super(id, label);
this.toDispose = [];
this.lastIsDirty = this.textFileService.isDirty();
this.enabled = this.lastIsDirty;
......@@ -534,13 +518,13 @@ export abstract class BaseSaveAllAction extends Action {
private registerListeners(): void {
// listen to files being changed locally
this.toDispose.push(this.textFileService.models.onModelsDirty(e => this.updateEnablement(true)));
this.toDispose.push(this.textFileService.models.onModelsSaved(e => this.updateEnablement(false)));
this.toDispose.push(this.textFileService.models.onModelsReverted(e => this.updateEnablement(false)));
this.toDispose.push(this.textFileService.models.onModelsSaveError(e => this.updateEnablement(true)));
this._register(this.textFileService.models.onModelsDirty(e => this.updateEnablement(true)));
this._register(this.textFileService.models.onModelsSaved(e => this.updateEnablement(false)));
this._register(this.textFileService.models.onModelsReverted(e => this.updateEnablement(false)));
this._register(this.textFileService.models.onModelsSaveError(e => this.updateEnablement(true)));
if (this.includeUntitled()) {
this.toDispose.push(this.untitledEditorService.onDidChangeDirty(resource => this.updateEnablement(this.untitledEditorService.isDirty(resource))));
this._register(this.untitledEditorService.onDidChangeDirty(resource => this.updateEnablement(this.untitledEditorService.isDirty(resource))));
}
}
......@@ -557,12 +541,6 @@ export abstract class BaseSaveAllAction extends Action {
return false;
});
}
public dispose(): void {
this.toDispose = dispose(this.toDispose);
super.dispose();
}
}
export class SaveAllAction extends BaseSaveAllAction {
......@@ -664,16 +642,14 @@ export class CollapseExplorerView extends Action {
public static readonly ID = 'workbench.files.action.collapseExplorerFolders';
public static readonly LABEL = nls.localize('collapseExplorerFolders', "Collapse Folders in Explorer");
private toDispose: IDisposable[] = [];
constructor(
id: string,
constructor(id: string,
label: string,
@IViewletService private readonly viewletService: IViewletService,
@IExplorerService readonly explorerService: IExplorerService
) {
super(id, label, 'explorer-action collapse-explorer');
this.toDispose.push(explorerService.onDidChangeEditable(e => {
this._register(explorerService.onDidChangeEditable(e => {
const elementIsBeingEdited = explorerService.isEditable(e);
this.enabled = !elementIsBeingEdited;
}));
......@@ -687,11 +663,6 @@ export class CollapseExplorerView extends Action {
}
});
}
dispose(): void {
super.dispose();
dispose(this.toDispose);
}
}
export class RefreshExplorerView extends Action {
......@@ -699,16 +670,14 @@ export class RefreshExplorerView extends Action {
public static readonly ID = 'workbench.files.action.refreshFilesExplorer';
public static readonly LABEL = nls.localize('refreshExplorer', "Refresh Explorer");
private toDispose: IDisposable[] = [];
constructor(
id: string,
label: string,
id: string, label: string,
@IViewletService private readonly viewletService: IViewletService,
@IExplorerService private readonly explorerService: IExplorerService
) {
super(id, label, 'explorer-action refresh-explorer');
this.toDispose.push(explorerService.onDidChangeEditable(e => {
this._register(explorerService.onDidChangeEditable(e => {
const elementIsBeingEdited = explorerService.isEditable(e);
this.enabled = !elementIsBeingEdited;
}));
......@@ -719,11 +688,6 @@ export class RefreshExplorerView extends Action {
this.explorerService.refresh()
);
}
dispose(): void {
super.dispose();
dispose(this.toDispose);
}
}
export class ShowOpenedFileInNewWindow extends Action {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册