From 1548af81aff1f97ff19259a3afd8b19eca7fa45a Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 8 Oct 2026 10:40:04 +0200 Subject: [PATCH] kate: find GitWidget's button bar and insert Ollie button there The GitWidget delays initialization until showEvent. Find the QHBoxLayout containing QToolButtons (the button bar) and insert our button there, next to Commit/Push/Pull buttons. --- kde/kate/ollie_kate.cpp | 93 ++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/kde/kate/ollie_kate.cpp b/kde/kate/ollie_kate.cpp index 51d58ec..3a5ed84 100644 --- a/kde/kate/ollie_kate.cpp +++ b/kde/kate/ollie_kate.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -465,20 +466,17 @@ void OllieKateView::setupGitPlusPlusDiffAction() void OllieKateView::setupProjectGitWidget() { + // Don't retry if we already have the button + if (m_mainWindow->window()->findChild(QStringLiteral("ollie_git_btn"))) { + return; + } + // Find the git tool view by name — it's created with ID "kateprojectgit" QWidget *gitToolView = m_mainWindow->window()->findChild(QStringLiteral("kateprojectgit")); - if (!gitToolView) { - // Try alternate lookup via mainWindow - for (auto *child : m_mainWindow->window()->findChildren()) { - if (child->objectName().contains(QStringLiteral("git"), Qt::CaseInsensitive)) { - gitToolView = child; - break; - } - } - } + if (!gitToolView) { // Schedule retry — plugin view might not be created yet - QTimer::singleShot(1000, this, &OllieKateView::setupProjectGitWidget); + QTimer::singleShot(2000, this, &OllieKateView::setupProjectGitWidget); return; } @@ -488,36 +486,55 @@ void OllieKateView::setupProjectGitWidget() m_gitTreeView = treeView; } - // Add Ollie button to the git tool view's button row - // Find the layout and add our button - if (auto *layout = gitToolView->layout()) { - // Create a button for Ollie actions - auto *ollieBtn = new QToolButton(gitToolView); - ollieBtn->setObjectName(QStringLiteral("ollie_git_btn")); - ollieBtn->setIcon(QIcon::fromTheme(QStringLiteral("system-run"))); - ollieBtn->setToolTip(QStringLiteral("Ollie AI Actions")); - ollieBtn->setPopupMode(QToolButton::InstantPopup); - ollieBtn->setAutoRaise(true); - - auto *menu = new QMenu(ollieBtn); - menu->addAction(QIcon::fromTheme(QStringLiteral("document-preview")), - QStringLiteral("Review Staged Changes"), - this, &OllieKateView::reviewStagedChanges); - menu->addAction(QIcon::fromTheme(QStringLiteral("document-preview")), - QStringLiteral("Review Unstaged Changes"), - this, &OllieKateView::reviewUnstagedChanges); - menu->addAction(QIcon::fromTheme(QStringLiteral("help-about")), - QStringLiteral("Explain Selected Files"), - this, &OllieKateView::askAboutGitSelection); - ollieBtn->setMenu(menu); - - // Try to insert at a reasonable position - if (auto *boxLayout = qobject_cast(layout)) { - boxLayout->insertWidget(0, ollieBtn); - } else { - layout->addWidget(ollieBtn); + // The GitWidget is inside the tool view and has a QHBoxLayout with buttons at the top + // Find the first QHBoxLayout (the button bar) and add our button there + QHBoxLayout *btnLayout = nullptr; + for (auto *child : gitToolView->findChildren()) { + // The button bar has QToolButtons as direct children + bool hasToolButtons = false; + for (int i = 0; i < child->count(); ++i) { + if (auto *item = child->itemAt(i)) { + if (qobject_cast(item->widget())) { + hasToolButtons = true; + break; + } + } + } + if (hasToolButtons) { + btnLayout = child; + break; } } + + if (!btnLayout) { + // Schedule retry — GitWidget might not be initialized yet (it delays init) + QTimer::singleShot(2000, this, &OllieKateView::setupProjectGitWidget); + return; + } + + // Create a button for Ollie actions + auto *ollieBtn = new QToolButton(gitToolView); + ollieBtn->setObjectName(QStringLiteral("ollie_git_btn")); + ollieBtn->setIcon(QIcon::fromTheme(QStringLiteral("system-run"))); + ollieBtn->setToolTip(QStringLiteral("Ollie AI Actions")); + ollieBtn->setPopupMode(QToolButton::InstantPopup); + ollieBtn->setAutoRaise(true); + + auto *menu = new QMenu(ollieBtn); + menu->addAction(QIcon::fromTheme(QStringLiteral("document-preview")), + QStringLiteral("Review Staged Changes"), + this, &OllieKateView::reviewStagedChanges); + menu->addAction(QIcon::fromTheme(QStringLiteral("document-preview")), + QStringLiteral("Review Unstaged Changes"), + this, &OllieKateView::reviewUnstagedChanges); + menu->addAction(QIcon::fromTheme(QStringLiteral("help-about")), + QStringLiteral("Explain Selected Files"), + this, &OllieKateView::askAboutGitSelection); + ollieBtn->setMenu(menu); + + // Insert before the menu button (last in the row) + int insertPos = btnLayout->count() > 0 ? btnLayout->count() - 1 : 0; + btnLayout->insertWidget(insertPos, ollieBtn); } void OllieKateView::onGitTreeContextMenu(const QPoint &)