]> SALOME platform Git repositories - modules/gui.git/blob - src/STD/STD_Application.cxx
Salome HOME
20b8f0837d9942d58cd2725e3a3c1b20bd782789
[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   if ( !activeStudy() )
219   {
220     createEmptyStudy();
221     activeStudy()->createDocument();
222     updateDesktopTitle();
223     updateCommandsStatus();
224   }
225   else
226   {
227     SUIT_Application* aApp = startApplication( 0, 0 );
228     if ( aApp->inherits( "STD_Application" ) )
229       ((STD_Application*)aApp)->onNewDoc();
230     else {
231       aApp->createEmptyStudy();
232       aApp->activeStudy()->createDocument();
233     }
234   }
235 }
236
237 /*!Put file name from file dialog to onOpenDoc(const QString&) function*/
238 void STD_Application::onOpenDoc()
239 {
240   // It is preferrable to use OS-specific file dialog box here !!!
241   QString aName = getFileName( true, QString::null, getFileFilter(), QString::null, 0 );
242   if ( aName.isNull() )
243     return;
244
245   onOpenDoc( aName );
246 }
247
248 /*! \retval true, if document was opened successful, else false.*/
249 bool STD_Application::onOpenDoc( const QString& aName )
250 {
251   bool res = true;
252   if ( !activeStudy() )
253   {
254     // if no study - open in current desktop
255     res = useFile( aName );
256   }
257   else
258   {
259     // if study exists - open in new desktop. Check: is the same file is opened?
260     SUIT_Session* aSession = SUIT_Session::session();
261     QPtrList<SUIT_Application> aAppList = aSession->applications();
262     bool isAlreadyOpen = false;
263     SUIT_Application* aApp = 0;
264     for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
265     {
266       aApp = it.current();
267       if ( aApp->activeStudy()->studyName() == aName )
268         isAlreadyOpen = true;
269     }
270     if ( !isAlreadyOpen )
271     {
272       aApp = startApplication( 0, 0 );
273       if ( aApp )
274         res = aApp->useFile( aName );
275     }
276     else
277       aApp->desktop()->setActiveWindow();
278   }
279   return res;
280 }
281
282 /*! called on loading the existent study */
283 void STD_Application::onLoadDoc()
284 {
285 }
286
287 /*! \retval true, if document was loaded successful, else false.*/
288 bool STD_Application::onLoadDoc( const QString& aName )
289 {
290   bool res = true;
291   if ( !activeStudy() )
292   {
293     // if no study - load in current desktop
294     res = useStudy( aName );
295   }
296   else
297   {
298     // if study exists - load in new desktop. Check: is the same file is loaded?
299     SUIT_Session* aSession = SUIT_Session::session();
300     QPtrList<SUIT_Application> aAppList = aSession->applications();
301     bool isAlreadyOpen = false;
302     SUIT_Application* aApp = 0;
303     for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
304     {
305       aApp = it.current();
306       if ( aApp->activeStudy()->studyName() == aName )
307         isAlreadyOpen = true;
308     }
309     if ( !isAlreadyOpen )
310     {
311       aApp = startApplication( 0, 0 );
312       if ( aApp )
313         res = aApp->useStudy( aName );
314     }
315     else
316       aApp->desktop()->setActiveWindow();
317   }
318   return res;
319 }
320
321 /*!Virtual function. Not implemented here.*/
322 void STD_Application::beforeCloseDoc( SUIT_Study* )
323 {
324 }
325
326 /*!Virtual function. Not implemented here.*/
327 void STD_Application::afterCloseDoc()
328 {
329 }
330
331 /*!Close document, if it's possible.*/
332 void STD_Application::onCloseDoc(bool ask)
333 {
334   if (ask)
335     if ( !isPossibleToClose() )
336       return;
337
338   SUIT_Study* study = activeStudy();
339
340   beforeCloseDoc( study );
341
342   if ( study )
343     study->closeDocument(myClosePermanently);
344
345   clearViewManagers();
346
347   setActiveStudy( 0 );
348   delete study;
349
350   int aNbStudies = 0;
351   QPtrList<SUIT_Application> apps = SUIT_Session::session()->applications();
352   for ( unsigned i = 0; i < apps.count(); i++ )
353     aNbStudies += apps.at( i )->getNbStudies();
354
355   // STV: aNbStudies - number of currently existing studies (exclude currently closed)
356   // STV: aNbStudies should be compared with 0.
357   if ( aNbStudies )
358     setDesktop( 0 );
359   else
360   {
361     updateDesktopTitle();
362     updateCommandsStatus();
363   }
364
365   afterCloseDoc();
366
367   if ( !desktop() )
368     closeApplication();
369 }
370
371 /*!Check the application on closing.
372  * \retval true if possible, else false
373  */
374 bool STD_Application::isPossibleToClose()
375 {
376   myClosePermanently = true; //SRN: BugID: IPAL9021
377   if ( activeStudy() )
378   {
379     activeStudy()->abortAllOperations();
380     if ( activeStudy()->isModified() )
381     {
382       QString sName = activeStudy()->studyName().stripWhiteSpace();
383       QString msg = sName.isEmpty() ? tr( "INF_DOC_MODIFIED" ) : tr ( "INF_DOCUMENT_MODIFIED" ).arg( sName );
384
385       //SRN: BugID: IPAL9021: Begin
386       STD_CloseDlg dlg(desktop());
387       switch( dlg.exec() )
388       {
389       case 1:
390         if ( activeStudy()->isSaved() )
391           onSaveDoc();
392         else if ( !onSaveAsDoc() )
393           return false;
394         break;
395       case 2:
396         break;
397       case 3:
398         myClosePermanently = false;
399         break;
400       case 4:
401       default:
402         return false;
403       }
404      //SRN: BugID: IPAL9021: End
405     }
406   }
407   return true;
408 }
409
410 /*!Save document if all ok, else error message.*/
411 void STD_Application::onSaveDoc()
412 {
413   if ( !activeStudy() )
414     return;
415
416   bool isOk = false;
417   if ( activeStudy()->isSaved() )
418   {
419     putInfo(tr("INF_DOC_SAVING") + activeStudy()->studyName());
420     isOk = activeStudy()->saveDocument();
421     if ( !isOk ) {
422       putInfo("");
423       SUIT_MessageBox::error1( desktop(), tr( "TIT_FILE_SAVEAS" ),
424                                tr( "MSG_CANT_SAVE" ).arg( activeStudy()->studyName() ),
425                                tr( "BUT_OK" ) );
426     } else {
427       putInfo(tr("INF_DOC_SAVED").arg(""));
428     }
429   }
430
431   if ( isOk )
432     updateCommandsStatus();
433   else
434     onSaveAsDoc();
435 }
436
437 /*! \retval TRUE, if doument saved successful, else FALSE.*/
438 bool STD_Application::onSaveAsDoc()
439 {
440   SUIT_Study* study = activeStudy();
441   if ( !study )
442     return false;
443
444   QString aName = getFileName( false, study->studyName(), getFileFilter(), QString::null, 0 );
445   if ( aName.isNull() )
446     return false;
447
448   putInfo(tr("INF_DOC_SAVING") + aName);
449   bool isOk = study->saveDocumentAs( aName );
450
451   if (isOk)
452     putInfo(tr("INF_DOC_SAVED").arg(aName));
453   else
454     putInfo("");
455
456   updateDesktopTitle();
457   updateCommandsStatus();
458
459   return isOk;
460 }
461
462 /*!Closing session.*/
463 void STD_Application::onExit()
464 {
465   int aAnswer = SUIT_MessageBox::info2(desktop(), tr("INF_DESK_EXIT"), tr("QUE_DESK_EXIT"),
466                                        tr ("BUT_OK"), tr ("BUT_CANCEL"), 1, 2, 2);
467   if (aAnswer == 1)
468     SUIT_Session::session()->closeSession();
469 }
470
471 /*!Virtual slot. Not implemented here.*/
472 void STD_Application::onCopy()
473 {
474 }
475
476 /*!Virtual slot. Not implemented here.*/
477 void STD_Application::onPaste()
478 {
479 }
480
481 /*!Sets \a theEnable for menu manager and for tool manager.*/
482 void STD_Application::setEditEnabled( bool theEnable )
483 {
484   myEditEnabled = theEnable;
485
486   QtxActionMenuMgr* mMgr = desktop()->menuMgr();
487   QtxActionToolMgr* tMgr = desktop()->toolMgr();
488
489   for ( int i = EditCopyId; i <= EditPasteId; i++ )
490   {
491     mMgr->setShown( i, myEditEnabled );
492     tMgr->setShown( i, myEditEnabled );
493   }
494 }
495
496 /*!\retval true, if document opened successful, else false.*/
497 bool STD_Application::useFile(const QString& theFileName)
498 {
499   bool res = SUIT_Application::useFile(theFileName);
500   updateDesktopTitle();
501   updateCommandsStatus();
502   return res;
503 }
504
505 /*!Update desktop title.*/
506 void STD_Application::updateDesktopTitle()
507 {
508   QString aTitle = applicationName();
509   QString aVer = applicationVersion();
510   if ( !aVer.isEmpty() )
511     aTitle += QString( " " ) + aVer;
512
513   if ( activeStudy() )
514   {
515     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
516     if ( !sName.isEmpty() )
517       aTitle += QString( " - [%1]" ).arg( sName );
518   }
519
520   desktop()->setCaption( aTitle );
521 }
522
523 /*!Update commands status.*/
524 void STD_Application::updateCommandsStatus()
525 {
526   bool aHasStudy = activeStudy() != 0;
527   bool aIsNeedToSave = false;
528   if ( aHasStudy )
529     aIsNeedToSave = !activeStudy()->isSaved() || activeStudy()->isModified();
530
531   if ( action( FileSaveId ) )
532     action( FileSaveId )->setEnabled( aIsNeedToSave );
533   if ( action( FileSaveAsId ) )
534     action( FileSaveAsId )->setEnabled( aHasStudy );
535   if ( action( FileCloseId ) )
536     action( FileCloseId )->setEnabled( aHasStudy );
537   if ( action( NewWindowId ) )
538     action( NewWindowId )->setEnabled( aHasStudy );
539 }
540
541 /*!\retval SUIT_ViewManager by viewer manager type name.*/
542 SUIT_ViewManager* STD_Application::viewManager( const QString& vmType ) const
543 {
544   SUIT_ViewManager* vm = 0;
545   for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current() && !vm; ++it )
546   {
547     if ( it.current()->getType() == vmType )
548       vm = it.current();
549   }
550   return vm;
551 }
552
553 /*! \param vmType - input view manager type name
554  * \param lst - output list of view managers with types \a vmType.
555  */
556 void STD_Application::viewManagers( const QString& vmType, ViewManagerList& lst ) const
557 {
558   for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current(); ++it )
559     if ( it.current()->getType() == vmType )
560       lst.append( it.current() );
561 }
562
563 /*!\param lst - output list of all view managers.*/
564 void STD_Application::viewManagers( ViewManagerList& lst ) const
565 {
566   for ( QPtrListIterator<SUIT_ViewManager> it( myViewMgrs ); it.current(); ++it )
567     lst.append( it.current() );
568 }
569
570 /*!\retval ViewManagerList - const list of all view managers.*/
571 ViewManagerList STD_Application::viewManagers() const
572 {
573   ViewManagerList lst;
574   viewManagers( lst );
575   return lst;
576 }
577
578 /*!\retval SUIT_ViewManager - return pointer to active view manager.*/
579 SUIT_ViewManager* STD_Application::activeViewManager() const
580 {
581   return myActiveViewMgr;
582 }
583
584 /*!Add view manager to view managers list, if it not already there.*/
585 void STD_Application::addViewManager( SUIT_ViewManager* vm )
586 {
587   if ( !vm )
588     return;
589
590   if ( !containsViewManager( vm ) )
591   {
592     myViewMgrs.append( vm );
593     connect( vm, SIGNAL( activated( SUIT_ViewManager* ) ),
594              this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
595     vm->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
596
597     emit viewManagerAdded( vm );
598   }
599 /*
600   if ( !activeViewManager() && myViewMgrs.count() == 1 )
601     setActiveViewManager( vm );
602 */
603 }
604
605 /*!Remove view manager from view managers list.*/
606 void STD_Application::removeViewManager( SUIT_ViewManager* vm )
607 {
608   if ( !vm )
609     return;
610
611   vm->closeAllViews();
612
613   emit viewManagerRemoved( vm );
614
615   vm->disconnectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
616   vm->disconnect();
617   myViewMgrs.removeRef( vm );
618
619   if ( myActiveViewMgr == vm )
620     myActiveViewMgr = 0;
621 }
622
623 /*!Remove all view managers from view managers list.*/
624 void STD_Application::clearViewManagers()
625 {
626   ViewManagerList lst;
627   viewManagers( lst );
628
629   for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
630     removeViewManager( it.current() );
631 }
632
633 /*!\retval TRUE, if view manager \a vm, already in view manager list (\a myViewMgrs).*/
634 bool STD_Application::containsViewManager( SUIT_ViewManager* vm ) const
635 {
636   return myViewMgrs.contains( vm ) > 0;
637 }
638
639 /*!Private slot, sets active manager to \vm, if \vm in view managers list.*/
640 void STD_Application::onViewManagerActivated( SUIT_ViewManager* vm )
641 {
642   setActiveViewManager( vm );
643 }
644
645 /*!Sets status bar show, if \on = true, else status bar hide.*/
646 void STD_Application::onViewStatusBar( bool on )
647 {
648   if ( on )
649     desktop()->statusBar()->show();
650   else
651     desktop()->statusBar()->hide();
652 }
653
654 /*!Call SUIT_MessageBox::info1(...) with about information.*/
655 void STD_Application::onHelpAbout()
656 {
657   SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
658 }
659
660 /*!Create empty study. \n
661  * Create new view manager and adding it to view managers list.
662  */
663 void STD_Application::createEmptyStudy()
664 {
665   SUIT_Application::createEmptyStudy();
666
667   SUIT_ViewManager* vm = new SUIT_ViewManager( activeStudy(), desktop(), new SUIT_ViewModel() );
668
669   addViewManager( vm );
670 }
671
672 /*!Sets active manager to \vm, if \vm in view managers list.*/
673 void STD_Application::setActiveViewManager( SUIT_ViewManager* vm )
674 {
675   if ( !containsViewManager( vm ) )
676     return;
677
678   myActiveViewMgr = vm;
679   emit viewManagerActivated( vm );
680 }
681
682 /*!Public slot. */
683 void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextMenuEvent* e )
684 {
685   QtxPopupMenu* popup = new QtxPopupMenu();
686   // fill popup by own items
687   QString title;
688   contextMenuPopup( client->popupClientType(), popup, title );
689   popup->setTitleText( title );
690
691   popup->insertSeparator();
692   // add items from popup client
693   client->contextMenuPopup( popup );
694
695   SUIT_Tools::simplifySeparators( popup );
696
697   if ( popup->count() )
698     popup->exec( e->globalPos() );
699   delete popup;
700 }
701
702 #include <qregexp.h>
703
704 /*!\retval QString - return file name from dialog.*/
705 QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
706                                       const QString& caption, QWidget* parent )
707 {
708   if ( !parent )
709     parent = desktop();
710   if ( open )
711   {
712     return QFileDialog::getOpenFileName( initial, filters, parent, 0, caption );
713   }
714   else
715   {
716     QString aName;
717     QString aUsedFilter;
718     QString anOldPath = initial;
719
720     bool isOk = false;
721     while ( !isOk )
722     {
723       // It is preferrable to use OS-specific file dialog box here !!!
724       aName = QFileDialog::getSaveFileName( anOldPath, filters, parent, 0, caption, &aUsedFilter );
725
726       if ( aName.isNull() )
727         isOk = true;
728       else
729       {
730               int aEnd = aUsedFilter.findRev( ')' );
731               int aStart = aUsedFilter.findRev( '(', aEnd );
732               QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 );
733
734         int idx = 0;
735         QStringList extList;
736         QRegExp rx( "[\b\\*]*\\.([\\w]+)" );
737         while ( ( idx = rx.search( wcStr, idx ) ) != -1 )
738         {
739           extList.append( rx.cap( 1 ) );
740           idx += rx.matchedLength();
741         }
742
743         if ( !extList.isEmpty() && !extList.contains( QFileInfo( aName ).extension() ) )
744           aName += QString( ".%1" ).arg( extList.first() );
745
746               if ( QFileInfo( aName ).exists() )
747         {
748                 int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TIT_FILE_SAVEAS" ),
749                                                                               tr( "MSG_FILE_EXISTS" ).arg( aName ),
750                                                                               tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 );
751                 if ( aAnswer == 3 )
752           {     // cancelled
753             aName = QString::null;
754                   isOk = true;
755           }
756                 else if ( aAnswer == 2 ) // not save to this file
757                   anOldPath = aName;             // not to return to the same initial dir at each "while" step
758                 else                     // overwrite the existing file
759                   isOk = true;
760         }
761               else
762                 isOk = true;
763       }
764     }
765     return aName;
766   }
767 }
768
769 /*!\retval QString - return directory name from dialog.*/
770 QString STD_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
771 {
772   if ( !parent )
773     parent = desktop();
774   return QFileDialog::getExistingDirectory( initial, parent, 0, caption, true );
775 }
776
777 void STD_Application::setDesktop( SUIT_Desktop* desk )
778 {
779   SUIT_Desktop* prev = desktop();
780
781   SUIT_Application::setDesktop( desk );
782
783   if ( prev != desk && desk )
784     connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
785              this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
786 }