Added automatic language switching option to debugger settings

Additionally, hiding of debugger menu entries was done as most of
them are irrelevant for QML debugging.
This commit is contained in:
Lasse Holmstedt
2010-03-18 10:56:25 +01:00
parent b14a208273
commit 492fffb4cc
9 changed files with 119 additions and 36 deletions

View File

@@ -2,11 +2,38 @@
<ui version="4.0"> <ui version="4.0">
<class>CommonOptionsPage</class> <class>CommonOptionsPage</class>
<widget class="QWidget" name="CommonOptionsPage"> <widget class="QWidget" name="CommonOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>357</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Language</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxChangeLanguageAutomatically">
<property name="toolTip">
<string>Changes the debugger language according to the currently opened file.</string>
</property>
<property name="text">
<string>Change debugger language automatically</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>User interface</string> <string>C++</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">

View File

@@ -442,6 +442,14 @@ DebuggerSettings *DebuggerSettings::instance()
item->setDefaultValue(20); item->setDefaultValue(20);
instance->insertItem(GdbWatchdogTimeout, item); instance->insertItem(GdbWatchdogTimeout, item);
// Language switching
item = new Utils::SavedAction(instance);
item->setSettingsKey(debugModeGroup, QLatin1String("ChangeLanguageAutomatically"));
item->setText(tr("Change debugger language automatically"));
item->setToolTip(tr("Changes the debugger language according to the currently opened file."));
item->setCheckable(true);
item->setDefaultValue(true);
instance->insertItem(SwitchLanguageAutomatically, item);
return instance; return instance;
} }

View File

@@ -136,7 +136,10 @@ enum DebuggerActionCode
SelectedPluginBreakpointsPattern, SelectedPluginBreakpointsPattern,
UsePreciseBreakpoints, UsePreciseBreakpoints,
BreakOnThrow, BreakOnThrow,
BreakOnCatch BreakOnCatch,
// UI/Language switching
SwitchLanguageAutomatically
}; };
// singleton access // singleton access

View File

@@ -466,10 +466,6 @@ void DebuggerManager::init()
connect(this, SIGNAL(emitShowOutput(int, QString)), connect(this, SIGNAL(emitShowOutput(int, QString)),
d->m_outputWindow, SLOT(showOutput(int, QString)), Qt::QueuedConnection); d->m_outputWindow, SLOT(showOutput(int, QString)), Qt::QueuedConnection);
// UI Switcher
connect(DebuggerUISwitcher::instance(), SIGNAL(languageChanged(QString)),
this, SLOT(languageChanged(QString)));
// Tooltip // Tooltip
//QTreeView *tooltipView = qobject_cast<QTreeView *>(d->m_tooltipWindow); //QTreeView *tooltipView = qobject_cast<QTreeView *>(d->m_tooltipWindow);
//tooltipView->setModel(d->m_watchHandler->model(TooltipsWatch)); //tooltipView->setModel(d->m_watchHandler->model(TooltipsWatch));
@@ -1929,14 +1925,6 @@ void DebuggerManager::fontSettingsChanged(const TextEditor::FontSettings &settin
changeFontSize(d->m_threadsWindow, size); changeFontSize(d->m_threadsWindow, size);
} }
// only update necessary menu items on language change
void DebuggerManager::languageChanged(const QString &debuggerLanguage)
{
const bool debuggerIsCPP = (debuggerLanguage == Constants::LANG_CPP);
d->m_actions.reverseDirectionAction->setEnabled(debuggerIsCPP);
theDebuggerAction(OperateByInstruction)->setEnabled(debuggerIsCPP);
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// //
// AbstractDebuggerEngine // AbstractDebuggerEngine

View File

@@ -280,7 +280,6 @@ public slots: // FIXME
void reloadFullStack(); void reloadFullStack();
void operateByInstructionTriggered(); void operateByInstructionTriggered();
void startFailed(); void startFailed();
void languageChanged(const QString &debuggerLanguage);
private: private:
Internal::ModulesHandler *modulesHandler() const; Internal::ModulesHandler *modulesHandler() const;

View File

@@ -359,6 +359,9 @@ QWidget *CommonOptionsPage::createPage(QWidget *parent)
m_ui.setupUi(w); m_ui.setupUi(w);
m_group.clear(); m_group.clear();
m_group.insert(theDebuggerAction(SwitchLanguageAutomatically),
m_ui.checkBoxChangeLanguageAutomatically);
m_group.insert(theDebuggerAction(ListSourceFiles), m_group.insert(theDebuggerAction(ListSourceFiles),
m_ui.checkBoxListSourceFiles); m_ui.checkBoxListSourceFiles);
m_group.insert(theDebuggerAction(UseAlternatingRowColors), m_group.insert(theDebuggerAction(UseAlternatingRowColors),
@@ -388,7 +391,9 @@ QWidget *CommonOptionsPage::createPage(QWidget *parent)
m_group.insert(theDebuggerAction(BreakOnCatch), 0); m_group.insert(theDebuggerAction(BreakOnCatch), 0);
if (m_searchKeywords.isEmpty()) { if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords) << ' ' << m_ui.checkBoxListSourceFiles->text() QTextStream(&m_searchKeywords) << ' '
<< m_ui.checkBoxChangeLanguageAutomatically->text()
<< m_ui.checkBoxListSourceFiles->text()
<< ' ' << m_ui.checkBoxUseMessageBoxForSignals->text() << ' ' << m_ui.checkBoxUseMessageBoxForSignals->text()
<< ' ' << m_ui.checkBoxUseAlternatingRowColors->text() << ' ' << m_ui.checkBoxUseAlternatingRowColors->text()
<< ' ' << m_ui.checkBoxUseToolTipsInMainEditor->text() << ' ' << m_ui.checkBoxUseToolTipsInMainEditor->text()
@@ -796,76 +801,89 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
QAction *sep = new QAction(this); QAction *sep = new QAction(this);
sep->setSeparator(true); sep->setSeparator(true);
cmd = am->registerAction(sep, _("Debugger.Sep.Step"), globalcontext); cmd = am->registerAction(sep, _("Debugger.Sep.Step"), globalcontext);
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.nextAction, cmd = am->registerAction(actions.nextAction,
Constants::NEXT, debuggercontext); Constants::NEXT, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::NEXT_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::NEXT_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.stepAction, cmd = am->registerAction(actions.stepAction,
Constants::STEP, debuggercontext); Constants::STEP, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::STEP_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::STEP_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.stepOutAction, cmd = am->registerAction(actions.stepOutAction,
Constants::STEPOUT, debuggercontext); Constants::STEPOUT, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::STEPOUT_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::STEPOUT_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.runToLineAction1, cmd = am->registerAction(actions.runToLineAction1,
Constants::RUN_TO_LINE1, debuggercontext); Constants::RUN_TO_LINE1, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_LINE_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_LINE_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.runToFunctionAction, cmd = am->registerAction(actions.runToFunctionAction,
Constants::RUN_TO_FUNCTION, debuggercontext); Constants::RUN_TO_FUNCTION, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_FUNCTION_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_FUNCTION_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.jumpToLineAction1, cmd = am->registerAction(actions.jumpToLineAction1,
Constants::JUMP_TO_LINE1, debuggercontext); Constants::JUMP_TO_LINE1, debuggercontext);
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.returnFromFunctionAction, cmd = am->registerAction(actions.returnFromFunctionAction,
Constants::RETURN_FROM_FUNCTION, debuggercontext); Constants::RETURN_FROM_FUNCTION, debuggercontext);
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.reverseDirectionAction, cmd = am->registerAction(actions.reverseDirectionAction,
Constants::REVERSE, debuggercontext); Constants::REVERSE, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::REVERSE_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::REVERSE_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
sep = new QAction(this); sep = new QAction(this);
sep->setSeparator(true); sep->setSeparator(true);
cmd = am->registerAction(sep, _("Debugger.Sep.Break"), globalcontext); cmd = am->registerAction(sep, _("Debugger.Sep.Break"), globalcontext);
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.snapshotAction, cmd = am->registerAction(actions.snapshotAction,
Constants::SNAPSHOT, debuggercontext); Constants::SNAPSHOT, debuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::SNAPSHOT_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::SNAPSHOT_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(theDebuggerAction(OperateByInstruction), cmd = am->registerAction(theDebuggerAction(OperateByInstruction),
Constants::OPERATE_BY_INSTRUCTION, debuggercontext); Constants::OPERATE_BY_INSTRUCTION, debuggercontext);
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.breakAction, cmd = am->registerAction(actions.breakAction,
Constants::TOGGLE_BREAK, cppeditorcontext); Constants::TOGGLE_BREAK, cppeditorcontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::TOGGLE_BREAK_KEY)); cmd->setDefaultKeySequence(QKeySequence(Constants::TOGGLE_BREAK_KEY));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
//mcppcontext->addAction(cmd); //mcppcontext->addAction(cmd);
sep = new QAction(this); sep = new QAction(this);
sep->setSeparator(true); sep->setSeparator(true);
cmd = am->registerAction(sep, _("Debugger.Sep.Watch"), globalcontext); cmd = am->registerAction(sep, _("Debugger.Sep.Watch"), globalcontext);
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.watchAction1, cmd = am->registerAction(actions.watchAction1,
Constants::ADD_TO_WATCH1, cppeditorcontext); Constants::ADD_TO_WATCH1, cppeditorcontext);
cmd->action()->setEnabled(true); cmd->action()->setEnabled(true);
//cmd->setDefaultKeySequence(QKeySequence(tr("ALT+D,ALT+W"))); //cmd->setDefaultKeySequence(QKeySequence(tr("ALT+D,ALT+W")));
m_uiSwitcher->addMenuAction(cmd); m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
// Editor context menu // Editor context menu
ActionContainer *editorContextMenu = ActionContainer *editorContextMenu =
@@ -979,6 +997,10 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
connect(theDebuggerAction(EnableReverseDebugging), SIGNAL(valueChanged(QVariant)), connect(theDebuggerAction(EnableReverseDebugging), SIGNAL(valueChanged(QVariant)),
this, SLOT(enableReverseDebuggingTriggered(QVariant))); this, SLOT(enableReverseDebuggingTriggered(QVariant)));
// UI Switcher
connect(DebuggerUISwitcher::instance(), SIGNAL(languageChanged(QString)),
this, SLOT(languageChanged(QString)));
return true; return true;
} }
@@ -1217,6 +1239,20 @@ void DebuggerPlugin::handleStateChanged(int state)
m_detachAction->setEnabled(detachable); m_detachAction->setEnabled(detachable);
} }
void DebuggerPlugin::languageChanged(const QString &language)
{
if (!m_manager)
return;
const bool debuggerIsCPP = (language == Constants::LANG_CPP);
m_startExternalAction->setVisible(debuggerIsCPP);
m_attachExternalAction->setVisible(debuggerIsCPP);
m_attachCoreAction->setVisible(debuggerIsCPP);
m_startRemoteAction->setVisible(debuggerIsCPP);
m_detachAction->setVisible(debuggerIsCPP);
}
void DebuggerPlugin::writeSettings() const void DebuggerPlugin::writeSettings() const
{ {
QSettings *s = settings(); QSettings *s = settings();
@@ -1242,9 +1278,8 @@ void DebuggerPlugin::onModeChanged(IMode *mode)
if (editorManager->currentEditor()) { if (editorManager->currentEditor()) {
editorManager->currentEditor()->widget()->setFocus(); editorManager->currentEditor()->widget()->setFocus();
if (editorManager->currentEditor()->id() == CppEditor::Constants::C_CPPEDITOR) { if (editorManager->currentEditor()->id() == CppEditor::Constants::C_CPPEDITOR)
m_uiSwitcher->setActiveLanguage(LANG_CPP); m_uiSwitcher->setActiveLanguage(LANG_CPP);
}
} }
} }

View File

@@ -119,6 +119,7 @@ private slots:
void attachCmdLine(); void attachCmdLine();
void enableReverseDebuggingTriggered(const QVariant &value); void enableReverseDebuggingTriggered(const QVariant &value);
void languageChanged(const QString &debuggerLanguage);
private: private:
void readSettings(); void readSettings();

View File

@@ -2,7 +2,12 @@
#include "debuggermainwindow.h" #include "debuggermainwindow.h"
#include <debugger/debuggerconstants.h> #include <debugger/debuggerconstants.h>
#include <utils/savedaction.h>
#include <utils/styledbar.h> #include <utils/styledbar.h>
#include <debugger/debuggerconstants.h>
#include <debugger/debuggeractions.h>
#include <coreplugin/modemanager.h> #include <coreplugin/modemanager.h>
#include <coreplugin/basemode.h> #include <coreplugin/basemode.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
@@ -115,11 +120,13 @@ DebuggerUISwitcher::~DebuggerUISwitcher()
void DebuggerUISwitcher::addMenuAction(Core::Command *command, const QString &group) void DebuggerUISwitcher::addMenuAction(Core::Command *command, const QString &group)
{ {
d->m_debugMenu->addAction(command, group); d->m_debugMenu->addAction(command, group);
m_menuCommands.insert(m_languages.indexOf(langName), command);
} }
void DebuggerUISwitcher::setActiveLanguage(const QString &langName) void DebuggerUISwitcher::setActiveLanguage(const QString &langName)
{ {
changeDebuggerUI(langName); if (theDebuggerAction(SwitchLanguageAutomatically)->isChecked())
changeDebuggerUI(langName);
} }
int DebuggerUISwitcher::activeLanguageId() const int DebuggerUISwitcher::activeLanguageId() const
@@ -263,6 +270,14 @@ void DebuggerUISwitcher::changeDebuggerUI(const QString &langName)
} }
} }
d->m_languageMenu->menu()->setTitle(tr("Language") + " (" + langName + ")"); d->m_languageMenu->menu()->setTitle(tr("Language") + " (" + langName + ")");
QHashIterator<int, Core::Command *> iter(m_menuCommands);
while (iter.hasNext()) {
iter.next();
bool active = (iter.key() == langId);
iter.value()->action()->setVisible(active);
}
emit languageChanged(langName); emit languageChanged(langName);
} }

View File

@@ -6,6 +6,7 @@
#include <QtCore/QObject> #include <QtCore/QObject>
QT_FORWARD_DECLARE_CLASS(QDockWidget); QT_FORWARD_DECLARE_CLASS(QDockWidget);
#include <QtCore/QMultiHash>
namespace Core { namespace Core {
class ActionContainer; class ActionContainer;
@@ -16,8 +17,10 @@ namespace Core {
namespace Utils { namespace Utils {
class FancyMainWindow; class FancyMainWindow;
class SavedAction;
} }
namespace Debugger { namespace Debugger {
struct DebuggerUISwitcherPrivate; struct DebuggerUISwitcherPrivate;
@@ -42,9 +45,11 @@ public:
void setToolbar(const QString &langName, QWidget *widget); void setToolbar(const QString &langName, QWidget *widget);
// menu actions are registered with this function // menu actions are registered with this function
void addMenuAction(Core::Command *command, void addMenuAction(Core::Command *command, const QString &langName,
const QString &group = QString()); const QString &group = QString());
// Changes the active language UI to the one specified by langName.
// Does nothing if automatic switching is toggled off from settings.
void setActiveLanguage(const QString &langName); void setActiveLanguage(const QString &langName);
int activeLanguageId() const; int activeLanguageId() const;
@@ -84,6 +89,8 @@ private:
QWidget *createMainWindow(Core::BaseMode *mode); QWidget *createMainWindow(Core::BaseMode *mode);
DebuggerUISwitcherPrivate *d; DebuggerUISwitcherPrivate *d;
QMultiHash< int, Core::Command *> m_menuCommands;
Utils::SavedAction *m_changeLanguageAction;
}; };
} }