forked from qt-creator/qt-creator
Debugger: Merge debug mode and analyze mode
On the user-visible side, only the 'Analyze' mode button disappears, and instead a combobox to switch between different tools in appears in the Debug mode toolbar. Internally, that's quite some re-organzition: The centralized 'Analyze mode is busy' flag is gone, allowing us to run e.g. ClangStaticAnalyzer and MemCheck in parallel. Analyzer tools and debugger now share the same mechanism to generate/load/save dock widgets. Analyzer tools now create and handle their own start/stop button when appropriate. In general, Analyzer tools can create/handle more than one run control at a time. Further consolidation is possible, e.g. RunControl state handling could be merged into the base ProjectExplorer::RunControl to avoid the still existing duplication in ~15 instances. Change-Id: I91e5940ebc4211f98056d507cf2f7b5f8efe7f07 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -24,37 +24,65 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "debuggermainwindow.h"
|
||||
#include "debuggerconstants.h"
|
||||
#include "debuggerinternalconstants.h"
|
||||
#include "analyzer/analyzericons.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/projectexplorericons.h>
|
||||
|
||||
#include <utils/styledbar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QDockWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QStackedWidget>
|
||||
#include <QToolButton>
|
||||
|
||||
using namespace Analyzer;
|
||||
using namespace Debugger;
|
||||
using namespace Core;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
namespace Utils {
|
||||
|
||||
MainWindowBase::MainWindowBase()
|
||||
const char LAST_PERSPECTIVE_KEY[] = "LastPerspective";
|
||||
|
||||
DebuggerMainWindow::DebuggerMainWindow()
|
||||
{
|
||||
m_controlsStackWidget = new QStackedWidget;
|
||||
m_statusLabel = new Utils::StatusLabel;
|
||||
m_toolBox = new QComboBox;
|
||||
|
||||
m_perspectiveChooser = new QComboBox;
|
||||
m_perspectiveChooser->setObjectName(QLatin1String("PerspectiveChooser"));
|
||||
connect(m_perspectiveChooser, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
|
||||
this, [this](int item) { restorePerspective(m_perspectiveChooser->itemData(item).toByteArray()); });
|
||||
|
||||
setDockNestingEnabled(true);
|
||||
setDockActionsVisible(false);
|
||||
setDocumentMode(true);
|
||||
|
||||
connect(this, &FancyMainWindow::resetLayout,
|
||||
this, &MainWindowBase::resetCurrentPerspective);
|
||||
this, &DebuggerMainWindow::resetCurrentPerspective);
|
||||
|
||||
auto dock = new QDockWidget(tr("Toolbar"));
|
||||
dock->setObjectName(QLatin1String("Toolbar"));
|
||||
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
dock->setAllowedAreas(Qt::BottomDockWidgetArea);
|
||||
dock->setTitleBarWidget(new QWidget(dock)); // hide title bar
|
||||
dock->setProperty("managed_dockwidget", QLatin1String("true"));
|
||||
|
||||
addDockWidget(Qt::BottomDockWidgetArea, dock);
|
||||
setToolBarDockWidget(dock);
|
||||
}
|
||||
|
||||
MainWindowBase::~MainWindowBase()
|
||||
DebuggerMainWindow::~DebuggerMainWindow()
|
||||
{
|
||||
// as we have to setParent(0) on dock widget that are not selected,
|
||||
// we keep track of all and make sure we don't leak any
|
||||
@@ -64,64 +92,155 @@ MainWindowBase::~MainWindowBase()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindowBase::registerPerspective(Id perspectiveId, const Perspective &perspective)
|
||||
void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, const Perspective &perspective)
|
||||
{
|
||||
m_perspectiveForPerspectiveId.insert(perspectiveId, perspective);
|
||||
m_perspectiveChooser->addItem(perspective.name(), perspectiveId);
|
||||
}
|
||||
|
||||
void MainWindowBase::registerToolbar(Id perspectiveId, QWidget *widget)
|
||||
void DebuggerMainWindow::registerToolbar(const QByteArray &perspectiveId, QWidget *widget)
|
||||
{
|
||||
m_toolbarForPerspectiveId.insert(perspectiveId, widget);
|
||||
m_controlsStackWidget->addWidget(widget);
|
||||
}
|
||||
|
||||
void MainWindowBase::showStatusMessage(const QString &message, int timeoutMS)
|
||||
void DebuggerMainWindow::showStatusMessage(const QString &message, int timeoutMS)
|
||||
{
|
||||
m_statusLabel->showStatusMessage(message, timeoutMS);
|
||||
}
|
||||
|
||||
void MainWindowBase::resetCurrentPerspective()
|
||||
QDockWidget *DebuggerMainWindow::dockWidget(const QByteArray &dockId) const
|
||||
{
|
||||
return m_dockForDockId.value(dockId);
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::resetCurrentPerspective()
|
||||
{
|
||||
loadPerspectiveHelper(m_currentPerspectiveId, false);
|
||||
}
|
||||
|
||||
void MainWindowBase::restorePerspective(Id perspectiveId)
|
||||
void DebuggerMainWindow::restorePerspective(const QByteArray &perspectiveId)
|
||||
{
|
||||
loadPerspectiveHelper(perspectiveId, true);
|
||||
|
||||
int index = m_perspectiveChooser->findData(perspectiveId);
|
||||
if (index == -1)
|
||||
index = m_perspectiveChooser->findData(m_currentPerspectiveId);
|
||||
if (index != -1)
|
||||
m_perspectiveChooser->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void MainWindowBase::loadPerspectiveHelper(Id perspectiveId, bool fromStoredSettings)
|
||||
void DebuggerMainWindow::finalizeSetup()
|
||||
{
|
||||
QTC_ASSERT(perspectiveId.isValid(), return);
|
||||
auto viewButton = new QToolButton;
|
||||
viewButton->setText(tr("Views"));
|
||||
|
||||
auto toolbar = new Utils::StyledBar;
|
||||
toolbar->setProperty("topBorder", true);
|
||||
auto hbox = new QHBoxLayout(toolbar);
|
||||
hbox->setMargin(0);
|
||||
hbox->setSpacing(0);
|
||||
hbox->addWidget(m_perspectiveChooser);
|
||||
hbox->addWidget(m_controlsStackWidget);
|
||||
hbox->addWidget(m_statusLabel);
|
||||
hbox->addWidget(new Utils::StyledSeparator);
|
||||
hbox->addStretch();
|
||||
hbox->addWidget(viewButton);
|
||||
|
||||
connect(viewButton, &QAbstractButton::clicked, [this, viewButton] {
|
||||
QMenu menu;
|
||||
addDockActionsToMenu(&menu);
|
||||
menu.exec(viewButton->mapToGlobal(QPoint()));
|
||||
});
|
||||
|
||||
toolBarDockWidget()->setWidget(toolbar);
|
||||
|
||||
Context debugcontext(Debugger::Constants::C_DEBUGMODE);
|
||||
|
||||
ActionContainer *viewsMenu = ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS);
|
||||
Command *cmd = ActionManager::registerAction(menuSeparator1(),
|
||||
"Debugger.Views.Separator1", debugcontext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||
cmd = ActionManager::registerAction(autoHideTitleBarsAction(),
|
||||
"Debugger.Views.AutoHideTitleBars", debugcontext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||
cmd = ActionManager::registerAction(menuSeparator2(),
|
||||
"Debugger.Views.Separator2", debugcontext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||
cmd = ActionManager::registerAction(resetLayoutAction(),
|
||||
"Debugger.Views.ResetSimple", debugcontext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||
|
||||
addDockActionsToMenu(viewsMenu->menu());
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::loadPerspectiveHelper(const QByteArray &perspectiveId, bool fromStoredSettings)
|
||||
{
|
||||
// Clean up old perspective.
|
||||
closeCurrentPerspective();
|
||||
if (!m_currentPerspectiveId.isEmpty()) {
|
||||
saveCurrentPerspective();
|
||||
foreach (QDockWidget *dockWidget, m_dockForDockId) {
|
||||
QTC_ASSERT(dockWidget, continue);
|
||||
removeDockWidget(dockWidget);
|
||||
dockWidget->hide();
|
||||
// Prevent saveState storing the data of the wrong children.
|
||||
dockWidget->setParent(0);
|
||||
}
|
||||
|
||||
ICore::removeAdditionalContext(Context(Id::fromName(m_currentPerspectiveId)));
|
||||
}
|
||||
|
||||
m_currentPerspectiveId = perspectiveId;
|
||||
|
||||
QTC_ASSERT(m_perspectiveForPerspectiveId.contains(perspectiveId), return);
|
||||
const auto operations = m_perspectiveForPerspectiveId.value(perspectiveId).operations();
|
||||
if (m_currentPerspectiveId.isEmpty()) {
|
||||
const QSettings *settings = ICore::settings();
|
||||
m_currentPerspectiveId = settings->value(QLatin1String(LAST_PERSPECTIVE_KEY)).toByteArray();
|
||||
if (m_currentPerspectiveId.isEmpty())
|
||||
m_currentPerspectiveId = Debugger::Constants::CppPerspectiveId;
|
||||
}
|
||||
|
||||
ICore::addAdditionalContext(Context(Id::fromName(m_currentPerspectiveId)));
|
||||
|
||||
QTC_ASSERT(m_perspectiveForPerspectiveId.contains(m_currentPerspectiveId), return);
|
||||
const auto operations = m_perspectiveForPerspectiveId.value(m_currentPerspectiveId).operations();
|
||||
for (const Perspective::Operation &operation : operations) {
|
||||
QDockWidget *dock = m_dockForDockId.value(operation.dockId);
|
||||
QTC_ASSERT(dock, continue);
|
||||
if (!dock) {
|
||||
QTC_CHECK(!operation.widget->objectName().isEmpty());
|
||||
dock = registerDockWidget(operation.dockId, operation.widget);
|
||||
|
||||
QAction *toggleViewAction = dock->toggleViewAction();
|
||||
toggleViewAction->setText(dock->windowTitle());
|
||||
|
||||
Command *cmd = ActionManager::registerAction(toggleViewAction,
|
||||
Id("Dock.").withSuffix(dock->objectName()),
|
||||
Context(Id::fromName(m_currentPerspectiveId)));
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
|
||||
ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS)->addAction(cmd);
|
||||
}
|
||||
if (operation.operationType == Perspective::Raise) {
|
||||
dock->raise();
|
||||
continue;
|
||||
}
|
||||
addDockWidget(operation.area, dock);
|
||||
QDockWidget *existing = m_dockForDockId.value(operation.existing);
|
||||
if (!existing && operation.area == Qt::BottomDockWidgetArea)
|
||||
existing = toolBarDockWidget();
|
||||
if (existing) {
|
||||
QDockWidget *anchor = m_dockForDockId.value(operation.anchorDockId);
|
||||
if (!anchor && operation.area == Qt::BottomDockWidgetArea)
|
||||
anchor = toolBarDockWidget();
|
||||
if (anchor) {
|
||||
switch (operation.operationType) {
|
||||
case Perspective::AddToTab:
|
||||
tabifyDockWidget(existing, dock);
|
||||
tabifyDockWidget(anchor, dock);
|
||||
break;
|
||||
case Perspective::SplitHorizontal:
|
||||
splitDockWidget(existing, dock, Qt::Horizontal);
|
||||
splitDockWidget(anchor, dock, Qt::Horizontal);
|
||||
break;
|
||||
case Perspective::SplitVertical:
|
||||
splitDockWidget(existing, dock, Qt::Vertical);
|
||||
splitDockWidget(anchor, dock, Qt::Vertical);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -135,66 +254,84 @@ void MainWindowBase::loadPerspectiveHelper(Id perspectiveId, bool fromStoredSett
|
||||
|
||||
if (fromStoredSettings) {
|
||||
QSettings *settings = ICore::settings();
|
||||
settings->beginGroup(perspectiveId.toString());
|
||||
settings->beginGroup(QString::fromLatin1(m_currentPerspectiveId));
|
||||
if (settings->value(QLatin1String("ToolSettingsSaved"), false).toBool())
|
||||
restoreSettings(settings);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
QTC_CHECK(m_toolbarForPerspectiveId.contains(perspectiveId));
|
||||
m_controlsStackWidget->setCurrentWidget(m_toolbarForPerspectiveId.value(perspectiveId));
|
||||
QTC_CHECK(m_toolbarForPerspectiveId.contains(m_currentPerspectiveId));
|
||||
m_controlsStackWidget->setCurrentWidget(m_toolbarForPerspectiveId.value(m_currentPerspectiveId));
|
||||
m_statusLabel->clear();
|
||||
}
|
||||
|
||||
void MainWindowBase::closeCurrentPerspective()
|
||||
void DebuggerMainWindow::saveCurrentPerspective()
|
||||
{
|
||||
if (!m_currentPerspectiveId.isValid())
|
||||
return;
|
||||
|
||||
saveCurrentPerspective();
|
||||
foreach (QDockWidget *dockWidget, m_dockForDockId) {
|
||||
QTC_ASSERT(dockWidget, continue);
|
||||
removeDockWidget(dockWidget);
|
||||
dockWidget->hide();
|
||||
// Prevent saveState storing the data of the wrong children.
|
||||
dockWidget->setParent(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindowBase::saveCurrentPerspective()
|
||||
{
|
||||
if (!m_currentPerspectiveId.isValid())
|
||||
if (m_currentPerspectiveId.isEmpty())
|
||||
return;
|
||||
QSettings *settings = ICore::settings();
|
||||
settings->beginGroup(m_currentPerspectiveId.toString());
|
||||
settings->beginGroup(QString::fromLatin1(m_currentPerspectiveId));
|
||||
saveSettings(settings);
|
||||
settings->setValue(QLatin1String("ToolSettingsSaved"), true);
|
||||
settings->endGroup();
|
||||
settings->setValue(m_lastSettingsName, m_currentPerspectiveId.toString());
|
||||
settings->setValue(QLatin1String(LAST_PERSPECTIVE_KEY), m_currentPerspectiveId);
|
||||
}
|
||||
|
||||
QDockWidget *MainWindowBase::registerDockWidget(Id dockId, QWidget *widget)
|
||||
QDockWidget *DebuggerMainWindow::registerDockWidget(const QByteArray &dockId, QWidget *widget)
|
||||
{
|
||||
QTC_ASSERT(!widget->objectName().isEmpty(), return 0);
|
||||
QDockWidget *dockWidget = addDockForWidget(widget);
|
||||
m_dockWidgets.append(MainWindowBase::DockPtr(dockWidget));
|
||||
dockWidget->setParent(0);
|
||||
m_dockWidgets.append(DebuggerMainWindow::DockPtr(dockWidget));
|
||||
m_dockForDockId[dockId] = dockWidget;
|
||||
return dockWidget;
|
||||
}
|
||||
|
||||
Core::Id MainWindowBase::currentPerspectiveId() const
|
||||
QString Perspective::name() const
|
||||
{
|
||||
return m_currentPerspectiveId;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
QString MainWindowBase::lastSettingsName() const
|
||||
void Perspective::setName(const QString &name)
|
||||
{
|
||||
return m_lastSettingsName;
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
void MainWindowBase::setLastSettingsName(const QString &lastSettingsName)
|
||||
QList<QWidget *> ToolbarDescription::widgets() const
|
||||
{
|
||||
m_lastSettingsName = lastSettingsName;
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Debugger
|
||||
void ToolbarDescription::addAction(QAction *action)
|
||||
{
|
||||
auto button = new QToolButton;
|
||||
button->setDefaultAction(action);
|
||||
m_widgets.append(button);
|
||||
}
|
||||
|
||||
void ToolbarDescription::addWidget(QWidget *widget)
|
||||
{
|
||||
m_widgets.append(widget);
|
||||
}
|
||||
|
||||
Perspective::Operation::Operation(const QByteArray &dockId, QWidget *widget, const QByteArray &anchorDockId,
|
||||
Perspective::OperationType splitType, bool visibleByDefault,
|
||||
Qt::DockWidgetArea area)
|
||||
: dockId(dockId), widget(widget), anchorDockId(anchorDockId),
|
||||
operationType(splitType), visibleByDefault(visibleByDefault), area(area)
|
||||
{}
|
||||
|
||||
Perspective::Perspective(const QString &name, const QVector<Operation> &splits)
|
||||
: m_name(name), m_operations(splits)
|
||||
{
|
||||
for (const Operation &split : splits)
|
||||
m_docks.append(split.dockId);
|
||||
}
|
||||
|
||||
void Perspective::addOperation(const Operation &operation)
|
||||
{
|
||||
m_docks.append(operation.dockId);
|
||||
m_operations.append(operation);
|
||||
}
|
||||
|
||||
} // Utils
|
||||
|
||||
Reference in New Issue
Block a user