From: vsr Date: Mon, 30 Dec 2019 09:03:04 +0000 (+0300) Subject: bos #16517 Implement method canOpen() to check that study file is accessible and... X-Git-Tag: V9_5_0a1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3568a68c1fc54190450b74ea099d67f3103faabe;p=modules%2Fgui.git bos #16517 Implement method canOpen() to check that study file is accessible and readable --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index fb14f540c..ba73f8d24 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1024,7 +1024,6 @@ void LightApp_Application::onOpenDoc() if ( aName.isNull() ) //Cancel return; - closeDoc(false); onOpenDoc( aName ); if ( !study ) // new study will be create in THIS application @@ -1034,12 +1033,30 @@ void LightApp_Application::onOpenDoc() } } +bool LightApp_Application::canOpenDoc( const QString& ) +{ + return true; +} + /*! SLOT: Opens new document. \param aName - name of file */ bool LightApp_Application::onOpenDoc( const QString& aName ) { + if ( !canOpenDoc(aName)) { + bool showError = !property("open_study_from_command_line").isValid() || + !property("open_study_from_command_line").toBool(); + + putInfo( tr("OPEN_DOCUMENT_PROBLEM") ); + if ( showError ) + SUIT_MessageBox::critical( desktop(), tr("ERR_ERROR"), tr("OPEN_DOCUMENT_PROBLEM")); + + return false; + } + + closeDoc(false); + if ( !checkExistingDoc() ) return false; diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 66a9032b3..6236e23b1 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -222,6 +222,8 @@ protected: virtual void setActiveStudy( SUIT_Study* ); virtual void updateCommandsStatus(); + virtual bool canOpenDoc( const QString& ); + virtual void beforeCloseDoc( SUIT_Study* ); virtual void afterCloseDoc(); virtual void moduleAdded( CAM_Module* ); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index cf148a657..d24daf374 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -2087,6 +2087,14 @@ void SalomeApp_Application::afterCloseDoc() LightApp_Application::afterCloseDoc(); } +bool SalomeApp_Application::canOpenDoc( const QString& url ) +{ + _PTR(Study) aStudyDS = getStudy(); + if ( aStudyDS ) + return aStudyDS->CanOpen( url.toUtf8().data() ); + return false; +} + /* Asks to close existing document. */ diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index ef34c4b26..e0bde79b7 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -173,6 +173,7 @@ protected: virtual PyConsole_Interp* createPyInterp(); #endif + virtual bool canOpenDoc( const QString& ); virtual void afterCloseDoc(); private slots: