diff --git a/src/drkonqidialog.h b/src/drkonqidialog.h --- a/src/drkonqidialog.h +++ b/src/drkonqidialog.h @@ -75,6 +75,7 @@ QDialogButtonBox* m_buttonBox = nullptr; QPushButton* m_debugButton = nullptr; QPushButton* m_restartButton = nullptr; + bool m_debugButtonInBox = false; }; #endif diff --git a/src/drkonqidialog.cpp b/src/drkonqidialog.cpp --- a/src/drkonqidialog.cpp +++ b/src/drkonqidialog.cpp @@ -173,47 +173,45 @@ //Set dialog buttons m_buttonBox->setStandardButtons(QDialogButtonBox::Close); - //Report bug button: User1 - QPushButton* reportButton = new QPushButton(m_buttonBox); - KGuiItem2 reportItem(i18nc("@action:button", "Report &Bug"), - QIcon::fromTheme(QStringLiteral("tools-report-bug")), - i18nc("@info:tooltip", "Starts the bug report assistant.")); - KGuiItem::assign(reportButton, reportItem); - m_buttonBox->addButton(reportButton, QDialogButtonBox::ActionRole); - - bool enableReportAssistant = !crashedApp->bugReportAddress().isEmpty() && - crashedApp->fakeExecutableBaseName() != QLatin1String("drkonqi") && - !DrKonqi::isSafer(); - reportButton->setEnabled(enableReportAssistant); - connect(reportButton, &QPushButton::clicked, this, &DrKonqiDialog::startBugReportAssistant); - //Default debugger button and menu (only for developer mode): User2 DebuggerManager *debuggerManager = DrKonqi::debuggerManager(); - m_debugButton = new QPushButton(m_buttonBox); + m_debugButton = new QPushButton(this); KGuiItem2 debugItem(i18nc("@action:button this is the debug menu button label which contains the debugging applications", - "&Debug"), QIcon::fromTheme(QStringLiteral("applications-development")), - i18nc("@info:tooltip", "Starts a program to debug " - "the crashed application.")); + "&Debug"), + QIcon::fromTheme(QStringLiteral("applications-development")), + i18nc("@info:tooltip", "Starts a program to debug the crashed application.")); KGuiItem::assign(m_debugButton, debugItem); - m_debugButton->setVisible(debuggerManager->showExternalDebuggers()); - // Do not add the button unless it is visible, otherwise the Box will force - // it visible as it calls show() explicitly. - if (m_debugButton->isVisible()) { - m_buttonBox->addButton(m_debugButton, QDialogButtonBox::ActionRole); - } + m_debugButton->setVisible(false); m_debugMenu = new QMenu(this); m_debugButton->setMenu(m_debugMenu); + // Only add the debugger if requested by the config or if a KDevelop session is running. + const bool showExternal = debuggerManager->showExternalDebuggers(); QList debuggers = debuggerManager->availableExternalDebuggers(); foreach(AbstractDebuggerLauncher *launcher, debuggers) { - addDebugger(launcher); + if (showExternal || qobject_cast(launcher)) { + addDebugger(launcher); + } } connect(debuggerManager, &DebuggerManager::externalDebuggerAdded, this, &DrKonqiDialog::addDebugger); connect(debuggerManager, &DebuggerManager::externalDebuggerRemoved, this, &DrKonqiDialog::removeDebugger); connect(debuggerManager, &DebuggerManager::debuggerRunning, this, &DrKonqiDialog::enableDebugMenu); + //Report bug button: User1 + QPushButton *reportButton = new QPushButton(m_buttonBox); + KGuiItem2 reportItem(i18nc("@action:button", "Report &Bug"), + QIcon::fromTheme(QStringLiteral("tools-report-bug")), + i18nc("@info:tooltip", "Starts the bug report assistant.")); + KGuiItem::assign(reportButton, reportItem); + m_buttonBox->addButton(reportButton, QDialogButtonBox::ActionRole); + + reportButton->setEnabled(!crashedApp->bugReportAddress().isEmpty() && + crashedApp->fakeExecutableBaseName() != QLatin1String("drkonqi") && + !DrKonqi::isSafer()); + connect(reportButton, &QPushButton::clicked, this, &DrKonqiDialog::startBugReportAssistant); + //Restart application button KGuiItem2 restartItem(i18nc("@action:button", "&Restart Application"), QIcon::fromTheme(QStringLiteral("system-reboot")), @@ -244,14 +242,36 @@ m_debugMenu->addAction(action); connect(action, &QAction::triggered, launcher, &AbstractDebuggerLauncher::start); m_debugMenuActions.insert(launcher, action); + + // Make sure that the debug button is the first button with action role to be + // inserted, then add the other buttons. See removeDebugger below for more information. + if (!m_debugButtonInBox) { + auto buttons = m_buttonBox->buttons(); + m_buttonBox->addButton(m_debugButton, QDialogButtonBox::ActionRole); + m_debugButton->setVisible(true); + for (QAbstractButton *button : buttons) { + if (m_buttonBox->buttonRole(button) == QDialogButtonBox::ActionRole) { + m_buttonBox->addButton(button, QDialogButtonBox::ActionRole); + } + } + m_debugButtonInBox = true; + } } void DrKonqiDialog::removeDebugger(AbstractDebuggerLauncher *launcher) { QAction *action = m_debugMenuActions.take(launcher); if ( action ) { m_debugMenu->removeAction(action); action->deleteLater(); + // Remove the button from the box, otherwise the box will force + // it visible as it calls show() explicitly. (QTBUG-3651) + if (m_debugMenu->isEmpty()) { + m_buttonBox->removeButton(m_debugButton); + m_debugButton->setVisible(false); + m_debugButton->setParent(this); + m_debugButtonInBox = false; + } } else { qCWarning(DRKONQI_LOG) << "Invalid launcher"; }