]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
bos #18503 Avoid adding non-existing directories to file dialog's side bar
authorvsr <vsr@opencascade.com>
Wed, 29 Jan 2020 16:31:05 +0000 (19:31 +0300)
committervsr <vsr@opencascade.com>
Wed, 29 Jan 2020 16:31:05 +0000 (19:31 +0300)
src/SUIT/SUIT_FileDlg.cxx
src/SUIT/SUIT_FileDlg.h
src/SalomeApp/resources/SalomeApp.xml

index 749c898796ff12901e9ac6c31f382a15c51be660..3da672826a8cc8aaef504e4f8787ada8deca51dd 100644 (file)
@@ -92,9 +92,8 @@
 #include <QApplication>
 #include <QListView>
 #include <QLineEdit>
-// GDD
 #include <QUrl>
-#include <QDesktopServices>
+#include <QStandardPaths>
 
 /*!
   \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<QUrl> 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.
 
index 66895e85f277b8139bb1ddab9700b5515b639f5d..159342fc4645efde46f8222637911e76f2391e7b 100644 (file)
@@ -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<QUrl>         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
 };
index 01c61f0e62066563baaa613cef414bb9de110e54..f41dcfcfde305ba7d98bc62638066fe3a24a914c 100644 (file)
     <parameter name="visibility_column_id_3" value="false" />
     <parameter name="visibility_column_id_4" value="false" />
   </section>
-  <section name="FileDlg">
-    <!-- "Open/Save File" dialog box preferences-->
-    <parameter name="QuickDirList" value="${DATA_DIR}" />
-  </section>
   <section name="Study">
     <!-- General study settings -->
     <parameter name="autoload_light_modules"     value="true" />