From face029990b428287506bf9af2d6b841586fd38e Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 29 Jan 2020 19:31:05 +0300 Subject: [PATCH] bos #18503 Avoid adding non-existing directories to file dialog's side bar --- src/SUIT/SUIT_FileDlg.cxx | 51 ++++++++++++++++++--------- src/SUIT/SUIT_FileDlg.h | 9 ++--- src/SalomeApp/resources/SalomeApp.xml | 4 --- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/SUIT/SUIT_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 749c89879..3da672826 100644 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -92,9 +92,8 @@ #include #include #include -// GDD #include -#include +#include /*! \brief Defines extension behavior. @@ -130,11 +129,10 @@ SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool if ( parent ) setWindowIcon( parent->windowIcon() ); - // GDD - myUrls.insert(0,QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation))); - myUrls.insert(0,QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))); - - setSidebarUrls(myUrls); + // standard side bar URLs + myUrls << QStandardPaths::writableLocation( QStandardPaths::ApplicationsLocation ); + myUrls << QStandardPaths::writableLocation( QStandardPaths::HomeLocation ); + myUrls << qgetenv( "DATA_DIR" ); // add quick directories widgets if ( showQuickDir ) { @@ -155,15 +153,12 @@ SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool if ( dirList.isEmpty() ) dirList << QDir::homePath(); - // GDD for ( int i = 0; i < dirList.count(); i++ ) { + // add to combo box myQuickCombo->addItem( dirList[i] ); - myUrls.append(QUrl::fromLocalFile(dirList[i])); + // add to side bar + myUrls << dirList[i]; } - - // GDD - setSidebarUrls(myUrls); - } else { delete myQuickLab; myQuickLab = 0; @@ -172,6 +167,9 @@ SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool } } + // update side bar + updateSideBar(); + setAcceptMode( open ? AcceptOpen: AcceptSave ); setWindowTitle( open ? tr( "INF_DESK_DOC_OPEN" ) : tr( "INF_DESK_DOC_SAVE" ) ); @@ -682,14 +680,18 @@ void SUIT_FileDlg::addQuickDir() } if ( !found ) { - dirList.append( dp ); + dirList << dp; resMgr->setValue( "FileDlg", "QuickDirList", dirList.join( ";" ) ); - // GDD + if ( !emptyAndHome ) { + // add to combo box myQuickCombo->addItem( dp ); - myUrls.append(QUrl::fromLocalFile( dp )); - setSidebarUrls(myUrls); + // add to side bar + myUrls << dp; } + + // update side bar + updateSideBar(); } } } @@ -721,6 +723,21 @@ void SUIT_FileDlg::polish() } } +/*! + \brief Update side bar URLs list +*/ +void SUIT_FileDlg::updateSideBar() +{ + QList urls; + + foreach ( QString url, myUrls ) { + if ( !url.isEmpty() && QFileInfo( url ).exists() ) + urls << QUrl::fromLocalFile( url ); + } + + setSidebarUrls( urls ); +} + /*! \brief Show dialog box for the file opening/saving. diff --git a/src/SUIT/SUIT_FileDlg.h b/src/SUIT/SUIT_FileDlg.h index 66895e85f..159342fc4 100644 --- a/src/SUIT/SUIT_FileDlg.h +++ b/src/SUIT/SUIT_FileDlg.h @@ -114,13 +114,14 @@ protected slots: private: void polish(); + void updateSideBar(); private: SUIT_FileValidator* myValidator; //!< file validator - QLabel* myQuickLab; //!< quick dir combo box - QComboBox* myQuickCombo; //!< quick dir combo box - QList myUrls; //!< quick dir Sidebar Urls - QPushButton* myQuickButton; //!< quick dir add button + QLabel* myQuickLab; //!< quick dir panel: label + QComboBox* myQuickCombo; //!< quick dir panel: combo box + QPushButton* myQuickButton; //!< quick dir panel: button + QStringList myUrls; //!< sidebar urls bool myCheckPermissions; //!< check permissions option static QString myLastVisitedPath; //!< last visited path }; diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index 01c61f0e6..f41dcfcfd 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -25,10 +25,6 @@ -
- - -
-- 2.39.2