From: vsr Date: Tue, 18 Aug 2009 07:54:03 +0000 (+0000) Subject: Issue 20430: EDF 1012 ALL : Automatic save X-Git-Tag: V5_1_3rc1~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=609c51d8dcc61f84771020fb54bed34fb201fb8e;p=modules%2Fgui.git Issue 20430: EDF 1012 ALL : Automatic save --- diff --git a/doc/salome/gui/images/pref11.png b/doc/salome/gui/images/pref11.png index 634da539e..39755e710 100755 Binary files a/doc/salome/gui/images/pref11.png and b/doc/salome/gui/images/pref11.png differ diff --git a/doc/salome/gui/images/studymanagement.png b/doc/salome/gui/images/studymanagement.png index f6b20973d..e50858a27 100755 Binary files a/doc/salome/gui/images/studymanagement.png and b/doc/salome/gui/images/studymanagement.png differ diff --git a/doc/salome/gui/input/salome_preferences.doc b/doc/salome/gui/input/salome_preferences.doc index dc5aba11a..8d37c64f5 100644 --- a/doc/salome/gui/input/salome_preferences.doc +++ b/doc/salome/gui/input/salome_preferences.doc @@ -30,6 +30,10 @@ ASCII format file (or files).
  • Store positions of windows - if checked in, positions of windows will be saved in a special file at the end of the current session and then restored for a new session.
  • +
  • Auto-save interval (min) - allows specify time interval (in +minutes) for automatic study saving operation. If the time interval is +equal to 0 ("Disabled" value is shown) the automatic saving is not +performed.
  • Store/restore last GUI state - if checked in, all GUI settings are saved with the rest of the data whenever you save the study. When the study is reopened, the GUI state is restored.
  • @@ -204,4 +208,4 @@ resizing columns on expanding an object browser item. Entry, IOR and Reference entry columns in the Object Browser. -*/ \ No newline at end of file +*/ diff --git a/doc/salome/gui/input/study_management_chapter.doc b/doc/salome/gui/input/study_management_chapter.doc index 524a4f121..b1d88af2c 100644 --- a/doc/salome/gui/input/study_management_chapter.doc +++ b/doc/salome/gui/input/study_management_chapter.doc @@ -16,9 +16,14 @@ All operations with studies are available from the \b File menu. \b New - creates a new study. The study will be created with default name \b Study1. It is possible to create several studies, each accessible from the task bar. + \b Open - allows to open an existing study by browsing for it in a standard Search File dialog box, choosing the required *.hdf file and clicking \b Open button. + +\b Reopen - reloads the current study from the *.hdf file. This menu command +can be used to reverse the study to the latest saved state. + \b Connect - allows to open an unloaded study. \image html loadstudy2.png Select one of the studies, which has been previously @@ -110,4 +115,4 @@ studies, giving the possibility to fast load the required study. \b Exit - unlike \b Close, closes not only the current, but all opened Salome studies. -*/ \ No newline at end of file +*/ diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 5f5a86d73..7465cf714 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -157,6 +157,7 @@ #include #include #include +#include #include @@ -227,6 +228,11 @@ LightApp_Application::LightApp_Application() setDesktop( desk ); + // initialize auto save timer + myAutoSaveTimer = new QTimer( this ); + myAutoSaveTimer->setSingleShot( true ); + connect( myAutoSaveTimer, SIGNAL( timeout() ), this, SLOT( onSaveDoc() ) ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ); @@ -1418,6 +1424,9 @@ void LightApp_Application::onStudySaved( SUIT_Study* s ) /*!Protected SLOT. On study closed.*/ void LightApp_Application::onStudyClosed( SUIT_Study* s ) { + // stop auto-save timer + myAutoSaveTimer->stop(); + // Bug 10396: clear selection mySelMgr->clearSelected(); @@ -1444,6 +1453,16 @@ void LightApp_Application::studyOpened( SUIT_Study* s ) updateViewManagers(); } +void LightApp_Application::studySaved( SUIT_Study* s ) +{ + CAM_Application::studyOpened( s ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + if ( aResMgr && activeStudy() ) { + int autoSaveInterval = aResMgr->integerValue( "Study", "auto_save_interval", 0 ); + if ( autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 ); + } +} + void LightApp_Application::studyCreated( SUIT_Study* s ) { CAM_Application::studyCreated( s ); @@ -1783,6 +1802,12 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" ); pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" ); + int autoSaveInterval = pref->addPreference( tr( "PREF_AUTO_SAVE" ), studyGroup, + LightApp_Preferences::IntSpin, "Study", "auto_save_interval" ); + pref->setItemProperty( "min", 0, autoSaveInterval ); + pref->setItemProperty( "max", 1440, autoSaveInterval ); + pref->setItemProperty( "special", tr( "PREF_AUTO_SAVE_DISABLED" ), autoSaveInterval ); + int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab ); QString platform; #ifdef WIN32 @@ -2264,6 +2289,11 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString { if( param=="store_positions" ) updateWindows(); + if( param=="auto_save_interval" ) { + myAutoSaveTimer->stop(); + int autoSaveInterval = resMgr->integerValue( "Study", "auto_save_interval", 0 ); + if ( activeStudy() && autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 ); + } } #ifndef DISABLE_PYCONSOLE @@ -2754,6 +2784,12 @@ void LightApp_Application::createEmptyStudy() if ( objectBrowser() ) objectBrowser()->updateTree(); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + if ( aResMgr && activeStudy() ) { + int autoSaveInterval = aResMgr->integerValue( "Study", "auto_save_interval", 0 ); + if ( autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 ); + } } /*! diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 953947f13..a1d1911e1 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -52,6 +52,7 @@ class QString; class QWidget; class QStringList; class QDockWidget; +class QTimer; #ifdef WIN32 #pragma warning( disable:4251 ) @@ -229,6 +230,7 @@ protected: virtual void studyOpened( SUIT_Study* ); virtual void studyCreated( SUIT_Study* ); + virtual void studySaved( SUIT_Study* ); void updatePreference( const QString&, const QString&, const QString& ); @@ -268,6 +270,7 @@ protected: WinGeom myWinGeom; SUIT_Accel* myAccel; + QTimer* myAutoSaveTimer; static LightApp_Preferences* _prefs_; diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index ebfc4ab4b..348795f7a 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -109,7 +109,8 @@
    - + +
    diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index c88514681..e1ddc72f0 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -118,6 +118,14 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASPREF_STORE_POS Store positions of windows + + PREF_AUTO_SAVE + Auto-save interval (min) + + + PREF_AUTO_SAVE_DISABLED + Disabled + PREF_PROJECTION_MODE Projection mode: diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index eefdd5165..c78579f0f 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -161,6 +161,10 @@ void STD_Application::createActions() tr( "MEN_DESK_FILE_OPEN" ), tr( "PRP_DESK_FILE_OPEN" ), Qt::CTRL+Qt::Key_O, desk, false, this, SLOT( onOpenDoc() ) ); + createAction( FileReopenId, tr( "TOT_DESK_FILE_REOPEN" ), QIcon(), + tr( "MEN_DESK_FILE_REOPEN" ), tr( "PRP_DESK_FILE_REOPEN" ), + 0, desk, false, this, SLOT( onReopenDoc() ) ); + createAction( FileCloseId, tr( "TOT_DESK_FILE_CLOSE" ), resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ), tr( "MEN_DESK_FILE_CLOSE" ), tr( "PRP_DESK_FILE_CLOSE" ), @@ -222,6 +226,7 @@ void STD_Application::createActions() createMenu( FileNewId, fileMenu, 0 ); createMenu( FileOpenId, fileMenu, 0 ); + createMenu( FileReopenId, fileMenu, 0 ); createMenu( FileCloseId, fileMenu, 5 ); createMenu( separator(), fileMenu, -1, 5 ); createMenu( FileSaveId, fileMenu, 5 ); @@ -326,6 +331,45 @@ bool STD_Application::onOpenDoc( const QString& aName ) return res; } +/*! Reload document from the file.*/ +bool STD_Application::onReopenDoc() +{ + bool res = false; + + SUIT_Study* study = activeStudy(); + if ( study && study->isSaved() ) { + // remember study name + QString studyName = study->studyName(); + + // close study + beforeCloseDoc( study ); + study->closeDocument( true ); + + // update views / windows / status bar / title + clearViewManagers(); + setActiveStudy( 0 ); + updateDesktopTitle(); + updateCommandsStatus(); + + // delete study + delete study; + study = 0; + + // post closing actions + afterCloseDoc(); + + // reload study from the file + res = useFile( studyName ) && activeStudy(); + + // if reloading is failed, close the desktop + if ( !res ) { + setDesktop( 0 ); + closeApplication(); + } + } + return res; +} + /*!Virtual function. Not implemented here.*/ void STD_Application::beforeCloseDoc( SUIT_Study* ) { @@ -621,12 +665,14 @@ void STD_Application::updateCommandsStatus() { SUIT_Application::updateCommandsStatus(); - bool aHasStudy = activeStudy() != 0; - bool aIsNeedToSave = false; - if ( aHasStudy ) - aIsNeedToSave = !activeStudy()->isSaved() || activeStudy()->isModified(); + bool aHasStudy = activeStudy() != 0; + bool aSaved = aHasStudy && activeStudy()->isSaved(); + bool aModified = aHasStudy && activeStudy()->isModified(); + bool aIsNeedToSave = aHasStudy && ( !aSaved || aModified ); - if ( action( FileSaveId ) ) + if ( action( FileReopenId ) ) + action( FileReopenId )->setEnabled( aSaved ); + if ( action( FileSaveId ) ) action( FileSaveId )->setEnabled( aIsNeedToSave ); if ( action( FileSaveAsId ) ) action( FileSaveAsId )->setEnabled( aHasStudy ); diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index 41ba71a88..08d336918 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -52,7 +52,7 @@ class STD_EXPORT STD_Application : public SUIT_Application Q_OBJECT public: - enum { MenuFileId, FileNewId, FileOpenId, FileCloseId, FileSaveId, FileSaveAsId, FileExitId, + enum { MenuFileId, FileNewId, FileOpenId, FileReopenId, FileCloseId, FileSaveId, FileSaveAsId, FileExitId, MenuViewId, ViewWindowsId, ViewToolBarsId, ViewStatusBarId, NewWindowId, MenuEditId, EditCutId, EditCopyId, EditPasteId, MenuHelpId, HelpAboutId, @@ -121,6 +121,8 @@ public slots: virtual void onOpenDoc(); virtual bool onOpenDoc( const QString& ); + virtual bool onReopenDoc(); + virtual void onExit(); virtual void onCopy(); diff --git a/src/STD/resources/STD_msg_en.ts b/src/STD/resources/STD_msg_en.ts index cfa9e93f4..30c0e5919 100644 --- a/src/STD/resources/STD_msg_en.ts +++ b/src/STD/resources/STD_msg_en.ts @@ -387,6 +387,10 @@ Do you want to overwrite it? TOT_DESK_FILE_OPEN Open document + + TOT_DESK_FILE_REOPEN + Reopen document + PRP_DESK_FILE_EXIT Exits the application @@ -395,6 +399,10 @@ Do you want to overwrite it? PRP_DESK_FILE_OPEN Opens an existing document + + PRP_DESK_FILE_REOPEN + Reload the current document from the file + PRP_DESK_FILE_SAVE Saves the active document @@ -423,6 +431,10 @@ Do you want to overwrite it? MEN_DESK_FILE_OPEN &Open... + + MEN_DESK_FILE_REOPEN + Reopen + MEN_DESK_FILE_LOAD Conn&ect... diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index 601889331..391fce0ba 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -198,6 +198,7 @@ +