Skip to content

Commit

Permalink
working copies - properly implement save, saveAs, saveAll (#84672)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 17, 2019
1 parent 40a67d1 commit 00688bf
Show file tree
Hide file tree
Showing 26 changed files with 551 additions and 399 deletions.
8 changes: 3 additions & 5 deletions src/vs/workbench/api/browser/mainThreadWorkspace.ts
Expand Up @@ -15,7 +15,7 @@ import { IFileMatch, IPatternInfo, ISearchProgressItem, ISearchService } from 'v
import { IWorkspaceContextService, WorkbenchState, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { ITextQueryBuilderOptions, QueryBuilder } from 'vs/workbench/contrib/search/common/queryBuilder';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
import { ExtHostContext, ExtHostWorkspaceShape, IExtHostContext, MainContext, MainThreadWorkspaceShape, IWorkspaceData, ITextSearchComplete } from '../common/extHost.protocol';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
Expand All @@ -37,7 +37,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
extHostContext: IExtHostContext,
@ISearchService private readonly _searchService: ISearchService,
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService,
@ITextFileService private readonly _textFileService: ITextFileService,
@IEditorService private readonly _editorService: IEditorService,
@IWorkspaceEditingService private readonly _workspaceEditingService: IWorkspaceEditingService,
@INotificationService private readonly _notificationService: INotificationService,
@IRequestService private readonly _requestService: IRequestService,
Expand Down Expand Up @@ -212,9 +212,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
// --- save & edit resources ---

$saveAll(includeUntitled?: boolean): Promise<boolean> {
return this._textFileService.saveAll(includeUntitled).then(result => {
return result.results.every(each => each.success === true);
});
return this._editorService.saveAll({ includeUntitled });
}

$resolveProxy(url: string): Promise<string | undefined> {
Expand Down
36 changes: 19 additions & 17 deletions src/vs/workbench/browser/contextkeys.ts
Expand Up @@ -8,7 +8,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
import { IWindowsConfiguration } from 'vs/platform/windows/common/windows';
import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorIsSaveableContext, toResource, SideBySideEditor, EditorAreaVisibleContext } from 'vs/workbench/common/editor';
import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorIsSaveableContext, EditorAreaVisibleContext, DirtyWorkingCopiesContext } from 'vs/workbench/common/editor';
import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom';
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand All @@ -21,8 +21,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { isMacintosh, isLinux, isWindows, isWeb } from 'vs/base/common/platform';
import { PanelPositionContext } from 'vs/workbench/common/panel';
import { getRemoteName } from 'vs/platform/remote/common/remoteHosts';
import { IFileService } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';

export const IsMacContext = new RawContextKey<boolean>('isMac', isMacintosh);
export const IsLinuxContext = new RawContextKey<boolean>('isLinux', isLinux);
Expand Down Expand Up @@ -51,6 +50,8 @@ export const IsFullscreenContext = new RawContextKey<boolean>('isFullscreen', fa
export class WorkbenchContextKeysHandler extends Disposable {
private inputFocusedContext: IContextKey<boolean>;

private dirtyWorkingCopiesContext: IContextKey<boolean>;

private activeEditorContext: IContextKey<string | null>;
private activeEditorIsSaveable: IContextKey<boolean>;

Expand All @@ -75,19 +76,18 @@ export class WorkbenchContextKeysHandler extends Disposable {
private panelPositionContext: IContextKey<string>;

constructor(
@IContextKeyService private contextKeyService: IContextKeyService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService,
@IWorkbenchEnvironmentService private environmentService: IWorkbenchEnvironmentService,
@IEditorService private editorService: IEditorService,
@IEditorGroupsService private editorGroupService: IEditorGroupsService,
@IWorkbenchLayoutService private layoutService: IWorkbenchLayoutService,
@IViewletService private viewletService: IViewletService,
@IFileService private fileService: IFileService
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IEditorService private readonly editorService: IEditorService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@IViewletService private readonly viewletService: IViewletService,
@IWorkingCopyService private readonly workingCopyService: IWorkingCopyService
) {
super();


// Platform
IsMacContext.bindTo(this.contextKeyService);
IsLinuxContext.bindTo(this.contextKeyService);
Expand Down Expand Up @@ -116,6 +116,9 @@ export class WorkbenchContextKeysHandler extends Disposable {
this.activeEditorGroupLast = ActiveEditorGroupLastContext.bindTo(this.contextKeyService);
this.multipleEditorGroupsContext = MultipleEditorGroupsContext.bindTo(this.contextKeyService);

// Working Copies
this.dirtyWorkingCopiesContext = DirtyWorkingCopiesContext.bindTo(this.contextKeyService);

// Inputs
this.inputFocusedContext = InputFocusedContext.bindTo(this.contextKeyService);

Expand Down Expand Up @@ -183,6 +186,8 @@ export class WorkbenchContextKeysHandler extends Disposable {
this._register(this.viewletService.onDidViewletOpen(() => this.updateSideBarContextKeys()));

this._register(this.layoutService.onPartVisibilityChange(() => this.editorAreaVisibleContext.set(this.layoutService.isVisible(Parts.EDITOR_PART))));

this._register(this.workingCopyService.onDidChangeDirty(w => this.dirtyWorkingCopiesContext.set(w.isDirty() || this.workingCopyService.hasDirty)));
}

private updateEditorContextKeys(): void {
Expand Down Expand Up @@ -217,10 +222,7 @@ export class WorkbenchContextKeysHandler extends Disposable {

if (activeControl) {
this.activeEditorContext.set(activeControl.getId());

const resource = toResource(activeControl.input, { supportSideBySide: SideBySideEditor.MASTER });
const canSave = resource ? this.fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled : false;
this.activeEditorIsSaveable.set(canSave);
this.activeEditorIsSaveable.set(!activeControl.input.isReadonly());
} else {
this.activeEditorContext.reset();
this.activeEditorIsSaveable.reset();
Expand Down
22 changes: 10 additions & 12 deletions src/vs/workbench/browser/parts/editor/editorActions.ts
Expand Up @@ -15,7 +15,6 @@ import { IResourceInput } from 'vs/platform/editor/common/editor';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { CLOSE_EDITOR_COMMAND_ID, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, MOVE_ACTIVE_EDITOR_COMMAND_ID, NAVIGATE_IN_ACTIVE_GROUP_PREFIX, ActiveEditorMoveArguments, SPLIT_EDITOR_LEFT, SPLIT_EDITOR_RIGHT, SPLIT_EDITOR_UP, SPLIT_EDITOR_DOWN, splitEditor, LAYOUT_EDITOR_GROUPS_COMMAND_ID, mergeAllGroups } from 'vs/workbench/browser/parts/editor/editorCommands';
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, EditorsOrder, GroupLocation, GroupDirection, preferredSideBySideGroupDirection, IFindGroupScope, GroupOrientation, EditorGroupLayout, GroupsOrder } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
Expand Down Expand Up @@ -598,10 +597,10 @@ export abstract class BaseCloseAllAction extends Action {
id: string,
label: string,
clazz: string | undefined,
private textFileService: ITextFileService,
private workingCopyService: IWorkingCopyService,
private fileDialogService: IFileDialogService,
protected editorGroupService: IEditorGroupsService
protected editorGroupService: IEditorGroupsService,
private editorService: IEditorService
) {
super(id, label, clazz);
}
Expand Down Expand Up @@ -647,11 +646,10 @@ export abstract class BaseCloseAllAction extends Action {

let saveOrRevert: boolean;
if (confirm === ConfirmResult.DONT_SAVE) {
await this.textFileService.revertAll(undefined, { soft: true });
await this.editorService.revertAll({ soft: true });
saveOrRevert = true;
} else {
const res = await this.textFileService.saveAll(true);
saveOrRevert = res.results.every(r => !!r.success);
saveOrRevert = await this.editorService.saveAll({ includeUntitled: true });
}

if (saveOrRevert) {
Expand All @@ -670,12 +668,12 @@ export class CloseAllEditorsAction extends BaseCloseAllAction {
constructor(
id: string,
label: string,
@ITextFileService textFileService: ITextFileService,
@IWorkingCopyService workingCopyService: IWorkingCopyService,
@IFileDialogService fileDialogService: IFileDialogService,
@IEditorGroupsService editorGroupService: IEditorGroupsService
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IEditorService editorService: IEditorService
) {
super(id, label, 'codicon-close-all', textFileService, workingCopyService, fileDialogService, editorGroupService);
super(id, label, 'codicon-close-all', workingCopyService, fileDialogService, editorGroupService, editorService);
}

protected doCloseAll(): Promise<any> {
Expand All @@ -691,12 +689,12 @@ export class CloseAllEditorGroupsAction extends BaseCloseAllAction {
constructor(
id: string,
label: string,
@ITextFileService textFileService: ITextFileService,
@IWorkingCopyService workingCopyService: IWorkingCopyService,
@IFileDialogService fileDialogService: IFileDialogService,
@IEditorGroupsService editorGroupService: IEditorGroupsService
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IEditorService editorService: IEditorService
) {
super(id, label, undefined, textFileService, workingCopyService, fileDialogService, editorGroupService);
super(id, label, undefined, workingCopyService, fileDialogService, editorGroupService, editorService);
}

protected async doCloseAll(): Promise<any> {
Expand Down
11 changes: 10 additions & 1 deletion src/vs/workbench/browser/parts/editor/textEditor.ts
Expand Up @@ -6,7 +6,7 @@
import { localize } from 'vs/nls';
import { URI } from 'vs/base/common/uri';
import { distinct, deepClone, assign } from 'vs/base/common/objects';
import { isObject, assertIsDefined } from 'vs/base/common/types';
import { isObject, assertIsDefined, withNullAsUndefined } from 'vs/base/common/types';
import { Dimension } from 'vs/base/browser/dom';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { EditorInput, EditorOptions, IEditorMemento, ITextEditor } from 'vs/workbench/common/editor';
Expand Down Expand Up @@ -249,6 +249,15 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
this.editorMemento.saveEditorState(this.group, resource, editorViewState);
}

getViewState(): IEditorViewState | undefined {
const resource = this.input?.getResource();
if (resource) {
return withNullAsUndefined(this.retrieveTextEditorViewState(resource));
}

return undefined;
}

protected retrieveTextEditorViewState(resource: URI): IEditorViewState | null {
const control = this.getControl();
if (!isCodeEditor(control)) {
Expand Down

0 comments on commit 00688bf

Please sign in to comment.