notebooks - tweak description for untitled files

This commit is contained in:
Benjamin Pasero 2021-06-01 07:54:02 +02:00
parent 1e446dfadf
commit 89157c1a87
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
9 changed files with 31 additions and 19 deletions

View file

@ -14,7 +14,6 @@ import { getResizesObserver } from 'vs/workbench/contrib/notebook/browser/view/r
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { BUILTIN_RENDERER_ID, NotebookCellOutputsSplice } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { DiffNestedCellViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { mimetypeIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
@ -250,9 +249,7 @@ export class OutputContainer extends Disposable {
private _outputContainer: HTMLElement,
@INotebookService private _notebookService: INotebookService,
@IQuickInputService private readonly _quickInputService: IQuickInputService,
@IOpenerService readonly _openerService: IOpenerService,
@ITextFileService readonly _textFileService: ITextFileService,
@IOpenerService readonly _openerService: IOpenerService
) {
super();
this._register(this._diffElementViewModel.onDidLayoutChange(() => {

View file

@ -22,7 +22,6 @@ import { ICellOutputViewModel, ICommonNotebookEditor, IOutputTransformContributi
import { OutputRendererRegistry } from 'vs/workbench/contrib/notebook/browser/view/output/rendererRegistry';
import { truncatedArrayOfString } from 'vs/workbench/contrib/notebook/browser/view/output/transforms/textHelper';
import { IOutputItemDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
class JavaScriptRendererContrib extends Disposable implements IOutputRendererContribution {
@ -126,7 +125,6 @@ class StreamRendererContrib extends Disposable implements IOutputRendererContrib
public notebookEditor: ICommonNotebookEditor,
@IOpenerService private readonly openerService: IOpenerService,
@IThemeService private readonly themeService: IThemeService,
@ITextFileService private readonly textFileService: ITextFileService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
) {
super();
@ -138,7 +136,7 @@ class StreamRendererContrib extends Disposable implements IOutputRendererContrib
items.forEach(item => {
const text = getStringValue(item);
const contentNode = DOM.$('span.output-stream');
truncatedArrayOfString(notebookUri!, output.cellViewModel, contentNode, [text], linkDetector, this.openerService, this.textFileService, this.themeService);
truncatedArrayOfString(notebookUri!, output.cellViewModel, contentNode, [text], linkDetector, this.openerService, this.themeService);
container.appendChild(contentNode);
});
@ -229,7 +227,6 @@ class PlainTextRendererContrib extends Disposable implements IOutputRendererCont
public notebookEditor: ICommonNotebookEditor,
@IOpenerService private readonly openerService: IOpenerService,
@IThemeService private readonly themeService: IThemeService,
@ITextFileService private readonly textFileService: ITextFileService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
@ -240,7 +237,7 @@ class PlainTextRendererContrib extends Disposable implements IOutputRendererCont
const str = items.map(getStringValue);
const contentNode = DOM.$('.output-plaintext');
truncatedArrayOfString(notebookUri!, output.cellViewModel, contentNode, str, linkDetector, this.openerService, this.textFileService, this.themeService);
truncatedArrayOfString(notebookUri!, output.cellViewModel, contentNode, str, linkDetector, this.openerService, this.themeService);
container.appendChild(contentNode);
return { type: RenderOutputType.Mainframe, supportAppend: true };

View file

@ -12,7 +12,6 @@ import { Range } from 'vs/editor/common/core/range';
import { PieceTreeTextBufferBuilder } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { handleANSIOutput } from 'vs/workbench/contrib/debug/browser/debugANSIHandling';
import { LinkDetector } from 'vs/workbench/contrib/debug/browser/linkDetector';
import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
@ -23,7 +22,7 @@ import { IGenericCellViewModel } from 'vs/workbench/contrib/notebook/browser/not
const SIZE_LIMIT = 65535;
const LINES_LIMIT = 500;
function generateViewMoreElement(notebookUri: URI, cellViewModel: IGenericCellViewModel, outputs: string[], openerService: IOpenerService, textFileService: ITextFileService) {
function generateViewMoreElement(notebookUri: URI, cellViewModel: IGenericCellViewModel, outputs: string[], openerService: IOpenerService) {
const md: IMarkdownString = {
value: '[show more (open the raw output data in a text editor) ...](command:workbench.action.openLargeOutput)',
isTrusted: true,
@ -47,7 +46,7 @@ function generateViewMoreElement(notebookUri: URI, cellViewModel: IGenericCellVi
return element;
}
export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGenericCellViewModel, container: HTMLElement, outputs: string[], linkDetector: LinkDetector, openerService: IOpenerService, textFileService: ITextFileService, themeService: IThemeService) {
export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGenericCellViewModel, container: HTMLElement, outputs: string[], linkDetector: LinkDetector, openerService: IOpenerService, themeService: IThemeService) {
const fullLen = outputs.reduce((p, c) => {
return p + c.length;
}, 0);
@ -65,7 +64,7 @@ export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGeneric
const truncatedText = buffer.getValueInRange(new Range(1, 1, sizeBufferLimitPosition.lineNumber, sizeBufferLimitPosition.column), EndOfLinePreference.TextDefined);
container.appendChild(handleANSIOutput(truncatedText, linkDetector, themeService, undefined));
// view more ...
container.appendChild(generateViewMoreElement(notebookUri, cellViewModel, outputs, openerService, textFileService));
container.appendChild(generateViewMoreElement(notebookUri, cellViewModel, outputs, openerService));
return;
}
}
@ -89,7 +88,7 @@ export function truncatedArrayOfString(notebookUri: URI, cellViewModel: IGeneric
pre.appendChild(handleANSIOutput(buffer.getValueInRange(new Range(1, 1, LINES_LIMIT - 5, buffer.getLineLastNonWhitespaceColumn(LINES_LIMIT - 5)), EndOfLinePreference.TextDefined), linkDetector, themeService, undefined));
// view more ...
container.appendChild(generateViewMoreElement(notebookUri, cellViewModel, outputs, openerService, textFileService));
container.appendChild(generateViewMoreElement(notebookUri, cellViewModel, outputs, openerService));
const lineCount = buffer.getLineCount();
const pre2 = DOM.$('div');

View file

@ -15,7 +15,6 @@ import { CellOutputContainer } from 'vs/workbench/contrib/notebook/browser/view/
import { ClickTargetType } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellWidgets';
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
export class CodeCell extends Disposable {
@ -31,8 +30,7 @@ export class CodeCell extends Disposable {
private templateData: CodeCellRenderTemplate,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@INotebookCellStatusBarService readonly notebookCellStatusBarService: INotebookCellStatusBarService,
@IOpenerService readonly openerService: IOpenerService,
@ITextFileService readonly textFileService: ITextFileService
@IOpenerService readonly openerService: IOpenerService
) {
super();

View file

@ -744,6 +744,7 @@ export interface INotebookEditorModel extends IEditorModel {
isDirty(): boolean;
isReadonly(): boolean;
isOrphaned(): boolean;
hasAssociatedFilePath(): boolean;
load(options?: INotebookLoadOptions): Promise<IResolvedNotebookEditorModel>;
save(options?: ISaveOptions): Promise<boolean>;
saveAs(target: URI): Promise<IEditorInput | undefined>;

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as glob from 'vs/base/common/glob';
import { IEditorInput, GroupIdentifier, ISaveOptions, IMoveResult, IRevertOptions, EditorInputCapabilities } from 'vs/workbench/common/editor';
import { IEditorInput, GroupIdentifier, ISaveOptions, IMoveResult, IRevertOptions, EditorInputCapabilities, Verbosity } from 'vs/workbench/common/editor';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { URI } from 'vs/base/common/uri';
import { isEqual, joinPath } from 'vs/base/common/resources';
@ -80,6 +80,14 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
return capabilities;
}
override getDescription(verbosity = Verbosity.MEDIUM): string | undefined {
if (!this.hasCapability(EditorInputCapabilities.Untitled) || this._editorModelReference?.object.hasAssociatedFilePath()) {
return super.getDescription(verbosity);
}
return undefined; // no description for untitled notebooks without associated file path
}
override isDirty() {
if (!this._editorModelReference) {
return this._defaultDirtyState;

View file

@ -134,6 +134,10 @@ export class ComplexNotebookEditorModel extends EditorModel implements INotebook
return false;
}
hasAssociatedFilePath(): boolean {
return false;
}
private _isUntitled(): boolean {
return this.resource.scheme === Schemas.untitled;
}
@ -466,6 +470,10 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
return SimpleNotebookEditorModel._isStoredFileWorkingCopy(this._workingCopy) && this._workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN);
}
hasAssociatedFilePath(): boolean {
return !SimpleNotebookEditorModel._isStoredFileWorkingCopy(this._workingCopy) && !!this._workingCopy?.hasAssociatedFilePath;
}
isReadonly(): boolean {
if (SimpleNotebookEditorModel._isStoredFileWorkingCopy(this._workingCopy)) {
return this._workingCopy.isReadonly();

View file

@ -110,6 +110,10 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
return false;
}
hasAssociatedFilePath(): boolean {
return false;
}
isDirty() {
return this._dirty;
}

View file

@ -138,7 +138,7 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi
const remoteAuthority = this.environmentService.remoteAuthority;
if (remoteAuthority) {
// https://github.com/microsoft/vscode/issues/94191
foldersToAdd = foldersToAdd.filter(f => f.uri.scheme !== Schemas.file && (f.uri.scheme !== Schemas.vscodeRemote || isEqualAuthority(f.uri.authority, remoteAuthority)));
foldersToAdd = foldersToAdd.filter(folder => folder.uri.scheme !== Schemas.file && (folder.uri.scheme !== Schemas.vscodeRemote || isEqualAuthority(folder.uri.authority, remoteAuthority)));
}
// If we are in no-workspace or single-folder workspace, adding folders has to