View Issue Details

IDProjectCategoryView StatusLast Update
0001675DraftBugpublic2015-01-05 22:44
Reportermghansen256Assigned Toyorik 
PrioritylowSeveritytrivialReproducibilityalways
Status closedResolutionfixed 
PlatformLinuxOSKubuntuOS Version14.04
Product Version0.14 
Target VersionFixed in Version0.15 
Summary0001675: File selection dialog for texture image starts in /usr/lib/freecad
DescriptionThe file selection dialog for the texture image for draft rectangles starts in /usr/lib/freecad. IMHO it would be useful to start it in the directory of the freecad document, then, assuming that images are located close to that document's file, the user does not have to navigate there.
Additional InformationOS: Ubuntu 14.04.1 LTS
Word size: 64-bit
Version: 0.15.3844 (Git)
Branch: master
Hash: 28490532f50135e2490f94cdf401b613a94b1ec2
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.0
TagsNo tags attached.

Activities

yorik

2014-08-08 19:25

administrator   ~0004930

Not sure how easy this is to do, but I'll have a look.

mghansen256

2014-08-18 19:44

reporter   ~0004962

Hi Yorik,

I made a pull request for this one:

https://github.com/FreeCAD/FreeCAD_sf_master/pull/31

I will also attach the patch.

Best regards,

Michael

mghansen256

2014-08-18 19:46

reporter  

1675-patch.diff (1,503 bytes)
diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp
index af58991..50b6a94 100644
--- a/src/Gui/FileDialog.cpp
+++ b/src/Gui/FileDialog.cpp
@@ -38,6 +38,7 @@
 
 #include <Base/Parameter.h>
 #include <App/Application.h>
+#include <App/Document.h>
 
 #include "FileDialog.h"
 #include "MainWindow.h"
@@ -525,11 +526,24 @@ void FileChooser::setFileName( const QString& s )
  */
 void FileChooser::chooseFile()
 {
+    QString prechosenDirectory = lineEdit->text();
+    if (prechosenDirectory.isEmpty()) {
+        App::Document* const doc = App::GetApplication().getActiveDocument();
+        const QString filename = QString::fromStdString(doc->FileName.getStrValue());
+
+        // if the document has no filename yet, start browsing in the users home directory
+        if (!filename.isEmpty()) {
+            prechosenDirectory = filename;
+        } else {
+            prechosenDirectory = QDir::homePath();
+        }
+    }
+
     QString fn;
     if ( mode() == File )
-        fn = QFileDialog::getOpenFileName( this, tr( "Select a file" ), lineEdit->text(), _filter );
+        fn = QFileDialog::getOpenFileName( this, tr( "Select a file" ), prechosenDirectory, _filter );
     else
-        fn = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), lineEdit->text() );
+        fn = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), prechosenDirectory );
 
     if (!fn.isEmpty()) {
         lineEdit->setText(fn);
1675-patch.diff (1,503 bytes)

wmayer

2014-08-19 13:46

administrator   ~0004971

https://github.com/mghansen256/FreeCAD_sf_master/commit/bff32fb6fb7b0260ba1c4cc1dd33d25fe908a19e

IMO, it's not a good idea to make a widget dependent on the document stuff. A better way could be to add a further Q_PROPERTY where the pre-chosen directory/file can be set from outside. This makes the usage of this widget more flexible.

Btw, your patch will lead to a crash when there is no document open.

mghansen256

2014-11-25 20:37

reporter   ~0005343

Hi wmayer,

thank you for the note about the crash. I updated the pull request to use FileDialog::getWorkingDirectory() to get an initial directory, then no new dependencies are introduced. The only drawback is that now the directory is taken from the last opened file, but still better than before.

Michael

Related Changesets

FreeCAD: master be919bb6

2015-01-05 22:58:54

mghansen256


Committer: wmayer Details Diff
Use the FreeCAD's working directory as initial directory for FileChooser. Affected Issues
0001675
mod - src/Gui/FileDialog.cpp Diff File

Issue History

Date Modified Username Field Change
2014-08-08 18:44 mghansen256 New Issue
2014-08-08 19:24 yorik Assigned To => yorik
2014-08-08 19:24 yorik Status new => assigned
2014-08-08 19:25 yorik Note Added: 0004930
2014-08-18 19:44 mghansen256 Note Added: 0004962
2014-08-18 19:46 mghansen256 File Added: 1675-patch.diff
2014-08-19 13:46 wmayer Note Added: 0004971
2014-09-18 13:39 yorik Status assigned => feedback
2014-11-25 20:37 mghansen256 Note Added: 0005343
2014-11-25 20:37 mghansen256 Status feedback => assigned
2015-01-05 22:44 wmayer Changeset attached => FreeCAD Master master be919bb6
2015-01-05 22:44 wmayer Status assigned => closed
2015-01-05 22:44 wmayer Resolution open => fixed
2015-01-05 22:44 wmayer Fixed in Version => 0.15