Skip to content

Commit ea31fe8

Browse files
committed
Update model filePath when saving
Fix the file extension automatically if it doesn't end in jGIS FIXME: Does not save changes to the shared document after changing the filePath.
1 parent f4426fc commit ea31fe8

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

packages/base/src/commands.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,31 @@ export function addCommands(
256256
label: trans.__('Save As...'),
257257
isEnabled: () => true,
258258
execute: async () => {
259-
const oldFilename = tracker.currentWidget?.model.filePath;
260-
const newFilename = (await InputDialog.getText({
261-
title: 'Save as...',
262-
label: 'New filename',
263-
placeholder: oldFilename,
264-
})).value;
259+
if (!tracker.currentWidget) {
260+
return;
261+
}
262+
263+
const model = tracker.currentWidget.model;
264+
const oldFilename = model.filePath;
265+
let newFilename = (
266+
await InputDialog.getText({
267+
title: 'Save as...',
268+
label: 'New filename',
269+
placeholder: oldFilename
270+
})
271+
).value;
265272

266273
if (!newFilename) {
267274
return;
268275
}
269276

270-
const content = tracker.currentWidget?.model.toJSON();
277+
if (newFilename.toLowerCase().endsWith('.qgz')) {
278+
throw Error('Not supported yet');
279+
} else if (!newFilename.toLowerCase().endsWith('.jgis')) {
280+
newFilename += '.jGIS';
281+
}
282+
283+
const content = model.toJSON();
271284

272285
// FIXME: This doesn't re-open the project file in the current view where the save button was clicked.
273286
app.serviceManager.contents.save(newFilename, {
@@ -276,9 +289,11 @@ export function addCommands(
276289
type: 'file',
277290
mimetype: 'text/json'
278291
});
292+
// FIXME: The widget will only save to this new filename once, as opposed to continuously saving changes to the file like we expect.
293+
model.filePath = newFilename;
294+
279295
// FIXME: Saves to the currently open directory, while the above save is to the JupyterLab root directory.
280296
// FIXME: Get "unsaved_project" from a constant
281-
// FIXME: unsaved_project is getting saved even though we're trying not to!
282297
if (oldFilename && !oldFilename.endsWith('unsaved_project')) {
283298
app.serviceManager.contents.save(oldFilename, {
284299
content: JSON.stringify(content),

0 commit comments

Comments
 (0)