@@ -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