]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
IPAL18008 Impossible to load script with '-' in the name
authordmv <dmv@opencascade.com>
Tue, 11 Mar 2008 09:29:06 +0000 (09:29 +0000)
committerdmv <dmv@opencascade.com>
Tue, 11 Mar 2008 09:29:06 +0000 (09:29 +0000)
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/resources/SalomeApp_msg_en.po

index 802d7d7b0fd5ea10fc7d4ff3161750f9ff73592f..c273404389d02e81e88a9682b57509b0f5f4109e 100644 (file)
@@ -54,6 +54,7 @@
 #include <PythonConsole_PyConsole.h>
 
 #include <SUIT_FileDlg.h>
+#include <SUIT_FileValidator.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_ActionOperation.h>
@@ -687,6 +688,27 @@ public:
   QCheckBox* mySaveGUIChk;
 };
 
+class DumpStudyFileValidator : public SUIT_FileValidator
+{
+ public:
+  DumpStudyFileValidator( QWidget* parent) : SUIT_FileValidator ( parent ) {};
+  virtual ~DumpStudyFileValidator() {};
+  virtual bool canSave( const QString& file );
+};
+
+bool DumpStudyFileValidator::canSave(const QString& file)
+{
+  // if file name is not correct...
+  if ( file.find( QRegExp("[-!?#*&]") ) != -1 ) {
+    SUIT_MessageBox::error1 ( parent(),
+                             QObject::tr("WRN_WARNING"),
+                             QObject::tr("WRN_FILE_NAME_BAD"),
+                             QObject::tr("BUT_OK") );
+    return false;
+  }
+  return SUIT_FileValidator::canSave( file );
+}
+
 /*!Private SLOT. On dump study.*/
 void SalomeApp_Application::onDumpStudy( )
 {
@@ -697,35 +719,17 @@ void SalomeApp_Application::onDumpStudy( )
   QStringList aFilters;
   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
 
-  DumpStudyFileDlg* fd = new DumpStudyFileDlg( desktop() );
-  fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
-  fd->setFilters( aFilters );
-  fd->myPublishChk->setChecked( true );
-  fd->mySaveGUIChk->setChecked( true );
-  QString aFileName;
-  while (1) {
-    fd->exec();
-    fd->raise();
-    aFileName = fd->selectedFile();
-    if (!aFileName.isEmpty()) {
-      if ( (aFileName.find('-', 0) == -1) && (aFileName.find('!', 0) == -1) && (aFileName.find('?', 0) == -1) &&
-          (aFileName.find('#', 0) == -1) && (aFileName.find('*', 0) == -1) && (aFileName.find('&', 0) == -1)) {
-       break;
-      }
-      else {
-      SUIT_MessageBox::warn1 ( desktop(),
-                              QObject::tr("WRN_WARNING"),
-                              tr("WRN_FILE_NAME_BAD"),
-                              QObject::tr("BUT_OK") );
-      }
-    }
-    else {
-      break;
-    }
-  }
-  bool toPublish = fd->myPublishChk->isChecked();
-  bool toSaveGUI = fd->mySaveGUIChk->isChecked();
-  delete fd;
+  DumpStudyFileDlg fd( desktop() );
+  fd.setValidator(new DumpStudyFileValidator ( &fd ) );
+  fd.setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
+  fd.setFilters( aFilters );
+  fd.myPublishChk->setChecked( true );
+  fd.mySaveGUIChk->setChecked( true );
+  fd.exec();
+  QString aFileName = fd.selectedFile();
+
+  bool toPublish = fd.myPublishChk->isChecked();
+  bool toSaveGUI = fd.mySaveGUIChk->isChecked();
 
   if ( !aFileName.isEmpty() ) {
     QFileInfo aFileInfo(aFileName);
index d6a6d6d90d3d8d6fa40d414aa2b4d6a329cdd75c..8d681a16042bc7f7de85191147d04bfb91c786ad 100644 (file)
@@ -222,7 +222,7 @@ msgid "SalomeApp_Application::WRN_DUMP_STUDY_FAILED"
 msgstr "Dump study failed"
 
 msgid "SalomeApp_Application::WRN_FILE_NAME_BAD"
-msgstr "Please enter correct file name"
+msgstr "Please enter correct file name. Special chars are not allowed."
 
 msgid "SAVE_POINT_OBJECT_TOOLTIP"
 msgstr "Saved GUI state: %1"