Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
7
import { URI } from '../../../../base/common/uri.js';
8
import { IResolvedNotebookEditorModel, NotebookEditorModelCreationOptions } from './notebookCommon.js';
9
import { IReference } from '../../../../base/common/lifecycle.js';
10
import { Event, IWaitUntil } from '../../../../base/common/event.js';
11
import { NotebookTextModel } from './model/notebookTextModel.js';
12
13
export const INotebookEditorModelResolverService = createDecorator<INotebookEditorModelResolverService>('INotebookModelResolverService');
14
15
/**
16
* A notebook file can only be opened ONCE per notebook type.
17
* This event fires when a file is already open as type A
18
* and there is request to open it as type B. Listeners must
19
* do cleanup (close editor, release references) or the request fails
20
*/
21
export interface INotebookConflictEvent extends IWaitUntil {
22
resource: URI;
23
viewType: string;
24
}
25
26
export interface IUntitledNotebookResource {
27
/**
28
* Depending on the value of `untitledResource` will
29
* resolve a untitled notebook that:
30
* - gets a unique name if `undefined` (e.g. `Untitled-1')
31
* - uses the resource directly if the scheme is `untitled:`
32
* - converts any other resource scheme to `untitled:` and will
33
* assume an associated file path
34
*
35
* Untitled notebook editors with associated path behave slightly
36
* different from other untitled editors:
37
* - they are dirty right when opening
38
* - they will not ask for a file path when saving but use the associated path
39
*/
40
untitledResource: URI | undefined;
41
}
42
43
export interface INotebookEditorModelResolverService {
44
readonly _serviceBrand: undefined;
45
46
readonly onDidSaveNotebook: Event<URI>;
47
readonly onDidChangeDirty: Event<IResolvedNotebookEditorModel>;
48
49
readonly onWillFailWithConflict: Event<INotebookConflictEvent>;
50
51
isDirty(resource: URI): boolean;
52
53
createUntitledNotebookTextModel(viewType: string): Promise<NotebookTextModel>;
54
55
resolve(resource: URI, viewType?: string, creationOptions?: NotebookEditorModelCreationOptions): Promise<IReference<IResolvedNotebookEditorModel>>;
56
resolve(resource: IUntitledNotebookResource, viewType: string, creationOtions?: NotebookEditorModelCreationOptions): Promise<IReference<IResolvedNotebookEditorModel>>;
57
}
58
59