issue #0001588: File browser dialogs initial starting directory ignores current working directory
This commit is contained in:
parent
43eb0899db
commit
b322668d4e
|
@ -1630,9 +1630,12 @@ void Application::runApplication(void)
|
|||
QIcon::setThemeName(QLatin1String("FreeCAD-default"));
|
||||
#endif
|
||||
|
||||
//#if defined(FC_OS_LINUX)
|
||||
// FileDialog::setWorkingDirectory(QDir::currentPath());
|
||||
//#endif
|
||||
#if defined(FC_OS_LINUX)
|
||||
// See #0001588
|
||||
FileDialog::setWorkingDirectory(QDir::currentPath());
|
||||
#else
|
||||
FileDialog::setWorkingDirectory(FileDialog::restoreLocation());
|
||||
#endif
|
||||
|
||||
Application app(true);
|
||||
MainWindow mw;
|
||||
|
|
|
@ -158,7 +158,7 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
|||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
urls << QUrl::fromLocalFile(getWorkingDirectory());
|
||||
urls << QUrl::fromLocalFile(QDir::currentPath());
|
||||
urls << QUrl::fromLocalFile(restoreLocation());
|
||||
|
||||
QString file;
|
||||
FileDialog dlg(parent);
|
||||
|
@ -238,7 +238,7 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c
|
|||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
urls << QUrl::fromLocalFile(getWorkingDirectory());
|
||||
urls << QUrl::fromLocalFile(QDir::currentPath());
|
||||
urls << QUrl::fromLocalFile(restoreLocation());
|
||||
|
||||
QString file;
|
||||
FileDialog dlg(parent);
|
||||
|
@ -297,7 +297,7 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt
|
|||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
urls << QUrl::fromLocalFile(getWorkingDirectory());
|
||||
urls << QUrl::fromLocalFile(QDir::currentPath());
|
||||
urls << QUrl::fromLocalFile(restoreLocation());
|
||||
|
||||
QStringList files;
|
||||
FileDialog dlg(parent);
|
||||
|
@ -330,6 +330,8 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt
|
|||
return files;
|
||||
}
|
||||
|
||||
QString FileDialog::workingDirectory;
|
||||
|
||||
/**
|
||||
* Returns the working directory for the file dialog. This path can be used in
|
||||
* combination with getSaveFileName(), getOpenFileName(), getOpenFileNames() or
|
||||
|
@ -337,14 +339,7 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt
|
|||
*/
|
||||
QString FileDialog::getWorkingDirectory()
|
||||
{
|
||||
std::string path = App::GetApplication().Config()["UserHomePath"];
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")->GetGroup("General");
|
||||
std::string dir = hPath->GetASCII("FileOpenSavePath", path.c_str());
|
||||
QFileInfo fi(QString::fromUtf8(dir.c_str()));
|
||||
if (!fi.exists())
|
||||
dir = path;
|
||||
return QString::fromUtf8(dir.c_str());
|
||||
return workingDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,6 +358,32 @@ void FileDialog::setWorkingDirectory(const QString& dir)
|
|||
dirName = info.absoluteFilePath();
|
||||
}
|
||||
|
||||
workingDirectory = dirName;
|
||||
saveLocation(dirName);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Return the last location where a file save or load dialog was used.
|
||||
* \return QString
|
||||
*/
|
||||
QString FileDialog::restoreLocation()
|
||||
{
|
||||
std::string path = App::GetApplication().Config()["UserHomePath"];
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")->GetGroup("General");
|
||||
std::string dir = hPath->GetASCII("FileOpenSavePath", path.c_str());
|
||||
QFileInfo fi(QString::fromUtf8(dir.c_str()));
|
||||
if (!fi.exists())
|
||||
dir = path;
|
||||
return QString::fromUtf8(dir.c_str());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Save the last location where a file save or load dialog was used.
|
||||
* \param dirName
|
||||
*/
|
||||
void FileDialog::saveLocation(const QString& dirName)
|
||||
{
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")->GetGroup("General");
|
||||
hPath->SetASCII("FileOpenSavePath", dirName.toUtf8());
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
#include <QFileDialog>
|
||||
#include <QFileIconProvider>
|
||||
#include <QFileSystemModel>
|
||||
#include <QCompleter>
|
||||
#include <QFileSystemModel>
|
||||
#include <QCompleter>
|
||||
|
||||
class QButtonGroup;
|
||||
class QGridLayout;
|
||||
|
@ -56,19 +56,24 @@ public:
|
|||
static QStringList getOpenFileNames( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(),
|
||||
const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0 );
|
||||
|
||||
/*! Return the last directory a file was read from or saved to. */
|
||||
static QString getWorkingDirectory();
|
||||
/*! Set the directory a file was read from or saved to. */
|
||||
static void setWorkingDirectory( const QString& );
|
||||
static QString restoreLocation();
|
||||
static void saveLocation(const QString&);
|
||||
|
||||
FileDialog(QWidget * parent = 0);
|
||||
~FileDialog();
|
||||
|
||||
void accept();
|
||||
|
||||
private:
|
||||
bool hasSuffix(const QString&) const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onSelectedFilter(const QString&);
|
||||
|
||||
private:
|
||||
bool hasSuffix(const QString&) const;
|
||||
static QString workingDirectory;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -180,8 +185,8 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
QLineEdit *lineEdit;
|
||||
QCompleter *completer;
|
||||
QFileSystemModel *fs_model;
|
||||
QCompleter *completer;
|
||||
QFileSystemModel *fs_model;
|
||||
QPushButton *button;
|
||||
Mode md;
|
||||
QString _filter;
|
||||
|
|
Loading…
Reference in New Issue
Block a user