Core: Use a consistent initial directory in open/save/locator

Use fileDialogInitialDirectory() for all of them.

Conditionally initialize lastVisitedDirectory to projects directory to
preserve existing behavior on Open, when no project is open yet.

Change-Id: I318a7c7741e70a68758f0cc068ce956135103f3f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Orgad Shaneh
2016-05-01 10:19:45 +03:00
committed by Orgad Shaneh
parent cc80ba2a7e
commit 08f807a134
2 changed files with 6 additions and 14 deletions

View File

@@ -229,6 +229,9 @@ DocumentManager::DocumentManager(QObject *parent)
qApp->installEventFilter(this); qApp->installEventFilter(this);
readSettings(); readSettings();
if (d->m_useProjectsDirectory)
setFileDialogLastVisitedDirectory(d->m_projectsDirectory);
} }
DocumentManager::~DocumentManager() DocumentManager::~DocumentManager()
@@ -886,13 +889,7 @@ QStringList DocumentManager::getOpenFileNames(const QString &filters,
const QString &pathIn, const QString &pathIn,
QString *selectedFilter) QString *selectedFilter)
{ {
QString path = pathIn; const QString &path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
if (path.isEmpty()) {
if (EditorManager::currentDocument() && !EditorManager::currentDocument()->isTemporary())
path = EditorManager::currentDocument()->filePath().toString();
if (path.isEmpty() && useProjectsDirectory())
path = projectsDirectory();
}
const QStringList files = QFileDialog::getOpenFileNames(ICore::dialogParent(), const QStringList files = QFileDialog::getOpenFileNames(ICore::dialogParent(),
tr("Open File"), tr("Open File"),
path, filters, path, filters,

View File

@@ -26,6 +26,7 @@
#include "filesystemfilter.h" #include "filesystemfilter.h"
#include "locatorwidget.h" #include "locatorwidget.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
@@ -63,13 +64,7 @@ FileSystemFilter::FileSystemFilter(LocatorWidget *locatorWidget)
void FileSystemFilter::prepareSearch(const QString &entry) void FileSystemFilter::prepareSearch(const QString &entry)
{ {
Q_UNUSED(entry) Q_UNUSED(entry)
IDocument *document= EditorManager::currentDocument(); m_currentDocumentDirectory = DocumentManager::fileDialogInitialDirectory();
if (document && !document->filePath().isEmpty()) {
const QFileInfo info = document->filePath().toFileInfo();
m_currentDocumentDirectory = info.absolutePath() + QLatin1Char('/');
} else {
m_currentDocumentDirectory.clear();
}
} }
QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,