From: vsr Date: Tue, 29 Jan 2008 09:22:54 +0000 (+0000) Subject: Improve study/session closing and module activation mechanism: for light modules... X-Git-Tag: for_M2008_07022008~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e5a13036313b4d8a837069d63105270fb38228f8;p=modules%2Fgui.git Improve study/session closing and module activation mechanism: for light modules no actions like "Load study", "Unload study" and "Shutdown standalone servers" should be proposed. --- diff --git a/src/STD/Makefile.am b/src/STD/Makefile.am index 9b5295002..742683632 100755 --- a/src/STD/Makefile.am +++ b/src/STD/Makefile.am @@ -31,7 +31,6 @@ salomeinclude_HEADERS= \ STD_MDIDesktop.h \ STD_SDIDesktop.h \ STD_TabDesktop.h \ - STD_CloseDlg.h \ STD_LoadStudiesDlg.h dist_libstd_la_SOURCES=\ @@ -39,7 +38,6 @@ dist_libstd_la_SOURCES=\ STD_MDIDesktop.cxx \ STD_SDIDesktop.cxx \ STD_TabDesktop.cxx \ - STD_CloseDlg.cxx \ STD_LoadStudiesDlg.cxx MOC_FILES= \ @@ -47,8 +45,8 @@ MOC_FILES= \ STD_MDIDesktop_moc.cxx \ STD_SDIDesktop_moc.cxx \ STD_TabDesktop_moc.cxx \ - STD_CloseDlg_moc.cxx \ STD_LoadStudiesDlg_moc.cxx + nodist_libstd_la_SOURCES= $(MOC_FILES) dist_salomeres_DATA=\ diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index f1b175ad6..177dd8295 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -20,8 +20,6 @@ #include "STD_MDIDesktop.h" -#include "STD_CloseDlg.h" - #include #include #include @@ -29,6 +27,7 @@ #include #include #include +#include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #include @@ -53,8 +53,9 @@ 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(); @@ -67,6 +68,18 @@ 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"*/ QString STD_Application::applicationName() const { @@ -117,7 +130,8 @@ void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e ) return; } - if ( !isPossibleToClose() ) + bool closePermanently; + if ( !isPossibleToClose( closePermanently ) ) { e->ignore(); return; @@ -363,7 +377,9 @@ void STD_Application::afterCloseDoc() /*!Close document, if it's possible.*/ void STD_Application::onCloseDoc( bool ask ) { - if ( ask && !isPossibleToClose() ) + bool closePermanently = true; + + if ( ask && !isPossibleToClose( closePermanently ) ) return; SUIT_Study* study = activeStudy(); @@ -371,7 +387,7 @@ void STD_Application::onCloseDoc( bool ask ) beforeCloseDoc( study ); if ( study ) - study->closeDocument(myClosePermanently); + study->closeDocument( closePermanently ); clearViewManagers(); @@ -405,42 +421,64 @@ void STD_Application::onCloseDoc( bool ask ) /*!Check the application on closing. * \retval true if possible, else 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 ); - - //SRN: BugID: IPAL9021: Begin - STD_CloseDlg dlg(desktop()); - switch( dlg.exec() ) - { - 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; - } - //SRN: BugID: IPAL9021: End + return closeAction( closeChoice( sName ), closePermanently ); } } return true; } +/*! + \brief Show dialog box to propose possible user actions when study is closed. + \param docName study name + \return chosen action ID + \sa closeAction() +*/ +int STD_Application::closeChoice( const QString& docName ) +{ + SUIT_MsgDlg dlg( desktop(), tr( "CLOSE_DLG_CAPTION" ), tr ( "CLOSE_DLG_DESCRIPTION" ), + QMessageBox::standardIcon( QMessageBox::Information ) ); + dlg.addButton( tr ( "CLOSE_DLG_SAVE_CLOSE" ), CloseSave ); + dlg.addButton( tr ( "CLOSE_DLG_CLOSE" ), CloseDiscard ); + + return dlg.exec(); +} + +/*! + \brief Process user actions selected from the dialog box when study is closed. + \param choice chosen action ID + \param closePermanently "forced study closing" flag + \return operation status + \sa closeChoice() +*/ +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; +} + /*!Save document if all ok, else error message.*/ void STD_Application::onSaveDoc() { @@ -514,10 +552,12 @@ bool STD_Application::onSaveAsDoc() /*!Closing session.*/ void STD_Application::onExit() { - STD_ExitDlg* dlg = new STD_ExitDlg(desktop()); - if( dlg->exec() == QDialog::Accepted ) { - SUIT_Session::session()->serversShutdown(dlg->isServersShutdown()); - delete dlg; + if ( !exitConfirmation() || + SUIT_MessageBox::info2( desktop(), + tr( "INF_DESK_EXIT" ), + tr( "QUE_DESK_EXIT" ), + tr( "BUT_OK" ), + tr( "BUT_CANCEL" ), 1, 2, 2 ) == 1 ) { SUIT_Session::session()->closeSession(); } } diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index 4e766ca98..13ff29e64 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -52,7 +52,7 @@ public: virtual QString applicationName() const; - virtual bool isPossibleToClose(); + virtual bool isPossibleToClose( bool& ); virtual bool useFile( const QString& ); virtual void createEmptyStudy(); @@ -84,6 +84,9 @@ public: virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& ) {} + bool exitConfirmation() const; + void setExitConfirmation( const bool ); + signals: /*!emit that view manager added*/ void viewManagerAdded( SUIT_ViewManager* ); @@ -133,6 +136,8 @@ protected: UserID }; + enum { CloseCancel, CloseSave, CloseDiscard }; + protected: virtual void createActions(); virtual void updateDesktopTitle(); @@ -152,13 +157,16 @@ protected: virtual void setActiveViewManager( SUIT_ViewManager* ); + virtual bool closeAction( const int, bool& ); + virtual int closeChoice( const QString& ); + private: ViewManagerList myViewMgrs; SUIT_ViewManager* myActiveViewMgr; private: + bool myExitConfirm; bool myEditEnabled; - bool myClosePermanently; }; #if defined WIN32 diff --git a/src/STD/STD_CloseDlg.cxx b/src/STD/STD_CloseDlg.cxx deleted file mode 100644 index d94fc5fff..000000000 --- a/src/STD/STD_CloseDlg.cxx +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -#include "STD_CloseDlg.h" - -#include -#include -#include -#include -#include - -#ifndef WNT -using namespace std; -#endif - -/*! - * \brief creates a Close dialog box - * \param parent a parent widget - * \param modal bool argument, if true the dialog box is a modal dialog box - * \param f style flags - */ - -STD_CloseDlg::STD_CloseDlg( QWidget* parent, bool modal, WFlags f ) -: QDialog( parent, "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) -{ - setSizeGripEnabled( true ); - setCaption( tr( "CLOSE_DLG_CAPTION" ) ); - - QVBoxLayout* m_vbL = new QVBoxLayout( this ); - m_vbL->setMargin( 11 ); - m_vbL->setSpacing( 6 ); - - QLabel* m_lIcon = new QLabel( this, "m_lDescr" ); - QPixmap pm = QMessageBox::standardIcon( QMessageBox::Warning ); - m_lIcon->setPixmap( pm ); - m_lIcon->setScaledContents( false ); - m_lIcon->setAlignment( Qt::AlignCenter ); - - QLabel* m_lDescr = new QLabel (this, "m_lDescr"); - m_lDescr->setText ( tr ("CLOSE_DLG_DESCRIPTION") ); - m_lDescr->setAlignment( Qt::AlignCenter ); - m_lDescr->setMinimumHeight( m_lDescr->sizeHint().height()*5 ); - m_lDescr->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - - QHBoxLayout* m_hl1 = new QHBoxLayout(); - m_hl1->setMargin( 0 ); m_hl1->setSpacing( 6 ); - m_hl1->addWidget( m_lIcon ); - m_hl1->addWidget( m_lDescr ); - - m_pb1 = new QPushButton( tr ("CLOSE_DLG_SAVE_CLOSE"), this ); - m_pb2 = new QPushButton( tr ("CLOSE_DLG_CLOSE"), this ); - m_pb3 = new QPushButton( tr ("CLOSE_DLG_UNLOAD"), this ); - m_pb4 = new QPushButton( tr ("BUT_CANCEL"), this ); - - QGridLayout* m_hl2 = new QGridLayout(); - m_hl2->setMargin( 0 ); m_hl2->setSpacing( 6 ); - m_hl2->addWidget( m_pb1, 0, 0 ); - m_hl2->addWidget( m_pb2, 0, 1 ); - m_hl2->addWidget( m_pb3, 0, 2 ); - m_hl2->addColSpacing( 3, 10 ); - m_hl2->setColStretch( 3, 5 ); - m_hl2->addWidget( m_pb4, 0, 4 ); - - m_vbL->addLayout( m_hl1 ); - m_vbL->addLayout( m_hl2 ); - - connect( m_pb1, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( m_pb2, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( m_pb3, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( m_pb4, SIGNAL( clicked() ), this, SLOT( reject() ) ); -} - -/*! - * \brief reaction on clicked(pressed) button - */ -void STD_CloseDlg::onButtonClicked() -{ - QPushButton* btn = ( QPushButton* )sender(); - if ( btn == m_pb1 ) - done( 1 ); - if ( btn == m_pb2 ) - done( 2 ); - if ( btn == m_pb3 ) - done( 3 ); -} - -/*! - * \brief creates a Exit dialog box - * \param parent a parent widget - * \param modal bool argument, if true the dialog box is a modal dialog box - * \param f style flags - */ - -STD_ExitDlg::STD_ExitDlg( QWidget* parent, bool modal, WFlags f ) -: QDialog( parent, "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) -{ - setSizeGripEnabled( true ); - setCaption( tr( "INF_DESK_EXIT" ) ); - - QVBoxLayout* m_vbL = new QVBoxLayout( this ); - m_vbL->setMargin( 11 ); - m_vbL->setSpacing( 6 ); - - QLabel* m_lIcon = new QLabel( this, "m_lDescr" ); - QPixmap pm = QMessageBox::standardIcon( QMessageBox::Question ); - m_lIcon->setPixmap( pm ); - m_lIcon->setScaledContents( false ); - m_lIcon->setAlignment( Qt::AlignCenter ); - - QLabel* m_lDescr = new QLabel (this, "m_lDescr"); - m_lDescr->setText ( tr ("QUE_DESK_EXIT") ); - m_lDescr->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - - myServersShutdown = new QCheckBox(tr("SHUTDOWN_SERVERS"), this); - myServersShutdown->setChecked(true); - - QVBoxLayout* m_vl1 = new QVBoxLayout(); - m_vl1->setMargin( 10 ); m_vl1->setSpacing( 16 ); - m_vl1->addWidget( m_lDescr ); - m_vl1->addWidget( myServersShutdown ); - - QHBoxLayout* m_hl1 = new QHBoxLayout(); - m_hl1->setMargin( 0 ); m_hl1->setSpacing( 6 ); - m_hl1->addWidget( m_lIcon ); - m_hl1->addStretch(); - m_hl1->addLayout( m_vl1 ); - m_hl1->addStretch(); - - QPushButton* m_pbOk = new QPushButton( tr ("BUT_OK"), this ); - QPushButton* m_pbCancel = new QPushButton( tr ("BUT_CANCEL"), this ); - - QGridLayout* m_hl2 = new QGridLayout(); - m_hl2->setMargin( 0 ); m_hl2->setSpacing( 6 ); - m_hl2->addWidget( m_pbOk, 0, 0 ); - m_hl2->setColStretch( 1, 5 ); - m_hl2->addWidget( m_pbCancel, 0, 2 ); - - m_vbL->addStretch(); - m_vbL->addLayout( m_hl1 ); - m_vbL->addStretch(); - m_vbL->addLayout( m_hl2 ); - - connect( m_pbOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); - connect( m_pbCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); -} - -/*! - * \brief get the check box status - */ -bool STD_ExitDlg::isServersShutdown() -{ - return myServersShutdown->isChecked(); -} - diff --git a/src/STD/STD_CloseDlg.h b/src/STD/STD_CloseDlg.h deleted file mode 100644 index a6f56ea4d..000000000 --- a/src/STD/STD_CloseDlg.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -#ifndef STD_CloseDlg_H -#define STD_CloseDlg_H - -#include -#include - -/*! \class QDialog - * \brief For more information see QT documentation. - */ -/*!\class STD_CloseDlg - * \brief Describes a dialog box shown on closing the active study - */ -class STD_CloseDlg: public QDialog -{ - Q_OBJECT - -public: - STD_CloseDlg ( QWidget * parent = 0, bool modal = FALSE, WFlags f = 0 ) ; - ~STD_CloseDlg ( ) { }; - -private slots: - void onButtonClicked(); - -private: - /*!\var m_pb1 - * \brief Private, stores a dialog button 1 - */ - QPushButton* m_pb1; - /*!\var m_pb2 - * \brief Private, stores a dialog button 2 - */ - QPushButton* m_pb2; - /*!\var m_pb3 - * \brief Private, stores a dialog button 3 - */ - QPushButton* m_pb3; - - /*!\var m_pb4 - * \brief Private, stores a dialog button 4 - */ - QPushButton* m_pb4; -}; - -/*!\class STD_ExitDlg - * \brief Describes a dialog box shown on question about quit application - */ -class STD_ExitDlg: public QDialog -{ - Q_OBJECT - -public: - STD_ExitDlg ( QWidget * parent = 0, bool modal = FALSE, WFlags f = 0 ) ; - ~STD_ExitDlg ( ) { }; - - bool isServersShutdown(); - -private: - QCheckBox* myServersShutdown; - -}; - -#endif - diff --git a/src/STD/resources/STD_msg_en.po b/src/STD/resources/STD_msg_en.po index 80626d01e..c70c031cc 100755 --- a/src/STD/resources/STD_msg_en.po +++ b/src/STD/resources/STD_msg_en.po @@ -345,7 +345,7 @@ msgid "STD_Application::INF_DOC_SAVING_FAILS" msgstr "Can't save file \"%1\".\nPossible reason is permission denied or disc full.\nTry to use another file name." msgid "CLOSE_DLG_SAVE_CLOSE" -msgstr "&Save&&Close" +msgstr "&Save && Close" msgid "CLOSE_DLG_CLOSE" msgstr "C&lose w/o saving" @@ -366,7 +366,7 @@ msgid "CLOSE_DLG_CAPTION" msgstr "Close active study" msgid "CLOSE_DLG_DESCRIPTION" -msgstr "Do you want to close or only unload the study" +msgstr "Study is modified. Do you want to save it?" msgid "DLG_LOAD_STUDY_CAPTION" msgstr "Load Study" @@ -374,9 +374,6 @@ msgstr "Load Study" msgid "MEN_STUDIES_CHOICE" msgstr "Choose existent study." -msgid "SHUTDOWN_SERVERS" -msgstr "Shutdown standalone servers" -