#include "STD_MDIDesktop.h"
+#include "STD_CloseDlg.h"
+
#include <SUIT_Tools.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <qfiledialog.h>
#include <qapplication.h>
+#include <iostream>
+
+/*!Create and return new instance of STD_Application*/
extern "C" STD_EXPORT SUIT_Application* createApplication()
{
return new STD_Application();
}
+/*!Constructor.*/
STD_Application::STD_Application()
: SUIT_Application(),
myEditEnabled( true ),
setDesktop( desk );
}
+/*!Destructor.*/
STD_Application::~STD_Application()
{
}
+/*! \retval QString "StdApplication"*/
QString STD_Application::applicationName() const
{
return QString( "StdApplication" );
}
+/*!Start STD_Application*/
void STD_Application::start()
{
createActions();
SUIT_Application::start();
}
+/*!Event on closing desktop*/
void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e )
{
if ( !isPossibleToClose() )
closeApplication();
}
+/*!Create actions, menus and tools*/
void STD_Application::createActions()
{
SUIT_Desktop* desk = desktop();
tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ),
0, desk, false, this, SLOT( onSaveAsDoc() ) );
- createAction( EditCutId, tr( "TOT_DESK_EDIT_CUT" ),
- resMgr->loadPixmap( "STD", tr( "ICON_EDIT_CUT" ) ),
- tr( "MEN_DESK_EDIT_CUT" ), tr( "PRP_DESK_EDIT_CUT" ),
- CTRL+Key_X, desk, false, this, SLOT( onCut() ) );
-
createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ),
resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ),
tr( "MEN_DESK_EDIT_COPY" ), tr( "PRP_DESK_EDIT_COPY" ),
tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
0, 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 );
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( separator(), fileMenu );
createMenu( FileExitId, fileMenu );
- createMenu( EditCutId, editMenu );
createMenu( EditCopyId, editMenu );
createMenu( EditPasteId, editMenu );
createMenu( separator(), editMenu );
createTool( FileSaveId, stdTBar );
createTool( FileCloseId, stdTBar );
createTool( separator(), stdTBar );
- createTool( EditCutId, stdTBar );
createTool( EditCopyId, stdTBar );
createTool( EditPasteId, stdTBar );
}
-/*!
- Opens new application
-*/
+/*!Opens new application*/
void STD_Application::onNewDoc()
{
if ( !activeStudy() )
}
}
+/*!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 !!!
onOpenDoc( aName );
}
+/*! \retval true, if document was opened successful, else false.*/
bool STD_Application::onOpenDoc( const QString& aName )
{
bool res = true;
if ( !activeStudy() )
{
// if no study - open in current desktop
- createEmptyStudy();
- res = activeStudy()->openDocument( aName );
- updateDesktopTitle();
- updateCommandsStatus();
+ res = useFile( aName );
}
else
{
return res;
}
+/*! called on loading the existent study */
+void STD_Application::onLoadDoc()
+{
+}
+
+/*! \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<SUIT_Application> aAppList = aSession->applications();
+ bool isAlreadyOpen = false;
+ SUIT_Application* aApp = 0;
+ for ( QPtrListIterator<SUIT_Application> 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->useStudy( aName );
+ }
+ else
+ aApp->desktop()->setActiveWindow();
+ }
+ return res;
+}
+
+/*!Virtual function. Not implemented here.*/
void STD_Application::beforeCloseDoc( SUIT_Study* )
{
}
+/*!Virtual function. Not implemented here.*/
void STD_Application::afterCloseDoc()
{
}
+/*!Close document, if it's possible.*/
void STD_Application::onCloseDoc()
{
if ( !isPossibleToClose() )
beforeCloseDoc( study );
if ( study )
- study->closeDocument();
+ study->closeDocument(myClosePermanently);
clearViewManagers();
closeApplication();
}
+/*!Check the application on closing.
+ * \retval true if possible, else false
+ */
bool STD_Application::isPossibleToClose()
{
+ myClosePermanently = true; //SRN: BugID: IPAL9021
if ( activeStudy() )
{
activeStudy()->abortAllOperations();
{
QString sName = activeStudy()->studyName().stripWhiteSpace();
QString msg = sName.isEmpty() ? tr( "INF_DOC_MODIFIED" ) : tr ( "INF_DOCUMENT_MODIFIED" ).arg( sName );
- int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TOT_DESK_FILE_CLOSE" ), msg,
- tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 );
- switch ( aAnswer )
+
+ //SRN: BugID: IPAL9021: Begin
+ STD_CloseDlg dlg(desktop());
+ switch( dlg.exec() )
{
case 1:
- if ( !activeStudy()->isSaved() )
- if ( !onSaveAsDoc() )
- return false;
- else
+ 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 true;
}
+/*!Save document if all ok, else error message.*/
void STD_Application::onSaveDoc()
{
if ( !activeStudy() )
onSaveAsDoc();
}
+/*! \retval TRUE, if doument saved successful, else FALSE.*/
bool STD_Application::onSaveAsDoc()
{
SUIT_Study* study = activeStudy();
return isOk;
}
+/*!Closing session.*/
void STD_Application::onExit()
{
SUIT_Session::session()->closeSession();
}
-void STD_Application::onCut()
-{
-}
-
+/*!Virtual slot. Not implemented here.*/
void STD_Application::onCopy()
{
}
+/*!Virtual slot. Not implemented here.*/
void STD_Application::onPaste()
{
}
+/*!Sets \a theEnable for menu manager and for tool manager.*/
void STD_Application::setEditEnabled( bool theEnable )
{
myEditEnabled = theEnable;
QtxActionMenuMgr* mMgr = desktop()->menuMgr();
QtxActionToolMgr* tMgr = desktop()->toolMgr();
- for ( int i = EditCutId; i <= EditPasteId; i++ )
+ for ( int i = EditCopyId; i <= EditPasteId; i++ )
{
mMgr->setShown( i, myEditEnabled );
tMgr->setShown( i, myEditEnabled );
}
}
+/*!\retval true, if document opened successful, else false.*/
bool STD_Application::useFile(const QString& theFileName)
{
bool res = SUIT_Application::useFile(theFileName);
return res;
}
+/*!Update desktop title.*/
void STD_Application::updateDesktopTitle()
{
QString aTitle = applicationName();
desktop()->setCaption( aTitle );
}
+/*!Update commands status.*/
void STD_Application::updateCommandsStatus()
{
bool aHasStudy = activeStudy() != 0;
action( NewWindowId )->setEnabled( aHasStudy );
}
+/*!\retval SUIT_ViewManager by viewer manager type name.*/
SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
{
SUIT_ViewManager* vm = 0;
return vm;
}
+/*! \param vmType - input view manager type name
+ * \param lst - output list of view managers with types \a vmType.
+ */
void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const
{
for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current(); ++it )
lst.append( it.current() );
}
+/*!\param lst - output list of all view managers.*/
void STD_Application::viewManagers( ViewManagerList& lst ) const
{
for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current(); ++it )
lst.append( it.current() );
}
+/*!\retval ViewManagerList - const list of all view managers.*/
ViewManagerList STD_Application::viewManagers() const
{
ViewManagerList lst;
return lst;
}
+/*!\retval SUIT_ViewManager - return pointer to active view manager.*/
SUIT_ViewManager* STD_Application::activeViewManager() const
{
return myActiveViewMgr;
}
+/*!Add view manager to view managers list, if it not already there.*/
void STD_Application::addViewManager( SUIT_ViewManager* vm )
{
if ( !vm )
*/
}
+/*!Remove view manager from view managers list.*/
void STD_Application::removeViewManager( SUIT_ViewManager* vm )
{
if ( !vm )
myActiveViewMgr = 0;
}
+/*!Remove all view managers from view managers list.*/
void STD_Application::clearViewManagers()
{
ViewManagerList lst;
removeViewManager( it.current() );
}
+/*!\retval 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;
}
+/*!Private slot, sets active manager to \vm, if \vm in view managers list.*/
void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
{
setActiveViewManager( vm );
}
+/*!Sets status bar show, if \on = true, else status bar hide.*/
void STD_Application::onViewStatusBar( bool on )
{
if ( on )
desktop()->statusBar()->hide();
}
+/*!Call SUIT_MessageBox::info1(...) with about information.*/
void STD_Application::onHelpAbout()
{
SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
}
+/*!Create empty study. \n
+ * Create new view manager and adding it to view managers list.
+ */
void STD_Application::createEmptyStudy()
{
SUIT_Application::createEmptyStudy();
addViewManager( vm );
}
+/*!Sets active manager to \vm, if \vm in view managers list.*/
void STD_Application::setActiveViewManager( SUIT_ViewManager* vm )
{
if ( !containsViewManager( vm ) )
emit viewManagerActivated( vm );
}
+/*!Public slot. */
void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e )
{
QtxPopupMenu* popup = new QtxPopupMenu();
delete popup;
}
+/*!\retval QString - return file name from dialog.*/
QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
const QString& caption, QWidget* parent )
{
if ( !parent )
parent = desktop();
- QStringList fls = QStringList::split( ";", filters, false );
if ( open )
{
- return QFileDialog::getOpenFileName( initial, fls.join( ";;" ), parent, 0, caption );
+ return QFileDialog::getOpenFileName( initial, filters, parent, 0, caption );
}
else
{
while ( !isOk )
{
// It is preferrable to use OS-specific file dialog box here !!!
- aName = QFileDialog::getSaveFileName( anOldPath, fls.join( ";;" ), parent,
+ aName = QFileDialog::getSaveFileName( anOldPath, filters, parent,
0, caption, &aUsedFilter);
if ( aName.isNull() )
return aName;
}
}
+
+/*!\retval QString - return directory name from dialog.*/
+QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
+{
+ if ( !parent )
+ parent = desktop();
+ return QFileDialog::getExistingDirectory( initial, parent, 0, caption, true );
+}
+
+void STD_Application::setDesktop( SUIT_Desktop* desk )
+{
+ SUIT_Desktop* prev = desktop();
+
+ SUIT_Application::setDesktop( desk );
+
+ if ( prev != desk && desk )
+ connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
+ this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
+}