Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open readonly files as readonly editors #52337

Merged
merged 2 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/vs/workbench/browser/parts/editor/textDiffEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {

// Set Editor Model
const diffEditor = this.getControl();
diffEditor.setModel((<TextDiffEditorModel>resolvedModel).textDiffEditorModel);
const resolvedDiffEditorModel = <TextDiffEditorModel>resolvedModel;
diffEditor.setModel(resolvedDiffEditorModel.textDiffEditorModel);

// Apply Options from TextOptions
let optionsGotApplied = false;
Expand All @@ -142,6 +143,8 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
this.previousDiffAction.updateEnablement();
}));

this.getControl().updateOptions({ readOnly: resolvedDiffEditorModel.isReadonly() });

this.updateIgnoreTrimWhitespaceAction();
}, error => {

Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/common/editor/textDiffEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class TextDiffEditorModel extends DiffEditorModel {
return !!this._textDiffEditorModel;
}

public isReadonly(): boolean {
return this.modifiedModel.isReadonly();
}

public dispose(): void {

// Free the diff editor model but do not propagate the dispose() call to the two models
Expand All @@ -76,4 +80,4 @@ export class TextDiffEditorModel extends DiffEditorModel {

super.dispose();
}
}
}
4 changes: 4 additions & 0 deletions src/vs/workbench/common/editor/textEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
return !!this.textEditorModelHandle;
}

public isReadonly(): boolean {
return false;
}

public dispose(): void {
if (this.modelDisposeListener) {
this.modelDisposeListener.dispose(); // dispose this first because it will trigger another dispose() otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export class TextFileEditor extends BaseTextEditor {
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
(<TextEditorOptions>options).apply(textEditor, ScrollType.Immediate);
}

textEditor.updateOptions({ readOnly: textFileModel.isReadonly() });
}, error => {

// In case we tried to open a file inside the text editor and the response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
// be disposed if we are dirty, but if we are not dirty, save() and dispose() can still be triggered
// one after the other without waiting for the save() to complete. If we are disposed(), we risk
// saving contents to disk that are stale (see https://github.com/Microsoft/vscode/issues/50942).
// To fix this issue, we will not store the contents to disk when we got disposed.
// To fix this issue, we will not store the contents to disk when we got disposed.
if (this.disposed) {
return void 0;
}
Expand Down Expand Up @@ -983,6 +983,10 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return !types.isUndefinedOrNull(this.lastResolvedDiskStat);
}

public isReadonly(): boolean {
return this.lastResolvedDiskStat.isReadonly;
}

/**
* Returns true if the dispose() method of this model has been called.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/services/textfile/common/textfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport

isResolved(): boolean;

isReadonly(): boolean;

isDisposed(): boolean;
}

Expand Down