Salome HOME
Save dialog appears again when previous attempt not successfull.
authorstv <stv@opencascade.com>
Fri, 10 Jun 2005 05:06:56 +0000 (05:06 +0000)
committerstv <stv@opencascade.com>
Fri, 10 Jun 2005 05:06:56 +0000 (05:06 +0000)
src/STD/STD_Application.cxx
src/STD/resources/STD_msg_en.po

index 4023ea33413f7e8156bba425c186bc8877227d31..73bd2eff84c1b8c8f60bf865714207e2e519eaca 100755 (executable)
@@ -343,11 +343,17 @@ void STD_Application::onSaveDoc()
   if ( !activeStudy() )
     return;
 
+  bool isOk = false;
   if ( activeStudy()->isSaved() )
   {
-    activeStudy()->saveDocument();
-    updateCommandsStatus();
+    isOk = activeStudy()->saveDocument();
+    if ( !isOk )
+      SUIT_MessageBox::error1( desktop(), tr( "TIT_FILE_SAVEAS" ),
+                              tr( "MSG_CANT_SAVE" ).arg( activeStudy()->studyName() ), tr( "BUT_OK" ) );
   }
+
+  if ( isOk )
+    updateCommandsStatus();
   else
     onSaveAsDoc();
 }
@@ -358,50 +364,58 @@ bool STD_Application::onSaveAsDoc()
   if ( !study )
     return false;
 
-  QString aName, aUsedFilter, anOldPath = study->studyName();
-  bool isSelected = false;
-  while( !isSelected )
+  QString aName;
+  QString aUsedFilter;
+  QString anOldPath = study->studyName();
+
+  bool isOk = false;
+  while ( !isOk )
   {
     // It is preferrable to use OS-specific file dialog box here !!!
     aName = QFileDialog::getSaveFileName( anOldPath, getFileFilter(), desktop(),
                                           0, QString::null, &aUsedFilter);
 
     if ( aName.isNull() )
-      break;
-
-    if ( !getFileFilter().isNull() )
-    { // check exstension and add if it is necessary
-      int aStart = aUsedFilter.find('*');
-      int aEnd = aUsedFilter.find(')', aStart + 1);
-      QString aExt = aUsedFilter.mid(aStart + 1, aEnd - aStart - 1);
-      if (aExt.contains('*') == 0 ) {  // if it is not *.*
-        // Check that there is an extension at the end of the name
-        QString aNameTail = aName.right(aExt.length());
+      isOk = true;
+    else
+    {
+      if ( !getFileFilter().isNull() ) // check exstension and add if it is necessary
+      {
+       int aStart = aUsedFilter.find( '*' );
+       int aEnd = aUsedFilter.find( ')', aStart + 1 );
+       QString aExt = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 );
+       if ( aExt.contains( '*' ) == 0 ) // if it is not *.*
+       {
+         // Check that there is an extension at the end of the name
+         QString aNameTail = aName.right( aExt.length() );
           if ( aNameTail != aExt )
             aName += aExt;
+       }
+      }
+      if ( QFileInfo( aName ).exists() )
+      {
+       int aAnswer = SUIT_MessageBox::warn2( desktop(), tr( "TIT_FILE_SAVEAS" ),
+                                             tr( "MSG_FILE_EXISTS" ).arg( aName ),
+                                             tr( "BUT_YES" ), tr( "BUT_NO" ), 1, 2, 2 );
+       if ( aAnswer != 2 )
+         isOk = true;
+       else
+         anOldPath = aName; // Not to return to the same initial dir at each "while" step
       }
-    }
-    QFile aFile( aName );
-    if ( aFile.exists() )
-    {
-      int aAnswer = SUIT_MessageBox::warn2( desktop(), tr("TIT_FILE_SAVEAS"),
-                                                     tr("MSG_FILE_EXISTS").arg(aName),
-                                                     tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
-      if ( aAnswer != 2 )
-        isSelected = true;
       else
-        anOldPath = aName; // Not to return to the same initial dir at each "while" step
+       isOk = true;
+
+      if ( isOk )
+       isOk = study->saveDocumentAs( aName );
     }
-    else
-      isSelected = true;
   }
 
   if ( aName.isNull() ) 
     return false;
 
-  study->saveDocumentAs( aName );
   updateDesktopTitle();
   updateCommandsStatus();
+
   return true;
 }
 
index a6104c82455a544cdd4cfedc640b3f0ae5dd43d9..fa0a1473ea67cbbd279e310e76c0ba004def6080 100755 (executable)
@@ -305,6 +305,9 @@ msgstr "SUIT Std application"
 msgid "MSG_FILE_EXISTS"
 msgstr "File \"%1\" already exists.\nDo you want to continue?"
 
+msgid "MSG_CANT_SAVE"
+msgstr "Can't save file \"%1\"."
+
 msgid "TIT_FILE_SAVEAS"
 msgstr "Save As"