@jupyterlab/docmanager
Advanced tools
Comparing version 4.0.0-alpha.16 to 4.0.0-alpha.17
import { ISessionContext } from '@jupyterlab/apputils'; | ||
import { IChangedArgs } from '@jupyterlab/coreutils'; | ||
import { IDocumentProviderFactory } from '@jupyterlab/docprovider'; | ||
@@ -10,2 +11,3 @@ import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; | ||
import { IDocumentManager, IDocumentWidgetOpener } from './tokens'; | ||
import { DocumentWidgetManager } from './widgetmanager'; | ||
/** | ||
@@ -49,2 +51,7 @@ * The document manager. | ||
/** | ||
* Whether to ask confirmation to close a tab or not. | ||
*/ | ||
get confirmClosingDocument(): boolean; | ||
set confirmClosingDocument(value: boolean); | ||
/** | ||
* Defines max acceptable difference, in milliseconds, between last modified timestamps on disk and client | ||
@@ -60,2 +67,6 @@ */ | ||
/** | ||
* Signal triggered when an attribute changes. | ||
*/ | ||
get stateChanged(): ISignal<IDocumentManager, IChangedArgs<any>>; | ||
/** | ||
* Get whether the document manager has been disposed. | ||
@@ -262,2 +273,3 @@ */ | ||
private _onActivateRequested; | ||
protected _onWidgetStateChanged(sender: DocumentWidgetManager, args: IChangedArgs<any>): void; | ||
protected translator: ITranslator; | ||
@@ -277,4 +289,4 @@ private _activateRequested; | ||
private _docProviderFactory; | ||
private _collaborative; | ||
private _isConnectedCallback; | ||
private _stateChanged; | ||
} | ||
@@ -322,7 +334,2 @@ /** | ||
/** | ||
* Whether the context should be collaborative. | ||
* If true, the context will connect through yjs_ws_server to share information if possible. | ||
*/ | ||
collaborative?: boolean; | ||
/** | ||
* Autosaving should be paused while this callback function returns `false`. | ||
@@ -329,0 +336,0 @@ * By default, it always returns `true`. |
@@ -35,6 +35,6 @@ // Copyright (c) Jupyter Development Team. | ||
this._renameUntitledFileOnSave = true; | ||
this._stateChanged = new Signal(this); | ||
this.translator = options.translator || nullTranslator; | ||
this.registry = options.registry; | ||
this.services = options.manager; | ||
this._collaborative = !!options.collaborative; | ||
this._dialogs = options.sessionDialogs || sessionContextDialogs; | ||
@@ -50,2 +50,3 @@ this._docProviderFactory = options.docProviderFactory; | ||
widgetManager.activateRequested.connect(this._onActivateRequested, this); | ||
widgetManager.stateChanged.connect(this._onWidgetStateChanged, this); | ||
this._widgetManager = widgetManager; | ||
@@ -67,16 +68,24 @@ this._setBusy = options.setBusy; | ||
set autosave(value) { | ||
this._autosave = value; | ||
// For each existing context, start/stop the autosave handler as needed. | ||
this._contexts.forEach(context => { | ||
const handler = Private.saveHandlerProperty.get(context); | ||
if (!handler) { | ||
return; | ||
} | ||
if (value === true && !handler.isActive) { | ||
handler.start(); | ||
} | ||
else if (value === false && handler.isActive) { | ||
handler.stop(); | ||
} | ||
}); | ||
if (this._autosave !== value) { | ||
const oldValue = this._autosave; | ||
this._autosave = value; | ||
// For each existing context, start/stop the autosave handler as needed. | ||
this._contexts.forEach(context => { | ||
const handler = Private.saveHandlerProperty.get(context); | ||
if (!handler) { | ||
return; | ||
} | ||
if (value === true && !handler.isActive) { | ||
handler.start(); | ||
} | ||
else if (value === false && handler.isActive) { | ||
handler.stop(); | ||
} | ||
}); | ||
this._stateChanged.emit({ | ||
name: 'autosave', | ||
oldValue, | ||
newValue: value | ||
}); | ||
} | ||
} | ||
@@ -90,13 +99,38 @@ /** | ||
set autosaveInterval(value) { | ||
this._autosaveInterval = value; | ||
// For each existing context, set the save interval as needed. | ||
this._contexts.forEach(context => { | ||
const handler = Private.saveHandlerProperty.get(context); | ||
if (!handler) { | ||
return; | ||
} | ||
handler.saveInterval = value || 120; | ||
}); | ||
if (this._autosaveInterval !== value) { | ||
const oldValue = this._autosaveInterval; | ||
this._autosaveInterval = value; | ||
// For each existing context, set the save interval as needed. | ||
this._contexts.forEach(context => { | ||
const handler = Private.saveHandlerProperty.get(context); | ||
if (!handler) { | ||
return; | ||
} | ||
handler.saveInterval = value || 120; | ||
}); | ||
this._stateChanged.emit({ | ||
name: 'autosaveInterval', | ||
oldValue, | ||
newValue: value | ||
}); | ||
} | ||
} | ||
/** | ||
* Whether to ask confirmation to close a tab or not. | ||
*/ | ||
get confirmClosingDocument() { | ||
return this._widgetManager.confirmClosingDocument; | ||
} | ||
set confirmClosingDocument(value) { | ||
if (this._widgetManager.confirmClosingDocument !== value) { | ||
const oldValue = this._widgetManager.confirmClosingDocument; | ||
this._widgetManager.confirmClosingDocument = value; | ||
this._stateChanged.emit({ | ||
name: 'confirmClosingDocument', | ||
oldValue, | ||
newValue: value | ||
}); | ||
} | ||
} | ||
/** | ||
* Defines max acceptable difference, in milliseconds, between last modified timestamps on disk and client | ||
@@ -108,7 +142,15 @@ */ | ||
set lastModifiedCheckMargin(value) { | ||
this._lastModifiedCheckMargin = value; | ||
// For each existing context, update the margin value. | ||
this._contexts.forEach(context => { | ||
context.lastModifiedCheckMargin = value; | ||
}); | ||
if (this._lastModifiedCheckMargin !== value) { | ||
const oldValue = this._lastModifiedCheckMargin; | ||
this._lastModifiedCheckMargin = value; | ||
// For each existing context, update the margin value. | ||
this._contexts.forEach(context => { | ||
context.lastModifiedCheckMargin = value; | ||
}); | ||
this._stateChanged.emit({ | ||
name: 'lastModifiedCheckMargin', | ||
oldValue, | ||
newValue: value | ||
}); | ||
} | ||
} | ||
@@ -122,5 +164,19 @@ /** | ||
set renameUntitledFileOnSave(value) { | ||
this._renameUntitledFileOnSave = value; | ||
if (this._renameUntitledFileOnSave !== value) { | ||
const oldValue = this._renameUntitledFileOnSave; | ||
this._renameUntitledFileOnSave = value; | ||
this._stateChanged.emit({ | ||
name: 'renameUntitledFileOnSave', | ||
oldValue, | ||
newValue: value | ||
}); | ||
} | ||
} | ||
/** | ||
* Signal triggered when an attribute changes. | ||
*/ | ||
get stateChanged() { | ||
return this._stateChanged; | ||
} | ||
/** | ||
* Get whether the document manager has been disposed. | ||
@@ -431,3 +487,2 @@ */ | ||
sessionDialogs: this._dialogs, | ||
collaborative: this._collaborative, | ||
docProviderFactory: this._docProviderFactory, | ||
@@ -528,2 +583,7 @@ lastModifiedCheckMargin: this._lastModifiedCheckMargin, | ||
} | ||
_onWidgetStateChanged(sender, args) { | ||
if (args.name === 'confirmClosingDocument') { | ||
this._stateChanged.emit(args); | ||
} | ||
} | ||
} | ||
@@ -530,0 +590,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
import { IChangedArgs } from '@jupyterlab/coreutils'; | ||
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; | ||
@@ -36,2 +37,6 @@ import { Contents, Kernel, ServiceManager } from '@jupyterlab/services'; | ||
/** | ||
* Whether to ask confirmation to close a tab or not. | ||
*/ | ||
confirmClosingDocument: boolean; | ||
/** | ||
* Determines the time interval for autosave in seconds. | ||
@@ -49,2 +54,6 @@ */ | ||
/** | ||
* Signal triggered when an attribute changes. | ||
*/ | ||
readonly stateChanged: ISignal<IDocumentManager, IChangedArgs<any>>; | ||
/** | ||
* Clone a widget. | ||
@@ -51,0 +60,0 @@ * |
@@ -0,1 +1,2 @@ | ||
import { IChangedArgs } from '@jupyterlab/coreutils'; | ||
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; | ||
@@ -20,2 +21,11 @@ import { ITranslator } from '@jupyterlab/translation'; | ||
/** | ||
* Whether to ask confirmation to close a tab or not. | ||
*/ | ||
get confirmClosingDocument(): boolean; | ||
set confirmClosingDocument(v: boolean); | ||
/** | ||
* Signal triggered when an attribute changes. | ||
*/ | ||
get stateChanged(): ISignal<DocumentWidgetManager, IChangedArgs<any>>; | ||
/** | ||
* Test whether the document widget manager is disposed. | ||
@@ -155,3 +165,5 @@ */ | ||
private _activateRequested; | ||
private _confirmClosingTab; | ||
private _isDisposed; | ||
private _stateChanged; | ||
} | ||
@@ -158,0 +170,0 @@ /** |
@@ -24,3 +24,5 @@ // Copyright (c) Jupyter Development Team. | ||
this._activateRequested = new Signal(this); | ||
this._confirmClosingTab = false; | ||
this._isDisposed = false; | ||
this._stateChanged = new Signal(this); | ||
this._registry = options.registry; | ||
@@ -36,2 +38,25 @@ this.translator = options.translator || nullTranslator; | ||
/** | ||
* Whether to ask confirmation to close a tab or not. | ||
*/ | ||
get confirmClosingDocument() { | ||
return this._confirmClosingTab; | ||
} | ||
set confirmClosingDocument(v) { | ||
if (this._confirmClosingTab !== v) { | ||
const oldValue = this._confirmClosingTab; | ||
this._confirmClosingTab = v; | ||
this._stateChanged.emit({ | ||
name: 'confirmClosingDocument', | ||
oldValue, | ||
newValue: v | ||
}); | ||
} | ||
} | ||
/** | ||
* Signal triggered when an attribute changes. | ||
*/ | ||
get stateChanged() { | ||
return this._stateChanged; | ||
} | ||
/** | ||
* Test whether the document widget manager is disposed. | ||
@@ -296,4 +321,4 @@ */ | ||
*/ | ||
_maybeClose(widget, translator) { | ||
var _a; | ||
async _maybeClose(widget, translator) { | ||
var _a, _b; | ||
translator = translator || nullTranslator; | ||
@@ -318,25 +343,55 @@ const trans = translator.load('jupyterlab'); | ||
}); | ||
const fileName = widget.title.label; | ||
const factory = Private.factoryProperty.get(widget); | ||
if (!factory) { | ||
return Promise.resolve([true, true]); | ||
const isDirty = context.model.dirty && | ||
widgets.length <= 1 && | ||
!((_a = factory === null || factory === void 0 ? void 0 : factory.readOnly) !== null && _a !== void 0 ? _a : true); | ||
// Ask confirmation | ||
if (this.confirmClosingDocument) { | ||
const buttons = [ | ||
Dialog.cancelButton(), | ||
Dialog.okButton({ | ||
label: isDirty ? trans.__('Close and save') : trans.__('Close') | ||
}) | ||
]; | ||
if (isDirty) { | ||
buttons.splice(1, 0, Dialog.warnButton({ label: trans.__('Close without saving') })); | ||
} | ||
const confirm = await showDialog({ | ||
title: trans.__('Confirmation'), | ||
body: trans.__('Please confirm you want to close "%1".', fileName), | ||
checkbox: isDirty | ||
? null | ||
: { | ||
label: trans.__('Do not ask me again.'), | ||
caption: trans.__('If checked, no confirmation to close a document will be asked in the future.') | ||
}, | ||
buttons | ||
}); | ||
if (confirm.isChecked) { | ||
this.confirmClosingDocument = false; | ||
} | ||
return Promise.resolve([ | ||
confirm.button.accept, | ||
isDirty ? confirm.button.displayType === 'warn' : true | ||
]); | ||
} | ||
const model = context.model; | ||
if (!model.dirty || widgets.length > 1 || factory.readOnly) { | ||
return Promise.resolve([true, true]); | ||
else { | ||
if (!isDirty) { | ||
return Promise.resolve([true, true]); | ||
} | ||
const saveLabel = ((_b = context.contentsModel) === null || _b === void 0 ? void 0 : _b.writable) | ||
? trans.__('Save') | ||
: trans.__('Save as'); | ||
const result = await showDialog({ | ||
title: trans.__('Save your work'), | ||
body: trans.__('Save changes in "%1" before closing?', fileName), | ||
buttons: [ | ||
Dialog.cancelButton(), | ||
Dialog.warnButton({ label: trans.__('Discard') }), | ||
Dialog.okButton({ label: saveLabel }) | ||
] | ||
}); | ||
return [result.button.accept, result.button.displayType === 'warn']; | ||
} | ||
const fileName = widget.title.label; | ||
const saveLabel = ((_a = context.contentsModel) === null || _a === void 0 ? void 0 : _a.writable) | ||
? trans.__('Save') | ||
: trans.__('Save as'); | ||
return showDialog({ | ||
title: trans.__('Save your work'), | ||
body: trans.__('Save changes in "%1" before closing?', fileName), | ||
buttons: [ | ||
Dialog.cancelButton(), | ||
Dialog.warnButton({ label: trans.__('Discard') }), | ||
Dialog.okButton({ label: saveLabel }) | ||
] | ||
}).then(result => { | ||
return [result.button.accept, result.button.displayType === 'warn']; | ||
}); | ||
} | ||
@@ -343,0 +398,0 @@ /** |
{ | ||
"name": "@jupyterlab/docmanager", | ||
"version": "4.0.0-alpha.16", | ||
"version": "4.0.0-alpha.17", | ||
"description": "JupyterLab - Document Manager", | ||
@@ -44,10 +44,10 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyterlab/apputils": "^4.0.0-alpha.16", | ||
"@jupyterlab/coreutils": "^6.0.0-alpha.16", | ||
"@jupyterlab/docprovider": "^4.0.0-alpha.16", | ||
"@jupyterlab/docregistry": "^4.0.0-alpha.16", | ||
"@jupyterlab/services": "^7.0.0-alpha.16", | ||
"@jupyterlab/statusbar": "^4.0.0-alpha.16", | ||
"@jupyterlab/translation": "^4.0.0-alpha.16", | ||
"@jupyterlab/ui-components": "^4.0.0-alpha.31", | ||
"@jupyterlab/apputils": "^4.0.0-alpha.17", | ||
"@jupyterlab/coreutils": "^6.0.0-alpha.17", | ||
"@jupyterlab/docprovider": "^4.0.0-alpha.17", | ||
"@jupyterlab/docregistry": "^4.0.0-alpha.17", | ||
"@jupyterlab/services": "^7.0.0-alpha.17", | ||
"@jupyterlab/statusbar": "^4.0.0-alpha.17", | ||
"@jupyterlab/translation": "^4.0.0-alpha.17", | ||
"@jupyterlab/ui-components": "^4.0.0-alpha.32", | ||
"@lumino/algorithm": "^2.0.0-alpha.6", | ||
@@ -63,7 +63,5 @@ "@lumino/coreutils": "^2.0.0-alpha.6", | ||
"devDependencies": { | ||
"@jupyterlab/testutils": "^4.0.0-alpha.16", | ||
"@types/jest": "^26.0.10", | ||
"jest": "^26.4.2", | ||
"@jupyterlab/testing": "^4.0.0-alpha.17", | ||
"@types/jest": "^29.2.0", | ||
"rimraf": "~3.0.0", | ||
"ts-jest": "^26.3.0", | ||
"typedoc": "~0.22.10", | ||
@@ -70,0 +68,0 @@ "typescript": "~4.7.3" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129157
5
2659