Salome HOME
Redesign SALOME documentation
[modules/gui.git] / src / STD / STD_Application.cxx
index e4eb217cda4f776cc84a3f77b8e22ba5231fca50..208115b83d0397b4d388bd9a2bb50414cdcdbf87 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -111,7 +111,7 @@ void STD_Application::closeApplication()
     beforeCloseDoc( study );
 
     study->closeDocument();
-
+    emit appClosed();
     setActiveStudy( 0 );
     delete study;
 
@@ -203,7 +203,8 @@ void STD_Application::createActions()
   createAction( NewWindowId, tr( "TOT_DESK_NEWWINDOW" ), QIcon(),
                 tr( "MEN_DESK_NEWWINDOW" ), tr( "PRP_DESK_NEWWINDOW" ), 0, desk  );
 
-  createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ), QIcon(),
+  createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ),
+                resMgr->loadPixmap( "STD", tr( "ICON_DESK_ABOUT" ) ),
                 tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
                 Qt::ALT+Qt::SHIFT+Qt::Key_A, desk, false, this, SLOT( onHelpAbout() ) );
 
@@ -219,7 +220,8 @@ void STD_Application::createActions()
   // Create menus
 
   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, MenuFileId, 0 );
-  int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, MenuEditId, 10 );
+  // Let the application developers insert some menus between Edit and View
+  int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, MenuEditId, 5 );
   int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1, MenuViewId, 10 );
   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, MenuHelpId, 1000 );
 
@@ -228,10 +230,9 @@ 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 );
   createMenu( FileSaveAsId, fileMenu, 5 );
+  createMenu( FileCloseId,  fileMenu, 5 );
   createMenu( separator(),  fileMenu, -1, 5 );
 
   createMenu( separator(),  fileMenu );
@@ -252,7 +253,8 @@ void STD_Application::createActions()
 
   // Create tool bars
 
-  int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ) );
+  int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ),  // title (language-dependant)
+                           QString( "SalomeStandard" ) );      // name (language-independant)
 
   // Create tool items
 
@@ -313,16 +315,19 @@ bool STD_Application::onNewDoc( const QString& name )
 void STD_Application::onOpenDoc()
 {
   // It is preferrable to use OS-specific file dialog box here !!!
-  QString aName = getFileName( true, QString(), getFileFilter(), QString(), 0 );
+  QString aName = getFileName( true, QString(), getFileFilter( true ), QString(), 0 );
   if ( aName.isNull() )
     return;
 
   onOpenDoc( aName );
 }
 
-/*! \retval true, if document was opened successful, else false.*/
+/*! \retval \c true, if document was opened successful, else \c false.*/
 bool STD_Application::onOpenDoc( const QString& aName )
 {
+  if ( !abortAllOperations() )
+    return false;
+
   QApplication::setOverrideCursor( Qt::WaitCursor );
 
   bool res = openAction( openChoice( aName ), aName );
@@ -355,8 +360,6 @@ bool STD_Application::onReopenDoc()
     // update views / windows / status bar / title
     clearViewManagers();
     setActiveStudy( 0 );
-    updateDesktopTitle();
-    updateCommandsStatus();
 
     // delete study
     delete study;
@@ -365,13 +368,21 @@ bool STD_Application::onReopenDoc()
     // post closing actions
     afterCloseDoc();
 
+    int aNbStudies = 0;
+    QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
+    for ( int i = 0; i < apps.count(); i++ )
+      aNbStudies += apps.at( i )->getNbStudies();
+
     // reload study from the file
     res = useFile( studyName ) && activeStudy();
 
     // if reloading is failed, close the desktop
-    if ( !res ) {
-      setDesktop( 0 );
+    if ( aNbStudies && !res )
       closeApplication();
+    else
+    {
+      updateDesktopTitle();
+      updateCommandsStatus();
     }
   }
   return res;
@@ -389,18 +400,32 @@ void STD_Application::afterCloseDoc()
 
 /*!Close document, if it's possible.*/
 void STD_Application::onCloseDoc( bool ask )
+{
+  closeDoc( ask );
+}
+
+/*!Close document, if it's possible.*/
+bool STD_Application::closeDoc( bool ask )
 {
   bool closePermanently = true;
 
   if ( ask && !isPossibleToClose( closePermanently ) )
-    return;
+    return false;
 
+  return closeActiveDoc( closePermanently );
+}
+
+/*!Close document.*/
+bool STD_Application::closeActiveDoc( bool permanently )
+{
   SUIT_Study* study = activeStudy();
+  if ( !study ) // no active study
+    return true;
 
   beforeCloseDoc( study );
 
   if ( study )
-    study->closeDocument( closePermanently );
+    study->closeDocument( permanently );
 
   clearViewManagers();
 
@@ -429,10 +454,11 @@ void STD_Application::onCloseDoc( bool ask )
 
   if ( !desktop() )
     closeApplication();
+  return true;
 }
 
 /*!Check the application on closing.
- * \retval true if possible, else false
+ * \retval \c true if possible, else \c false
  */
 bool STD_Application::isPossibleToClose( bool& closePermanently )
 {
@@ -450,7 +476,7 @@ bool STD_Application::isPossibleToClose( bool& closePermanently )
 
 int STD_Application::closeChoice( const QString& docName )
 {
-  int answer = SUIT_MessageBox::question( desktop(), tr( "CLOSE_STUDY" ), tr( "CLOSE_QUESTION" ).arg( docName ),
+  int answer = SUIT_MessageBox::question( desktop(), tr( "CLOSE_STUDY" ), tr( "CLOSE_QUESTION" ),
                                           SUIT_MessageBox::Save | SUIT_MessageBox::Discard | SUIT_MessageBox::Cancel,
                                           SUIT_MessageBox::Save );
 
@@ -542,6 +568,9 @@ void STD_Application::onSaveDoc()
   if ( !activeStudy() )
     return;
 
+  if ( !abortAllOperations() )
+    return;
+
   bool isOk = false;
   if ( activeStudy()->isSaved() )
   {
@@ -570,17 +599,20 @@ void STD_Application::onSaveDoc()
     onSaveAsDoc();
 }
 
-/*! \retval TRUE, if doument saved successful, else FALSE.*/
+/*! \retval \c true, if document saved successfully, else \c false.*/
 bool STD_Application::onSaveAsDoc()
 {
   SUIT_Study* study = activeStudy();
   if ( !study )
     return false;
 
+  if ( !abortAllOperations() )
+    return false;
+
   bool isOk = false;
   while ( !isOk )
   {
-    QString aName = getFileName( false, study->studyName(), getFileFilter(), QString(), 0 );
+    QString aName = getFileName( false, study->studyName(), getFileFilter( false ), QString(), 0 );
     if ( aName.isNull() )
       return false;
 
@@ -638,7 +670,7 @@ void STD_Application::setEditEnabled( bool theEnable )
   }
 }
 
-/*!\retval true, if document opened successful, else false.*/
+/*!\retval \c true, if document opened successfully, else \c false.*/
 bool STD_Application::useFile(const QString& theFileName)
 {
   bool res = SUIT_Application::useFile( theFileName );
@@ -695,7 +727,7 @@ SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
   SUIT_ViewManager* vm = 0;
   for ( QList<SUIT_ViewManager*>::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end() && !vm; ++it )
   {
-    if ( (*it)->getType() == vmType )
+    if ( (*it)->getType() == vmType && !(*it)->getDetached())
       vm = *it;
   }
   return vm;
@@ -788,7 +820,7 @@ void STD_Application::clearViewManagers()
   }
 }
 
-/*!\retval TRUE, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
+/*!\retval \c true, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
 bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const
 {
   return myViewMgrs.contains( vm );
@@ -800,7 +832,7 @@ void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
   setActiveViewManager( vm );
 }
 
-/*!Sets status bar show, if \on = true, else status bar hide.*/
+/*!Shows status bar, if on is \c true, else hides status bar.*/
 void STD_Application::onViewStatusBar( bool on )
 {
   if ( on )
@@ -853,6 +885,12 @@ void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextM
   delete popup;
 }
 
+/*!\retval QString - return file extension(s).*/
+QString STD_Application::getFileFilter( bool /*open*/ ) const
+{
+  return QString();
+}
+
 /*!\retval QString - return file name from dialog.*/
 QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
                                       const QString& caption, QWidget* parent )
@@ -991,3 +1029,11 @@ int STD_Application::viewManagerId( const SUIT_ViewManager* theManager) const
   return myViewMgrs.indexOf(const_cast<SUIT_ViewManager*>(theManager));
 }
 
+/*!
+  \brief Abort active operations if there are any
+  \return \c false if some operation cannot be aborted
+*/
+bool STD_Application::abortAllOperations()
+{
+  return true;
+}