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.
This commit is contained in:
parent
b745170898
commit
1548af81af
|
|
@ -12,6 +12,7 @@
|
|||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QHash>
|
||||
#include <QHBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
|
|
@ -465,20 +466,17 @@ void OllieKateView::setupGitPlusPlusDiffAction()
|
|||
|
||||
void OllieKateView::setupProjectGitWidget()
|
||||
{
|
||||
// Don't retry if we already have the button
|
||||
if (m_mainWindow->window()->findChild<QToolButton *>(QStringLiteral("ollie_git_btn"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the git tool view by name — it's created with ID "kateprojectgit"
|
||||
QWidget *gitToolView = m_mainWindow->window()->findChild<QWidget *>(QStringLiteral("kateprojectgit"));
|
||||
if (!gitToolView) {
|
||||
// Try alternate lookup via mainWindow
|
||||
for (auto *child : m_mainWindow->window()->findChildren<QWidget *>()) {
|
||||
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<QBoxLayout *>(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<QHBoxLayout *>()) {
|
||||
// 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<QToolButton *>(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 &)
|
||||
|
|
|
|||
Loading…
Reference in New Issue