+// 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/
+//
#include "STD_Application.h"
#include "STD_MDIDesktop.h"
updateCommandsStatus();
setEditEnabled( myEditEnabled );
+ loadPreferences();
+
SUIT_Application::start();
}
+/*!
+ Close the Application
+*/
+void STD_Application::closeApplication()
+{
+ if ( desktop() )
+ savePreferences();
+ SUIT_Study* study = activeStudy();
+
+ if ( study ){
+ study->closeDocument();
+
+ setActiveStudy( 0 );
+ delete study;
+ }
+
+ 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;
}
return;
}
- SUIT_Study* study = activeStudy();
-
- if ( study )
- study->closeDocument();
-
- setActiveStudy( 0 );
- delete study;
-
- setDesktop( 0 );
-
closeApplication();
}
createAction( FileSaveAsId, tr( "TOT_DESK_FILE_SAVEAS" ), QIconSet(),
tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ),
- 0, desk, false, this, SLOT( onSaveAsDoc() ) );
+ CTRL+Key_A, desk, false, this, SLOT( onSaveAsDoc() ) );
createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ),
resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ),
QAction* a = createAction( ViewStatusBarId, tr( "TOT_DESK_VIEW_STATUSBAR" ),
QIconSet(), tr( "MEN_DESK_VIEW_STATUSBAR" ),
- tr( "PRP_DESK_VIEW_STATUSBAR" ), 0, desk, true );
+ tr( "PRP_DESK_VIEW_STATUSBAR" ), SHIFT+Key_S, desk, true );
a->setOn( desk->statusBar()->isVisibleTo( desk ) );
connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onViewStatusBar( bool ) ) );
createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ), QIconSet(),
tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
- 0, desk, false, this, SLOT( onHelpAbout() ) );
+ SHIFT+Key_A, desk, false, this, SLOT( onHelpAbout() ) );
//SRN: BugID IPAL9021, add an action "Load"
createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ),
// 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 );
+ int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, MenuEditId, 10 );
+ 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( 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( separator(), fileMenu, -1, 0 );
- 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( ViewWindowsId, viewMenu );
createMenu( ViewStatusBarId, viewMenu );
- createMenu( separator(), viewMenu );
+ createMenu( separator(), viewMenu );
createMenu( HelpAboutId, helpMenu );
createMenu( separator(), helpMenu );
/*!Opens new application*/
void STD_Application::onNewDoc()
{
+ QApplication::setOverrideCursor( Qt::waitCursor );
+
if ( !activeStudy() )
{
createEmptyStudy();
activeStudy()->createDocument();
- updateDesktopTitle();
- updateCommandsStatus();
+ studyCreated( activeStudy() );
}
else
{
SUIT_Application* aApp = startApplication( 0, 0 );
if ( aApp->inherits( "STD_Application" ) )
((STD_Application*)aApp)->onNewDoc();
- else {
+ else
+ {
aApp->createEmptyStudy();
aApp->activeStudy()->createDocument();
}
}
+
+ QApplication::restoreOverrideCursor();
}
/*!Put file name from file dialog to onOpenDoc(const QString&) function*/
/*! \retval true, if document was opened successful, else false.*/
bool STD_Application::onOpenDoc( const QString& aName )
{
+ QApplication::setOverrideCursor( Qt::waitCursor );
+
bool res = true;
if ( !activeStudy() )
{
aApp = startApplication( 0, 0 );
if ( aApp )
res = aApp->useFile( aName );
+ if ( !res )
+ aApp->closeApplication();
}
else
aApp->desktop()->setActiveWindow();
}
+
+ QApplication::restoreOverrideCursor();
+
return res;
}
}
/*!Close document, if it's possible.*/
-void STD_Application::onCloseDoc(bool ask)
+void STD_Application::onCloseDoc( bool ask )
{
- if (ask)
- if ( !isPossibleToClose() )
- return;
+ if ( ask && !isPossibleToClose() )
+ return;
SUIT_Study* study = activeStudy();
// STV: aNbStudies - number of currently existing studies (exclude currently closed)
// STV: aNbStudies should be compared with 0.
if ( aNbStudies )
+ {
+ savePreferences();
setDesktop( 0 );
+ }
else
{
updateDesktopTitle();
case 2:
break;
case 3:
- myClosePermanently = false;
+ myClosePermanently = false;
break;
case 4:
default:
bool isOk = false;
if ( activeStudy()->isSaved() )
{
- putInfo(tr("INF_DOC_SAVING") + activeStudy()->studyName());
+ putInfo( tr( "INF_DOC_SAVING" ) + activeStudy()->studyName() );
+
+ QApplication::setOverrideCursor( Qt::waitCursor );
+
isOk = activeStudy()->saveDocument();
- if ( !isOk ) {
- putInfo("");
- SUIT_MessageBox::error1( desktop(), tr( "TIT_FILE_SAVEAS" ),
- tr( "MSG_CANT_SAVE" ).arg( activeStudy()->studyName() ),
- tr( "BUT_OK" ) );
- } else {
- putInfo(tr("INF_DOC_SAVED").arg(""));
+
+ QApplication::restoreOverrideCursor();
+
+ if ( !isOk )
+ {
+ putInfo( "" );
+ // displaying a message box as SUIT_Validator in case file can't be written (the most frequent case)
+ SUIT_MessageBox::error1( desktop(),
+ tr( "ERR_ERROR" ),
+ tr( "ERR_PERMISSION_DENIED" ).arg( activeStudy()->studyName() ),
+ tr( "BUT_OK" ) );
}
+ else
+ putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) );
}
if ( isOk )
- updateCommandsStatus();
+ studySaved( activeStudy() );
else
onSaveAsDoc();
}
if ( !study )
return false;
- QString aName = getFileName( false, study->studyName(), getFileFilter(), QString::null, 0 );
- if ( aName.isNull() )
- return false;
+ bool isOk = false;
+ while ( !isOk )
+ {
+ QString aName = getFileName( false, study->studyName(), getFileFilter(), QString::null, 0 );
+ if ( aName.isNull() )
+ return false;
- putInfo(tr("INF_DOC_SAVING") + aName);
- bool isOk = study->saveDocumentAs( aName );
+ QApplication::setOverrideCursor( Qt::waitCursor );
- if (isOk)
- putInfo(tr("INF_DOC_SAVED").arg(aName));
- else
- putInfo("");
+ putInfo( tr( "INF_DOC_SAVING" ) + aName );
+ isOk = study->saveDocumentAs( aName );
- updateDesktopTitle();
- updateCommandsStatus();
+ putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : "" );
+
+ QApplication::restoreOverrideCursor();
+
+ if ( !isOk )
+ SUIT_MessageBox::error1( desktop(), tr( "ERROR" ),
+ tr( "INF_DOC_SAVING_FAILS" ).arg( aName ),
+ tr( "BUT_OK" ) );
+ }
+
+ studySaved( activeStudy() );
return isOk;
}
/*!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::info2( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
+ tr( "BUT_OK" ), tr( "BUT_CANCEL" ), 1, 2, 2 );
+ if ( aAnswer == 1 )
SUIT_Session::session()->closeSession();
}
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.*/
bool STD_Application::useFile(const QString& theFileName)
{
- bool res = SUIT_Application::useFile(theFileName);
- updateDesktopTitle();
- updateCommandsStatus();
+ bool res = SUIT_Application::useFile( theFileName );
+
+ if ( res )
+ studyOpened( activeStudy() );
+
return res;
}
return QFileDialog::getExistingDirectory( initial, parent, 0, caption, true );
}
+/*!
+ Changes desktop
+ \param desk - new desktop
+*/
void STD_Application::setDesktop( SUIT_Desktop* desk )
{
SUIT_Desktop* prev = desktop();
connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
}
+
+/*!
+ 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();
+}