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"
|
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-03-10 08:53:49 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/findplaceholder.h>
|
2016-02-29 18:15:36 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2018-03-06 08:35:17 +01:00
|
|
|
#include <coreplugin/modemanager.h>
|
2016-03-10 08:53:49 +01:00
|
|
|
#include <coreplugin/navigationwidget.h>
|
|
|
|
|
#include <coreplugin/outputpane.h>
|
|
|
|
|
#include <coreplugin/rightpane.h>
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
#include <utils/algorithm.h>
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <utils/styledbar.h>
|
2016-02-29 18:15:36 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2016-04-24 22:51:24 +02:00
|
|
|
#include <utils/proxyaction.h>
|
2018-03-06 08:35:17 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2016-02-29 18:15:36 +01:00
|
|
|
|
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>
|
2017-07-11 15:57:45 +02:00
|
|
|
#include <QStandardItemModel>
|
2017-10-26 16:32:48 +02:00
|
|
|
#include <QTimer>
|
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
|
|
|
{
|
2016-05-12 11:57:29 +02:00
|
|
|
m_centralWidgetStack = new QStackedWidget;
|
2016-03-02 13:23:30 +01:00
|
|
|
m_statusLabel = new Utils::StatusLabel;
|
2016-05-12 11:57:29 +02:00
|
|
|
m_editorPlaceHolder = new EditorManagerPlaceHolder;
|
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),
|
2018-08-01 17:33:41 +02:00
|
|
|
this, [this](int item) {
|
|
|
|
|
restorePerspective(findPerspective(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);
|
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
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
savePerspectiveHelper(m_currentPerspective);
|
2018-07-24 15:40:35 +02:00
|
|
|
|
2016-05-12 11:57:29 +02:00
|
|
|
delete m_editorPlaceHolder;
|
2018-07-23 22:28:49 +02:00
|
|
|
m_editorPlaceHolder = nullptr;
|
2016-04-11 13:30:44 +02: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
|
2016-04-15 11:40:15 +02:00
|
|
|
foreach (QDockWidget *dock, m_dockForDockId) {
|
|
|
|
|
if (dock && !dock->parentWidget())
|
|
|
|
|
delete dock;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
foreach (const Perspective *perspective, m_perspectives)
|
2016-05-12 11:57:29 +02:00
|
|
|
delete perspective;
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, Perspective *perspective)
|
2016-03-01 07:51:06 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
m_perspectives.append(perspective);
|
|
|
|
|
perspective->m_id = perspectiveId;
|
2018-07-24 14:28:31 +02:00
|
|
|
QByteArray parentPerspective = perspective->parentPerspective();
|
|
|
|
|
// Add "main" perspectives to the chooser.
|
|
|
|
|
if (parentPerspective.isEmpty()) {
|
2018-08-01 17:33:41 +02:00
|
|
|
m_perspectiveChooser->addItem(perspective->name(), perspective->m_id);
|
2018-07-24 14:28:31 +02:00
|
|
|
increaseChooserWidthIfNecessary(perspective->name());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerMainWindow::increaseChooserWidthIfNecessary(const QString &visibleName)
|
|
|
|
|
{
|
2016-03-09 13:54:27 +01:00
|
|
|
const int oldWidth = m_perspectiveChooser->width();
|
2018-07-24 14:28:31 +02:00
|
|
|
const int contentWidth = m_perspectiveChooser->fontMetrics().width(visibleName);
|
2016-03-09 13:54:27 +01:00
|
|
|
QStyleOptionComboBox option;
|
|
|
|
|
option.initFrom(m_perspectiveChooser);
|
|
|
|
|
const QSize sz(contentWidth, 1);
|
|
|
|
|
const int width = m_perspectiveChooser->style()->sizeFromContents(
|
|
|
|
|
QStyle::CT_ComboBox, &option, sz).width();
|
|
|
|
|
if (width > oldWidth)
|
|
|
|
|
m_perspectiveChooser->setFixedWidth(width);
|
2016-03-01 07:51:06 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
void DebuggerMainWindow::destroyDynamicPerspective(Perspective *perspective)
|
2018-07-24 14:28:31 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(perspective, return);
|
2018-08-01 17:33:41 +02:00
|
|
|
savePerspectiveHelper(perspective);
|
|
|
|
|
|
|
|
|
|
m_perspectives.removeAll(perspective);
|
2018-07-24 14:28:31 +02:00
|
|
|
// Dynamic perspectives are currently not visible in the chooser.
|
|
|
|
|
// This might change in the future, make sure we notice.
|
2018-08-01 17:33:41 +02:00
|
|
|
const int idx = indexInChooser(perspective);
|
2018-07-24 14:28:31 +02:00
|
|
|
QTC_ASSERT(idx == -1, m_perspectiveChooser->removeItem(idx));
|
|
|
|
|
QByteArray parentPerspective = perspective->parentPerspective();
|
|
|
|
|
delete perspective;
|
|
|
|
|
// All dynamic perspectives currently have a static parent perspective.
|
|
|
|
|
// This might change in the future, make sure we notice.
|
|
|
|
|
QTC_CHECK(!parentPerspective.isEmpty());
|
2018-08-01 17:33:41 +02:00
|
|
|
restorePerspective(findPerspective(parentPerspective));
|
2018-07-24 14:28:31 +02: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
|
|
|
}
|
|
|
|
|
|
2017-10-26 16:32:48 +02:00
|
|
|
void DebuggerMainWindow::raiseDock(const QByteArray &dockId)
|
|
|
|
|
{
|
|
|
|
|
QDockWidget *dock = m_dockForDockId.value(dockId);
|
|
|
|
|
QTC_ASSERT(dock, return);
|
|
|
|
|
QAction *act = dock->toggleViewAction();
|
|
|
|
|
if (!act->isChecked())
|
2017-11-07 10:50:17 +01:00
|
|
|
QTimer::singleShot(1, act, [act] { act->trigger(); });
|
2017-10-26 16:32:48 +02:00
|
|
|
dock->raise();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
QByteArray DebuggerMainWindow::currentPerspective() const
|
|
|
|
|
{
|
|
|
|
|
return m_currentPerspective ? m_currentPerspective->m_id : QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 13:33:30 +02:00
|
|
|
void DebuggerMainWindow::onModeChanged(Core::Id mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == Debugger::Constants::MODE_DEBUG) {
|
|
|
|
|
setDockActionsVisible(true);
|
2018-08-01 17:33:41 +02:00
|
|
|
restorePerspective(nullptr);
|
2016-08-26 13:33:30 +02:00
|
|
|
} else {
|
|
|
|
|
setDockActionsVisible(false);
|
|
|
|
|
|
|
|
|
|
// Hide dock widgets manually in case they are floating.
|
|
|
|
|
foreach (QDockWidget *dockWidget, dockWidgets()) {
|
|
|
|
|
if (dockWidget->isFloating())
|
|
|
|
|
dockWidget->hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-11 15:57:45 +02:00
|
|
|
void DebuggerMainWindow::setPerspectiveEnabled(const QByteArray &perspectiveId, bool enabled)
|
|
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
Perspective *perspective = findPerspective(perspectiveId);
|
|
|
|
|
const int index = indexInChooser(perspective);
|
2017-07-11 15:57:45 +02:00
|
|
|
QTC_ASSERT(index != -1, return);
|
|
|
|
|
auto model = qobject_cast<QStandardItemModel*>(m_perspectiveChooser->model());
|
|
|
|
|
QTC_ASSERT(model, return);
|
|
|
|
|
QStandardItem *item = model->item(index, 0);
|
|
|
|
|
item->setFlags(enabled ? item->flags() | Qt::ItemIsEnabled : item->flags() & ~Qt::ItemIsEnabled );
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
Perspective *DebuggerMainWindow::findPerspective(const QByteArray &perspectiveId) const
|
|
|
|
|
{
|
|
|
|
|
return Utils::findOr(m_perspectives, nullptr, [&](Perspective *perspective) {
|
|
|
|
|
return perspective->m_id == perspectiveId;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void DebuggerMainWindow::resetCurrentPerspective()
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
loadPerspectiveHelper(m_currentPerspective, false);
|
2016-03-01 07:51:06 +01:00
|
|
|
}
|
2016-02-29 18:15:36 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
int DebuggerMainWindow::indexInChooser(Perspective *perspective) const
|
2016-03-01 07:51:06 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
return perspective ? m_perspectiveChooser->findData(perspective->m_id) : -1;
|
|
|
|
|
}
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
void DebuggerMainWindow::restorePerspective(Perspective *perspective)
|
|
|
|
|
{
|
|
|
|
|
loadPerspectiveHelper(perspective, true);
|
|
|
|
|
|
|
|
|
|
const int index = indexInChooser(m_currentPerspective);
|
2016-03-02 13:57:37 +01:00
|
|
|
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-24 13:59:05 +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;
|
2017-06-27 13:39:22 +02:00
|
|
|
viewButton->setText(tr("&Views"));
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-03-06 08:35:17 +01:00
|
|
|
auto closeButton = new QToolButton();
|
|
|
|
|
closeButton->setIcon(Utils::Icons::CLOSE_SPLIT_BOTTOM.icon());
|
|
|
|
|
closeButton->setToolTip(tr("Leave Debug Mode"));
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
auto toolbuttonBox = new QWidget;
|
|
|
|
|
m_toolbuttonBoxLayout = new QHBoxLayout(toolbuttonBox);
|
|
|
|
|
m_toolbuttonBoxLayout->setMargin(0);
|
|
|
|
|
m_toolbuttonBoxLayout->setSpacing(0);
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
auto toolbar = new Utils::StyledBar;
|
|
|
|
|
toolbar->setProperty("topBorder", true);
|
|
|
|
|
auto hbox = new QHBoxLayout(toolbar);
|
|
|
|
|
hbox->setMargin(0);
|
|
|
|
|
hbox->setSpacing(0);
|
|
|
|
|
hbox->addWidget(m_perspectiveChooser);
|
2018-08-01 17:33:41 +02:00
|
|
|
hbox->addWidget(toolbuttonBox);
|
|
|
|
|
hbox->addStretch(3);
|
2016-03-02 13:57:37 +01:00
|
|
|
hbox->addWidget(m_statusLabel);
|
2016-04-16 22:31:19 +02:00
|
|
|
hbox->addStretch(1);
|
2016-03-15 10:19:35 +01:00
|
|
|
hbox->addWidget(new Utils::StyledSeparator);
|
2016-03-02 13:57:37 +01:00
|
|
|
hbox->addWidget(viewButton);
|
2018-03-06 08:35:17 +01:00
|
|
|
hbox->addWidget(closeButton);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
connect(viewButton, &QAbstractButton::clicked, [this, viewButton] {
|
|
|
|
|
QMenu menu;
|
|
|
|
|
addDockActionsToMenu(&menu);
|
|
|
|
|
menu.exec(viewButton->mapToGlobal(QPoint()));
|
|
|
|
|
});
|
|
|
|
|
|
2018-03-06 08:35:17 +01:00
|
|
|
connect(closeButton, &QAbstractButton::clicked, [] {
|
|
|
|
|
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
Context debugcontext(Debugger::Constants::C_DEBUGMODE);
|
|
|
|
|
|
|
|
|
|
ActionContainer *viewsMenu = ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS);
|
2016-09-07 18:14:04 +02:00
|
|
|
Command *cmd = ActionManager::registerAction(showCentralWidgetAction(),
|
|
|
|
|
"Debugger.Views.ShowCentralWidget", debugcontext);
|
|
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
|
|
|
|
cmd->setAttribute(Command::CA_UpdateText);
|
|
|
|
|
viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
|
|
|
|
cmd = ActionManager::registerAction(menuSeparator1(),
|
2016-03-02 13:57:37 +01:00
|
|
|
"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);
|
|
|
|
|
|
2016-03-09 13:26:02 +01:00
|
|
|
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"));
|
|
|
|
|
dock->setWidget(toolbar);
|
|
|
|
|
m_toolbarDock = dock;
|
|
|
|
|
|
|
|
|
|
addDockWidget(Qt::BottomDockWidgetArea, dock);
|
2016-03-24 13:59:05 +01:00
|
|
|
}
|
2016-03-10 08:53:49 +01:00
|
|
|
|
2016-05-12 11:57:29 +02:00
|
|
|
QWidget *createModeWindow(const Core::Id &mode, DebuggerMainWindow *mainWindow)
|
2016-03-24 13:59:05 +01:00
|
|
|
{
|
2016-03-10 08:53:49 +01:00
|
|
|
auto editorHolderLayout = new QVBoxLayout;
|
|
|
|
|
editorHolderLayout->setMargin(0);
|
|
|
|
|
editorHolderLayout->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
auto editorAndFindWidget = new QWidget;
|
|
|
|
|
editorAndFindWidget->setLayout(editorHolderLayout);
|
2016-05-12 11:57:29 +02:00
|
|
|
editorHolderLayout->addWidget(mainWindow->centralWidgetStack());
|
2016-03-10 08:53:49 +01:00
|
|
|
editorHolderLayout->addWidget(new FindToolBarPlaceHolder(editorAndFindWidget));
|
|
|
|
|
|
|
|
|
|
auto documentAndRightPane = new MiniSplitter;
|
|
|
|
|
documentAndRightPane->addWidget(editorAndFindWidget);
|
|
|
|
|
documentAndRightPane->addWidget(new RightPanePlaceHolder(mode));
|
|
|
|
|
documentAndRightPane->setStretchFactor(0, 1);
|
|
|
|
|
documentAndRightPane->setStretchFactor(1, 0);
|
|
|
|
|
|
|
|
|
|
auto centralEditorWidget = new QWidget;
|
|
|
|
|
auto centralLayout = new QVBoxLayout(centralEditorWidget);
|
|
|
|
|
centralEditorWidget->setLayout(centralLayout);
|
|
|
|
|
centralLayout->setMargin(0);
|
|
|
|
|
centralLayout->setSpacing(0);
|
|
|
|
|
centralLayout->addWidget(documentAndRightPane);
|
|
|
|
|
centralLayout->setStretch(0, 1);
|
|
|
|
|
centralLayout->setStretch(1, 0);
|
|
|
|
|
|
|
|
|
|
// Right-side window with editor, output etc.
|
|
|
|
|
auto mainWindowSplitter = new MiniSplitter;
|
2016-03-24 13:59:05 +01:00
|
|
|
mainWindowSplitter->addWidget(mainWindow);
|
2016-03-10 08:53:49 +01:00
|
|
|
mainWindowSplitter->addWidget(new OutputPanePlaceHolder(mode, mainWindowSplitter));
|
|
|
|
|
auto outputPane = new OutputPanePlaceHolder(mode, mainWindowSplitter);
|
|
|
|
|
outputPane->setObjectName(QLatin1String("DebuggerOutputPanePlaceHolder"));
|
|
|
|
|
mainWindowSplitter->addWidget(outputPane);
|
|
|
|
|
mainWindowSplitter->setStretchFactor(0, 10);
|
|
|
|
|
mainWindowSplitter->setStretchFactor(1, 0);
|
|
|
|
|
mainWindowSplitter->setOrientation(Qt::Vertical);
|
|
|
|
|
|
|
|
|
|
// Navigation and right-side window.
|
|
|
|
|
auto splitter = new MiniSplitter;
|
2016-05-12 11:57:29 +02:00
|
|
|
splitter->setFocusProxy(mainWindow->centralWidgetStack());
|
2016-09-17 18:31:56 +03:00
|
|
|
splitter->addWidget(new NavigationWidgetPlaceHolder(mode, Side::Left));
|
2016-03-10 08:53:49 +01:00
|
|
|
splitter->addWidget(mainWindowSplitter);
|
|
|
|
|
splitter->setStretchFactor(0, 0);
|
|
|
|
|
splitter->setStretchFactor(1, 1);
|
|
|
|
|
splitter->setObjectName(QLatin1String("DebugModeWidget"));
|
2016-03-24 13:59:05 +01:00
|
|
|
mainWindow->setCentralWidget(centralEditorWidget);
|
2016-03-10 08:53:49 +01:00
|
|
|
|
2016-03-24 13:59:05 +01:00
|
|
|
return splitter;
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
void DebuggerMainWindow::loadPerspectiveHelper(Perspective *perspective, bool fromStoredSettings)
|
2016-03-02 13:57:37 +01:00
|
|
|
{
|
2016-03-01 07:51:06 +01:00
|
|
|
// Clean up old perspective.
|
2018-08-01 17:33:41 +02:00
|
|
|
if (m_currentPerspective) {
|
|
|
|
|
savePerspectiveHelper(m_currentPerspective);
|
2018-07-31 16:13:11 +02:00
|
|
|
for (QDockWidget *dock : m_dockForDockId) {
|
|
|
|
|
QTC_ASSERT(dock, continue);
|
|
|
|
|
dock->setParent(nullptr);
|
|
|
|
|
dock->widget()->setParent(nullptr);
|
|
|
|
|
ActionManager::unregisterAction(dock->toggleViewAction(),
|
|
|
|
|
Id("Dock.").withSuffix(dock->objectName()));
|
|
|
|
|
delete dock;
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
2018-07-31 16:13:11 +02:00
|
|
|
m_dockForDockId.clear();
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
ICore::removeAdditionalContext(Context(Id::fromName(m_currentPerspective->m_id)));
|
|
|
|
|
QWidget *central = m_currentPerspective->centralWidget();
|
2016-05-12 11:57:29 +02:00
|
|
|
m_centralWidgetStack->removeWidget(central ? central : m_editorPlaceHolder);
|
2016-03-01 07:51:06 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
// Detach potentially re-used widgets to prevent deletion.
|
|
|
|
|
for (const Perspective::ToolbarOperation &op : m_currentPerspective->m_toolbarOperations) {
|
|
|
|
|
if (op.widget)
|
|
|
|
|
op.widget->setParent(nullptr);
|
|
|
|
|
if (op.toolbutton)
|
|
|
|
|
op.toolbutton->setParent(nullptr);
|
|
|
|
|
if (op.separator)
|
|
|
|
|
op.separator->setParent(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (QLayoutItem *item = m_toolbuttonBoxLayout->takeAt(0))
|
|
|
|
|
delete item;
|
|
|
|
|
}
|
2016-03-01 07:51:06 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
if (perspective) {
|
|
|
|
|
m_currentPerspective = perspective;
|
|
|
|
|
} else {
|
2016-03-02 13:57:37 +01:00
|
|
|
const QSettings *settings = ICore::settings();
|
2018-08-01 17:33:41 +02:00
|
|
|
m_currentPerspective = findPerspective(settings->value(QLatin1String(LAST_PERSPECTIVE_KEY)).toByteArray());
|
|
|
|
|
if (!m_currentPerspective)
|
|
|
|
|
m_currentPerspective = findPerspective(Debugger::Constants::CppPerspectiveId);
|
|
|
|
|
if (!m_currentPerspective && !m_perspectives.isEmpty())
|
|
|
|
|
m_currentPerspective = m_perspectives.first();
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
2018-08-01 17:33:41 +02:00
|
|
|
QTC_ASSERT(m_currentPerspective, return);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
ICore::addAdditionalContext(Context(Id::fromName(m_currentPerspective->m_id)));
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
m_currentPerspective->aboutToActivate();
|
|
|
|
|
|
|
|
|
|
for (const Perspective::ToolbarOperation &op : m_currentPerspective->m_toolbarOperations) {
|
|
|
|
|
if (op.widget)
|
|
|
|
|
m_toolbuttonBoxLayout->addWidget(op.widget);
|
|
|
|
|
if (op.toolbutton)
|
|
|
|
|
m_toolbuttonBoxLayout->addWidget(op.toolbutton);
|
|
|
|
|
if (op.separator)
|
|
|
|
|
m_toolbuttonBoxLayout->addWidget(op.separator);
|
2018-07-24 15:40:35 +02:00
|
|
|
}
|
2018-08-01 17:33:41 +02:00
|
|
|
|
|
|
|
|
for (const Perspective::Operation &op : m_currentPerspective->m_operations) {
|
2018-07-31 16:13:11 +02:00
|
|
|
QTC_ASSERT(op.widget, continue);
|
|
|
|
|
const QByteArray dockId = op.widget->objectName().toUtf8();
|
|
|
|
|
QDockWidget *dock = m_dockForDockId.value(dockId);
|
2016-03-02 13:57:37 +01:00
|
|
|
if (!dock) {
|
2018-07-31 16:13:11 +02:00
|
|
|
QTC_CHECK(!dockId.isEmpty());
|
|
|
|
|
dock = addDockForWidget(op.widget);
|
|
|
|
|
m_dockForDockId[dockId] = dock;
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
QAction *toggleViewAction = dock->toggleViewAction();
|
|
|
|
|
toggleViewAction->setText(dock->windowTitle());
|
|
|
|
|
|
|
|
|
|
Command *cmd = ActionManager::registerAction(toggleViewAction,
|
|
|
|
|
Id("Dock.").withSuffix(dock->objectName()),
|
2018-08-01 17:33:41 +02:00
|
|
|
Context(Id::fromName(m_currentPerspective->m_id)));
|
2016-03-02 13:57:37 +01:00
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
|
|
|
|
|
|
|
|
|
ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS)->addAction(cmd);
|
|
|
|
|
}
|
2016-04-11 13:30:44 +02:00
|
|
|
// Restore parent/child relation, so that the widget hierarchy is clear.
|
|
|
|
|
dock->setParent(this);
|
2018-07-31 16:13:11 +02:00
|
|
|
if (op.operationType == Perspective::Raise) {
|
2016-03-02 14:39:20 +01:00
|
|
|
dock->raise();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-07-31 16:13:11 +02:00
|
|
|
addDockWidget(op.area, dock);
|
|
|
|
|
QDockWidget *anchor = m_dockForDockId.value(op.anchorDockId);
|
|
|
|
|
if (!anchor && op.area == Qt::BottomDockWidgetArea)
|
2016-03-09 13:26:02 +01:00
|
|
|
anchor = m_toolbarDock;
|
2016-03-02 13:57:37 +01:00
|
|
|
if (anchor) {
|
2018-07-31 16:13:11 +02:00
|
|
|
switch (op.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
|
|
|
}
|
|
|
|
|
}
|
2018-07-31 16:13:11 +02:00
|
|
|
if (!op.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();
|
2018-08-01 17:33:41 +02:00
|
|
|
settings->beginGroup(QString::fromLatin1(m_currentPerspective->m_id));
|
2016-02-29 18:15:36 +01:00
|
|
|
if (settings->value(QLatin1String("ToolSettingsSaved"), false).toBool())
|
|
|
|
|
restoreSettings(settings);
|
|
|
|
|
settings->endGroup();
|
2016-09-07 18:14:04 +02:00
|
|
|
} else {
|
|
|
|
|
// By default, show the central widget
|
|
|
|
|
showCentralWidgetAction()->setChecked(true);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
QWidget *central = m_currentPerspective->centralWidget();
|
2016-05-12 11:57:29 +02:00
|
|
|
m_centralWidgetStack->addWidget(central ? central : m_editorPlaceHolder);
|
2016-09-07 18:14:04 +02:00
|
|
|
showCentralWidgetAction()->setText(central ? central->windowTitle() : tr("Editor"));
|
2016-05-12 11:57:29 +02:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
m_statusLabel->clear();
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
void DebuggerMainWindow::savePerspectiveHelper(const Perspective *perspective)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
if (!perspective)
|
2016-03-01 07:51:06 +01:00
|
|
|
return;
|
2016-02-29 18:15:36 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2018-08-01 17:33:41 +02:00
|
|
|
settings->beginGroup(QString::fromLatin1(perspective->m_id));
|
2016-02-29 18:15:36 +01:00
|
|
|
saveSettings(settings);
|
|
|
|
|
settings->setValue(QLatin1String("ToolSettingsSaved"), true);
|
|
|
|
|
settings->endGroup();
|
2018-08-01 17:33:41 +02:00
|
|
|
settings->setValue(QLatin1String(LAST_PERSPECTIVE_KEY), perspective->m_id);
|
2016-02-29 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 11:57:29 +02:00
|
|
|
Perspective::~Perspective()
|
|
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
for (const ToolbarOperation &op : m_toolbarOperations) {
|
|
|
|
|
// op.widget and op.actions are owned by the plugins
|
|
|
|
|
delete op.toolbutton;
|
|
|
|
|
delete op.separator;
|
|
|
|
|
}
|
2018-07-31 12:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Perspective::setCentralWidget(QWidget *centralWidget)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_centralWidget == nullptr, return);
|
|
|
|
|
m_centralWidget = centralWidget;
|
2016-05-12 11:57:29 +02:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 13:57:11 +01:00
|
|
|
void Perspective::setAboutToActivateCallback(const Perspective::Callback &cb)
|
|
|
|
|
{
|
|
|
|
|
m_aboutToActivateCallback = cb;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 14:32:03 +01:00
|
|
|
void Perspective::aboutToActivate() const
|
2016-11-21 13:57:11 +01:00
|
|
|
{
|
|
|
|
|
if (m_aboutToActivateCallback)
|
|
|
|
|
m_aboutToActivateCallback();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 14:28:31 +02:00
|
|
|
QByteArray Perspective::parentPerspective() const
|
|
|
|
|
{
|
|
|
|
|
return m_parentPerspective;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Perspective::setParentPerspective(const QByteArray &parentPerspective)
|
|
|
|
|
{
|
|
|
|
|
m_parentPerspective = parentPerspective;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
QToolButton *Perspective::addToolbarAction(QAction *action, const QIcon &toolbarIcon)
|
2016-03-02 13:57:37 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
ToolbarOperation op;
|
|
|
|
|
op.action = action;
|
|
|
|
|
op.icon = toolbarIcon;
|
|
|
|
|
op.toolbutton = new QToolButton;
|
2018-08-10 14:31:55 +02:00
|
|
|
// QStyle::polish is called before it is added to the toolbar, explicitly make it a panel widget
|
|
|
|
|
op.toolbutton->setProperty("panelwidget", true);
|
2018-08-01 17:33:41 +02:00
|
|
|
op.toolbutton->setDefaultAction(toolbarIcon.isNull()
|
|
|
|
|
? action : ProxyAction::proxyActionWithIcon(action, toolbarIcon));
|
|
|
|
|
m_toolbarOperations.append(op);
|
|
|
|
|
|
|
|
|
|
return op.toolbutton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Perspective::addToolbarWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
ToolbarOperation op;
|
|
|
|
|
op.widget = widget;
|
2018-08-10 14:31:55 +02:00
|
|
|
// QStyle::polish is called before it is added to the toolbar, explicitly make it a panel widget
|
|
|
|
|
op.widget->setProperty("panelwidget", true);
|
2018-08-01 17:33:41 +02:00
|
|
|
m_toolbarOperations.append(op);
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
void Perspective::addToolbarSeparator()
|
2016-03-02 13:57:37 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
ToolbarOperation op;
|
|
|
|
|
op.separator = new StyledSeparator;
|
|
|
|
|
m_toolbarOperations.append(op);
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-01 17:33:41 +02:00
|
|
|
QWidget *Perspective::centralWidget() const
|
2016-03-02 13:57:37 +01:00
|
|
|
{
|
2018-08-01 17:33:41 +02:00
|
|
|
return m_centralWidget;
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 16:13:11 +02:00
|
|
|
Perspective::Perspective(const QString &name)
|
|
|
|
|
: m_name(name)
|
2016-02-29 18:15:36 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 16:13:11 +02:00
|
|
|
void Perspective::addWindow(QWidget *widget, OperationType type, QWidget *anchorWidget,
|
|
|
|
|
bool visibleByDefault, Qt::DockWidgetArea area)
|
2018-07-24 11:50:08 +02:00
|
|
|
{
|
2018-07-31 16:13:11 +02:00
|
|
|
Operation op;
|
|
|
|
|
op.widget = widget;
|
|
|
|
|
if (anchorWidget)
|
|
|
|
|
op.anchorDockId = anchorWidget->objectName().toUtf8();
|
|
|
|
|
op.operationType = type;
|
|
|
|
|
op.visibleByDefault = visibleByDefault;
|
|
|
|
|
op.area = area;
|
|
|
|
|
m_operations.append(op);
|
2018-07-24 11:50:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
} // Utils
|