Skip to content

Commit 8a199bd

Browse files
committed
feat: enable save as file dialog in desktop builds
1 parent 9d66e81 commit 8a199bd

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/command/DefaultMenus.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,15 @@ define(function (require, exports, module) {
122122
menu.addMenuDivider();
123123
menu.addMenuItem(Commands.FILE_SAVE);
124124
menu.addMenuItem(Commands.FILE_SAVE_ALL);
125+
if(Phoenix.isNativeApp){
126+
menu.addMenuItem(Commands.FILE_SAVE_AS);
127+
// save as is not yet supported in browser as in our vfs implements only open folder, so vfs needs to
128+
// be changed. Also, we dont know how the ux for save as will be in virtual paths.
129+
}
125130
menu.addMenuItem(Commands.FILE_DUPLICATE_FILE);
126131
menu.addMenuItem(Commands.FILE_DOWNLOAD_PROJECT, undefined, undefined, undefined, {
127132
hideWhenCommandDisabled: true
128133
});
129-
// menu.addMenuItem(Commands.FILE_SAVE_AS); not yet available in phoenix
130134
// menu.addMenuItem(Commands.FILE_PROJECT_SETTINGS); not yet available in phoenix
131135
menu.addMenuDivider();
132136
menu.addMenuItem(Commands.FILE_EXTENSION_MANAGER);

src/document/DocumentCommandHandlers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,12 @@ define(function (require, exports, module) {
10701070

10711071
if (FileViewController.getFileSelectionFocus() === FileViewController.PROJECT_MANAGER) {
10721072
// If selection is in the tree, leave workingset unchanged - even if orig file is in the list
1073-
fileOpenPromise = FileViewController
1074-
.openAndSelectDocument(path, FileViewController.PROJECT_MANAGER);
1073+
setTimeout(()=>{
1074+
fileOpenPromise = FileViewController
1075+
.openAndSelectDocument(path, FileViewController.PROJECT_MANAGER);
1076+
}, 100); // this is in a timeout as the file tree may not have updated yet after save as
1077+
// file created, and we wait for the file watcher events to get triggered so that the file
1078+
// selection is updated.
10751079
} else {
10761080
// If selection is in workingset, replace orig item in place with the new file
10771081
var info = MainViewManager.findInAllWorkingSets(doc.file.fullPath).shift();

src/filesystem/impls/appshell/AppshellFileSystem.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
/*global appshell, Phoenix*/
22+
/*global appshell, path*/
2323
/*eslint-env es6*/
2424
// jshint ignore: start
2525

@@ -330,7 +330,23 @@ define(function (require, exports, module) {
330330
* @param {function(?string, string=)} callback
331331
*/
332332
function showSaveDialog(title, initialPath, proposedNewFilename, callback) {
333-
appshell.fs.showSaveDialog(title, initialPath, proposedNewFilename, _wrap(callback));
333+
if(Phoenix.isNativeApp){
334+
const wrappedCallback = _wrap(callback);
335+
appshell.fs.showSaveDialog({
336+
title,
337+
defaultPath: Phoenix.fs.getTauriPlatformPath(path.join(initialPath, proposedNewFilename || ""))
338+
// no filter option for now filters: undefined
339+
}).then(fileSavePath => {
340+
if(!fileSavePath) {
341+
wrappedCallback(FileSystemError.NOT_READABLE);
342+
return;
343+
}
344+
wrappedCallback(null, fileSavePath);
345+
}).catch(wrappedCallback);
346+
return;
347+
}
348+
console.error("showSaveDialog is not yet supported in web browsers...");
349+
callback(FileSystemError.NOT_SUPPORTED);
334350
}
335351

336352
function _createStatObject(stats, realPath) {

0 commit comments

Comments
 (0)