From fd6d0d8c294b7d80fe97363c2e32050d8de66bc9 Mon Sep 17 00:00:00 2001 From: Mathias Hasselmann Date: Wed, 7 Nov 2012 21:17:11 +0200 Subject: [PATCH] ProjectExplorer: Show VCS topic in tree Topic is usually the current branch name Change-Id: Id6ecc48744a5b3d9c7502b36b4895eb18d0ff0c6 Reviewed-by: Tobias Hunger --- src/plugins/coreplugin/iversioncontrol.cpp | 5 +++++ src/plugins/coreplugin/iversioncontrol.h | 5 +++++ src/plugins/projectexplorer/projectmodels.cpp | 15 ++++++++++++++- src/plugins/projectexplorer/projectnodes.cpp | 18 ++++++++++++++++++ src/plugins/projectexplorer/projectnodes.h | 3 +++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/plugins/coreplugin/iversioncontrol.cpp b/src/plugins/coreplugin/iversioncontrol.cpp index cfb25378979..e92052c6564 100644 --- a/src/plugins/coreplugin/iversioncontrol.cpp +++ b/src/plugins/coreplugin/iversioncontrol.cpp @@ -41,4 +41,9 @@ QString IVersionControl::vcsMakeWritableText() const return QString(); } +QString IVersionControl::vcsTopic(const QString &) +{ + return QString(); +} + } diff --git a/src/plugins/coreplugin/iversioncontrol.h b/src/plugins/coreplugin/iversioncontrol.h index f77c133ee5d..e150fedcf6e 100644 --- a/src/plugins/coreplugin/iversioncontrol.h +++ b/src/plugins/coreplugin/iversioncontrol.h @@ -136,6 +136,11 @@ public: */ virtual QString vcsGetRepositoryURL(const QString &director) = 0; + /*! + * Topic (e.g. name of the current branch) + */ + virtual QString vcsTopic(const QString &directory); + /*! * Create a snapshot of the current state and return an identifier or * an empty string in case of failure. diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index 18c6cd64bb6..38c6afe2618 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -258,7 +258,20 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const if (Node *node = nodeForIndex(index)) { FolderNode *folderNode = qobject_cast(node); switch (role) { - case Qt::DisplayRole: + case Qt::DisplayRole: { + QString name = node->displayName(); + + if (node->parentFolderNode() + && node->parentFolderNode()->nodeType() == SessionNodeType) { + const QString vcsTopic = node->vcsTopic(); + + if (!vcsTopic.isEmpty()) + name += " (" + vcsTopic + ")"; + } + + result = name; + break; + } case Qt::EditRole: { result = node->displayName(); break; diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 586be2d5f7b..4444996627c 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -34,6 +34,9 @@ #include #include +#include +#include +#include #include #include @@ -104,6 +107,11 @@ QString Node::displayName() const return QFileInfo(path()).fileName(); } +QString Node::vcsTopic() const +{ + return QString(); +} + QString Node::tooltip() const { return QDir::toNativeSeparators(path()); @@ -269,6 +277,16 @@ ProjectNode::ProjectNode(const QString &projectFilePath) setDisplayName(QFileInfo(projectFilePath).fileName()); } +QString ProjectNode::vcsTopic() const { + const QString dir = QFileInfo(path()).absolutePath(); + + if (Core::IVersionControl *const vc = + Core::ICore::vcsManager()->findVersionControlForDirectory(dir)) + return vc->vcsTopic(dir); + + return QString(); +} + QList ProjectNode::subProjectNodes() const { return m_subProjectNodes; diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index d57765ada59..5cbdee4a9a2 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -86,6 +86,7 @@ public: FolderNode *parentFolderNode() const; // parent folder or project QString path() const; // file system path virtual QString displayName() const; + virtual QString vcsTopic() const; virtual QString tooltip() const; protected: @@ -183,6 +184,8 @@ public: HasSubProjectRunConfigurations }; + QString vcsTopic() const; + // all subFolders that are projects QList subProjectNodes() const;