forked from qt-creator/qt-creator
Fix default wrong directory if no files are open in the editor
Task-number: QTCREATORBUG-13831 Change-Id: Iaeb11014ed16bc9f08d7c12d81c1b7b8a4163d21 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -156,6 +156,7 @@ struct DocumentManagerPrivate
|
||||
QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen).
|
||||
bool m_blockActivated;
|
||||
QString m_lastVisitedDirectory;
|
||||
QString m_defaultLocationForNewFiles;
|
||||
QString m_projectsDirectory;
|
||||
bool m_useProjectsDirectory;
|
||||
QString m_buildDirectory;
|
||||
@@ -1243,18 +1244,41 @@ void readSettings()
|
||||
/*!
|
||||
|
||||
Returns the initial directory for a new file dialog. If there is
|
||||
a current file, uses that, otherwise uses the last visited directory.
|
||||
a current file, uses that, otherwise if there is a default location for
|
||||
new files, uses that, otherwise uses the last visited directory.
|
||||
|
||||
\sa setFileDialogLastVisitedDirectory
|
||||
\sa setDefaultLocationForNewFiles
|
||||
*/
|
||||
|
||||
QString DocumentManager::fileDialogInitialDirectory()
|
||||
{
|
||||
if (EditorManager::currentDocument() && !EditorManager::currentDocument()->isTemporary())
|
||||
return QFileInfo(EditorManager::currentDocument()->filePath().toString()).absolutePath();
|
||||
if (!d->m_defaultLocationForNewFiles.isEmpty())
|
||||
return d->m_defaultLocationForNewFiles;
|
||||
return d->m_lastVisitedDirectory;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Sets the default location for new files
|
||||
|
||||
\sa fileDialogInitialDirectory
|
||||
*/
|
||||
QString DocumentManager::defaultLocationForNewFiles()
|
||||
{
|
||||
return d->m_defaultLocationForNewFiles;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the default location for new files
|
||||
*/
|
||||
void DocumentManager::setDefaultLocationForNewFiles(const QString &location)
|
||||
{
|
||||
d->m_defaultLocationForNewFiles = location;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Returns the directory for projects. Defaults to HOME.
|
||||
|
@@ -125,6 +125,9 @@ public:
|
||||
|
||||
static QString fileDialogInitialDirectory();
|
||||
|
||||
static QString defaultLocationForNewFiles();
|
||||
static void setDefaultLocationForNewFiles(const QString &location);
|
||||
|
||||
static bool useProjectsDirectory();
|
||||
static void setUseProjectsDirectory(bool);
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/documentmanager.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
@@ -72,6 +73,13 @@ ProjectTree::ProjectTree(QObject *parent)
|
||||
|
||||
connect(qApp, &QApplication::focusChanged,
|
||||
this, &ProjectTree::focusChanged);
|
||||
|
||||
connect(SessionManager::instance(), &SessionManager::projectAdded,
|
||||
this, &ProjectTree::updateDefaultLocationForNewFiles);
|
||||
connect(SessionManager::instance(), &SessionManager::projectRemoved,
|
||||
this, &ProjectTree::updateDefaultLocationForNewFiles);
|
||||
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
||||
this, &ProjectTree::updateDefaultLocationForNewFiles);
|
||||
}
|
||||
|
||||
void ProjectTree::aboutToShutDown()
|
||||
@@ -215,9 +223,20 @@ void ProjectTree::update(Node *node, Project *project)
|
||||
|
||||
emit currentProjectChanged(m_currentProject);
|
||||
|
||||
updateDefaultLocationForNewFiles();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
void ProjectTree::updateDefaultLocationForNewFiles()
|
||||
{
|
||||
if (m_currentProject)
|
||||
Core::DocumentManager::setDefaultLocationForNewFiles(m_currentProject->projectDirectory().toString());
|
||||
else if (SessionManager::startupProject())
|
||||
Core::DocumentManager::setDefaultLocationForNewFiles(SessionManager::startupProject()->projectDirectory().toString());
|
||||
else
|
||||
Core::DocumentManager::setDefaultLocationForNewFiles(QString());
|
||||
}
|
||||
|
||||
void ProjectTree::updateContext()
|
||||
{
|
||||
Core::Context oldContext;
|
||||
|
@@ -130,6 +130,7 @@ public: // for nodes to emit signals, do not call unless you are a node
|
||||
void collapseAll();
|
||||
|
||||
private:
|
||||
void updateDefaultLocationForNewFiles();
|
||||
void focusChanged();
|
||||
void updateFromProjectTreeWidget(Internal::ProjectTreeWidget *widget);
|
||||
void documentManagerCurrentFileChanged();
|
||||
|
Reference in New Issue
Block a user