mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 10:17:27 +02:00
Merge pull request #2602 from alicevision/fix/ValidateSaveFile
[BugFix] File save dialog now requires a valid filename
This commit is contained in:
commit
feedad4775
1 changed files with 53 additions and 0 deletions
|
@ -59,6 +59,47 @@ Page {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: invalidFilepathDialog
|
||||||
|
|
||||||
|
MessageDialog {
|
||||||
|
title: "Invalid Filepath"
|
||||||
|
|
||||||
|
required property string filepath
|
||||||
|
|
||||||
|
preset: "Warning"
|
||||||
|
text: "The provided filepath is not valid."
|
||||||
|
detailedText: "Filepath: " + filepath
|
||||||
|
helperText: "Please provide a valid filepath to save the file."
|
||||||
|
|
||||||
|
standardButtons: Dialog.Ok
|
||||||
|
onClosed: destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateFilepathForSave(filepath: string, sourceSaveDialog: Dialog): bool {
|
||||||
|
/**
|
||||||
|
* Return true if `filepath` is valid for saving a file to disk.
|
||||||
|
* Otherwise, show a warning dialog and returns false.
|
||||||
|
* Closing the warning dialog reopens the specified `sourceSaveDialog`, to allow the user to try again.
|
||||||
|
*/
|
||||||
|
const emptyFilename = Filepath.basename(filepath).trim() === ".mg";
|
||||||
|
|
||||||
|
// Provided filename is valid
|
||||||
|
if (!emptyFilename) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instantiate the Warning Dialog with the provided filepath
|
||||||
|
const warningDialog = invalidFilepathDialog.createObject(root, {"filepath": Filepath.urlToString(filepath)});
|
||||||
|
|
||||||
|
// And open the dialog
|
||||||
|
warningDialog.closed.connect(sourceSaveDialog.open);
|
||||||
|
warningDialog.open();
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// File dialogs
|
// File dialogs
|
||||||
Platform.FileDialog {
|
Platform.FileDialog {
|
||||||
id: saveFileDialog
|
id: saveFileDialog
|
||||||
|
@ -71,6 +112,12 @@ Page {
|
||||||
defaultSuffix: ".mg"
|
defaultSuffix: ".mg"
|
||||||
fileMode: Platform.FileDialog.SaveFile
|
fileMode: Platform.FileDialog.SaveFile
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
|
if (!validateFilepathForSave(currentFile, saveFileDialog))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only save a valid file
|
||||||
_reconstruction.saveAs(currentFile)
|
_reconstruction.saveAs(currentFile)
|
||||||
MeshroomApp.addRecentProjectFile(currentFile.toString())
|
MeshroomApp.addRecentProjectFile(currentFile.toString())
|
||||||
closed(Platform.Dialog.Accepted)
|
closed(Platform.Dialog.Accepted)
|
||||||
|
@ -89,6 +136,12 @@ Page {
|
||||||
defaultSuffix: ".mg"
|
defaultSuffix: ".mg"
|
||||||
fileMode: Platform.FileDialog.SaveFile
|
fileMode: Platform.FileDialog.SaveFile
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
|
if (!validateFilepathForSave(currentFile, saveTemplateDialog))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only save a valid template
|
||||||
_reconstruction.saveAsTemplate(currentFile)
|
_reconstruction.saveAsTemplate(currentFile)
|
||||||
closed(Platform.Dialog.Accepted)
|
closed(Platform.Dialog.Accepted)
|
||||||
MeshroomApp.reloadTemplateList()
|
MeshroomApp.reloadTemplateList()
|
||||||
|
|
Loading…
Add table
Reference in a new issue