From: stv Date: Fri, 10 Jun 2005 05:06:56 +0000 (+0000) Subject: Save dialog appears again when previous attempt not successfull. X-Git-Tag: T3_0_0_a3~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c1e771d77fdb92cf7635ab9dc54f0e6e34bbe66f;p=modules%2Fgui.git Save dialog appears again when previous attempt not successfull. --- diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 4023ea334..73bd2eff8 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -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; } diff --git a/src/STD/resources/STD_msg_en.po b/src/STD/resources/STD_msg_en.po index a6104c824..fa0a1473e 100755 --- a/src/STD/resources/STD_msg_en.po +++ b/src/STD/resources/STD_msg_en.po @@ -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"