Commit f292a5e4 authored by Eike Ziller's avatar Eike Ziller

Add projects directory to folder navigation widget

Change-Id: Ia925fa99ba0f11be860f214e7809731ddf990268
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 716808d9
......@@ -1365,7 +1365,10 @@ FileName DocumentManager::projectsDirectory()
void DocumentManager::setProjectsDirectory(const FileName &directory)
{
d->m_projectsDirectory = directory;
if (d->m_projectsDirectory != directory) {
d->m_projectsDirectory = directory;
emit m_instance->projectsDirectoryChanged(d->m_projectsDirectory);
}
}
/*!
......
......@@ -146,6 +146,7 @@ signals:
void allDocumentsRenamed(const QString &from, const QString &to);
/// emitted if one document changed its name e.g. due to save as
void documentRenamed(Core::IDocument *document, const QString &from, const QString &to);
void projectsDirectoryChanged(const Utils::FileName &directory);
protected:
bool eventFilter(QObject *obj, QEvent *e);
......
......@@ -27,6 +27,7 @@
#include "projectexplorer.h"
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/fileiconprovider.h>
......@@ -56,6 +57,8 @@
const int PATH_ROLE = Qt::UserRole;
const int ID_ROLE = Qt::UserRole + 1;
const char PROJECTSDIRECTORYROOT_ID[] = "A.Projects";
namespace ProjectExplorer {
namespace Internal {
......@@ -167,7 +170,7 @@ void FolderNavigationWidget::toggleAutoSynchronization()
setAutoSynchronization(!m_autoSync);
}
void FolderNavigationWidget::addRootDirectory(
void FolderNavigationWidget::insertRootDirectory(
const FolderNavigationWidgetFactory::RootDirectory &directory)
{
// insert sorted
......@@ -175,10 +178,13 @@ void FolderNavigationWidget::addRootDirectory(
while (index < m_rootSelector->count()
&& m_rootSelector->itemData(index, ID_ROLE).toString() < directory.id)
++index;
m_rootSelector->insertItem(index, directory.displayName);
if (m_rootSelector->itemData(index, ID_ROLE).toString() != directory.id)
m_rootSelector->insertItem(index, directory.displayName);
m_rootSelector->setItemData(index, qVariantFromValue(directory.path), PATH_ROLE);
m_rootSelector->setItemData(index, directory.id, ID_ROLE);
m_rootSelector->setItemData(index, directory.path.toUserOutput(), Qt::ToolTipRole);
if (m_rootSelector->currentIndex() == index)
setRootDirectory(directory.path);
if (m_autoSync) // we might find a better root for current selection now
setCurrentEditor(Core::EditorManager::currentEditor());
}
......@@ -351,22 +357,27 @@ FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
setPriority(400);
setId("File System");
setActivationSequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Y") : tr("Alt+Y")));
addRootDirectory(
insertRootDirectory(
{QLatin1String("A.Computer"), FolderNavigationWidget::tr("Computer"), Utils::FileName()});
addRootDirectory({QLatin1String("A.Home"),
FolderNavigationWidget::tr("Home"),
Utils::FileName::fromString(QDir::homePath())});
insertRootDirectory({QLatin1String("A.Home"),
FolderNavigationWidget::tr("Home"),
Utils::FileName::fromString(QDir::homePath())});
updateProjectsDirectoryRoot();
connect(Core::DocumentManager::instance(),
&Core::DocumentManager::projectsDirectoryChanged,
this,
&FolderNavigationWidgetFactory::updateProjectsDirectoryRoot);
}
Core::NavigationView FolderNavigationWidgetFactory::createWidget()
{
auto fnw = new FolderNavigationWidget;
for (const RootDirectory &root : m_rootDirectories)
fnw->addRootDirectory(root);
fnw->insertRootDirectory(root);
connect(this,
&FolderNavigationWidgetFactory::rootDirectoryAdded,
fnw,
&FolderNavigationWidget::addRootDirectory);
&FolderNavigationWidget::insertRootDirectory);
connect(this,
&FolderNavigationWidgetFactory::rootDirectoryRemoved,
fnw,
......@@ -404,20 +415,34 @@ void FolderNavigationWidgetFactory::restoreSettings(QSettings *settings, int pos
fnw->setAutoSynchronization(settings->value(baseKey + QLatin1String(".SyncWithEditor"), true).toBool());
}
void FolderNavigationWidgetFactory::addRootDirectory(const RootDirectory &directory)
void FolderNavigationWidgetFactory::insertRootDirectory(const RootDirectory &directory)
{
m_rootDirectories.append(directory);
const int index = rootIndex(directory.id);
if (index < 0)
m_rootDirectories.append(directory);
emit m_instance->rootDirectoryAdded(directory);
}
void FolderNavigationWidgetFactory::removeRootDirectory(const QString &id)
{
const int index = Utils::indexOf(m_rootDirectories,
[id](const RootDirectory &entry) { return entry.id == id; });
const int index = rootIndex(id);
QTC_ASSERT(index >= 0, return );
m_rootDirectories.removeAt(index);
emit m_instance->rootDirectoryRemoved(id);
}
int FolderNavigationWidgetFactory::rootIndex(const QString &id)
{
return Utils::indexOf(m_rootDirectories,
[id](const RootDirectory &entry) { return entry.id == id; });
}
void FolderNavigationWidgetFactory::updateProjectsDirectoryRoot()
{
insertRootDirectory({QLatin1String(PROJECTSDIRECTORYROOT_ID),
FolderNavigationWidget::tr("Projects"),
Core::DocumentManager::projectsDirectory()});
}
} // namespace Internal
} // namespace ProjectExplorer
......@@ -63,7 +63,7 @@ public:
void saveSettings(QSettings *settings, int position, QWidget *widget) override;
void restoreSettings(QSettings *settings, int position, QWidget *widget) override;
static void addRootDirectory(const RootDirectory &directory);
static void insertRootDirectory(const RootDirectory &directory);
static void removeRootDirectory(const QString &id);
signals:
......@@ -71,6 +71,8 @@ signals:
void rootDirectoryRemoved(const QString &id);
private:
static int rootIndex(const QString &id);
void updateProjectsDirectoryRoot();
static QVector<RootDirectory> m_rootDirectories;
};
......@@ -89,7 +91,7 @@ public:
void setAutoSynchronization(bool sync);
void toggleAutoSynchronization();
void addRootDirectory(const FolderNavigationWidgetFactory::RootDirectory &directory);
void insertRootDirectory(const FolderNavigationWidgetFactory::RootDirectory &directory);
void removeRootDirectory(const QString &id);
protected:
......
......@@ -386,7 +386,7 @@ void SessionManager::addProject(Project *pro)
m_instance, [pro]() { m_instance->projectDisplayNameChanged(pro); });
emit m_instance->projectAdded(pro);
FolderNavigationWidgetFactory::addRootDirectory(
FolderNavigationWidgetFactory::insertRootDirectory(
{"P." + pro->displayName() + "." + pro->projectFilePath().toString(),
pro->displayName(),
pro->projectFilePath().parentDir()});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment