Skip to content

Commit 89c4f54

Browse files
committed
[ui] FileSaveDialog: Added Validation to the file save process
Validating the filename to ensure that the file does not gets saved with just the extension
1 parent 648b095 commit 89c4f54

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

meshroom/ui/qml/Application.qml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,47 @@ Page {
5959
return ""
6060
}
6161

62+
Component {
63+
id: invalidFilepathDialog
64+
65+
MessageDialog {
66+
title: "Invalid Filepath"
67+
68+
required property string filepath
69+
70+
preset: "Warning"
71+
text: "The provided filepath is not valid."
72+
detailedText: "Filepath: " + filepath
73+
helperText: "Please provide a valid filepath to save the file."
74+
75+
standardButtons: Dialog.Ok
76+
onClosed: destroy()
77+
}
78+
}
79+
80+
function validateFilepathForSave(filepath: string, sourceSaveDialog: Dialog): bool {
81+
/**
82+
* Returns if the provided savefile is not a valid file.
83+
* Shows a Warning Dialog in case the file is not a valid one.
84+
* Accepting the dialog reopens the source dialog from which this function was inkvoked.
85+
*/
86+
const invalidBaseName = Filepath.basename(filepath).trim() === ".mg";
87+
88+
// Provided filename is valid
89+
if (!invalidBaseName) {
90+
return true
91+
}
92+
93+
// Instantiate the Warning Dialog with the provided filepath
94+
const warningDialog = invalidFilepathDialog.createObject(root, {"filepath": Filepath.urlToString(filepath)});
95+
96+
// And open the dialog
97+
warningDialog.closed.connect(sourceSaveDialog.open);
98+
warningDialog.open();
99+
100+
return false
101+
}
102+
62103
// File dialogs
63104
Platform.FileDialog {
64105
id: saveFileDialog
@@ -71,6 +112,13 @@ Page {
71112
defaultSuffix: ".mg"
72113
fileMode: Platform.FileDialog.SaveFile
73114
onAccepted: {
115+
// Validate if the filename without any spaces is just .mg ?
116+
if (!validateFilepathForSave(currentFile, saveFileDialog))
117+
{
118+
return;
119+
}
120+
121+
// Only save a valid file
74122
_reconstruction.saveAs(currentFile)
75123
MeshroomApp.addRecentProjectFile(currentFile.toString())
76124
closed(Platform.Dialog.Accepted)
@@ -89,6 +137,13 @@ Page {
89137
defaultSuffix: ".mg"
90138
fileMode: Platform.FileDialog.SaveFile
91139
onAccepted: {
140+
// Validate if the filename without any spaces is just .mg ?
141+
if (!validateFilepathForSave(currentFile, saveTemplateDialog))
142+
{
143+
return;
144+
}
145+
146+
// Only save a valid template
92147
_reconstruction.saveAsTemplate(currentFile)
93148
closed(Platform.Dialog.Accepted)
94149
MeshroomApp.reloadTemplateList()

0 commit comments

Comments
 (0)