From f1ffad7eb89c121632d3b6731128748c5ffbae96 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 22 Jul 2026 16:16:23 +0200 Subject: [PATCH] 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. --- gitplusplus.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gitplusplus.cpp b/gitplusplus.cpp index ac6e054..6fd7ebb 100644 --- a/gitplusplus.cpp +++ b/gitplusplus.cpp @@ -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();