Commit 8bbf212d authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Fix changing branch doesn't update the branch button


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent e979cc2e
......@@ -72,26 +72,14 @@ KateProjectView::KateProjectView(KateProjectPluginView *pluginView, KateProject
/**
* Setup git checkout stuff
*/
m_branchBtn->setHidden(!GitUtils::isGitRepo(m_project->baseDir()));
connect(m_branchBtn, &QPushButton::clicked, this, [this, mainWindow] {
BranchCheckoutDialog bd(mainWindow->window(), m_pluginView, m_project->baseDir());
bd.openDialog();
});
connect(m_project, &KateProject::modelChanged, this, [this] {
if (GitUtils::isGitRepo(m_project->baseDir())) {
m_branchBtn->setHidden(false);
m_branchBtn->setText(GitUtils::getCurrentBranchName(m_project->baseDir()));
if (m_branchChangedWatcher.files().isEmpty()) {
m_branchChangedWatcher.addPath(m_project->baseDir() + QStringLiteral("/.git/HEAD"));
}
} else {
if (!m_branchChangedWatcher.files().isEmpty()) {
m_branchChangedWatcher.removePaths(m_branchChangedWatcher.files());
}
m_branchBtn->setHidden(true);
}
});
checkAndRefreshGit();
connect(m_project, &KateProject::modelChanged, this, &KateProjectView::checkAndRefreshGit);
connect(&m_branchChangedWatcher, &QFileSystemWatcher::fileChanged, this, [this] {
m_project->reload(true);
});
......@@ -159,3 +147,19 @@ void KateProjectView::showFileGitHistory(const QString &file)
m_stackWidget->addWidget(fhs);
m_stackWidget->setCurrentWidget(fhs);
}
void KateProjectView::checkAndRefreshGit()
{
if (GitUtils::isGitRepo(m_project->baseDir())) {
m_branchBtn->setHidden(false);
m_branchBtn->setText(GitUtils::getCurrentBranchName(m_project->baseDir()));
if (m_branchChangedWatcher.files().isEmpty()) {
m_branchChangedWatcher.addPath(m_project->baseDir() + QStringLiteral("/.git/HEAD"));
}
} else {
if (!m_branchChangedWatcher.files().isEmpty()) {
m_branchChangedWatcher.removePaths(m_branchChangedWatcher.files());
}
m_branchBtn->setHidden(true);
}
}
......@@ -73,6 +73,13 @@ private Q_SLOTS:
void showFileGitHistory(const QString &file);
/**
* On project model change, check if project
* is a git repo and then show/hide the branch
* button accordingly
*/
void checkAndRefreshGit();
private:
/**
* our plugin view
......
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