]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Save file dialog updated.
authorsbh <sergey.belash@opencascade.com>
Tue, 20 May 2014 12:46:11 +0000 (16:46 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 20 May 2014 12:46:11 +0000 (16:46 +0400)
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 40c545b2c2567000db3f10b3f75d8d6357be071b..85046a2db26f5ded3eb2a860dfcbd747ee9d7a83 100644 (file)
@@ -69,7 +69,7 @@ QString XGUI_Workshop::featureIcon(const std::string& theId)
 
 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   : QObject(),
-  myCurrentFile(QString()),
+  myCurrentDir(QString()),
   myPartSetModule(NULL),
   mySalomeConnector(theConnector),
   myPropertyPanel(0),
@@ -418,21 +418,21 @@ void XGUI_Workshop::onOpen()
       return;
     }
     aDoc->close();
-    myCurrentFile = "";
+    myCurrentDir = "";
   }
 
   //show file dialog, check if readable and open
-  myCurrentFile = QFileDialog::getExistingDirectory(mainWindow());
-  if(myCurrentFile.isEmpty())
+  myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
+  if(myCurrentDir.isEmpty())
     return;
-  QFileInfo aFileInfo(myCurrentFile);
+  QFileInfo aFileInfo(myCurrentDir);
   if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
-    myCurrentFile = "";
+    myCurrentDir = "";
     return;
   }
   QApplication::setOverrideCursor(Qt::WaitCursor);
-  aDoc->load(myCurrentFile.toLatin1().constData());
+  aDoc->load(myCurrentDir.toLatin1().constData());
   QApplication::restoreOverrideCursor();
   updateCommandStatus();
 }
@@ -440,28 +440,38 @@ void XGUI_Workshop::onOpen()
 //******************************************************
 void XGUI_Workshop::onSave()
 {
-  if(myCurrentFile.isEmpty()) {
+  if(myCurrentDir.isEmpty()) {
     onSaveAs();
     return;
   }
-  saveDocument(myCurrentFile);
+  saveDocument(myCurrentDir);
   updateCommandStatus();
 }
 
 //******************************************************
 void XGUI_Workshop::onSaveAs()
 {
-  QString aTemp = myCurrentFile;
-  myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
-  if(myCurrentFile.isEmpty()) {
-    myCurrentFile = aTemp;
+  QFileDialog dialog(mainWindow());
+  dialog.setWindowTitle(tr("Select directory to save files..."));
+  dialog.setFileMode(QFileDialog::Directory);
+  dialog.setFilter(tr("Folders (*)"));
+  dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
+  dialog.setViewMode(QFileDialog::Detail);
+
+  if(!dialog.exec()) {
     return;
   }
-  QFileInfo aFileInfo(myCurrentFile);
-  if(aFileInfo.exists() && !aFileInfo.isWritable()) {
-    QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
-    return;
+  QString aTempDir = dialog.selectedFiles().first();
+  QDir aDir(aTempDir);
+  if(aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).isEmpty()) {
+    int answer = QMessageBox::question(myMainWindow,
+                                       QString(),
+                                       tr("The folder already contains some files, save anyway?"),
+                                       QMessageBox::Save|QMessageBox::Cancel);
+    if(answer == QMessageBox::Cancel)
+      return;
   }
+  myCurrentDir = aTempDir;
   onSave();
 }
 
index cd77d3b13a29f56584cbca2bba009767b65366de..306e6d644b57d3e54cd3778312940e13b5ad445e 100644 (file)
@@ -156,7 +156,7 @@ private:
   //! Activates or deactivates currently selected part
   void activatePart(bool toActivate);
 
-  QString myCurrentFile;
+  QString myCurrentDir;
   XGUI_MainWindow* myMainWindow;
   XGUI_Module* myPartSetModule;
   XGUI_ObjectsBrowser* myObjectBrowser;