debuggermainwindow.cpp 24.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "debuggermainwindow.h"
#include "debuggerplugin.h"

#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <utils/fancymainwindow.h>

#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/imode.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h>
#include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h>
#include <coreplugin/rightpane.h>

hjk's avatar
hjk committed
51
#include <projectexplorer/project.h>
52
#include <projectexplorer/projectexplorer.h>
hjk's avatar
hjk committed
53
54
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfiguration.h>
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>

#include <QtCore/QDebug>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <QtCore/QSettings>

#include <QtGui/QDockWidget>
#include <QtGui/QMenu>
#include <QtGui/QResizeEvent>
#include <QtGui/QStackedWidget>
#include <QtGui/QVBoxLayout>

using namespace Core;
71
using namespace ProjectExplorer;
72
using namespace Debugger::Constants;
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

namespace Debugger {
namespace Internal {

class DockWidgetEventFilter : public QObject
{
    Q_OBJECT

public:
    explicit DockWidgetEventFilter(QObject *parent = 0) : QObject(parent) {}

signals:
    void widgetResized();

protected:
    virtual bool eventFilter(QObject *obj, QEvent *event);
};

bool DockWidgetEventFilter::eventFilter(QObject *obj, QEvent *event)
{
    switch (event->type()) {
    case QEvent::Resize:
    case QEvent::ZOrderChange:
        emit widgetResized();
        break;
    default:
        break;
    }
    return QObject::eventFilter(obj, event);
}

104
class DebuggerMainWindowPrivate : public QObject
105
{
106
107
    Q_OBJECT

108
109
110
public:
    explicit DebuggerMainWindowPrivate(DebuggerMainWindow *mainWindow);

111
112
113
114
115
116
    void activateQmlCppLayout();
    void activateCppLayout();
    void hideInactiveWidgets();
    void createViewsMenuItems();
    bool isQmlCppActive() const;
    bool isQmlActive() const;
117
    void setSimpleDockWidgetArrangement();
hjk's avatar
hjk committed
118
    void updateUi();
hjk's avatar
hjk committed
119
120
121
    // Debuggable languages are registered with this function.
    void addLanguage(const DebuggerLanguage &language, const Core::Context &context);

122
123
124
125
126
127
128
129
130
131

public slots:
    void resetDebuggerLayout();

    void updateUiForProject(ProjectExplorer::Project *project);
    void updateUiForTarget(ProjectExplorer::Target *target);
    void updateUiForRunConfiguration(ProjectExplorer::RunConfiguration *rc);
    void updateUiForCurrentRunConfiguration();
    void updateUiOnFileListChange();

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
public:
    DebuggerMainWindow *q;
    QList<QDockWidget *> m_dockWidgets;

    QHash<QString, QVariant> m_dockWidgetActiveStateCpp;
    QHash<QString, QVariant> m_dockWidgetActiveStateQmlCpp;
    Internal::DockWidgetEventFilter *m_resizeEventFilter;

    QMap<DebuggerLanguage, QWidget *> m_toolBars;

    DebuggerLanguages m_supportedLanguages;
    int m_languageCount;

    QStackedWidget *m_toolbarStack;

    QHash<DebuggerLanguage, Context> m_contextsForLanguage;

    bool m_inDebugMode;
    bool m_changingUI;

    DebuggerLanguages m_previousDebugLanguages;
    DebuggerLanguages m_activeDebugLanguages;

    ActionContainer *m_viewsMenu;

157
158
159
    QWeakPointer<Project> m_previousProject;
    QWeakPointer<Target> m_previousTarget;
    QWeakPointer<RunConfiguration> m_previousRunConfiguration;
160
161
162
163
164
165
166
167
168
169
170
171
172
};

DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *mw)
    : q(mw)
    , m_resizeEventFilter(new Internal::DockWidgetEventFilter(mw))
    , m_supportedLanguages(AnyLanguage)
    , m_languageCount(0)
    , m_toolbarStack(new QStackedWidget)
    , m_inDebugMode(false)
    , m_changingUI(false)
    , m_previousDebugLanguages(AnyLanguage)
    , m_activeDebugLanguages(AnyLanguage)
    , m_viewsMenu(0)
hjk's avatar
hjk committed
173
{}
174

175
void DebuggerMainWindowPrivate::updateUiOnFileListChange()
176
{
177
178
    if (m_previousProject)
        updateUiForTarget(m_previousProject.data()->activeTarget());
179
180
}

181
void DebuggerMainWindowPrivate::updateUiForProject(Project *project)
182
183
184
{
    if (!project)
        return;
185
186
    if (m_previousProject) {
        disconnect(m_previousProject.data(),
187
188
189
            SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
            this, SLOT(updateUiForTarget(ProjectExplorer::Target*)));
    }
190
    m_previousProject = project;
191
192
193
194
195
196
197
    connect(project, SIGNAL(fileListChanged()),
        SLOT(updateUiOnFileListChange()));
    connect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
        SLOT(updateUiForTarget(ProjectExplorer::Target*)));
    updateUiForTarget(project->activeTarget());
}

198
void DebuggerMainWindowPrivate::updateUiForTarget(Target *target)
199
200
201
202
{
    if (!target)
        return;

203
204
    if (m_previousTarget) {
         disconnect(m_previousTarget.data(),
205
206
207
            SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
            this, SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
    }
208
    m_previousTarget = target;
209
210
211
212
213
214
215
    connect(target,
        SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
        SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
    updateUiForRunConfiguration(target->activeRunConfiguration());
}

// updates default debug language settings per run config.
216
void DebuggerMainWindowPrivate::updateUiForRunConfiguration(RunConfiguration *rc)
217
{
218
219
220
221
    if (!rc)
        return;
    if (m_previousRunConfiguration)
        disconnect(m_previousRunConfiguration.data(), SIGNAL(debuggersChanged()),
222
                   this, SLOT(updateUiForCurrentRunConfiguration()));
223
224
225
226
227
228
    m_previousRunConfiguration = rc;
    connect(m_previousRunConfiguration.data(),
            SIGNAL(debuggersChanged()),
            SLOT(updateUiForCurrentRunConfiguration()));
    updateUiForCurrentRunConfiguration();
}
229

230
231
232
void DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration()
{
    q->updateActiveLanguages();
233
234
}

235
236
237
238
239
} // namespace Internal

using namespace Internal;

DebuggerMainWindow::DebuggerMainWindow()
240
{
241
242
    d = new DebuggerMainWindowPrivate(this);
    d->createViewsMenuItems();
hjk's avatar
hjk committed
243
244
    d->addLanguage(CppLanguage, Context(C_CPPDEBUGGER));
    d->addLanguage(QmlLanguage, Context(C_QMLDEBUGGER));
245
246
247
248
249
}

DebuggerMainWindow::~DebuggerMainWindow()
{
    delete d;
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
}

void DebuggerMainWindow::updateActiveLanguages()
{
    DebuggerLanguages newLanguages = AnyLanguage;

    if (d->m_previousRunConfiguration) {
        if (d->m_previousRunConfiguration.data()->useCppDebugger())
            newLanguages = CppLanguage;
        if (d->m_previousRunConfiguration.data()->useQmlDebugger())
            newLanguages |= QmlLanguage;
    }

    if (newLanguages != d->m_activeDebugLanguages) {
        d->m_activeDebugLanguages = newLanguages;
        emit activeLanguagesChanged(d->m_activeDebugLanguages);
    }

268
    d->updateUi();
269
270
271
272
273
274
275
276
277
278
279
}

DebuggerLanguages DebuggerMainWindow::activeDebugLanguages() const
{
    return d->m_activeDebugLanguages;
}

void DebuggerMainWindow::onModeChanged(IMode *mode)
{
    d->m_inDebugMode = (mode->id() == Constants::MODE_DEBUG);
    setDockActionsVisible(d->m_inDebugMode);
280
    d->hideInactiveWidgets();
281
282
283
284
285
286
287
288

    if (mode->id() != Constants::MODE_DEBUG)
        //|| DebuggerPlugin::instance()->hasSnapshots())
       return;

    updateActiveLanguages();
}

289
void DebuggerMainWindowPrivate::hideInactiveWidgets()
290
291
{
    // Hide all the debugger windows if mode is different.
292
    if (m_inDebugMode)
293
294
        return;
    // Hide dock widgets manually in case they are floating.
295
    foreach (QDockWidget *dockWidget, m_dockWidgets) {
296
297
298
299
300
        if (dockWidget->isFloating())
            dockWidget->hide();
    }
}

301
void DebuggerMainWindowPrivate::createViewsMenuItems()
302
303
304
305
{
    ICore *core = ICore::instance();
    ActionManager *am = core->actionManager();
    Context globalcontext(Core::Constants::C_GLOBAL);
306
307
    m_viewsMenu = am->actionContainer(Id(Core::Constants::M_WINDOW_VIEWS));
    QTC_ASSERT(m_viewsMenu, return)
308

309
310
311
    QAction *openMemoryEditorAction = new QAction(this);
    openMemoryEditorAction->setText(tr("Memory..."));
    connect(openMemoryEditorAction, SIGNAL(triggered()),
312
       q, SIGNAL(memoryEditorRequested()));
313
314
315

    // Add menu items
    Command *cmd = 0;
316
    cmd = am->registerAction(openMemoryEditorAction,
317
318
        Core::Id("Debugger.Views.OpenMemoryEditor"),
        Core::Context(Constants::C_DEBUGMODE));
319
320
    m_viewsMenu->addAction(cmd);
    cmd = am->registerAction(q->menuSeparator1(),
321
        Core::Id("Debugger.Views.Separator1"), globalcontext);
322
323
    m_viewsMenu->addAction(cmd);
    cmd = am->registerAction(q->toggleLockedAction(),
324
        Core::Id("Debugger.Views.ToggleLocked"), globalcontext);
325
326
    m_viewsMenu->addAction(cmd);
    cmd = am->registerAction(q->menuSeparator2(),
327
        Core::Id("Debugger.Views.Separator2"), globalcontext);
328
329
    m_viewsMenu->addAction(cmd);
    cmd = am->registerAction(q->resetLayoutAction(),
330
        Core::Id("Debugger.Views.ResetSimple"), globalcontext);
331
    m_viewsMenu->addAction(cmd);
332
333
}

hjk's avatar
hjk committed
334
void DebuggerMainWindowPrivate::addLanguage(const DebuggerLanguage &languageId,
hjk's avatar
hjk committed
335
    const Context &context)
336
{
hjk's avatar
hjk committed
337
338
    m_supportedLanguages = m_supportedLanguages | languageId;
    m_languageCount++;
339

hjk's avatar
hjk committed
340
341
    m_toolBars.insert(languageId, 0);
    m_contextsForLanguage.insert(languageId, context);
342
343
}

344
void DebuggerMainWindowPrivate::updateUi()
345
{
346
    if (m_changingUI || !m_inDebugMode)
347
348
        return;

349
    m_changingUI = true;
350

351
    if (isQmlActive())
352
        activateQmlCppLayout();
353
    else
354
355
        activateCppLayout();

356
    m_previousDebugLanguages = m_activeDebugLanguages;
357

358
    m_changingUI = false;
359
360
}

361
void DebuggerMainWindowPrivate::activateQmlCppLayout()
362
363
{
    ICore *core = ICore::instance();
364
365
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
366
367

    // always use cpp toolbar
368
    m_toolbarStack->setCurrentWidget(m_toolBars.value(CppLanguage));
369

370
371
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
372
        core->updateAdditionalContexts(qmlCppContext, Context());
373
374
375
376
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
        core->updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
            Context());
377
378
    }

379
    q->restoreSettings(m_dockWidgetActiveStateQmlCpp);
380
381
382
    core->updateAdditionalContexts(Context(), qmlCppContext);
}

383
void DebuggerMainWindowPrivate::activateCppLayout()
384
385
{
    ICore *core = ICore::instance();
386
387
388
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
    m_toolbarStack->setCurrentWidget(m_toolBars.value(CppLanguage));
389

390
391
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
392
        core->updateAdditionalContexts(qmlCppContext, Context());
393
394
395
396
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
        core->updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
            Context());
397
398
    }

399
    q->restoreSettings(m_dockWidgetActiveStateCpp);
400

401
    const Context &cppContext = m_contextsForLanguage.value(CppLanguage);
402
403
404
405
406
407
408
409
410
411
412
413
    core->updateAdditionalContexts(Context(), cppContext);
}

void DebuggerMainWindow::setToolbar(const DebuggerLanguage &language, QWidget *widget)
{
    Q_ASSERT(d->m_toolBars.contains(language));
    d->m_toolBars[language] = widget;
    d->m_toolbarStack->addWidget(widget);
}

QDockWidget *DebuggerMainWindow::dockWidget(const QString &objectName) const
{
414
    foreach (QDockWidget *dockWidget, d->m_dockWidgets) {
415
416
417
418
419
420
        if (dockWidget->objectName() == objectName)
            return dockWidget;
    }
    return 0;
}

421
422
423
424
425
426
bool DebuggerMainWindow::isDockVisible(const QString &objectName) const
{
    QDockWidget *dock = dockWidget(objectName);
    return dock && dock->toggleViewAction()->isChecked();
}

427
428
429
430
/*!
    Keep track of dock widgets so they can be shown/hidden for different languages
*/
QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &language,
hjk's avatar
hjk committed
431
    QWidget *widget)
432
433
434
435
{
//    qDebug() << "CREATE DOCK" << widget->objectName() << "LANGUAGE ID" << language
//             << "VISIBLE BY DEFAULT" << ((d->m_activeDebugLanguages & language) ? "true" : "false");
    QDockWidget *dockWidget = addDockForWidget(widget);
hjk's avatar
hjk committed
436
437
    dockWidget->setObjectName(widget->objectName());
    addDockWidget(Qt::TopDockWidgetArea, dockWidget);
438
439
440
441
442
443
444
445
446
447
    d->m_dockWidgets.append(dockWidget);

    if (!(d->m_activeDebugLanguages & language))
        dockWidget->hide();

    Context globalContext(Core::Constants::C_GLOBAL);

    ActionManager *am = ICore::instance()->actionManager();
    QAction *toggleViewAction = dockWidget->toggleViewAction();
    Command *cmd = am->registerAction(toggleViewAction,
hjk's avatar
hjk committed
448
             QString("Debugger." + widget->objectName()), globalContext);
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
    cmd->setAttribute(Command::CA_Hide);
    d->m_viewsMenu->addAction(cmd);

    dockWidget->installEventFilter(d->m_resizeEventFilter);

    connect(dockWidget->toggleViewAction(), SIGNAL(triggered(bool)),
        SLOT(updateDockWidgetSettings()));
    connect(dockWidget, SIGNAL(topLevelChanged(bool)),
        SLOT(updateDockWidgetSettings()));
    connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
        SLOT(updateDockWidgetSettings()));

    return dockWidget;
}

QWidget *DebuggerMainWindow::createContents(IMode *mode)
{
    ICore *core = ICore::instance();
    ActionManager *am = core->actionManager();
468
    ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
469
    connect(pe->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
470
        d, SLOT(updateUiForProject(ProjectExplorer::Project*)));
471
472
473
474
475
476
477
478
479
480
    connect(d->m_resizeEventFilter, SIGNAL(widgetResized()),
        SLOT(updateDockWidgetSettings()));

    d->m_viewsMenu = am->actionContainer(Core::Id(Core::Constants::M_WINDOW_VIEWS));
    QTC_ASSERT(d->m_viewsMenu, return 0)

    //d->m_mainWindow = new Internal::DebuggerMainWindow(this);
    setDocumentMode(true);
    setDockNestingEnabled(true);
    connect(this, SIGNAL(resetLayout()),
481
        d, SLOT(resetDebuggerLayout()));
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
    connect(toggleLockedAction(), SIGNAL(triggered()),
        SLOT(updateDockWidgetSettings()));

    QBoxLayout *editorHolderLayout = new QVBoxLayout;
    editorHolderLayout->setMargin(0);
    editorHolderLayout->setSpacing(0);

    QWidget *editorAndFindWidget = new QWidget;
    editorAndFindWidget->setLayout(editorHolderLayout);
    editorHolderLayout->addWidget(new EditorManagerPlaceHolder(mode));
    editorHolderLayout->addWidget(new FindToolBarPlaceHolder(editorAndFindWidget));

    MiniSplitter *documentAndRightPane = new MiniSplitter;
    documentAndRightPane->addWidget(editorAndFindWidget);
    documentAndRightPane->addWidget(new RightPanePlaceHolder(mode));
    documentAndRightPane->setStretchFactor(0, 1);
    documentAndRightPane->setStretchFactor(1, 0);

    Utils::StyledBar *debugToolBar = new Utils::StyledBar;
    debugToolBar->setProperty("topBorder", true);
    QHBoxLayout *debugToolBarLayout = new QHBoxLayout(debugToolBar);
    debugToolBarLayout->setMargin(0);
    debugToolBarLayout->setSpacing(0);
    debugToolBarLayout->addWidget(d->m_toolbarStack);
    debugToolBarLayout->addStretch();
    debugToolBarLayout->addWidget(new Utils::StyledSeparator);

    QDockWidget *dock = new QDockWidget(tr("Debugger Toolbar"));
    dock->setObjectName(QLatin1String("Debugger Toolbar"));
    dock->setWidget(debugToolBar);
    dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dock->setAllowedAreas(Qt::BottomDockWidgetArea);
    dock->setTitleBarWidget(new QWidget(dock));
    addDockWidget(Qt::BottomDockWidgetArea, dock);
    setToolBarDockWidget(dock);

    QWidget *centralWidget = new QWidget;
    setCentralWidget(centralWidget);

    QVBoxLayout *centralLayout = new QVBoxLayout(centralWidget);
    centralWidget->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.
    MiniSplitter *mainWindowSplitter = new MiniSplitter;
    mainWindowSplitter->addWidget(this);
532
533
534
    QWidget *outputPane = new OutputPanePlaceHolder(mode, mainWindowSplitter);
    outputPane->setObjectName(QLatin1String("DebuggerOutputPanePlaceHolder"));
    mainWindowSplitter->addWidget(outputPane);
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
    mainWindowSplitter->setStretchFactor(0, 10);
    mainWindowSplitter->setStretchFactor(1, 0);
    mainWindowSplitter->setOrientation(Qt::Vertical);

    // Navigation and right-side window.
    MiniSplitter *splitter = new MiniSplitter;
    splitter->addWidget(new NavigationWidgetPlaceHolder(mode));
    splitter->addWidget(mainWindowSplitter);
    splitter->setStretchFactor(0, 0);
    splitter->setStretchFactor(1, 1);
    return splitter;
}

void DebuggerMainWindow::writeSettings() const
{
hjk's avatar
hjk committed
550
551
552
553
554
555
    ICore *core = ICore::instance();
    QTC_ASSERT(core, return);
    QSettings *settings = core->settings();
    QTC_ASSERT(settings, return);

    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
556
557
558
    QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
559
        settings->setValue(it.key(), it.value());
560
    }
hjk's avatar
hjk committed
561
    settings->endGroup();
562

hjk's avatar
hjk committed
563
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
564
565
566
    it = QHashIterator<QString, QVariant>(d->m_dockWidgetActiveStateQmlCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
567
        settings->setValue(it.key(), it.value());
568
    }
hjk's avatar
hjk committed
569
    settings->endGroup();
570
571
572
573
}

void DebuggerMainWindow::readSettings()
{
hjk's avatar
hjk committed
574
575
576
577
578
    ICore *core = ICore::instance();
    QTC_ASSERT(core, return);
    QSettings *settings = core->settings();
    QTC_ASSERT(settings, return);

579
580
581
    d->m_dockWidgetActiveStateCpp.clear();
    d->m_dockWidgetActiveStateQmlCpp.clear();

hjk's avatar
hjk committed
582
583
584
585
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateCpp.insert(key, settings->value(key));
    settings->endGroup();
586

hjk's avatar
hjk committed
587
588
589
590
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateQmlCpp.insert(key, settings->value(key));
    settings->endGroup();
591
592
593
594
595

    // reset initial settings when there are none yet
    DebuggerLanguages langs = d->m_activeDebugLanguages;
    if (d->m_dockWidgetActiveStateCpp.isEmpty()) {
        d->m_activeDebugLanguages = CppLanguage;
596
        d->resetDebuggerLayout();
597
598
599
    }
    if (d->m_dockWidgetActiveStateQmlCpp.isEmpty()) {
        d->m_activeDebugLanguages = QmlLanguage;
600
        d->resetDebuggerLayout();
601
602
603
604
    }
    d->m_activeDebugLanguages = langs;
}

605
void DebuggerMainWindowPrivate::resetDebuggerLayout()
606
{
607
    setSimpleDockWidgetArrangement();
608
609

    if (isQmlActive())
610
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
611
    else
612
        m_dockWidgetActiveStateCpp = q->saveSettings();
613

614
    q->updateActiveLanguages();
615
616
617
618
619
620
621
}

void DebuggerMainWindow::updateDockWidgetSettings()
{
    if (!d->m_inDebugMode || d->m_changingUI)
        return;

622
    if (d->isQmlActive())
623
624
625
626
627
        d->m_dockWidgetActiveStateQmlCpp = saveSettings();
    else
        d->m_dockWidgetActiveStateCpp = saveSettings();
}

628
bool DebuggerMainWindowPrivate::isQmlCppActive() const
629
{
630
631
    return (m_activeDebugLanguages & CppLanguage)
        && (m_activeDebugLanguages & QmlLanguage);
632
633
}

634
bool DebuggerMainWindowPrivate::isQmlActive() const
635
{
636
    return (m_activeDebugLanguages & QmlLanguage);
637
638
639
640
641
}

QMenu *DebuggerMainWindow::createPopupMenu()
{
    QMenu *menu = 0;
hjk's avatar
hjk committed
642
    if (!d->m_dockWidgets.isEmpty()) {
643
        menu = FancyMainWindow::createPopupMenu();
hjk's avatar
hjk committed
644
        foreach (QDockWidget *dockWidget, d->m_dockWidgets)
645
646
647
648
649
650
651
            if (dockWidget->parentWidget() == this)
                menu->addAction(dockWidget->toggleViewAction());
        menu->addSeparator();
    }
    return menu;
}

652
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
653
654
655
656
657
658
659
660
661
662
{
    QTC_ASSERT(q, return);
    q->setTrackingEnabled(false);

    foreach (QDockWidget *dockWidget, m_dockWidgets) {
        dockWidget->setFloating(false);
        q->removeDockWidget(dockWidget);
    }

    // FIXME: Temporary.
hjk's avatar
hjk committed
663
664
665
666
667
668
669
670
671
672
673
674
    QDockWidget *m_breakDock =
        q->dockWidget(Constants::DOCKWIDGET_BREAK);
    QDockWidget *m_stackDock =
        q->dockWidget(Constants::DOCKWIDGET_STACK);
    QDockWidget *m_watchDock =
        q->dockWidget(Constants::DOCKWIDGET_WATCHERS);
    QDockWidget *m_snapshotsDock =
        q->dockWidget(Constants::DOCKWIDGET_SNAPSHOTS);
    QDockWidget *m_threadsDock =
        q->dockWidget(Constants::DOCKWIDGET_THREADS);
    QDockWidget *m_outputDock =
        q->dockWidget(Constants::DOCKWIDGET_OUTPUT);
675
676
    QDockWidget *m_qmlInspectorDock =
        q->dockWidget(Constants::DOCKWIDGET_QML_INSPECTOR);
677
678
679
680
681
682
683
684
685
686
    QDockWidget *m_scriptConsoleDock =
        q->dockWidget(Constants::DOCKWIDGET_QML_SCRIPTCONSOLE);
    QDockWidget *m_modulesDock =
        q->dockWidget(Constants::DOCKWIDGET_MODULES);
    QDockWidget *m_registerDock =
        q->dockWidget(Constants::DOCKWIDGET_REGISTER);
    QDockWidget *m_sourceFilesDock =
        q->dockWidget(Constants::DOCKWIDGET_SOURCE_FILES);

    foreach (QDockWidget *dockWidget, m_dockWidgets) {
687
        if (dockWidget == m_outputDock /*|| dockWidget == m_consoleDock*/)
688
            q->addDockWidget(Qt::TopDockWidgetArea, dockWidget);
689
        else
690
691
692
693
            q->addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
        dockWidget->hide();
    }

694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
    if (m_activeDebugLanguages.testFlag(Debugger::CppLanguage)
            && m_activeDebugLanguages.testFlag(Debugger::QmlLanguage)) {
        // cpp + qml
        foreach (QDockWidget *dockWidget, m_dockWidgets) {
            if (dockWidget == m_outputDock)
                q->addDockWidget(Qt::TopDockWidgetArea, dockWidget);
            else
                q->addDockWidget(Qt::BottomDockWidgetArea, dockWidget);

            if (dockWidget == m_qmlInspectorDock)
                dockWidget->show();
            else
                dockWidget->hide();
        }

709
710
        m_stackDock->show();
        m_watchDock->show();
711
        m_breakDock->show();
712
        m_threadsDock->show();
713
714
715
716
717
718
719
720
        m_snapshotsDock->show();
        m_qmlInspectorDock->show();

        q->splitDockWidget(q->toolBarDockWidget(), m_stackDock, Qt::Vertical);
        q->splitDockWidget(m_stackDock, m_watchDock, Qt::Horizontal);
        q->tabifyDockWidget(m_watchDock, m_breakDock);
        q->tabifyDockWidget(m_watchDock, m_qmlInspectorDock);

721
    } else {
722
723
724
725
726
727
728
729
730
731
732
733
734
735

        if ((m_activeDebugLanguages.testFlag(CppLanguage)
                && !m_activeDebugLanguages.testFlag(QmlLanguage))
            || m_activeDebugLanguages == AnyLanguage) {
            m_stackDock->show();
            m_breakDock->show();
            m_watchDock->show();
            m_threadsDock->show();
            m_snapshotsDock->show();
        } else {
            m_stackDock->show();
            m_breakDock->show();
            m_watchDock->show();
            m_scriptConsoleDock->show();
hjk's avatar
hjk committed
736
737
            if (m_qmlInspectorDock)
                m_qmlInspectorDock->show();
738
739
740
741
742
743
744
745
746
747
        }
        q->splitDockWidget(q->toolBarDockWidget(), m_stackDock, Qt::Vertical);
        q->splitDockWidget(m_stackDock, m_watchDock, Qt::Horizontal);
        q->tabifyDockWidget(m_watchDock, m_breakDock);
        q->tabifyDockWidget(m_watchDock, m_modulesDock);
        q->tabifyDockWidget(m_watchDock, m_registerDock);
        q->tabifyDockWidget(m_watchDock, m_threadsDock);
        q->tabifyDockWidget(m_watchDock, m_sourceFilesDock);
        q->tabifyDockWidget(m_watchDock, m_snapshotsDock);
        q->tabifyDockWidget(m_watchDock, m_scriptConsoleDock);
hjk's avatar
hjk committed
748
749
        if (m_qmlInspectorDock)
            q->tabifyDockWidget(m_watchDock, m_qmlInspectorDock);
750
751
752
753
754
    }

    q->setTrackingEnabled(true);
}

755
756
757
} // namespace Debugger

#include "debuggermainwindow.moc"