From 44fbcfe8ac0b5599b7475b48ad897fbec132640f Mon Sep 17 00:00:00 2001 From: dmv Date: Tue, 11 Mar 2008 09:29:06 +0000 Subject: [PATCH] IPAL18008 Impossible to load script with '-' in the name --- src/SalomeApp/SalomeApp_Application.cxx | 62 +++++++++++---------- src/SalomeApp/resources/SalomeApp_msg_en.po | 2 +- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 802d7d7b0..c27340438 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -54,6 +54,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.po b/src/SalomeApp/resources/SalomeApp_msg_en.po index d6a6d6d90..8d681a160 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.po +++ b/src/SalomeApp/resources/SalomeApp_msg_en.po @@ -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" -- 2.39.2