@@ -11,12 +11,12 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
1111import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService' ;
1212import { URI } from 'vs/base/common/uri' ;
1313import { IWorkingCopyService , IWorkingCopy , IWorkingCopyBackup , WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService' ;
14- import { basename } from 'vs/base/common/resources' ;
1514import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
1615import { IBackupFileService } from 'vs/workbench/services/backup/common/backup' ;
1716import { Schemas } from 'vs/base/common/network' ;
1817import { IFileStatWithMetadata , IFileService } from 'vs/platform/files/common/files' ;
1918import { INotificationService , Severity } from 'vs/platform/notification/common/notification' ;
19+ import { ILabelService } from 'vs/platform/label/common/label' ;
2020
2121
2222export interface INotebookLoadOptions {
@@ -29,7 +29,7 @@ export interface INotebookLoadOptions {
2929}
3030
3131
32- export class NotebookEditorModel extends EditorModel implements IWorkingCopy , INotebookEditorModel {
32+ export class NotebookEditorModel extends EditorModel implements INotebookEditorModel {
3333 protected readonly _onDidChangeDirty = this . _register ( new Emitter < void > ( ) ) ;
3434 readonly onDidChangeDirty = this . _onDidChangeDirty . event ;
3535 private readonly _onDidChangeContent = this . _register ( new Emitter < void > ( ) ) ;
@@ -41,31 +41,29 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
4141 return this . _notebook ;
4242 }
4343
44- private _name ! : string ;
45-
46- get name ( ) {
47- return this . _name ;
48- }
49-
50- private _workingCopyResource : URI ;
44+ private readonly _name : string ;
45+ private readonly _workingCopyResource : URI ;
5146
5247 constructor (
53- public readonly resource : URI ,
54- public readonly viewType : string ,
48+ readonly resource : URI ,
49+ readonly viewType : string ,
5550 @INotebookService private readonly _notebookService : INotebookService ,
5651 @IWorkingCopyService private readonly _workingCopyService : IWorkingCopyService ,
5752 @IBackupFileService private readonly _backupFileService : IBackupFileService ,
5853 @IFileService private readonly _fileService : IFileService ,
59- @INotificationService private readonly _notificationService : INotificationService
54+ @INotificationService private readonly _notificationService : INotificationService ,
55+ @ILabelService labelService : ILabelService ,
6056 ) {
6157 super ( ) ;
6258
59+ this . _name = labelService . getUriBasenameLabel ( resource ) ;
60+
6361 const input = this ;
6462 this . _workingCopyResource = resource . with ( { scheme : Schemas . vscodeNotebook } ) ;
6563 const workingCopyAdapter = new class implements IWorkingCopy {
6664 readonly resource = input . _workingCopyResource ;
67- get name ( ) { return input . name ; }
68- readonly capabilities = input . isUntitled ( ) ? WorkingCopyCapabilities . Untitled : input . capabilities ;
65+ get name ( ) { return input . _name ; }
66+ readonly capabilities = input . isUntitled ( ) ? WorkingCopyCapabilities . Untitled : WorkingCopyCapabilities . None ;
6967 readonly onDidChangeDirty = input . onDidChangeDirty ;
7068 readonly onDidChangeContent = input . onDidChangeContent ;
7169 isDirty ( ) : boolean { return input . isDirty ( ) ; }
@@ -77,8 +75,6 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
7775 this . _register ( this . _workingCopyService . registerWorkingCopy ( workingCopyAdapter ) ) ;
7876 }
7977
80- capabilities = WorkingCopyCapabilities . None ;
81-
8278 async backup ( ) : Promise < IWorkingCopyBackup < NotebookDocumentBackupData > > {
8379 if ( this . _notebook . supportBackup ) {
8480 const tokenSource = new CancellationTokenSource ( ) ;
@@ -138,15 +134,13 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
138134 }
139135
140136 private async _loadFromProvider ( forceReloadFromDisk : boolean , editorId : string | undefined , backupId : string | undefined ) {
141- const notebook = await this . _notebookService . resolveNotebook ( this . viewType ! , this . resource , forceReloadFromDisk , editorId , backupId ) ;
142- this . _notebook = notebook ! ;
137+ this . _notebook = await this . _notebookService . resolveNotebook ( this . viewType ! , this . resource , forceReloadFromDisk , editorId , backupId ) ;
138+
143139 const newStats = await this . _resolveStats ( this . resource ) ;
144140 this . _lastResolvedFileStat = newStats ;
145141
146142 this . _register ( this . _notebook ) ;
147143
148- this . _name = basename ( this . _notebook ! . uri ) ;
149-
150144 this . _register ( this . _notebook . onDidChangeContent ( ( ) => {
151145 this . _onDidChangeContent . fire ( ) ;
152146 } ) ) ;
0 commit comments