+/*! Purpose : SLOT. Open new document with \a aName.*/
+bool SalomeApp_Application::onOpenDoc( const QString& aName )
+{
+ bool res = false, toOpen = true, isAlreadyOpen = false;
+
+ // Look among opened studies
+ if (activeStudy()) { // at least one study is opened
+ SUIT_Session* aSession = SUIT_Session::session();
+ QPtrList<SUIT_Application> aAppList = aSession->applications();
+ QPtrListIterator<SUIT_Application> it (aAppList);
+ SUIT_Application* aApp = 0;
+ // iterate on all applications
+ for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
+ if (aApp->activeStudy()->studyName() == aName) {
+ isAlreadyOpen = true; // Already opened, ask user what to do
+
+ // The document ... is already open.
+ // Do you want to reload it?
+ int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
+ tr("QUE_DOC_ALREADYOPEN").arg(aName),
+ tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
+ if (aAnswer == 1) { // reload
+ if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
+ // Opened in THIS (active) application.
+ STD_Application* app1 = (STD_Application*)aAppList.at(0);
+ STD_Application* app2 = (STD_Application*)aAppList.at(1);
+ if (!app1 || !app2) {
+ // Error
+ return false;
+ }
+ if (app1->activeStudy()->studyName() == aName) {
+ // app1 is this application, we need another one
+ app1 = app2;
+ }
+ // Close document of this application. This application will be destroyed.
+ onCloseDoc(/*ask = */false);
+ // Open the file with another application, as this one will be destroyed.
+ return app1->onOpenDoc(aName);
+ } else {
+ // Opened in another application.
+ STD_Application* app = (STD_Application*)aApp;
+ if (app)
+ app->onCloseDoc(/*ask = */false);
+ }
+ } else { // do not reload
+ // OK, the study will not be reloaded, but we call
+ // CAM_Application::onOpenDoc( aName ) all the same.
+ // It will activate a desktop of the study <aName>.
+ }
+ }
+ }