Salome HOME
no message
[modules/gui.git] / src / STD / STD_Application.cxx
1 #include "STD_Application.h"
2
3 #include "STD_MDIDesktop.h"
4
5 #include "STD_CloseDlg.h"
6
7 #include <SUIT_Tools.h>
8 #include <SUIT_Desktop.h>
9 #include <SUIT_Session.h>
10 #include <SUIT_ViewModel.h>
11 #include <SUIT_Operation.h>
12 #include <SUIT_MessageBox.h>
13 #include <SUIT_ResourceMgr.h>
14
15 #include <QtxDockAction.h>
16 #include <QtxActionMenuMgr.h>
17 #include <QtxActionToolMgr.h>
18 #include <QtxPopupMenu.h>
19
20 #include <qmenubar.h>
21 #include <qtoolbar.h>
22 #include <qpopupmenu.h>
23 #include <qstatusbar.h>
24 #include <qfiledialog.h>
25 #include <qapplication.h>
26
27 #include <iostream>
28
29 /*!Create and return new instance of STD_Application*/
30 extern "C" STD_EXPORT SUIT_Application* createApplication()
31 {
32   return new STD_Application();
33 }
34
35 /*!Constructor.*/
36 STD_Application::STD_Application()
37 : SUIT_Application(),
38 myEditEnabled( true ),
39 myActiveViewMgr( 0 )
40 {
41   STD_MDIDesktop* desk = new STD_MDIDesktop();
42
43   setDesktop( desk );
44 }
45
46 /*!Destructor.*/
47 STD_Application::~STD_Application()
48 {
49 }
50
51 /*! \retval QString "StdApplication"*/
52 QString STD_Application::applicationName() const
53 {
54   return QString( "StdApplication" );
55 }
56
57 /*!Start STD_Application*/
58 void STD_Application::start()
59 {
60   createActions();
61
62   updateDesktopTitle();
63   updateCommandsStatus();
64   setEditEnabled( myEditEnabled );
65
66   SUIT_Application::start();
67 }
68
69 /*!Event on closing desktop*/
70 void STD_Application::onDesktopClosing( SUIT_Desktop*, QCloseEvent* e )
71 {
72   if (SUIT_Session::session()->applications().count() < 2) {
73     onExit();
74     return;
75   }
76
77   if ( !isPossibleToClose() )
78   {
79     e->ignore();
80     return;
81   }
82
83   SUIT_Study* study = activeStudy();
84
85   if ( study )
86     study->closeDocument();
87
88   setActiveStudy( 0 );
89   delete study;
90
91   setDesktop( 0 );
92
93   closeApplication();
94 }
95
96 /*!Create actions, menus and tools*/
97 void STD_Application::createActions()
98 {
99   SUIT_Desktop* desk = desktop();
100   SUIT_ResourceMgr* resMgr = resourceMgr();
101   if ( !desk || !resMgr )
102     return;
103
104   // Create actions
105
106   createAction( FileNewId, tr( "TOT_DESK_FILE_NEW" ),
107                 resMgr->loadPixmap( "STD", tr( "ICON_FILE_NEW" ) ),
108                 tr( "MEN_DESK_FILE_NEW" ), tr( "PRP_DESK_FILE_NEW" ),
109                 CTRL+Key_N, desk, false, this, SLOT( onNewDoc() ) );
110
111   createAction( FileOpenId, tr( "TOT_DESK_FILE_OPEN" ),
112                 resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ),
113                 tr( "MEN_DESK_FILE_OPEN" ), tr( "PRP_DESK_FILE_OPEN" ),
114                 CTRL+Key_O, desk, false, this, SLOT( onOpenDoc() ) );
115
116   createAction( FileCloseId, tr( "TOT_DESK_FILE_CLOSE" ),
117                 resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ),
118                 tr( "MEN_DESK_FILE_CLOSE" ), tr( "PRP_DESK_FILE_CLOSE" ),
119                 CTRL+Key_W, desk, false, this, SLOT( onCloseDoc() ) );
120
121   createAction( FileExitId, tr( "TOT_DESK_FILE_EXIT" ), QIconSet(),
122                 tr( "MEN_DESK_FILE_EXIT" ), tr( "PRP_DESK_FILE_EXIT" ),
123                 CTRL+Key_Q, desk, false, this, SLOT( onExit() ) );
124
125   createAction( FileSaveId, tr( "TOT_DESK_FILE_SAVE" ),
126                 resMgr->loadPixmap( "STD", tr( "ICON_FILE_SAVE" ) ),
127                 tr( "MEN_DESK_FILE_SAVE" ), tr( "PRP_DESK_FILE_SAVE" ),
128                 CTRL+Key_S, desk, false, this, SLOT( onSaveDoc() ) );
129
130   createAction( FileSaveAsId, tr( "TOT_DESK_FILE_SAVEAS" ), QIconSet(),
131                 tr( "MEN_DESK_FILE_SAVEAS" ), tr( "PRP_DESK_FILE_SAVEAS" ),
132                 0, desk, false, this, SLOT( onSaveAsDoc() ) );
133
134   createAction( EditCopyId, tr( "TOT_DESK_EDIT_COPY" ),
135                 resMgr->loadPixmap( "STD", tr( "ICON_EDIT_COPY" ) ),
136                 tr( "MEN_DESK_EDIT_COPY" ), tr( "PRP_DESK_EDIT_COPY" ),
137                 CTRL+Key_C, desk, false, this, SLOT( onCopy() ) );
138
139   createAction( EditPasteId, tr( "TOT_DESK_EDIT_PASTE" ),
140                 resMgr->loadPixmap( "STD", tr( "ICON_EDIT_PASTE" ) ),
141                 tr( "MEN_DESK_EDIT_PASTE" ), tr( "PRP_DESK_EDIT_PASTE" ),
142                 CTRL+Key_V, desk, false, this, SLOT( onPaste() ) );
143
144   QAction* a = createAction( ViewStatusBarId, tr( "TOT_DESK_VIEW_STATUSBAR" ),
145                              QIconSet(), tr( "MEN_DESK_VIEW_STATUSBAR" ),
146                              tr( "PRP_DESK_VIEW_STATUSBAR" ), 0, desk, true );
147   a->setOn( desk->statusBar()->isVisibleTo( desk ) );
148   connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onViewStatusBar( bool ) ) );
149
150   createAction( NewWindowId, tr( "TOT_DESK_NEWWINDOW" ), QIconSet(),
151                 tr( "MEN_DESK_NEWWINDOW" ), tr( "PRP_DESK_NEWWINDOW" ), 0, desk  );
152
153   createAction( HelpAboutId, tr( "TOT_DESK_HELP_ABOUT" ), QIconSet(),
154                 tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ),
155                 0, desk, false, this, SLOT( onHelpAbout() ) );
156
157   //SRN: BugID IPAL9021, add an action "Load"
158   createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ),
159                 resMgr->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ),
160                 tr( "MEN_DESK_FILE_LOAD" ), tr( "PRP_DESK_FILE_LOAD" ),
161                 CTRL+Key_L, desk, false, this, SLOT( onLoadDoc() ) );
162   //SRN: BugID IPAL9021: End
163
164   QtxDockAction* da = new QtxDockAction( tr( "TOT_DOCK_WINDOWS" ), tr( "MEN_DOCK_WINDOWS" ), desk );
165   registerAction( ViewWindowsId, da );
166   da->setAutoPlace( false );
167
168   // Create menus
169
170   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
171   int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 10 );
172   int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1, -1, 10 );
173   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
174
175   // Create menu items
176
177   createMenu( FileNewId, fileMenu, 0 );
178   createMenu( FileOpenId, fileMenu, 0 );
179   createMenu( FileLoadId, fileMenu, 0 );  //SRN: BugID IPAL9021, add a menu item "Load"
180   createMenu( FileCloseId, fileMenu, 0 );
181   createMenu( separator(), fileMenu, -1, 0 );
182   createMenu( FileSaveId, fileMenu, 0 );
183   createMenu( FileSaveAsId, fileMenu, 0 );
184   createMenu( separator(), fileMenu, -1, 0 );
185
186   createMenu( separator(), fileMenu );
187   createMenu( FileExitId, fileMenu );
188
189   createMenu( EditCopyId, editMenu );
190   createMenu( EditPasteId, editMenu );
191   createMenu( separator(), editMenu );
192
193   createMenu( ViewWindowsId, viewMenu );
194   createMenu( ViewStatusBarId, viewMenu );
195   createMenu( separator(), viewMenu );
196
197   createMenu( HelpAboutId, helpMenu );
198   createMenu( separator(), helpMenu );
199
200   // Create tool bars
201
202   int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ) );
203
204   // Create tool items
205
206   createTool( FileNewId, stdTBar );
207   createTool( FileOpenId, stdTBar );
208   createTool( FileSaveId, stdTBar );
209   createTool( FileCloseId, stdTBar );
210   createTool( separator(), stdTBar );
211   createTool( EditCopyId, stdTBar );
212   createTool( EditPasteId, stdTBar );
213 }
214
215 /*!Opens new application*/
216 void STD_Application::onNewDoc()
217 {
218   QApplication::setOverrideCursor( Qt::waitCursor );
219
220   if ( !activeStudy() )
221   {
222     createEmptyStudy();
223     activeStudy()->createDocument();
224     studyCreated( activeStudy() );
225   }
226   else
227   {
228     SUIT_Application* aApp = startApplication( 0, 0 );
229     if ( aApp->inherits( "STD_Application" ) )
230       ((STD_Application*)aApp)->onNewDoc();
231     else
232     {
233       aApp->createEmptyStudy();
234       aApp->activeStudy()->createDocument();
235     }
236   }
237
238   QApplication::restoreOverrideCursor();
239 }
240
241 /*!Put file name from file dialog to onOpenDoc(const QString&) function*/
242 void STD_Application::onOpenDoc()
243 {
244   // It is preferrable to use OS-specific file dialog box here !!!
245   QString aName = getFileName( true, QString::null, getFileFilter(), QString::null, 0 );
246   if ( aName.isNull() )
247     return;
248
249   onOpenDoc( aName );
250 }
251
252 /*! \retval true, if document was opened successful, else false.*/
253 bool STD_Application::onOpenDoc( const QString& aName )
254 {
255   QApplication::setOverrideCursor( Qt::waitCursor );
256
257   bool res = true;
258   if ( !activeStudy() )
259   {
260     // if no study - open in current desktop
261     res = useFile( aName );
262   }
263   else
264   {
265     // if study exists - open in new desktop. Check: is the same file is opened?
266     SUIT_Session* aSession = SUIT_Session::session();
267     QPtrList<SUIT_Application> aAppList = aSession->applications();
268     bool isAlreadyOpen = false;
269     SUIT_Application* aApp = 0;
270     for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
271     {
272       aApp = it.current();
273       if ( aApp->activeStudy()->studyName() == aName )
274         isAlreadyOpen = true;
275     }
276     if ( !isAlreadyOpen )
277     {
278       aApp = startApplication( 0, 0 );
279       if ( aApp )
280         res = aApp->useFile( aName );
281       if ( !res )
282         aApp->closeApplication();
283     }
284     else
285       aApp->desktop()->setActiveWindow();
286   }
287
288   QApplication::restoreOverrideCursor();
289
290   return res;
291 }
292
293 /*! called on loading the existent study */
294 void STD_Application::onLoadDoc()
295 {
296 }
297
298 /*! \retval true, if document was loaded successful, else false.*/
299 bool STD_Application::onLoadDoc( const QString& aName )
300 {
301   bool res = true;
302   if ( !activeStudy() )
303   {
304     // if no study - load in current desktop
305     res = useStudy( aName );
306   }
307   else
308   {
309     // if study exists - load in new desktop. Check: is the same file is loaded?
310     SUIT_Session* aSession = SUIT_Session::session();
311     QPtrList<SUIT_Application> aAppList = aSession->applications();
312     bool isAlreadyOpen = false;
313     SUIT_Application* aApp = 0;
314     for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
315     {
316       aApp = it.current();
317       if ( aApp->activeStudy()->studyName() == aName )
318         isAlreadyOpen = true;
319     }
320     if ( !isAlreadyOpen )
321     {
322       aApp = startApplication( 0, 0 );
323       if ( aApp )
324         res = aApp->useStudy( aName );
325     }
326     else
327       aApp->desktop()->setActiveWindow();
328   }
329   return res;
330 }
331
332 /*!Virtual function. Not implemented here.*/
333 void STD_Application::beforeCloseDoc( SUIT_Study* )
334 {
335 }
336
337 /*!Virtual function. Not implemented here.*/
338 void STD_Application::afterCloseDoc()
339 {
340 }
341
342 /*!Close document, if it's possible.*/
343 void STD_Application::onCloseDoc( bool ask )
344 {
345   if ( ask && !isPossibleToClose() )
346     return;
347
348   SUIT_Study* study = activeStudy();
349
350   beforeCloseDoc( study );
351
352   if ( study )
353     study->closeDocument(myClosePermanently);
354
355   clearViewManagers();
356
357   setActiveStudy( 0 );
358   delete study;
359
360   int aNbStudies = 0;
361   QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
362   for ( unsigned i = 0; i < apps.count(); i++ )
363     aNbStudies += apps.at( i )->getNbStudies();
364
365   // STV: aNbStudies - number of currently existing studies (exclude currently closed)
366   // STV: aNbStudies should be compared with 0.
367   if ( aNbStudies )
368     setDesktop( 0 );
369   else
370   {
371     updateDesktopTitle();
372     updateCommandsStatus();
373   }
374
375   afterCloseDoc();
376
377   if ( !desktop() )
378     closeApplication();
379 }
380
381 /*!Check the application on closing.
382  * \retval true if possible, else false
383  */
384 bool STD_Application::isPossibleToClose()
385 {
386   myClosePermanently = true; //SRN: BugID: IPAL9021
387   if ( activeStudy() )
388   {
389     activeStudy()->abortAllOperations();
390     if ( activeStudy()->isModified() )
391     {
392       QString sName = activeStudy()->studyName().stripWhiteSpace();
393       QString msg = sName.isEmpty() ? tr( "INF_DOC_MODIFIED" ) : tr ( "INF_DOCUMENT_MODIFIED" ).arg( sName );
394
395       //SRN: BugID: IPAL9021: Begin
396       STD_CloseDlg dlg(desktop());
397       switch( dlg.exec() )
398       {
399       case 1:
400         if ( activeStudy()->isSaved() )
401           onSaveDoc();
402         else if ( !onSaveAsDoc() )
403           return false;
404         break;
405       case 2:
406         break;
407       case 3:
408               myClosePermanently = false;
409         break;
410       case 4:
411       default:
412         return false;
413       }
414      //SRN: BugID: IPAL9021: End
415     }
416   }
417   return true;
418 }
419
420 /*!Save document if all ok, else error message.*/
421 void STD_Application::onSaveDoc()
422 {
423   if ( !activeStudy() )
424     return;
425
426   bool isOk = false;
427   if ( activeStudy()->isSaved() )
428   {
429     putInfo( tr( "INF_DOC_SAVING" ) + activeStudy()->studyName() );
430
431     QApplication::setOverrideCursor( Qt::waitCursor );
432
433     isOk = activeStudy()->saveDocument();
434
435     QApplication::restoreOverrideCursor();
436
437     if ( !isOk )
438     {
439       putInfo( "" );
440       SUIT_MessageBox::error1( desktop(), tr( "TIT_FILE_SAVEAS" ),
441                                                  tr( "MSG_CANT_SAVE" ).arg( activeStudy()->studyName() ), tr( "BUT_OK" ) );
442     }
443     else
444       putInfo( tr( "INF_DOC_SAVED" ).arg( "" ) );
445   }
446
447   if ( isOk )
448     studySaved( activeStudy() );
449   else
450     onSaveAsDoc();
451 }
452
453 /*! \retval TRUE, if doument saved successful, else FALSE.*/
454 bool STD_Application::onSaveAsDoc()
455 {
456   SUIT_Study* study = activeStudy();
457   if ( !study )
458     return false;
459
460   bool isOk = false;
461   while ( !isOk )
462   {
463     QString aName = getFileName( false, study->studyName(), getFileFilter(), QString::null, 0 );
464     if ( aName.isNull() )
465       return false;
466
467     QApplication::setOverrideCursor( Qt::waitCursor );
468
469     putInfo( tr( "INF_DOC_SAVING" ) + aName );
470     isOk = study->saveDocumentAs( aName );
471
472     putInfo( isOk ? tr( "INF_DOC_SAVED" ).arg( aName ) : "" );
473
474     QApplication::restoreOverrideCursor();
475
476     if ( !isOk )
477       SUIT_MessageBox::error1( desktop(), tr( "ERROR" ),
478                              tr( "INF_DOC_SAVING_FAILS" ).arg( aName ), tr( "BUT_OK" ) );
479   }
480
481   studySaved( activeStudy() );
482
483   return isOk;
484 }
485
486 /*!Closing session.*/
487 void STD_Application::onExit()
488 {
489   int aAnswer = SUIT_MessageBox::info2( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ),
490                                         tr( "BUT_OK" ), tr( "BUT_CANCEL" ), 1, 2, 2 );
491   if ( aAnswer == 1 )
492     SUIT_Session::session()->closeSession();
493 }
494
495 /*!Virtual slot. Not implemented here.*/
496 void STD_Application::onCopy()
497 {
498 }
499
500 /*!Virtual slot. Not implemented here.*/
501 void STD_Application::onPaste()
502 {
503 }
504
505 /*!Sets \a theEnable for menu manager and for tool manager.*/
506 void STD_Application::setEditEnabled( bool theEnable )
507 {
508   myEditEnabled = theEnable;
509
510   QtxActionMenuMgr* mMgr = desktop()->menuMgr();
511   QtxActionToolMgr* tMgr = desktop()->toolMgr();
512
513   for ( int i = EditCopyId; i <= EditPasteId; i++ )
514   {
515     mMgr->setShown( i, myEditEnabled );
516     tMgr->setShown( i, myEditEnabled );
517   }
518 }
519
520 /*!\retval true, if document opened successful, else false.*/
521 bool STD_Application::useFile(const QString& theFileName)
522 {
523   bool res = SUIT_Application::useFile( theFileName );
524
525   if ( res )
526     studyOpened( activeStudy() );
527
528   return res;
529 }
530
531 /*!Update desktop title.*/
532 void STD_Application::updateDesktopTitle()
533 {
534   QString aTitle = applicationName();
535   QString aVer = applicationVersion();
536   if ( !aVer.isEmpty() )
537     aTitle += QString( " " ) + aVer;
538
539   if ( activeStudy() )
540   {
541     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
542     if ( !sName.isEmpty() )
543       aTitle += QString( " - [%1]" ).arg( sName );
544   }
545
546   desktop()->setCaption( aTitle );
547 }
548
549 /*!Update commands status.*/
550 void STD_Application::updateCommandsStatus()
551 {
552   bool aHasStudy = activeStudy() != 0;
553   bool aIsNeedToSave = false;
554   if ( aHasStudy )
555     aIsNeedToSave = !activeStudy()->isSaved() || activeStudy()->isModified();
556
557   if ( action( FileSaveId ) )
558     action( FileSaveId )->setEnabled( aIsNeedToSave );
559   if ( action( FileSaveAsId ) )
560     action( FileSaveAsId )->setEnabled( aHasStudy );
561   if ( action( FileCloseId ) )
562     action( FileCloseId )->setEnabled( aHasStudy );
563   if ( action( NewWindowId ) )
564     action( NewWindowId )->setEnabled( aHasStudy );
565 }
566
567 /*!\retval SUIT_ViewManager by viewer manager type name.*/
568 SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
569 {
570   SUIT_ViewManager* vm = 0;
571   for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current() && !vm; ++it )
572   {
573     if ( it.current()->getType() == vmType )
574       vm = it.current();
575   }
576   return vm;
577 }
578
579 /*! \param vmType - input view manager type name
580  * \param lst - output list of view managers with types \a vmType.
581  */
582 void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const
583 {
584   for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current(); ++it )
585     if ( it.current()->getType() == vmType )
586       lst.append( it.current() );
587 }
588
589 /*!\param lst - output list of all view managers.*/
590 void STD_Application::viewManagers( ViewManagerList& lst ) const
591 {
592   for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current(); ++it )
593     lst.append( it.current() );
594 }
595
596 /*!\retval ViewManagerList - const list of all view managers.*/
597 ViewManagerList STD_Application::viewManagers() const
598 {
599   ViewManagerList lst;
600   viewManagers( lst );
601   return lst;
602 }
603
604 /*!\retval SUIT_ViewManager - return pointer to active view manager.*/
605 SUIT_ViewManager* STD_Application::activeViewManager() const
606 {
607   return myActiveViewMgr;
608 }
609
610 /*!Add view manager to view managers list, if it not already there.*/
611 void STD_Application::addViewManager( SUIT_ViewManager* vm )
612 {
613   if ( !vm )
614     return;
615
616   if ( !containsViewManager( vm ) )
617   {
618     myViewMgrs.append( vm );
619     connect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
620              this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
621     vm->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
622
623     emit viewManagerAdded( vm );
624   }
625 /*
626   if ( !activeViewManager() && myViewMgrs.count() == 1 )
627     setActiveViewManager( vm );
628 */
629 }
630
631 /*!Remove view manager from view managers list.*/
632 void STD_Application::removeViewManager( SUIT_ViewManager* vm )
633 {
634   if ( !vm )
635     return;
636
637   vm->closeAllViews();
638
639   emit viewManagerRemoved( vm );
640
641   vm->disconnectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
642   vm->disconnect();
643   myViewMgrs.removeRef( vm );
644
645   if ( myActiveViewMgr == vm )
646     myActiveViewMgr = 0;
647 }
648
649 /*!Remove all view managers from view managers list.*/
650 void STD_Application::clearViewManagers()
651 {
652   ViewManagerList lst;
653   viewManagers( lst );
654
655   for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
656     removeViewManager( it.current() );
657 }
658
659 /*!\retval TRUE, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
660 bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const
661 {
662   return myViewMgrs.contains( vm ) > 0;
663 }
664
665 /*!Private slot, sets active manager to \vm, if \vm in view managers list.*/
666 void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
667 {
668   setActiveViewManager( vm );
669 }
670
671 /*!Sets status bar show, if \on = true, else status bar hide.*/
672 void STD_Application::onViewStatusBar( bool on )
673 {
674   if ( on )
675     desktop()->statusBar()->show();
676   else
677     desktop()->statusBar()->hide();
678 }
679
680 /*!Call SUIT_MessageBox::info1(...) with about information.*/
681 void STD_Application::onHelpAbout()
682 {
683   SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
684 }
685
686 /*!Create empty study. \n
687  * Create new view manager and adding it to view managers list.
688  */
689 void STD_Application::createEmptyStudy()
690 {
691   SUIT_Application::createEmptyStudy();
692
693   SUIT_ViewManager* vm = new SUIT_ViewManager( activeStudy(), desktop(), new SUIT_ViewModel() );
694
695   addViewManager( vm );
696 }
697
698 /*!Sets active manager to \vm, if \vm in view managers list.*/
699 void STD_Application::setActiveViewManager( SUIT_ViewManager* vm )
700 {
701   if ( !containsViewManager( vm ) )
702     return;
703
704   myActiveViewMgr = vm;
705   emit viewManagerActivated( vm );
706 }
707
708 /*!Public slot. */
709 void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e )
710 {
711   QtxPopupMenu* popup = new QtxPopupMenu();
712   // fill popup by own items
713   QString title;
714   contextMenuPopup( client->popupClientType(), popup, title );
715   popup->setTitleText( title );
716
717   popup->insertSeparator();
718   // add items from popup client
719   client->contextMenuPopup( popup );
720
721   SUIT_Tools::simplifySeparators( popup );
722
723   if ( popup->count() )
724     popup->exec( e->globalPos() );
725   delete popup;
726 }
727
728 #include <qregexp.h>
729
730 /*!\retval QString - return file name from dialog.*/
731 QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
732                                       const QString& caption, QWidget* parent )
733 {
734   if ( !parent )
735     parent = desktop();
736   if ( open )
737   {
738     return QFileDialog::getOpenFileName( initial, filters, parent, 0, caption );
739   }
740   else
741   {
742     QString aName;
743     QString aUsedFilter;
744     QString anOldPath = initial;
745
746     bool isOk = false;
747     while ( !isOk )
748     {
749       // It is preferrable to use OS-specific file dialog box here !!!
750       aName = QFileDialog::getSaveFileName( anOldPath, filters, parent, 0, caption, &aUsedFilter );
751
752       if ( aName.isNull() )
753         isOk = true;
754       else
755       {
756               int aEnd = aUsedFilter.findRev( ')' );
757               int aStart = aUsedFilter.findRev( '(', aEnd );
758               QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 );
759
760         int idx = 0;
761         QStringList extList;
762         QRegExp rx( "[\b\\*]*\\.([\\w]+)" );
763         while ( ( idx = rx.search( wcStr, idx ) ) != -1 )
764         {
765           extList.append( rx.cap( 1 ) );
766           idx += rx.matchedLength();
767         }
768
769         if ( !extList.isEmpty() && !extList.contains( QFileInfo( aName ).extension() ) )
770           aName += QString( ".%1" ).arg( extList.first() );
771
772               if ( QFileInfo( aName ).exists() )
773         {
774                 int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TIT_FILE_SAVEAS" ),
775                                                                               tr( "MSG_FILE_EXISTS" ).arg( aName ),
776                                                                               tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 );
777                 if ( aAnswer == 3 )
778           {     // cancelled
779             aName = QString::null;
780                   isOk = true;
781           }
782                 else if ( aAnswer == 2 ) // not save to this file
783                   anOldPath = aName;             // not to return to the same initial dir at each "while" step
784                 else                     // overwrite the existing file
785                   isOk = true;
786         }
787               else
788                 isOk = true;
789       }
790     }
791     return aName;
792   }
793 }
794
795 /*!\retval QString - return directory name from dialog.*/
796 QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
797 {
798   if ( !parent )
799     parent = desktop();
800   return QFileDialog::getExistingDirectory( initial, parent, 0, caption, true );
801 }
802
803 void STD_Application::setDesktop( SUIT_Desktop* desk )
804 {
805   SUIT_Desktop* prev = desktop();
806
807   SUIT_Application::setDesktop( desk );
808
809   if ( prev != desk && desk )
810     connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
811              this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
812 }
813
814 void STD_Application::studyCreated( SUIT_Study* )
815 {
816   updateDesktopTitle();
817   updateCommandsStatus();
818 }
819
820 void STD_Application::studyOpened( SUIT_Study* )
821 {
822   updateDesktopTitle();
823   updateCommandsStatus();
824 }
825
826 void STD_Application::studySaved( SUIT_Study* )
827 {
828   updateDesktopTitle();
829   updateCommandsStatus();
830 }