Commit 9f528528 authored by hjk's avatar hjk
Browse files

debugger: move some private bits to DebuggerMainWindowPrivate

parent a77353b4
......@@ -68,6 +68,7 @@
#include <QtGui/QVBoxLayout>
using namespace Core;
using namespace ProjectExplorer;
namespace Debugger {
namespace Internal {
......@@ -102,11 +103,30 @@ bool DockWidgetEventFilter::eventFilter(QObject *obj, QEvent *event)
// first: language id, second: menu item
typedef QPair<DebuggerLanguage, QAction *> ViewsMenuItems;
class DebuggerMainWindowPrivate
class DebuggerMainWindowPrivate : public QObject
{
Q_OBJECT
public:
explicit DebuggerMainWindowPrivate(DebuggerMainWindow *mainWindow);
void activateQmlCppLayout();
void activateCppLayout();
void hideInactiveWidgets();
void createViewsMenuItems();
bool isQmlCppActive() const;
bool isQmlActive() const;
public slots:
void updateUi();
void resetDebuggerLayout();
void updateUiForProject(ProjectExplorer::Project *project);
void updateUiForTarget(ProjectExplorer::Target *target);
void updateUiForRunConfiguration(ProjectExplorer::RunConfiguration *rc);
void updateUiForCurrentRunConfiguration();
void updateUiOnFileListChange();
public:
DebuggerMainWindow *q;
QList<ViewsMenuItems> m_viewsMenuItems;
......@@ -137,9 +157,9 @@ public:
QMultiHash<DebuggerLanguage, Command *> m_menuCommands;
QWeakPointer<ProjectExplorer::Project> m_previousProject;
QWeakPointer<ProjectExplorer::Target> m_previousTarget;
QWeakPointer<ProjectExplorer::RunConfiguration> m_previousRunConfiguration;
QWeakPointer<Project> m_previousProject;
QWeakPointer<Target> m_previousTarget;
QWeakPointer<RunConfiguration> m_previousRunConfiguration;
bool m_initialized;
QSettings *m_settings;
......@@ -163,36 +183,22 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *mw)
{
}
} // namespace Internal
using namespace Internal;
DebuggerMainWindow::DebuggerMainWindow()
void DebuggerMainWindowPrivate::updateUiOnFileListChange()
{
d = new DebuggerMainWindowPrivate(this);
if (m_previousProject)
updateUiForTarget(m_previousProject.data()->activeTarget());
}
DebuggerMainWindow::~DebuggerMainWindow()
{
delete d;
}
void DebuggerMainWindow::updateUiOnFileListChange()
{
if (d->m_previousProject)
updateUiForTarget(d->m_previousProject.data()->activeTarget());
}
void DebuggerMainWindow::updateUiForProject(ProjectExplorer::Project *project)
void DebuggerMainWindowPrivate::updateUiForProject(Project *project)
{
if (!project)
return;
if (d->m_previousProject) {
disconnect(d->m_previousProject.data(),
if (m_previousProject) {
disconnect(m_previousProject.data(),
SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
this, SLOT(updateUiForTarget(ProjectExplorer::Target*)));
}
d->m_previousProject = project;
m_previousProject = project;
connect(project, SIGNAL(fileListChanged()),
SLOT(updateUiOnFileListChange()));
connect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
......@@ -200,17 +206,17 @@ void DebuggerMainWindow::updateUiForProject(ProjectExplorer::Project *project)
updateUiForTarget(project->activeTarget());
}
void DebuggerMainWindow::updateUiForTarget(ProjectExplorer::Target *target)
void DebuggerMainWindowPrivate::updateUiForTarget(Target *target)
{
if (!target)
return;
if (d->m_previousTarget) {
disconnect(d->m_previousTarget.data(),
if (m_previousTarget) {
disconnect(m_previousTarget.data(),
SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
this, SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
}
d->m_previousTarget = target;
m_previousTarget = target;
connect(target,
SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
......@@ -218,26 +224,37 @@ void DebuggerMainWindow::updateUiForTarget(ProjectExplorer::Target *target)
}
// updates default debug language settings per run config.
void DebuggerMainWindow::updateUiForRunConfiguration(ProjectExplorer::RunConfiguration *rc)
void DebuggerMainWindowPrivate::updateUiForRunConfiguration(RunConfiguration *rc)
{
if (rc) {
if (d->m_previousRunConfiguration) {
disconnect(d->m_previousRunConfiguration.data(),
SIGNAL(debuggersChanged()),
this, SLOT(updateUiForCurrentRunConfiguration()));
}
d->m_previousRunConfiguration = rc;
connect(d->m_previousRunConfiguration.data(),
SIGNAL(debuggersChanged()),
if (!rc)
return;
if (m_previousRunConfiguration)
disconnect(m_previousRunConfiguration.data(), SIGNAL(debuggersChanged()),
this, SLOT(updateUiForCurrentRunConfiguration()));
m_previousRunConfiguration = rc;
connect(m_previousRunConfiguration.data(),
SIGNAL(debuggersChanged()),
SLOT(updateUiForCurrentRunConfiguration()));
updateUiForCurrentRunConfiguration();
}
updateUiForCurrentRunConfiguration();
}
void DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration()
{
q->updateActiveLanguages();
}
void DebuggerMainWindow::updateUiForCurrentRunConfiguration()
} // namespace Internal
using namespace Internal;
DebuggerMainWindow::DebuggerMainWindow()
{
updateActiveLanguages();
d = new DebuggerMainWindowPrivate(this);
}
DebuggerMainWindow::~DebuggerMainWindow()
{
delete d;
}
void DebuggerMainWindow::updateActiveLanguages()
......@@ -256,7 +273,7 @@ void DebuggerMainWindow::updateActiveLanguages()
emit activeLanguagesChanged(d->m_activeDebugLanguages);
}
updateUi();
d->updateUi();
}
DebuggerLanguages DebuggerMainWindow::supportedLanguages() const
......@@ -280,7 +297,7 @@ void DebuggerMainWindow::onModeChanged(IMode *mode)
{
d->m_inDebugMode = (mode->id() == Constants::MODE_DEBUG);
setDockActionsVisible(d->m_inDebugMode);
hideInactiveWidgets();
d->hideInactiveWidgets();
if (mode->id() != Constants::MODE_DEBUG)
//|| DebuggerPlugin::instance()->hasSnapshots())
......@@ -289,47 +306,47 @@ void DebuggerMainWindow::onModeChanged(IMode *mode)
updateActiveLanguages();
}
void DebuggerMainWindow::hideInactiveWidgets()
void DebuggerMainWindowPrivate::hideInactiveWidgets()
{
// Hide all the debugger windows if mode is different.
if (d->m_inDebugMode)
if (m_inDebugMode)
return;
// Hide dock widgets manually in case they are floating.
foreach (QDockWidget *dockWidget, d->m_dockWidgets) {
foreach (QDockWidget *dockWidget, m_dockWidgets) {
if (dockWidget->isFloating())
dockWidget->hide();
}
}
void DebuggerMainWindow::createViewsMenuItems()
void DebuggerMainWindowPrivate::createViewsMenuItems()
{
ICore *core = ICore::instance();
ActionManager *am = core->actionManager();
Context globalcontext(Core::Constants::C_GLOBAL);
d->m_openMemoryEditorAction = new QAction(this);
d->m_openMemoryEditorAction->setText(tr("Memory..."));
connect(d->m_openMemoryEditorAction, SIGNAL(triggered()),
SIGNAL(memoryEditorRequested()));
m_openMemoryEditorAction = new QAction(this);
m_openMemoryEditorAction->setText(tr("Memory..."));
connect(m_openMemoryEditorAction, SIGNAL(triggered()),
q, SIGNAL(memoryEditorRequested()));
// Add menu items
Command *cmd = 0;
cmd = am->registerAction(d->m_openMemoryEditorAction,
cmd = am->registerAction(m_openMemoryEditorAction,
Core::Id("Debugger.Views.OpenMemoryEditor"),
Core::Context(Constants::C_DEBUGMODE));
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(menuSeparator1(),
m_viewsMenu->addAction(cmd);
cmd = am->registerAction(q->menuSeparator1(),
Core::Id("Debugger.Views.Separator1"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(toggleLockedAction(),
m_viewsMenu->addAction(cmd);
cmd = am->registerAction(q->toggleLockedAction(),
Core::Id("Debugger.Views.ToggleLocked"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(menuSeparator2(),
m_viewsMenu->addAction(cmd);
cmd = am->registerAction(q->menuSeparator2(),
Core::Id("Debugger.Views.Separator2"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(resetLayoutAction(),
m_viewsMenu->addAction(cmd);
cmd = am->registerAction(q->resetLayoutAction(),
Core::Id("Debugger.Views.ResetSimple"), globalcontext);
d->m_viewsMenu->addAction(cmd);
m_viewsMenu->addAction(cmd);
}
void DebuggerMainWindow::addLanguage(const DebuggerLanguage &languageId, const Context &context)
......@@ -341,69 +358,70 @@ void DebuggerMainWindow::addLanguage(const DebuggerLanguage &languageId, const C
d->m_toolBars.insert(languageId, 0);
d->m_contextsForLanguage.insert(languageId, context);
updateUiForRunConfiguration(0);
d->updateUiForRunConfiguration(0);
if (activate)
updateUi();
d->updateUi();
}
void DebuggerMainWindow::updateUi()
void DebuggerMainWindowPrivate::updateUi()
{
if (d->m_changingUI || !d->m_initialized || !d->m_inDebugMode)
if (m_changingUI || !m_initialized || !m_inDebugMode)
return;
d->m_changingUI = true;
m_changingUI = true;
if (isQmlActive()) {
if (isQmlActive())
activateQmlCppLayout();
} else {
else
activateCppLayout();
}
d->m_previousDebugLanguages = d->m_activeDebugLanguages;
m_previousDebugLanguages = m_activeDebugLanguages;
d->m_changingUI = false;
m_changingUI = false;
}
void DebuggerMainWindow::activateQmlCppLayout()
void DebuggerMainWindowPrivate::activateQmlCppLayout()
{
ICore *core = ICore::instance();
Context qmlCppContext = d->m_contextsForLanguage.value(QmlLanguage);
qmlCppContext.add(d->m_contextsForLanguage.value(CppLanguage));
Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
// always use cpp toolbar
d->m_toolbarStack->setCurrentWidget(d->m_toolBars.value(CppLanguage));
m_toolbarStack->setCurrentWidget(m_toolBars.value(CppLanguage));
if (d->m_previousDebugLanguages & QmlLanguage) {
d->m_dockWidgetActiveStateQmlCpp = saveSettings();
if (m_previousDebugLanguages & QmlLanguage) {
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
core->updateAdditionalContexts(qmlCppContext, Context());
} else if (d->m_previousDebugLanguages & CppLanguage) {
d->m_dockWidgetActiveStateCpp = saveSettings();
core->updateAdditionalContexts(d->m_contextsForLanguage.value(CppLanguage), Context());
} else if (m_previousDebugLanguages & CppLanguage) {
m_dockWidgetActiveStateCpp = q->saveSettings();
core->updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
Context());
}
restoreSettings(d->m_dockWidgetActiveStateQmlCpp);
q->restoreSettings(m_dockWidgetActiveStateQmlCpp);
core->updateAdditionalContexts(Context(), qmlCppContext);
}
void DebuggerMainWindow::activateCppLayout()
void DebuggerMainWindowPrivate::activateCppLayout()
{
ICore *core = ICore::instance();
Context qmlCppContext = d->m_contextsForLanguage.value(QmlLanguage);
qmlCppContext.add(d->m_contextsForLanguage.value(CppLanguage));
d->m_toolbarStack->setCurrentWidget(d->m_toolBars.value(CppLanguage));
Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
m_toolbarStack->setCurrentWidget(m_toolBars.value(CppLanguage));
if (d->m_previousDebugLanguages & QmlLanguage) {
d->m_dockWidgetActiveStateQmlCpp = saveSettings();
if (m_previousDebugLanguages & QmlLanguage) {
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
core->updateAdditionalContexts(qmlCppContext, Context());
} else if (d->m_previousDebugLanguages & CppLanguage) {
d->m_dockWidgetActiveStateCpp = saveSettings();
core->updateAdditionalContexts(d->m_contextsForLanguage.value(CppLanguage), Context());
} else if (m_previousDebugLanguages & CppLanguage) {
m_dockWidgetActiveStateCpp = q->saveSettings();
core->updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
Context());
}
restoreSettings(d->m_dockWidgetActiveStateCpp);
q->restoreSettings(m_dockWidgetActiveStateCpp);
const Context &cppContext = d->m_contextsForLanguage.value(CppLanguage);
const Context &cppContext = m_contextsForLanguage.value(CppLanguage);
core->updateAdditionalContexts(Context(), cppContext);
}
......@@ -500,11 +518,9 @@ QWidget *DebuggerMainWindow::createContents(IMode *mode)
{
ICore *core = ICore::instance();
ActionManager *am = core->actionManager();
ProjectExplorer::ProjectExplorerPlugin *pe =
ProjectExplorer::ProjectExplorerPlugin::instance();
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
connect(pe->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
SLOT(updateUiForProject(ProjectExplorer::Project*)));
d, SLOT(updateUiForProject(ProjectExplorer::Project*)));
connect(d->m_resizeEventFilter, SIGNAL(widgetResized()),
SLOT(updateDockWidgetSettings()));
......@@ -516,7 +532,7 @@ QWidget *DebuggerMainWindow::createContents(IMode *mode)
setDocumentMode(true);
setDockNestingEnabled(true);
connect(this, SIGNAL(resetLayout()),
SLOT(resetDebuggerLayout()));
d, SLOT(resetDebuggerLayout()));
connect(toggleLockedAction(), SIGNAL(triggered()),
SLOT(updateDockWidgetSettings()));
......@@ -619,11 +635,11 @@ void DebuggerMainWindow::readSettings()
DebuggerLanguages langs = d->m_activeDebugLanguages;
if (d->m_dockWidgetActiveStateCpp.isEmpty()) {
d->m_activeDebugLanguages = CppLanguage;
resetDebuggerLayout();
d->resetDebuggerLayout();
}
if (d->m_dockWidgetActiveStateQmlCpp.isEmpty()) {
d->m_activeDebugLanguages = QmlLanguage;
resetDebuggerLayout();
d->resetDebuggerLayout();
}
d->m_activeDebugLanguages = langs;
}
......@@ -631,28 +647,28 @@ void DebuggerMainWindow::readSettings()
void DebuggerMainWindow::initialize(QSettings *settings)
{
d->m_settings = settings;
createViewsMenuItems();
d->createViewsMenuItems();
emit dockResetRequested(AnyLanguage);
readSettings();
updateUi();
d->updateUi();
hideInactiveWidgets();
d->hideInactiveWidgets();
setDockActionsVisible(false);
d->m_initialized = true;
}
void DebuggerMainWindow::resetDebuggerLayout()
void DebuggerMainWindowPrivate::resetDebuggerLayout()
{
emit dockResetRequested(d->m_activeDebugLanguages);
emit q->dockResetRequested(m_activeDebugLanguages);
if (isQmlActive())
d->m_dockWidgetActiveStateQmlCpp = saveSettings();
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
else
d->m_dockWidgetActiveStateCpp = saveSettings();
m_dockWidgetActiveStateCpp = q->saveSettings();
updateActiveLanguages();
q->updateActiveLanguages();
}
void DebuggerMainWindow::updateDockWidgetSettings()
......@@ -660,21 +676,21 @@ void DebuggerMainWindow::updateDockWidgetSettings()
if (!d->m_inDebugMode || d->m_changingUI)
return;
if (isQmlActive())
if (d->isQmlActive())
d->m_dockWidgetActiveStateQmlCpp = saveSettings();
else
d->m_dockWidgetActiveStateCpp = saveSettings();
}
bool DebuggerMainWindow::isQmlCppActive() const
bool DebuggerMainWindowPrivate::isQmlCppActive() const
{
return (d->m_activeDebugLanguages & CppLanguage)
&& (d->m_activeDebugLanguages & QmlLanguage);
return (m_activeDebugLanguages & CppLanguage)
&& (m_activeDebugLanguages & QmlLanguage);
}
bool DebuggerMainWindow::isQmlActive() const
bool DebuggerMainWindowPrivate::isQmlActive() const
{
return (d->m_activeDebugLanguages & QmlLanguage);
return (m_activeDebugLanguages & QmlLanguage);
}
QMenu *DebuggerMainWindow::createPopupMenu()
......
......@@ -49,12 +49,6 @@ class Context;
class IMode;
}
namespace ProjectExplorer {
class Project;
class Target;
class RunConfiguration;
}
namespace Debugger {
namespace Internal {
......@@ -69,28 +63,28 @@ public:
DebuggerMainWindow();
~DebuggerMainWindow();
// debuggable languages are registered with this function.
// Debuggable languages are registered with this function.
void addLanguage(const DebuggerLanguage &language, const Core::Context &context);
// debugger toolbars are registered with this function
// Debugger toolbars are registered with this function
void setToolbar(const DebuggerLanguage &language, QWidget *widget);
// menu actions are registered with this function
// Menu actions are registered with this function
void addMenuAction(Core::Command *command, const DebuggerLanguage &language,
const QString &group = QString());
// all supported languages
// All supported languages
DebuggerLanguages supportedLanguages() const;
// active languages to be debugged.
// Active languages to be debugged.
DebuggerLanguages activeDebugLanguages() const;
// called when all dependent plugins have loaded
// Called when all dependent plugins have loaded
void initialize(QSettings *settings);
void onModeChanged(Core::IMode *mode);
// most common debugger windows
// Most common debugger windows
QDockWidget *breakWindow() const;
QDockWidget *stackWindow() const;
QDockWidget *watchWindow() const;
......@@ -101,7 +95,7 @@ public:
QDockWidget *dockWidget(const QString &objectName) const;
// dockwidgets are registered to the main window
// Dockwidgets are registered to the main window.
QDockWidget *createDockWidget(const DebuggerLanguage &language, QWidget *widget,
Qt::DockWidgetArea area = Qt::TopDockWidgetArea);
......@@ -109,22 +103,12 @@ public:
QMenu *createPopupMenu();
signals:
// emit when user changes active languages from the menu.
// Emit when user changes active languages from the menu.
// Both UI and debugger startup are affected.
void activeLanguagesChanged(Debugger::DebuggerLanguages activeLanguages);
void dockResetRequested(Debugger::DebuggerLanguages activeLanguages);
void memoryEditorRequested();
private slots:
void updateUi();
void resetDebuggerLayout();
void updateUiForProject(ProjectExplorer::Project *project);
void updateUiForTarget(ProjectExplorer::Target *target);
void updateUiForRunConfiguration(ProjectExplorer::RunConfiguration *rc);
void updateUiForCurrentRunConfiguration();
void updateUiOnFileListChange();
public slots:
void updateActiveLanguages();
void updateDockWidgetSettings();
......@@ -132,14 +116,7 @@ public slots:
void writeSettings() const;
private:
void activateQmlCppLayout();
void activateCppLayout();
void hideInactiveWidgets();
void createViewsMenuItems();
bool isQmlCppActive() const;
bool isQmlActive() const;
friend class Internal::DebuggerMainWindowPrivate;
Internal::DebuggerMainWindowPrivate *d;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment