forked from qt-creator/qt-creator
Git: Only show Tags root node when tags are enabled and exist
Create it on demand. Remove on clear Change-Id: Ic29e82a859f99b5d739c25be83aa6c40a1ee2cc8 Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
8f05239b92
commit
39755c09b9
@@ -202,8 +202,6 @@ BranchModel::BranchModel(GitClient *client, QObject *parent) :
|
|||||||
// Abuse the sha field for ref prefix
|
// Abuse the sha field for ref prefix
|
||||||
m_rootNode->append(new BranchNode(tr("Local Branches"), QLatin1String("refs/heads")));
|
m_rootNode->append(new BranchNode(tr("Local Branches"), QLatin1String("refs/heads")));
|
||||||
m_rootNode->append(new BranchNode(tr("Remote Branches"), QLatin1String("refs/remotes")));
|
m_rootNode->append(new BranchNode(tr("Remote Branches"), QLatin1String("refs/remotes")));
|
||||||
if (m_client->settings()->boolValue(GitSettings::showTagsKey))
|
|
||||||
m_rootNode->append(new BranchNode(tr("Tags"), QLatin1String("refs/tags")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BranchModel::~BranchModel()
|
BranchModel::~BranchModel()
|
||||||
@@ -335,6 +333,8 @@ void BranchModel::clear()
|
|||||||
foreach (BranchNode *root, m_rootNode->children)
|
foreach (BranchNode *root, m_rootNode->children)
|
||||||
while (root->count())
|
while (root->count())
|
||||||
delete root->children.takeLast();
|
delete root->children.takeLast();
|
||||||
|
if (hasTags())
|
||||||
|
m_rootNode->children.takeLast();
|
||||||
|
|
||||||
m_currentBranch = 0;
|
m_currentBranch = 0;
|
||||||
}
|
}
|
||||||
@@ -457,6 +457,11 @@ QString BranchModel::sha(const QModelIndex &idx) const
|
|||||||
return node->sha;
|
return node->sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BranchModel::hasTags() const
|
||||||
|
{
|
||||||
|
return m_rootNode->children.count() > Tags;
|
||||||
|
}
|
||||||
|
|
||||||
bool BranchModel::isLocal(const QModelIndex &idx) const
|
bool BranchModel::isLocal(const QModelIndex &idx) const
|
||||||
{
|
{
|
||||||
if (!idx.isValid())
|
if (!idx.isValid())
|
||||||
@@ -475,7 +480,7 @@ bool BranchModel::isLeaf(const QModelIndex &idx) const
|
|||||||
|
|
||||||
bool BranchModel::isTag(const QModelIndex &idx) const
|
bool BranchModel::isTag(const QModelIndex &idx) const
|
||||||
{
|
{
|
||||||
if (!idx.isValid())
|
if (!idx.isValid() || !hasTags())
|
||||||
return false;
|
return false;
|
||||||
return indexToNode(idx)->isTag();
|
return indexToNode(idx)->isTag();
|
||||||
}
|
}
|
||||||
@@ -640,14 +645,17 @@ void BranchModel::parseOutputLine(const QString &line)
|
|||||||
nameParts.removeFirst(); // remove refs...
|
nameParts.removeFirst(); // remove refs...
|
||||||
|
|
||||||
BranchNode *root = 0;
|
BranchNode *root = 0;
|
||||||
if (nameParts.first() == QLatin1String("heads"))
|
if (nameParts.first() == QLatin1String("heads")) {
|
||||||
root = m_rootNode->children.at(LocalBranches);
|
root = m_rootNode->children.at(LocalBranches);
|
||||||
else if (nameParts.first() == QLatin1String("remotes"))
|
} else if (nameParts.first() == QLatin1String("remotes")) {
|
||||||
root = m_rootNode->children.at(RemoteBranches);
|
root = m_rootNode->children.at(RemoteBranches);
|
||||||
else if (showTags && nameParts.first() == QLatin1String("tags"))
|
} else if (showTags && nameParts.first() == QLatin1String("tags")) {
|
||||||
|
if (!hasTags()) // Tags is missing, add it
|
||||||
|
m_rootNode->append(new BranchNode(tr("Tags"), QLatin1String("refs/tags")));
|
||||||
root = m_rootNode->children.at(Tags);
|
root = m_rootNode->children.at(Tags);
|
||||||
else
|
} else {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nameParts.removeFirst();
|
nameParts.removeFirst();
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public:
|
|||||||
QString fullName(const QModelIndex &idx, bool includePrefix = false) const;
|
QString fullName(const QModelIndex &idx, bool includePrefix = false) const;
|
||||||
QStringList localBranchNames() const;
|
QStringList localBranchNames() const;
|
||||||
QString sha(const QModelIndex &idx) const;
|
QString sha(const QModelIndex &idx) const;
|
||||||
|
bool hasTags() const;
|
||||||
bool isLocal(const QModelIndex &idx) const;
|
bool isLocal(const QModelIndex &idx) const;
|
||||||
bool isLeaf(const QModelIndex &idx) const;
|
bool isLeaf(const QModelIndex &idx) const;
|
||||||
bool isTag(const QModelIndex &idx) const;
|
bool isTag(const QModelIndex &idx) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user