X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSTD%2FSTD_Application.cxx;h=208115b83d0397b4d388bd9a2bb50414cdcdbf87;hb=41aded95c12ed86b77866d9dfe5212fa66869ab2;hp=706ecedb5620104e0fb2fb220245d06ac66101c9;hpb=232b55569765049c7d1cceb5096a45f8584c9369;p=modules%2Fgui.git diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 706ecedb5..208115b83 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -1,48 +1,47 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// 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 +// // 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. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// License as published by the Free Software Foundation; either +// 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "STD_Application.h" #include "STD_MDIDesktop.h" -#include "STD_CloseDlg.h" - #include +#include #include #include -#include -#include #include +#include #include #include +#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /*!Create and return new instance of STD_Application*/ extern "C" STD_EXPORT SUIT_Application* createApplication() @@ -53,17 +52,29 @@ extern "C" STD_EXPORT SUIT_Application* createApplication() /*!Constructor.*/ STD_Application::STD_Application() : SUIT_Application(), -myEditEnabled( true ), -myActiveViewMgr( 0 ) + myActiveViewMgr( 0 ), + myExitConfirm( true ), + myEditEnabled( true ) { - STD_MDIDesktop* desk = new STD_MDIDesktop(); - - setDesktop( desk ); + setDesktop( new STD_MDIDesktop() ); } /*!Destructor.*/ STD_Application::~STD_Application() { + clearViewManagers(); +} + +/*! \retval requirement of exit confirmation*/ +bool STD_Application::exitConfirmation() const +{ + return myExitConfirm; +} + +/*! Set the requirement of exit confirmation*/ +void STD_Application::setExitConfirmation( const bool on ) +{ + myExitConfirm = on; } /*! \retval QString "StdApplication"*/ @@ -81,33 +92,53 @@ void STD_Application::start() updateCommandsStatus(); setEditEnabled( myEditEnabled ); + loadPreferences(); + SUIT_Application::start(); } +/*! + Close the Application +*/ +void STD_Application::closeApplication() +{ + if ( desktop() ) + savePreferences(); + SUIT_Study* study = activeStudy(); + + if ( study ) + { + beforeCloseDoc( study ); + + study->closeDocument(); + emit appClosed(); + setActiveStudy( 0 ); + delete study; + + afterCloseDoc(); + } + + setDesktop( 0 ); + + SUIT_Application::closeApplication(); +} + /*!Event on closing desktop*/ void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e ) { - if (SUIT_Session::session()->applications().count() < 2) { + if ( SUIT_Session::session()->applications().count() < 2 ) + { onExit(); return; } - if ( !isPossibleToClose() ) + bool closePermanently; + if ( !isPossibleToClose( closePermanently ) ) { e->ignore(); return; } - SUIT_Study* study = activeStudy(); - - if ( study ) - study->closeDocument(); - - setActiveStudy( 0 ); - delete study; - - setDesktop( 0 ); - closeApplication(); } @@ -124,100 +155,106 @@ void STD_Application::createActions() createAction( FileNewId, tr( "TOT_DESK_FILE_NEW" ), resMgr->loadPixmap( "STD", tr( "ICON_FILE_NEW" ) ), tr( "MEN_DESK_FILE_NEW" ), tr( "PRP_DESK_FILE_NEW" ), - CTRL+Key_N, desk, false, this, SLOT( onNewDoc() ) ); + Qt::CTRL+Qt::Key_N, desk, false, this, SLOT( onNewDoc() ) ); createAction( FileOpenId, tr( "TOT_DESK_FILE_OPEN" ), resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ), tr( "MEN_DESK_FILE_OPEN" ), tr( "PRP_DESK_FILE_OPEN" ), - CTRL+Key_O, desk, false, this, SLOT( onOpenDoc() ) ); + 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" ), - CTRL+Key_W, desk, false, this, SLOT( onCloseDoc() ) ); + Qt::CTRL+Qt::Key_W, desk, false, this, SLOT( onCloseDoc() ) ); - createAction( FileExitId, tr( "TOT_DESK_FILE_EXIT" ), QIconSet(), + createAction( FileExitId, tr( "TOT_DESK_FILE_EXIT" ), QIcon(), tr( "MEN_DESK_FILE_EXIT" ), tr( "PRP_DESK_FILE_EXIT" ), - CTRL+Key_Q, desk, false, this, SLOT( onExit() ) ); + Qt::CTRL+Qt::Key_Q, desk, false, this, SLOT( onExit() ) ); createAction( FileSaveId, tr( "TOT_DESK_FILE_SAVE" ), resMgr->loadPixmap( "STD", tr( "ICON_FILE_SAVE" ) ), tr( "MEN_DESK_FILE_SAVE" ), tr( "PRP_DESK_FILE_SAVE" ), - CTRL+Key_S, desk, false, this, SLOT( onSaveDoc() ) ); + Qt::CTRL+Qt::Key_S, desk, false, this, SLOT( onSaveDoc() ) ); - createAction( FileSaveAsId, tr( "TOT_DESK_FILE_SAVEAS" ), QIconSet(), + createAction( FileSaveAsId, tr( "TOT_DESK_FILE_SAVEAS" ), QIcon(), tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ), - 0, desk, false, this, SLOT( onSaveAsDoc() ) ); + Qt::CTRL+Qt::SHIFT+Qt::Key_S, desk, false, this, SLOT( onSaveAsDoc() ) ); createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ), resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ), tr( "MEN_DESK_EDIT_COPY" ), tr( "PRP_DESK_EDIT_COPY" ), - CTRL+Key_C, desk, false, this, SLOT( onCopy() ) ); + Qt::CTRL+Qt::Key_C, desk, false, this, SLOT( onCopy() ) ); createAction( EditPasteId, tr( "TOT_DESK_EDIT_PASTE" ), resMgr->loadPixmap( "STD", tr( "ICON_EDIT_PASTE" ) ), tr( "MEN_DESK_EDIT_PASTE" ), tr( "PRP_DESK_EDIT_PASTE" ), - CTRL+Key_V, desk, false, this, SLOT( onPaste() ) ); + Qt::CTRL+Qt::Key_V, desk, false, this, SLOT( onPaste() ) ); QAction* a = createAction( ViewStatusBarId, tr( "TOT_DESK_VIEW_STATUSBAR" ), - QIconSet(), tr( "MEN_DESK_VIEW_STATUSBAR" ), - tr( "PRP_DESK_VIEW_STATUSBAR" ), 0, desk, true ); - a->setOn( desk->statusBar()->isVisibleTo( desk ) ); + QIcon(), tr( "MEN_DESK_VIEW_STATUSBAR" ), + tr( "PRP_DESK_VIEW_STATUSBAR" ), Qt::ALT+Qt::SHIFT+Qt::Key_S, desk, true ); + a->setChecked( desk->statusBar()->isVisibleTo( desk ) ); connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onViewStatusBar( bool ) ) ); - createAction( NewWindowId, tr( "TOT_DESK_NEWWINDOW" ), QIconSet(), + createAction( NewWindowId, tr( "TOT_DESK_NEWWINDOW" ), QIcon(), tr( "MEN_DESK_NEWWINDOW" ), tr( "PRP_DESK_NEWWINDOW" ), 0, desk ); - createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ), QIconSet(), + createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ), + resMgr->loadPixmap( "STD", tr( "ICON_DESK_ABOUT" ) ), tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ), - 0, desk, false, this, SLOT( onHelpAbout() ) ); + Qt::ALT+Qt::SHIFT+Qt::Key_A, desk, false, this, SLOT( onHelpAbout() ) ); - //SRN: BugID IPAL9021, add an action "Load" - createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ), - resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ), - tr( "MEN_DESK_FILE_LOAD" ), tr( "PRP_DESK_FILE_LOAD" ), - CTRL+Key_L, desk, false, this, SLOT( onLoadDoc() ) ); - //SRN: BugID IPAL9021: End - QtxDockAction* da = new QtxDockAction( tr( "TOT_DOCK_WINDOWS" ), tr( "MEN_DOCK_WINDOWS" ), desk ); - registerAction( ViewWindowsId, da ); - da->setAutoPlace( false ); + QtxDockAction* dwa = new QtxDockAction( tr( "TOT_DOCKWINDOWS" ), tr( "MEN_DESK_VIEW_DOCKWINDOWS" ), desk ); + dwa->setDockType( QtxDockAction::DockWidget ); + registerAction( ViewWindowsId, dwa ); + + QtxDockAction* tba = new QtxDockAction( tr( "TOT_TOOLBARS" ), tr( "MEN_DESK_VIEW_TOOLBARS" ), desk ); + tba->setDockType( QtxDockAction::ToolBar ); + registerAction( ViewToolBarsId, tba ); // Create menus - int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 ); - int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 10 ); - int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1, -1, 10 ); - int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 ); + int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, MenuFileId, 0 ); + // 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 ); // Create menu items - createMenu( FileNewId, fileMenu, 0 ); - createMenu( FileOpenId, fileMenu, 0 ); - createMenu( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load" - createMenu( FileCloseId, fileMenu, 0 ); - createMenu( separator(), fileMenu, -1, 0 ); - createMenu( FileSaveId, fileMenu, 0 ); - createMenu( FileSaveAsId, fileMenu, 0 ); - createMenu( separator(), fileMenu, -1, 0 ); + createMenu( FileNewId, fileMenu, 0 ); + createMenu( FileOpenId, fileMenu, 0 ); + createMenu( FileReopenId, fileMenu, 0 ); + createMenu( FileSaveId, fileMenu, 5 ); + createMenu( FileSaveAsId, fileMenu, 5 ); + createMenu( FileCloseId, fileMenu, 5 ); + createMenu( separator(), fileMenu, -1, 5 ); - createMenu( separator(), fileMenu ); - createMenu( FileExitId, fileMenu ); + createMenu( separator(), fileMenu ); + createMenu( FileExitId, fileMenu ); - createMenu( EditCopyId, editMenu ); + createMenu( EditCopyId, editMenu ); createMenu( EditPasteId, editMenu ); createMenu( separator(), editMenu ); - createMenu( ViewWindowsId, viewMenu ); - createMenu( ViewStatusBarId, viewMenu ); - createMenu( separator(), viewMenu ); + createMenu( ViewToolBarsId, viewMenu, 0 ); + createMenu( ViewWindowsId, viewMenu, 0 ); + createMenu( separator(), viewMenu, -1, 10 ); + createMenu( ViewStatusBarId, viewMenu, 10 ); + createMenu( separator(), viewMenu ); createMenu( HelpAboutId, helpMenu ); createMenu( separator(), helpMenu ); // 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 @@ -233,116 +270,120 @@ void STD_Application::createActions() /*!Opens new application*/ void STD_Application::onNewDoc() { - QApplication::setOverrideCursor( Qt::waitCursor ); + onNewDoc( QString() ); +} + +/*!Opens new application*/ +bool STD_Application::onNewDoc( const QString& name ) +{ + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool res = true; if ( !activeStudy() ) { createEmptyStudy(); - activeStudy()->createDocument(); - studyCreated( activeStudy() ); + res = activeStudy()->createDocument( name ); + if ( res ) + studyCreated( activeStudy() ); + else + { + SUIT_Study* st = activeStudy(); + setActiveStudy( 0 ); + delete st; + } } else { SUIT_Application* aApp = startApplication( 0, 0 ); if ( aApp->inherits( "STD_Application" ) ) - ((STD_Application*)aApp)->onNewDoc(); + res = ((STD_Application*)aApp)->onNewDoc( name ); else { aApp->createEmptyStudy(); - aApp->activeStudy()->createDocument(); + res = aApp->activeStudy()->createDocument( name ); } + if ( !res ) + aApp->closeApplication(); } QApplication::restoreOverrideCursor(); + + return res; } /*!Put file name from file dialog to onOpenDoc(const QString&) function*/ void STD_Application::onOpenDoc() { // It is preferrable to use OS-specific file dialog box here !!! - QString aName = getFileName( true, QString::null, getFileFilter(), QString::null, 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 ) { - QApplication::setOverrideCursor( Qt::waitCursor ); + if ( !abortAllOperations() ) + return false; - bool res = true; - if ( !activeStudy() ) - { - // if no study - open in current desktop - res = useFile( aName ); - } - else - { - // if study exists - open in new desktop. Check: is the same file is opened? - SUIT_Session* aSession = SUIT_Session::session(); - QPtrList aAppList = aSession->applications(); - bool isAlreadyOpen = false; - SUIT_Application* aApp = 0; - for ( QPtrListIterator it( aAppList ); it.current() && !isAlreadyOpen; ++it ) - { - aApp = it.current(); - if ( aApp->activeStudy()->studyName() == aName ) - isAlreadyOpen = true; - } - if ( !isAlreadyOpen ) - { - aApp = startApplication( 0, 0 ); - if ( aApp ) - res = aApp->useFile( aName ); - if ( !res ) - aApp->closeApplication(); - } - else - aApp->desktop()->setActiveWindow(); - } + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool res = openAction( openChoice( aName ), aName ); + QApplication::restoreOverrideCursor(); return res; } -/*! called on loading the existent study */ -void STD_Application::onLoadDoc() +/*! Reload document from the file.*/ +bool STD_Application::onReopenDoc() { -} + bool res = false; -/*! \retval true, if document was loaded successful, else false.*/ -bool STD_Application::onLoadDoc( const QString& aName ) -{ - bool res = true; - if ( !activeStudy() ) - { - // if no study - load in current desktop - res = useStudy( aName ); - } - else - { - // if study exists - load in new desktop. Check: is the same file is loaded? - SUIT_Session* aSession = SUIT_Session::session(); - QPtrList aAppList = aSession->applications(); - bool isAlreadyOpen = false; - SUIT_Application* aApp = 0; - for ( QPtrListIterator it( aAppList ); it.current() && !isAlreadyOpen; ++it ) - { - aApp = it.current(); - if ( aApp->activeStudy()->studyName() == aName ) - isAlreadyOpen = true; - } - if ( !isAlreadyOpen ) + SUIT_Study* study = activeStudy(); + if ( study && study->isSaved() ) { + // ask user for the confirmation + if ( SUIT_MessageBox::question( desktop(), tr( "REOPEN_STUDY" ), tr( "REOPEN_QUESTION" ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No + ) == SUIT_MessageBox::No ) + return false; + + // remember study name + QString studyName = study->studyName(); + + // close study + beforeCloseDoc( study ); + study->closeDocument( true ); + + // update views / windows / status bar / title + clearViewManagers(); + setActiveStudy( 0 ); + + // delete study + delete study; + study = 0; + + // post closing actions + afterCloseDoc(); + + int aNbStudies = 0; + QList 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 ( aNbStudies && !res ) + closeApplication(); + else { - aApp = startApplication( 0, 0 ); - if ( aApp ) - res = aApp->useStudy( aName ); + updateDesktopTitle(); + updateCommandsStatus(); } - else - aApp->desktop()->setActiveWindow(); } return res; } @@ -360,79 +401,165 @@ void STD_Application::afterCloseDoc() /*!Close document, if it's possible.*/ void STD_Application::onCloseDoc( bool ask ) { - if ( ask && !isPossibleToClose() ) - return; + closeDoc( ask ); +} + +/*!Close document, if it's possible.*/ +bool STD_Application::closeDoc( bool ask ) +{ + bool closePermanently = true; + + if ( ask && !isPossibleToClose( closePermanently ) ) + 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(myClosePermanently); + study->closeDocument( permanently ); clearViewManagers(); setActiveStudy( 0 ); - delete study; int aNbStudies = 0; - QPtrList apps = SUIT_Session::session()->applications(); - for ( unsigned i = 0; i < apps.count(); i++ ) + QList apps = SUIT_Session::session()->applications(); + for ( int i = 0; i < apps.count(); i++ ) aNbStudies += apps.at( i )->getNbStudies(); - // STV: aNbStudies - number of currently existing studies (exclude currently closed) - // STV: aNbStudies should be compared with 0. if ( aNbStudies ) + { + savePreferences(); setDesktop( 0 ); + } else { updateDesktopTitle(); updateCommandsStatus(); } + // IPAL19532: deleting study should be performed after calling setDesktop(0) + delete study; + afterCloseDoc(); 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 STD_Application::isPossibleToClose( bool& closePermanently ) { - myClosePermanently = true; //SRN: BugID: IPAL9021 if ( activeStudy() ) { activeStudy()->abortAllOperations(); if ( activeStudy()->isModified() ) { - QString sName = activeStudy()->studyName().stripWhiteSpace(); - QString msg = sName.isEmpty() ? tr( "INF_DOC_MODIFIED" ) : tr ( "INF_DOCUMENT_MODIFIED" ).arg( sName ); + QString sName = activeStudy()->studyName().trimmed(); + return closeAction( closeChoice( sName ), closePermanently ); + } + } + return true; +} + +int STD_Application::closeChoice( const QString& 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 ); - //SRN: BugID: IPAL9021: Begin - STD_CloseDlg dlg(desktop()); - switch( dlg.exec() ) + int res = CloseCancel; + if ( answer == SUIT_MessageBox::Save ) + res = CloseSave; + else if ( answer == SUIT_MessageBox::Discard ) + res = CloseDiscard; + + return res; +} + +bool STD_Application::closeAction( const int choice, bool& closePermanently ) +{ + bool res = true; + switch( choice ) + { + case CloseSave: + if ( activeStudy()->isSaved() ) + onSaveDoc(); + else if ( !onSaveAsDoc() ) + res = false; + break; + case CloseDiscard: + break; + case CloseCancel: + default: + res = false; + } + + return res; +} + +int STD_Application::openChoice( const QString& aName ) +{ + SUIT_Session* aSession = SUIT_Session::session(); + + bool isAlreadyOpen = false; + QList aAppList = aSession->applications(); + for ( QList::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it ) + isAlreadyOpen = (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName; + return isAlreadyOpen ? OpenExist : OpenNew; +} + +bool STD_Application::openAction( const int choice, const QString& aName ) +{ + bool res = true; + switch ( choice ) + { + case OpenExist: + { + SUIT_Application* aApp = 0; + SUIT_Session* aSession = SUIT_Session::session(); + QList aAppList = aSession->applications(); + for ( QList::iterator it = aAppList.begin(); it != aAppList.end() && !aApp; ++it ) { - case 1: - if ( activeStudy()->isSaved() ) - onSaveDoc(); - else if ( !onSaveAsDoc() ) - return false; - break; - case 2: - break; - case 3: - myClosePermanently = false; - break; - case 4: - default: - return false; + if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName ) + aApp = *it; } - //SRN: BugID: IPAL9021: End + if ( aApp ) + aApp->desktop()->activateWindow(); + else + res = false; } + break; + case OpenNew: + if ( !activeStudy() ) + res = useFile( aName ); + else + { + SUIT_Application* aApp = startApplication( 0, 0 ); + if ( aApp ) + res = aApp->useFile( aName ); + if ( !res ) + aApp->closeApplication(); + } + break; + case OpenCancel: + default: + res = false; } - return true; + + return res; } /*!Save document if all ok, else error message.*/ @@ -441,12 +568,15 @@ void STD_Application::onSaveDoc() if ( !activeStudy() ) return; + if ( !abortAllOperations() ) + return; + bool isOk = false; if ( activeStudy()->isSaved() ) { putInfo( tr( "INF_DOC_SAVING" ) + activeStudy()->studyName() ); - QApplication::setOverrideCursor( Qt::waitCursor ); + QApplication::setOverrideCursor( Qt::WaitCursor ); isOk = activeStudy()->saveDocument(); @@ -455,8 +585,9 @@ void STD_Application::onSaveDoc() if ( !isOk ) { putInfo( "" ); - SUIT_MessageBox::error1( desktop(), tr( "TIT_FILE_SAVEAS" ), - tr( "MSG_CANT_SAVE" ).arg( activeStudy()->studyName() ), tr( "BUT_OK" ) ); + // displaying a message box as SUIT_Validator in case file can't be written (the most frequent case) + SUIT_MessageBox::critical( desktop(), tr( "ERR_ERROR" ), + tr( "INF_DOC_SAVING_FAILS" ).arg( activeStudy()->studyName() ) ); } else putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) ); @@ -468,21 +599,24 @@ 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::null, 0 ); + QString aName = getFileName( false, study->studyName(), getFileFilter( false ), QString(), 0 ); if ( aName.isNull() ) return false; - QApplication::setOverrideCursor( Qt::waitCursor ); + QApplication::setOverrideCursor( Qt::WaitCursor ); putInfo( tr( "INF_DOC_SAVING" ) + aName ); isOk = study->saveDocumentAs( aName ); @@ -492,8 +626,7 @@ bool STD_Application::onSaveAsDoc() QApplication::restoreOverrideCursor(); if ( !isOk ) - SUIT_MessageBox::error1( desktop(), tr( "ERROR" ), - tr( "INF_DOC_SAVING_FAILS" ).arg( aName ), tr( "BUT_OK" ) ); + SUIT_MessageBox::critical( desktop(), tr( "ERROR" ), tr( "INF_DOC_SAVING_FAILS" ).arg( aName ) ); } studySaved( activeStudy() ); @@ -504,9 +637,11 @@ bool STD_Application::onSaveAsDoc() /*!Closing session.*/ void STD_Application::onExit() { - int aAnswer = SUIT_MessageBox::info2( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ), - tr( "BUT_OK" ), tr( "BUT_CANCEL" ), 1, 2, 2 ); - if ( aAnswer == 1 ) + int aAnswer = SUIT_MessageBox::Ok; + if ( exitConfirmation() ) + aAnswer = SUIT_MessageBox::question( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ), + SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Cancel ); + if ( aAnswer == SUIT_MessageBox::Ok ) SUIT_Session::session()->closeSession(); } @@ -530,12 +665,12 @@ void STD_Application::setEditEnabled( bool theEnable ) for ( int i = EditCopyId; i <= EditPasteId; i++ ) { - mMgr->setShown( i, myEditEnabled ); - tMgr->setShown( i, myEditEnabled ); + mMgr->setShown( mMgr->actionId(action(i)), myEditEnabled ); + tMgr->setShown( tMgr->actionId(action(i)), myEditEnabled ); } } -/*!\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 ); @@ -556,23 +691,27 @@ void STD_Application::updateDesktopTitle() if ( activeStudy() ) { - QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false ); + QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false ); if ( !sName.isEmpty() ) aTitle += QString( " - [%1]" ).arg( sName ); } - desktop()->setCaption( aTitle ); + desktop()->setWindowTitle( aTitle ); } /*!Update commands status.*/ void STD_Application::updateCommandsStatus() { - bool aHasStudy = activeStudy() != 0; - bool aIsNeedToSave = false; - if ( aHasStudy ) - aIsNeedToSave = !activeStudy()->isSaved() || activeStudy()->isModified(); + SUIT_Application::updateCommandsStatus(); + + 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 ); @@ -586,10 +725,10 @@ void STD_Application::updateCommandsStatus() SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const { SUIT_ViewManager* vm = 0; - for ( QPtrListIterator it( myViewMgrs ); it.current() && !vm; ++it ) + for ( QList::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end() && !vm; ++it ) { - if ( it.current()->getType() == vmType ) - vm = it.current(); + if ( (*it)->getType() == vmType && !(*it)->getDetached()) + vm = *it; } return vm; } @@ -599,16 +738,18 @@ SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const */ void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const { - for ( QPtrListIterator it( myViewMgrs ); it.current(); ++it ) - if ( it.current()->getType() == vmType ) - lst.append( it.current() ); + for ( QList::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it ) + { + if ( (*it)->getType() == vmType ) + lst.append( *it ); + } } /*!\param lst - output list of all view managers.*/ void STD_Application::viewManagers( ViewManagerList& lst ) const { - for ( QPtrListIterator it( myViewMgrs ); it.current(); ++it ) - lst.append( it.current() ); + for ( QList::const_iterator it = myViewMgrs.begin(); it != myViewMgrs.end(); ++it ) + lst.append( *it ); } /*!\retval ViewManagerList - const list of all view managers.*/ @@ -657,8 +798,9 @@ void STD_Application::removeViewManager( SUIT_ViewManager* vm ) emit viewManagerRemoved( vm ); vm->disconnectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); - vm->disconnect(); - myViewMgrs.removeRef( vm ); + disconnect( vm, SIGNAL( activated( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) ); + myViewMgrs.removeAll( vm ); if ( myActiveViewMgr == vm ) myActiveViewMgr = 0; @@ -670,14 +812,18 @@ void STD_Application::clearViewManagers() ViewManagerList lst; viewManagers( lst ); - for ( QPtrListIterator it( lst ); it.current(); ++it ) - removeViewManager( it.current() ); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + { + QPointer vm = *it; + removeViewManager( vm ); + delete vm; + } } -/*!\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 ) > 0; + return myViewMgrs.contains( vm ); } /*!Private slot, sets active manager to \vm, if \vm in view managers list.*/ @@ -686,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 ) @@ -698,7 +844,7 @@ void STD_Application::onViewStatusBar( bool on ) /*!Call SUIT_MessageBox::info1(...) with about information.*/ void STD_Application::onHelpAbout() { - SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" ); + SUIT_MessageBox::information( desktop(), tr( "About" ), tr( "ABOUT_INFO" ) ); } /*!Create empty study. \n @@ -707,10 +853,6 @@ void STD_Application::onHelpAbout() void STD_Application::createEmptyStudy() { SUIT_Application::createEmptyStudy(); - - SUIT_ViewManager* vm = new SUIT_ViewManager( activeStudy(), desktop(), new SUIT_ViewModel() ); - - addViewManager( vm ); } /*!Sets active manager to \vm, if \vm in view managers list.*/ @@ -726,35 +868,37 @@ void STD_Application::setActiveViewManager( SUIT_ViewManager* vm ) /*!Public slot. */ void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e ) { - QtxPopupMenu* popup = new QtxPopupMenu(); + QtxMenu* popup = new QtxMenu(); // fill popup by own items QString title; contextMenuPopup( client->popupClientType(), popup, title ); popup->setTitleText( title ); - popup->insertSeparator(); + popup->addSeparator(); // add items from popup client client->contextMenuPopup( popup ); SUIT_Tools::simplifySeparators( popup ); - if ( popup->count() ) + if ( !popup->actions().isEmpty() ) popup->exec( e->globalPos() ); delete popup; } -#include +/*!\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 ) + const QString& caption, QWidget* parent ) { if ( !parent ) parent = desktop(); if ( open ) - { - return QFileDialog::getOpenFileName( initial, filters, parent, 0, caption ); - } + return QFileDialog::getOpenFileName( parent, caption, initial, filters ); else { QString aName; @@ -765,45 +909,45 @@ QString STD_Application::getFileName( bool open, const QString& initial, const Q while ( !isOk ) { // It is preferrable to use OS-specific file dialog box here !!! - aName = QFileDialog::getSaveFileName( anOldPath, filters, parent, 0, caption, &aUsedFilter ); + aName = QFileDialog::getSaveFileName( parent, caption, anOldPath, filters, &aUsedFilter ); if ( aName.isNull() ) isOk = true; else { - int aEnd = aUsedFilter.findRev( ')' ); - int aStart = aUsedFilter.findRev( '(', aEnd ); - QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 ); + int aEnd = aUsedFilter.lastIndexOf( ')' ); + int aStart = aUsedFilter.lastIndexOf( '(', aEnd ); + QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 ); int idx = 0; QStringList extList; QRegExp rx( "[\b\\*]*\\.([\\w]+)" ); - while ( ( idx = rx.search( wcStr, idx ) ) != -1 ) + while ( ( idx = rx.indexIn( wcStr, idx ) ) != -1 ) { extList.append( rx.cap( 1 ) ); idx += rx.matchedLength(); } - if ( !extList.isEmpty() && !extList.contains( QFileInfo( aName ).extension() ) ) + if ( !extList.isEmpty() && !extList.contains( SUIT_Tools::extension( aName ) ) ) aName += QString( ".%1" ).arg( extList.first() ); - if ( QFileInfo( aName ).exists() ) + if ( QFileInfo( aName ).exists() ) { - int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TIT_FILE_SAVEAS" ), - tr( "MSG_FILE_EXISTS" ).arg( aName ), - tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 ); - if ( aAnswer == 3 ) + int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ), + tr( "MSG_FILE_EXISTS" ).arg( aName ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes ); + if ( aAnswer == SUIT_MessageBox::Cancel ) { // cancelled - aName = QString::null; - isOk = true; + aName = QString(); + isOk = true; } - else if ( aAnswer == 2 ) // not save to this file - anOldPath = aName; // not to return to the same initial dir at each "while" step - else // overwrite the existing file - isOk = true; + else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file + anOldPath = aName; // not to return to the same initial dir at each "while" step + else // overwrite the existing file + isOk = true; } - else - isOk = true; + else + isOk = true; } } return aName; @@ -815,34 +959,81 @@ QString STD_Application::getDirectory( const QString& initial, const QString& ca { if ( !parent ) parent = desktop(); - return QFileDialog::getExistingDirectory( initial, parent, 0, caption, true ); + + return QFileDialog::getExistingDirectory( parent, caption, initial ); } +/*! + Changes desktop + \param desk - new desktop +*/ void STD_Application::setDesktop( SUIT_Desktop* desk ) { - SUIT_Desktop* prev = desktop(); - SUIT_Application::setDesktop( desk ); - if ( prev != desk && desk ) + if ( desk ) { connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), - this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); + this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ), Qt::UniqueConnection ); + } +} + +/*! + Allow to load preferences before the desktop will be shown. +*/ +void STD_Application::loadPreferences() +{ +} + +/*! + Allow to save preferences before the application will be closed. +*/ +void STD_Application::savePreferences() +{ } +/*! + Custom activity after study is created + Updates desktop and actions +*/ void STD_Application::studyCreated( SUIT_Study* ) { updateDesktopTitle(); updateCommandsStatus(); } +/*! + Custom activity after study is opened + Updates desktop and actions +*/ void STD_Application::studyOpened( SUIT_Study* ) { updateDesktopTitle(); updateCommandsStatus(); } +/*! + Custom activity after study is opened + Updates desktop and actions +*/ void STD_Application::studySaved( SUIT_Study* ) { updateDesktopTitle(); updateCommandsStatus(); } + +/*! + Return index of the view ma +*/ +int STD_Application::viewManagerId( const SUIT_ViewManager* theManager) const +{ + return myViewMgrs.indexOf(const_cast(theManager)); +} + +/*! + \brief Abort active operations if there are any + \return \c false if some operation cannot be aborted +*/ +bool STD_Application::abortAllOperations() +{ + return true; +}