Clear git state when project is closed

When viewChanged fires with no active project/document, reset all git
state, hide workspace controls, and show "No project" in the repo label.
This commit is contained in:
Levi Neely 2026-07-22 16:16:23 +02:00
parent 55b4fef0a0
commit f1ffad7eb8
1 changed files with 26 additions and 0 deletions

View File

@ -545,6 +545,32 @@ GitPlusPlusView::GitPlusPlusView(GitPlusPlusPlugin *plugin, KTextEditor::MainWin
// Refresh everything when the active view changes (project might have changed)
connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, [this]() {
QString newDir = projectBaseDir();
if (newDir.isEmpty() && !m_gitDir.isEmpty()) {
// Project closed — clear git state
m_gitDir.clear();
m_isWorkspace = false;
m_workspaceDir.clear();
m_workspaceSourceDir.clear();
m_workspaceRepos.clear();
m_repoCombo->hide();
m_repoCombo->clear();
m_model->parseStatus({});
m_worktreeList->clear();
m_workspaceList->clear();
m_branchList->clear();
m_stashList->clear();
m_logList->clear();
m_currentBranch.clear();
m_allBranches.clear();
m_remoteBranches.clear();
m_repoLabel->setText(QStringLiteral("No project"));
m_repoLabel->setStyleSheet(QStringLiteral("font-weight: bold; padding: 2px 4px; color: gray;"));
if (m_statusBarWidget)
m_statusBarWidget->setText(QStringLiteral("Git++"));
delete m_watcher;
m_watcher = nullptr;
return;
}
if (!newDir.isEmpty() && newDir != m_gitDir) {
m_gitDir = newDir;
detectWorkspace();