From: rnv Date: Tue, 25 Mar 2008 07:21:16 +0000 (+0000) Subject: Implementation of NPAL15860 (EDF PAL 409: to have in file menu a history of the open... X-Git-Tag: TG_start_ELNO_visualization X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=250f562cf4f179ff473c70758c779d55d508ad61;p=modules%2Fgui.git Implementation of NPAL15860 (EDF PAL 409: to have in file menu a history of the open studies). --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 2e59728d0..d69115d96 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -516,8 +516,12 @@ void LightApp_Application::createActions() } //! MRU + int maxMostRecentlyStudies = resMgr->integerValue("MaxMRU", "MaxValue", 5); QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk ); + mru->setVisibleCount(maxMostRecentlyStudies); + mru->setInsertMode(QtxMRUAction::AddFirst); connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) ); + mru->loadLinks(resMgr, "MostRecentlyStudies"); registerAction( MRUId, mru ); // default icon for neutral point ('SALOME' module) @@ -628,11 +632,10 @@ void LightApp_Application::createActions() createMenu( PreferencesId, fileMenu, 15, -1 ); createMenu( separator(), fileMenu, -1, 15, -1 ); - /* createMenu( separator(), fileMenu, -1, 100, -1 ); createMenu( MRUId, fileMenu, 100, -1 ); createMenu( separator(), fileMenu, -1, 100, -1 ); - */ + } /*!On module activation action.*/ @@ -821,16 +824,8 @@ bool LightApp_Application::onOpenDoc( const QString& aName ) } bool res = CAM_Application::onOpenDoc( aName ); - - QAction* a = action( MRUId ); - if ( a && a->inherits( "QtxMRUAction" ) ) - { - QtxMRUAction* mru = (QtxMRUAction*)a; - if ( res ) - mru->insert( aName ); - else - mru->remove( aName ); - } + if(res) + addMRUStudy(aName); return res; } @@ -887,6 +882,61 @@ void LightApp_Application::setActiveStudy( SUIT_Study* study ) activateWindows(); } +/*! + Remove items from the "File -> Most recently used" sub menu +*/ +void LightApp_Application::removeMRUStudy( const QString& studyName ){ + QAction* a = action( MRUId ); + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( a && a->inherits( "QtxMRUAction" ) && resMgr ) { + QtxMRUAction* mru = (QtxMRUAction*)a; + mru->remove( studyName ); + mru->saveLinks(resMgr, "MostRecentlyStudies"); + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList aAppList = aSession->applications(); + LightApp_Application* theApp = 0; + for ( QPtrListIterator it( aAppList ); it.current() ; ++it ) { + theApp = (LightApp_Application*)it.current(); + if(theApp) + theApp->updateMRUStudies(); + } + } +} + +/*! + Add items in the "File -> Most recently used" sub menu +*/ +void LightApp_Application::addMRUStudy(const QString& studyName){ + QAction* a = action( MRUId ); + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( a && a->inherits( "QtxMRUAction" ) && !studyName.isNull() && resMgr) { + QtxMRUAction* mru = (QtxMRUAction*)a; + mru->insert( studyName ); + mru->saveLinks(resMgr, "MostRecentlyStudies",false); + + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList aAppList = aSession->applications(); + LightApp_Application* theApp = 0; + for ( QPtrListIterator it( aAppList ); it.current() ; ++it ) { + theApp = (LightApp_Application*)it.current(); + if(theApp) + theApp->updateMRUStudies(); + } + } +} + +/*! + Update items in the "File -> Most recently used" sub menu +*/ +void LightApp_Application::updateMRUStudies(){ + QAction* a = action( MRUId ); + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( a && a->inherits( "QtxMRUAction" ) && resMgr) { + QtxMRUAction* mru = (QtxMRUAction*)a; + mru->loadLinks(resMgr, "MostRecentlyStudies"); + } +} + /*! Enables/Disables menu items and toolbar buttons. Rebuild menu */ @@ -1507,9 +1557,13 @@ void LightApp_Application::onStudyOpened( SUIT_Study* theStudy ) } /*!Protected SLOT. On study saved.*/ -void LightApp_Application::onStudySaved( SUIT_Study* ) +void LightApp_Application::onStudySaved( SUIT_Study* s ) { emit studySaved(); + if( s ){ + QString aStudyName = s->studyName(); + addMRUStudy( aStudyName ); + } } /*!Protected SLOT. On study closed.*/ @@ -1622,7 +1676,21 @@ void LightApp_Application::onPreferenceChanged( QString& modName, QString& secti /*!Private SLOT. On open document with name \a aName.*/ void LightApp_Application::onMRUActivated( QString aName ) { - onOpenDoc( aName ); + if ( aName.isNull() ) + return; + + QFile aFile(aName); + if(!aFile.exists()) { + // displaying a message box as SUIT_Validator in case file can't be open + SUIT_MessageBox::error1( desktop(), + tr( "ERR_ERROR" ), + tr( "ERR_DOC_NOT_EXISTS" ).arg( aName ), + tr( "BUT_OK" ) ); + removeMRUStudy(aName); + } + else { + onOpenDoc( aName ); + } } /*!Remove all windows from study.*/ diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index e83e3c2fd..fb83e0608 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -133,7 +133,7 @@ public: const QString& caption, QWidget* parent ); void updateActions(); - + SUIT_ViewManager* getViewManager( const QString&, const bool ); virtual void addViewManager( SUIT_ViewManager* ); virtual void removeViewManager( SUIT_ViewManager* ); @@ -162,6 +162,10 @@ public: virtual bool event( QEvent* ); virtual bool checkDataObject( LightApp_DataObject* theObj ); + + virtual void updateMRUStudies(); + virtual void addMRUStudy( const QString& studyName ); + virtual void removeMRUStudy( const QString& studyName ); signals: void studyOpened(); diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 0c2f9ee0c..16a566b96 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -59,6 +59,10 @@ +
+ + +
@@ -90,4 +94,8 @@
+
+ + +
diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index c138bb49f..340601cc7 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -350,3 +350,5 @@ msgstr "&Open..." msgid "LightApp_Application::ACTIVATE_MODULE_OP_NEW" msgstr "&New" +msgid "LightApp_Application::ERR_DOC_NOT_EXISTS" +msgstr "Can not open %1.\n File does not exist" diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 0a4f4e18d..4fbe1d0b9 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -369,8 +369,7 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName ) if (toOpen) res = CAM_Application::onOpenDoc( aName ); - - QAction* a = action( MRUId ); + /* QAction* a = action( MRUId ); if ( a && a->inherits( "QtxMRUAction" ) ) { QtxMRUAction* mru = (QtxMRUAction*)a; @@ -378,8 +377,11 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName ) mru->insert( aName ); else mru->remove( aName ); - } + }*/ + if(res) + addMRUStudy(aName); return res; + } /*!SLOT. Load document.*/ diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index b4da14ade..95368e9bc 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -111,6 +111,10 @@ +
+ + +