Skip to content

Commit f91e3ee

Browse files
committed
working copy - reduce dirty listeners and support "save all" action enablement (#84672)
1 parent 5e7b782 commit f91e3ee

File tree

4 files changed

+23
-43
lines changed

4 files changed

+23
-43
lines changed

src/vs/workbench/browser/parts/editor/editorActions.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1274,8 +1274,6 @@ export class BaseQuickOpenEditorInGroupAction extends Action {
12741274
run(): Promise<any> {
12751275
const keys = this.keybindingService.lookupKeybindings(this.id);
12761276

1277-
1278-
12791277
this.quickOpenService.show(NAVIGATE_IN_ACTIVE_GROUP_PREFIX, { quickNavigateConfiguration: { keybindings: keys } });
12801278

12811279
return Promise.resolve(true);

src/vs/workbench/contrib/files/browser/fileActions.ts

+9-25
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
1919
import { IFileService } from 'vs/platform/files/common/files';
2020
import { toResource, SideBySideEditor } from 'vs/workbench/common/editor';
2121
import { ExplorerViewlet } from 'vs/workbench/contrib/files/browser/explorerViewlet';
22-
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
2322
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
2423
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
2524
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
@@ -47,6 +46,7 @@ import { onUnexpectedError, getErrorMessage } from 'vs/base/common/errors';
4746
import { asDomUri, triggerDownload } from 'vs/base/browser/dom';
4847
import { mnemonicButtonLabel } from 'vs/base/common/labels';
4948
import { IAutoSaveConfigurationService } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
49+
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
5050

5151
export const NEW_FILE_COMMAND_ID = 'explorer.newFile';
5252
export const NEW_FILE_LABEL = nls.localize('newFile', "New File");
@@ -512,38 +512,30 @@ export abstract class BaseSaveAllAction extends Action {
512512
constructor(
513513
id: string,
514514
label: string,
515-
@ITextFileService private readonly textFileService: ITextFileService,
516-
@IUntitledTextEditorService private readonly untitledTextEditorService: IUntitledTextEditorService,
517515
@ICommandService protected commandService: ICommandService,
518516
@INotificationService private notificationService: INotificationService,
517+
@IWorkingCopyService private readonly workingCopyService: IWorkingCopyService
519518
) {
520519
super(id, label);
521520

522-
this.lastIsDirty = this.textFileService.isDirty();
521+
this.lastIsDirty = this.workingCopyService.hasDirty;
523522
this.enabled = this.lastIsDirty;
524523

525524
this.registerListeners();
526525
}
527526

528-
protected abstract includeUntitled(): boolean;
529527
protected abstract doRun(context: any): Promise<any>;
530528

531529
private registerListeners(): void {
532530

533-
// listen to files being changed locally
534-
this._register(this.textFileService.models.onModelsDirty(e => this.updateEnablement(true)));
535-
this._register(this.textFileService.models.onModelsSaved(e => this.updateEnablement(false)));
536-
this._register(this.textFileService.models.onModelsReverted(e => this.updateEnablement(false)));
537-
this._register(this.textFileService.models.onModelsSaveError(e => this.updateEnablement(true)));
538-
539-
if (this.includeUntitled()) {
540-
this._register(this.untitledTextEditorService.onDidChangeDirty(resource => this.updateEnablement(this.untitledTextEditorService.isDirty(resource))));
541-
}
531+
// update enablement based on working copy changes
532+
this._register(this.workingCopyService.onDidChangeDirty(() => this.updateEnablement()));
542533
}
543534

544-
private updateEnablement(isDirty: boolean): void {
545-
if (this.lastIsDirty !== isDirty) {
546-
this.enabled = this.textFileService.isDirty();
535+
private updateEnablement(): void {
536+
const hasDirty = this.workingCopyService.hasDirty;
537+
if (this.lastIsDirty !== hasDirty) {
538+
this.enabled = hasDirty;
547539
this.lastIsDirty = this.enabled;
548540
}
549541
}
@@ -569,10 +561,6 @@ export class SaveAllAction extends BaseSaveAllAction {
569561
protected doRun(context: any): Promise<any> {
570562
return this.commandService.executeCommand(SAVE_ALL_COMMAND_ID);
571563
}
572-
573-
protected includeUntitled(): boolean {
574-
return true;
575-
}
576564
}
577565

578566
export class SaveAllInGroupAction extends BaseSaveAllAction {
@@ -587,10 +575,6 @@ export class SaveAllInGroupAction extends BaseSaveAllAction {
587575
protected doRun(context: any): Promise<any> {
588576
return this.commandService.executeCommand(SAVE_ALL_IN_GROUP_COMMAND_ID, {}, context);
589577
}
590-
591-
protected includeUntitled(): boolean {
592-
return true;
593-
}
594578
}
595579

596580
export class CloseGroupAction extends Action {

src/vs/workbench/contrib/search/browser/searchView.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class SearchView extends ViewletPanel {
178178
this.viewletState = this.memento.getMemento(StorageScope.WORKSPACE);
179179

180180
this._register(this.fileService.onFileChanges(e => this.onFilesChanged(e)));
181-
this._register(this.untitledTextEditorService.onDidChangeDirty(e => this.onUntitledDidChangeDirty(e)));
181+
this._register(this.untitledTextEditorService.onDidDisposeModel(e => this.onUntitledDidDispose(e)));
182182
this._register(this.contextService.onDidChangeWorkbenchState(() => this.onDidChangeWorkbenchState()));
183183
this._register(this.searchHistoryService.onDidClearHistory(() => this.clearHistory()));
184184

@@ -1581,18 +1581,16 @@ export class SearchView extends ViewletPanel {
15811581
return undefined;
15821582
}
15831583

1584-
private onUntitledDidChangeDirty(resource: URI): void {
1584+
private onUntitledDidDispose(resource: URI): void {
15851585
if (!this.viewModel) {
15861586
return;
15871587
}
15881588

15891589
// remove search results from this resource as it got disposed
1590-
if (!this.untitledTextEditorService.isDirty(resource)) {
1591-
const matches = this.viewModel.searchResult.matches();
1592-
for (let i = 0, len = matches.length; i < len; i++) {
1593-
if (resource.toString() === matches[i].resource.toString()) {
1594-
this.viewModel.searchResult.remove(matches[i]);
1595-
}
1590+
const matches = this.viewModel.searchResult.matches();
1591+
for (let i = 0, len = matches.length; i < len; i++) {
1592+
if (resource.toString() === matches[i].resource.toString()) {
1593+
this.viewModel.searchResult.remove(matches[i]);
15961594
}
15971595
}
15981596
}

src/vs/workbench/services/untitled/common/untitledTextEditorService.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,17 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
117117
private mapResourceToInput = new ResourceMap<UntitledTextEditorInput>();
118118
private mapResourceToAssociatedFilePath = new ResourceMap<boolean>();
119119

120-
private readonly _onDidChangeContent: Emitter<URI> = this._register(new Emitter<URI>());
121-
readonly onDidChangeContent: Event<URI> = this._onDidChangeContent.event;
120+
private readonly _onDidChangeContent = this._register(new Emitter<URI>());
121+
readonly onDidChangeContent = this._onDidChangeContent.event;
122122

123-
private readonly _onDidChangeDirty: Emitter<URI> = this._register(new Emitter<URI>());
124-
readonly onDidChangeDirty: Event<URI> = this._onDidChangeDirty.event;
123+
private readonly _onDidChangeDirty = this._register(new Emitter<URI>());
124+
readonly onDidChangeDirty = this._onDidChangeDirty.event;
125125

126-
private readonly _onDidChangeEncoding: Emitter<URI> = this._register(new Emitter<URI>());
127-
readonly onDidChangeEncoding: Event<URI> = this._onDidChangeEncoding.event;
126+
private readonly _onDidChangeEncoding = this._register(new Emitter<URI>());
127+
readonly onDidChangeEncoding = this._onDidChangeEncoding.event;
128128

129-
private readonly _onDidDisposeModel: Emitter<URI> = this._register(new Emitter<URI>());
130-
readonly onDidDisposeModel: Event<URI> = this._onDidDisposeModel.event;
129+
private readonly _onDidDisposeModel = this._register(new Emitter<URI>());
130+
readonly onDidDisposeModel = this._onDidDisposeModel.event;
131131

132132
constructor(
133133
@IInstantiationService private readonly instantiationService: IInstantiationService,

0 commit comments

Comments
 (0)