2016-02-29 18:15:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "debuggermainwindow.h"
|
2016-03-02 13:57:37 +01:00
|
|
|
#include "debuggerconstants.h"
|
|
|
|
|
#include "debuggerinternalconstants.h"
|
|
|
|
|
#include "analyzer/analyzericons.h"
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2016-02-29 18:15:36 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/styledbar.h>
|
2016-02-29 18:15:36 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <QAction>
|
2016-02-29 18:15:36 +01:00
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDockWidget>
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QMenu>
|
2016-02-29 18:15:36 +01:00
|
|
|
#include <QStackedWidget>
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <QToolButton>
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
using namespace Debugger;
|
2016-02-29 18:15:36 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
const char LAST_PERSPECTIVE_KEY[] = "LastPerspective";
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
DebuggerMainWindow::DebuggerMainWindow()
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
|
|
|
|
m_controlsStackWidget = new QStackedWidget;
|
2016-03-02 13:23:30 +01:00
|
|
|
m_statusLabel = new Utils::StatusLabel;
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
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()); });
|
2016-02-29 18:15:36 +01:00
|
|
|
|
|
|
|
|
setDockNestingEnabled(true);
|
|
|
|
|
setDockActionsVisible(false);
|
|
|
|
|
setDocumentMode(true);
|
2016-03-01 07:51:06 +01:00
|
|
|
|
|
|
|
|
connect(this, &FancyMainWindow::resetLayout,
|
2016-03-02 13:57:37 +01:00
|
|
|
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);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
DebuggerMainWindow::~DebuggerMainWindow()
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
|
foreach (const DockPtr &ptr, m_dockWidgets) {
|
|
|
|
|
if (ptr)
|
|
|
|
|
delete ptr.data();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, const Perspective &perspective)
|
2016-03-01 07:51:06 +01:00
|
|
|
{
|
|
|
|
|
m_perspectiveForPerspectiveId.insert(perspectiveId, perspective);
|
2016-03-02 13:57:37 +01:00
|
|
|
m_perspectiveChooser->addItem(perspective.name(), perspectiveId);
|
2016-03-01 07:51:06 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::registerToolbar(const QByteArray &perspectiveId, QWidget *widget)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-01 07:51:06 +01:00
|
|
|
m_toolbarForPerspectiveId.insert(perspectiveId, widget);
|
|
|
|
|
m_controlsStackWidget->addWidget(widget);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::showStatusMessage(const QString &message, int timeoutMS)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-02 13:23:30 +01:00
|
|
|
m_statusLabel->showStatusMessage(message, timeoutMS);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
QDockWidget *DebuggerMainWindow::dockWidget(const QByteArray &dockId) const
|
|
|
|
|
{
|
|
|
|
|
return m_dockForDockId.value(dockId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerMainWindow::resetCurrentPerspective()
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-01 07:51:06 +01:00
|
|
|
loadPerspectiveHelper(m_currentPerspectiveId, false);
|
|
|
|
|
}
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::restorePerspective(const QByteArray &perspectiveId)
|
2016-03-01 07:51:06 +01:00
|
|
|
{
|
|
|
|
|
loadPerspectiveHelper(perspectiveId, true);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
int index = m_perspectiveChooser->findData(perspectiveId);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
index = m_perspectiveChooser->findData(m_currentPerspectiveId);
|
|
|
|
|
if (index != -1)
|
|
|
|
|
m_perspectiveChooser->setCurrentIndex(index);
|
2016-03-01 07:51:06 +01:00
|
|
|
}
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::finalizeSetup()
|
2016-03-01 07:51:06 +01:00
|
|
|
{
|
2016-03-02 13:57:37 +01:00
|
|
|
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);
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2016-03-01 07:51:06 +01:00
|
|
|
// Clean up old perspective.
|
2016-03-02 13:57:37 +01:00
|
|
|
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)));
|
|
|
|
|
}
|
2016-03-01 07:51:06 +01:00
|
|
|
|
|
|
|
|
m_currentPerspectiveId = perspectiveId;
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
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();
|
2016-03-02 14:39:20 +01:00
|
|
|
for (const Perspective::Operation &operation : operations) {
|
|
|
|
|
QDockWidget *dock = m_dockForDockId.value(operation.dockId);
|
2016-03-02 13:57:37 +01:00
|
|
|
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);
|
|
|
|
|
}
|
2016-03-02 14:39:20 +01:00
|
|
|
if (operation.operationType == Perspective::Raise) {
|
|
|
|
|
dock->raise();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
addDockWidget(operation.area, dock);
|
2016-03-02 13:57:37 +01:00
|
|
|
QDockWidget *anchor = m_dockForDockId.value(operation.anchorDockId);
|
|
|
|
|
if (!anchor && operation.area == Qt::BottomDockWidgetArea)
|
|
|
|
|
anchor = toolBarDockWidget();
|
|
|
|
|
if (anchor) {
|
2016-03-02 14:39:20 +01:00
|
|
|
switch (operation.operationType) {
|
2016-02-29 18:15:36 +01:00
|
|
|
case Perspective::AddToTab:
|
2016-03-02 13:57:37 +01:00
|
|
|
tabifyDockWidget(anchor, dock);
|
2016-02-29 18:15:36 +01:00
|
|
|
break;
|
|
|
|
|
case Perspective::SplitHorizontal:
|
2016-03-02 13:57:37 +01:00
|
|
|
splitDockWidget(anchor, dock, Qt::Horizontal);
|
2016-02-29 18:15:36 +01:00
|
|
|
break;
|
|
|
|
|
case Perspective::SplitVertical:
|
2016-03-02 13:57:37 +01:00
|
|
|
splitDockWidget(anchor, dock, Qt::Vertical);
|
2016-02-29 18:15:36 +01:00
|
|
|
break;
|
2016-03-02 14:39:20 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-02 14:39:20 +01:00
|
|
|
if (!operation.visibleByDefault)
|
2016-02-29 18:15:36 +01:00
|
|
|
dock->hide();
|
2016-03-01 07:51:06 +01:00
|
|
|
else
|
|
|
|
|
dock->show();
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fromStoredSettings) {
|
|
|
|
|
QSettings *settings = ICore::settings();
|
2016-03-02 13:57:37 +01:00
|
|
|
settings->beginGroup(QString::fromLatin1(m_currentPerspectiveId));
|
2016-02-29 18:15:36 +01:00
|
|
|
if (settings->value(QLatin1String("ToolSettingsSaved"), false).toBool())
|
|
|
|
|
restoreSettings(settings);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
QTC_CHECK(m_toolbarForPerspectiveId.contains(m_currentPerspectiveId));
|
|
|
|
|
m_controlsStackWidget->setCurrentWidget(m_toolbarForPerspectiveId.value(m_currentPerspectiveId));
|
|
|
|
|
m_statusLabel->clear();
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::saveCurrentPerspective()
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-02 13:57:37 +01:00
|
|
|
if (m_currentPerspectiveId.isEmpty())
|
2016-03-01 07:51:06 +01:00
|
|
|
return;
|
2016-02-29 18:15:36 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2016-03-02 13:57:37 +01:00
|
|
|
settings->beginGroup(QString::fromLatin1(m_currentPerspectiveId));
|
2016-02-29 18:15:36 +01:00
|
|
|
saveSettings(settings);
|
|
|
|
|
settings->setValue(QLatin1String("ToolSettingsSaved"), true);
|
|
|
|
|
settings->endGroup();
|
2016-03-02 13:57:37 +01:00
|
|
|
settings->setValue(QLatin1String(LAST_PERSPECTIVE_KEY), m_currentPerspectiveId);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
QDockWidget *DebuggerMainWindow::registerDockWidget(const QByteArray &dockId, QWidget *widget)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!widget->objectName().isEmpty(), return 0);
|
|
|
|
|
QDockWidget *dockWidget = addDockForWidget(widget);
|
2016-03-02 13:57:37 +01:00
|
|
|
dockWidget->setParent(0);
|
|
|
|
|
m_dockWidgets.append(DebuggerMainWindow::DockPtr(dockWidget));
|
2016-02-29 18:15:36 +01:00
|
|
|
m_dockForDockId[dockId] = dockWidget;
|
|
|
|
|
return dockWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
QString Perspective::name() const
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-02 13:57:37 +01:00
|
|
|
return m_name;
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void Perspective::setName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
m_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QWidget *> ToolbarDescription::widgets() const
|
|
|
|
|
{
|
|
|
|
|
return m_widgets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-02 13:57:37 +01:00
|
|
|
for (const Operation &split : splits)
|
|
|
|
|
m_docks.append(split.dockId);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void Perspective::addOperation(const Operation &operation)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2016-03-02 13:57:37 +01:00
|
|
|
m_docks.append(operation.dockId);
|
|
|
|
|
m_operations.append(operation);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
} // Utils
|