From: vsr Date: Fri, 17 Jun 2005 05:53:26 +0000 (+0000) Subject: getFileName() function is defined as pure virtual public in the SUIT_Application... X-Git-Tag: T3_0_0_a4~99 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cdf54cac61b806165bb0a6921bf46b871456ec4d;p=modules%2Fgui.git getFileName() function is defined as pure virtual public in the SUIT_Application class to be used from all packages in order to unify Open/Save dialog boxes throughout in the application. --- diff --git a/src/LogWindow/LogWindow.cxx b/src/LogWindow/LogWindow.cxx index a676a7645..0b846b720 100755 --- a/src/LogWindow/LogWindow.cxx +++ b/src/LogWindow/LogWindow.cxx @@ -27,9 +27,9 @@ #include #include #include +#include #include -#include #include #include #include @@ -214,33 +214,23 @@ void LogWindow::updateActions() void LogWindow::onSaveToFile() { - QString aUsedFilter; - QString aName = QFileDialog::getSaveFileName( QString::null, QString( "*.log" ), this, - 0, QString::null, &aUsedFilter ); - if ( aName.isNull() ) + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if ( !app ) return; - int aStart = aUsedFilter.find('*'); - int aEnd = aUsedFilter.find(')', aStart + 1); - QString aExt = aUsedFilter.mid(aStart + 1, aEnd - aStart - 1); - if ( aExt.contains('*') == 0 ) - { - if ( aName.contains( aExt, false ) == 0 ) - aName += aExt; - } - + // call application-specific "Save file" dialog box + QString aName = app->getFileName( false, QString::null, QString( "*.log" ), QString::null, 0 ); + if ( aName.isNull() ) + return; - if ( !aName.isNull() ) - { - QApplication::setOverrideCursor( Qt::waitCursor ); + QApplication::setOverrideCursor( Qt::waitCursor ); - bool bOk = saveLog( aName ); + bool bOk = saveLog( aName ); - QApplication::restoreOverrideCursor(); + QApplication::restoreOverrideCursor(); - if ( !bOk ) - SUIT_MessageBox::error1( this, tr( "Error" ), tr( "Can't save file" ), tr( "OK" ) ); - } + if ( !bOk ) + SUIT_MessageBox::error1( this, tr( "Error" ), tr( "Can't save file" ), tr( "OK" ) ); } void LogWindow::onSelectAll() diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 3ad2b67fa..89427f76a 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -225,7 +225,7 @@ void STD_Application::onNewDoc() void STD_Application::onOpenDoc() { // It is preferrable to use OS-specific file dialog box here !!! - QString aName = getFileName( true ); + QString aName = getFileName( true, QString::null, getFileFilter(), QString::null, 0 ); if ( aName.isNull() ) return; @@ -364,7 +364,7 @@ bool STD_Application::onSaveAsDoc() if ( !study ) return false; - QString aName = getFileName( false ); + QString aName = getFileName( false, study->studyName(), getFileFilter(), QString::null, 0 ); if ( aName.isNull() ) return false; @@ -590,25 +590,28 @@ void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextM delete popup; } -QString STD_Application::getFileName( bool open ) +QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) { + if ( !parent ) + parent = desktop(); + QStringList fls = QStringList::split( ";", filters, false ); if ( open ) { - return QFileDialog::getOpenFileName( QString::null, getFileFilter(), desktop() ); + return QFileDialog::getOpenFileName( initial, fls.join( ";;" ), parent, 0, caption ); } else { - SUIT_Study* study = activeStudy(); QString aName; QString aUsedFilter; - QString anOldPath = study->studyName(); + QString anOldPath = initial; 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); + aName = QFileDialog::getSaveFileName( anOldPath, fls.join( ";;" ), parent, + 0, caption, &aUsedFilter); if ( aName.isNull() ) isOk = true; diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index bb8c25a02..a8d4a1fe5 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -56,6 +56,8 @@ public: void viewManagers( const QString&, ViewManagerList& ) const; virtual QString getFileFilter() const { return QString::null; } + QString getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ); virtual void start(); @@ -99,8 +101,6 @@ protected: virtual void setActiveViewManager( SUIT_ViewManager* ); - virtual QString getFileName( bool ); - private: ViewManagerList myViewMgrs; SUIT_ViewManager* myActiveViewMgr; diff --git a/src/STD/resources/STD_msg_en.po b/src/STD/resources/STD_msg_en.po index fa0a1473e..8a917960b 100755 --- a/src/STD/resources/STD_msg_en.po +++ b/src/STD/resources/STD_msg_en.po @@ -303,7 +303,7 @@ msgid "STD_Application::ABOUT_INFO" msgstr "SUIT Std application" msgid "MSG_FILE_EXISTS" -msgstr "File \"%1\" already exists.\nDo you want to continue?" +msgstr "File \"%1\" already exists.\nDo you want to overwrite it?" msgid "MSG_CANT_SAVE" msgstr "Can't save file \"%1\"." diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 5ef047b62..bd2f6c776 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -69,6 +69,10 @@ public: //! Puts the message to the status bar void putInfo ( const QString&, const int = 0 ); + //! Invokes application-specific "Open/Save" file dialog and returns the selected file name. + virtual QString getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) = 0; + signals: void applicationClosed( SUIT_Application* ); void activated( SUIT_Application* ); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 6063e1fa7..467b1ff55 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1124,10 +1124,11 @@ void SalomeApp_Application::onProperties() //study->updateCaptions(); } -QString SalomeApp_Application::getFileName( bool open ) +QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) { - QStringList filtersList; - filtersList.append( getFileFilter() ); - QString initial = open ? QString( "" ) : ( activeStudy() ? activeStudy()->studyName() : QString( "" ) ); - return SUIT_FileDlg::getFileName( desktop(), initial, filtersList, QString::null, open, true ); + if ( !parent ) + parent = desktop(); + QStringList fls = QStringList::split( ";", filters, false ); + return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true ); } diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index b6328e688..adb93cb4e 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -74,6 +74,9 @@ public: QtxResourceEdit* resourceEdit() const; virtual QString getFileFilter() const; + QString getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ); + SUIT_ViewManager* getViewManager( const QString&, const bool ); void updateActions(); @@ -125,8 +128,6 @@ protected: virtual void beforeCloseDoc( SUIT_Study* ); virtual void afterCloseDoc(); - virtual QString getFileName( bool ); - private slots: void onNewWindow(); void onModuleActivation( QAction* );