Skip to content

Commit af2c19e

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 af2c19e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

meshroom/ui/qml/Application.qml

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

62+
Dialog {
63+
id: invalidFileDialog
64+
title: "Invalid File"
65+
66+
// The dialog to reopen when user clicks 'OK'
67+
property var redial: null
68+
69+
x: parent.width / 2 - width / 2
70+
y: parent.height / 2 - height / 2
71+
height: 120
72+
73+
// What appears in the dialog
74+
Row {
75+
MaterialLabel { text: MaterialIcons.warning; color: "#FF9800"; font.pointSize: 30 }
76+
Label { width: 20 } // A kind of spacer
77+
78+
Column {
79+
Label { text: "The filepath provided is not valid. Please provide a valid file path/name to save the file." }
80+
Label { id: message; text: ""; color: "#FF9800" }
81+
Label { text: "Click OK to return to File Dialog, Cancel to cancel the save process." }
82+
}
83+
}
84+
85+
// Standard buttons for the Dialog
86+
standardButtons: Dialog.Ok | Dialog.Cancel
87+
88+
onAccepted: {
89+
if (redial) redial.open()
90+
}
91+
onRejected: {
92+
if (redial) redial.closed(Platform.Dialog.Rejected)
93+
}
94+
95+
function show(filepath) {
96+
// Update the message which is displayed on the error dialog
97+
message.text = "Provided Path: " + filepath
98+
99+
// open the dialog
100+
this.open()
101+
}
102+
}
103+
62104
// File dialogs
63105
Platform.FileDialog {
64106
id: saveFileDialog
@@ -71,6 +113,15 @@ Page {
71113
defaultSuffix: ".mg"
72114
fileMode: Platform.FileDialog.SaveFile
73115
onAccepted: {
116+
// Validate if the filename without any spaces is just .mg ?
117+
if (Filepath.basename(currentFile).trim() === ".mg") {
118+
// If that's the case then show an error to the user about the filepath being wrong
119+
invalidFileDialog.redial = saveFileDialog
120+
invalidFileDialog.show(Filepath.urlToString(currentFile))
121+
return
122+
}
123+
124+
// Only save a valid file
74125
_reconstruction.saveAs(currentFile)
75126
MeshroomApp.addRecentProjectFile(currentFile.toString())
76127
closed(Platform.Dialog.Accepted)
@@ -89,6 +140,15 @@ Page {
89140
defaultSuffix: ".mg"
90141
fileMode: Platform.FileDialog.SaveFile
91142
onAccepted: {
143+
// Validate if the filename without any spaces is just .mg ?
144+
if (Filepath.basename(currentFile).trim() === ".mg") {
145+
// If that's the case then show an error to the user about the filepath being wrong
146+
invalidFileDialog.redial = saveTemplateDialog
147+
invalidFileDialog.show(Filepath.urlToString(currentFile))
148+
return
149+
}
150+
151+
// Only save a valid template
92152
_reconstruction.saveAsTemplate(currentFile)
93153
closed(Platform.Dialog.Accepted)
94154
MeshroomApp.reloadTemplateList()

0 commit comments

Comments
 (0)