Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFileSelector.cpp
index ae84af37e4f03a1397e91afc4252abe7541f3dbe..85b1772b0a036a417398a0e56e08bc68901189e3 100644 (file)
 #include <memory>
 #include <string>
 
+
+/// Default path
+static QString myDefaultPath;
+
+
 ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent,
                                                              const Config_WidgetAPI* theData)
 : ModuleBase_ModelWidget(theParent, theData), myFileDialog(0)
 {
   myTitle = translate(theData->getProperty("title"));
   myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN;
-  myDefaultPath = QString::fromStdString(theData->getProperty("path"));
+  if (myDefaultPath.isNull() || myDefaultPath.isEmpty())
+    myDefaultPath = QString::fromStdString(theData->getProperty("path"));
 
   if (myDefaultPath.isEmpty())
     myDefaultPath = Config_PropManager::string("Plugins", "import_initial_path").c_str();
@@ -139,12 +145,14 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
       ? myDefaultPath
       : QFileInfo(myPathField->text()).absolutePath();
   QString aFilter = filterString();
+
   // use Option prohibited native dialog using to have both lower/upper extensions of files
   // satisfied to dialog filter on Linux(Calibre) Issue #2055
   myFileDialog = new QFileDialog(this, myTitle, aDefaultPath, aFilter);
   myFileDialog->setNameFilter(aFilter);
   myFileDialog->setOptions(QFileDialog::DontUseNativeDialog);
-  myFileDialog->setAcceptMode(myType == WFS_SAVE ? QFileDialog::AcceptSave : QFileDialog::AcceptOpen);
+  myFileDialog->setAcceptMode(myType == WFS_SAVE ? QFileDialog::AcceptSave
+                                                 : QFileDialog::AcceptOpen);
   if (myFileDialog->exec() == QDialog::Accepted)
   {
     mySelectedFilter = myFileDialog->selectedNameFilter();
@@ -155,6 +163,7 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
         if (myType == WFS_SAVE)
           aFileName = applyExtension(aFileName, mySelectedFilter);
         myPathField->setText(aFileName);
+        myDefaultPath = QFileInfo(aFileName).absolutePath();
         emit focusOutWidget(this);
       }
     }