Commit d5bdad22 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

context-based hiding/showing of debug menu entries

the previous implementation relied on poking around with setVisible
of the menu actions. Now, command attribute CA_Hide is used instead for
the necessary entries.

Reviewed-by: hjk
parent 8c83a9d0
......@@ -47,9 +47,10 @@ const char * const STEPOUT = "Debugger.StepOut";
const char * const NEXT = "Debugger.NextLine";
const char * const REVERSE = "Debugger.ReverseDirection";
const char * const M_DEBUG_LANGUAGES = "Debugger.Menu.View.Languages";
const char * const M_DEBUG_LANGUAGES = "Debugger.Menu.View.Languages";
const char * const M_DEBUG_VIEWS = "Debugger.Menu.View.Debug";
const char * const C_BASEDEBUGGER = "BaseDebugger";
const char * const C_GDBDEBUGGER = "Gdb Debugger";
const char * const GDBRUNNING = "Gdb.Running";
......
......@@ -683,7 +683,6 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_debugMode = new DebugMode(this);
m_uiSwitcher = new DebuggerUISwitcher(m_debugMode, this);
ExtensionSystem::PluginManager::instance()->addObject(m_uiSwitcher);
m_uiSwitcher->addLanguage(LANG_CPP);
ICore *core = ICore::instance();
QTC_ASSERT(core, return false);
......@@ -700,8 +699,11 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
QList<int> cppcontext;
cppcontext << uidm->uniqueIdentifier(PE::LANG_CXX);
QList<int> debuggercontext;
debuggercontext << uidm->uniqueIdentifier(C_GDBDEBUGGER);
QList<int> baseDebuggerContext;
baseDebuggerContext << uidm->uniqueIdentifier(C_BASEDEBUGGER);
QList<int> gdbDebuggercontext;
gdbDebuggercontext << uidm->uniqueIdentifier(C_GDBDEBUGGER);
QList<int> cppeditorcontext;
cppeditorcontext << uidm->uniqueIdentifier(CppEditor::Constants::C_CPPEDITOR);
......@@ -711,6 +713,8 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_gdbRunningContext = uidm->uniqueIdentifier(Constants::GDBRUNNING);
m_uiSwitcher->addLanguage(LANG_CPP, gdbDebuggercontext);
DebuggerManager *manager = new DebuggerManager(this);
ExtensionSystem::PluginManager::instance()->addObject(manager);
const QList<Core::IOptionsPage *> engineOptionPages =
......@@ -722,7 +726,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
QList<int> context;
context.append(uidm->uniqueIdentifier(CC::C_EDITORMANAGER));
context.append(uidm->uniqueIdentifier(C_GDBDEBUGGER));
context.append(uidm->uniqueIdentifier(C_BASEDEBUGGER));
context.append(uidm->uniqueIdentifier(CC::C_NAVIGATION_PANE));
m_debugMode->setContext(context);
......@@ -765,22 +769,27 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
cmd = am->registerAction(m_startExternalAction,
Constants::STARTEXTERNAL, globalcontext);
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_attachExternalAction,
Constants::ATTACHEXTERNAL, globalcontext);
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_attachCoreAction,
Constants::ATTACHCORE, globalcontext);
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_startRemoteAction,
Constants::ATTACHREMOTE, globalcontext);
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_detachAction,
Constants::DETACH, globalcontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(actions.stopAction,
......@@ -804,47 +813,55 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.nextAction,
Constants::NEXT, debuggercontext);
Constants::NEXT, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::NEXT_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.stepAction,
Constants::STEP, debuggercontext);
Constants::STEP, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::STEP_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.stepOutAction,
Constants::STEPOUT, debuggercontext);
Constants::STEPOUT, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::STEPOUT_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.runToLineAction1,
Constants::RUN_TO_LINE1, debuggercontext);
Constants::RUN_TO_LINE1, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_LINE_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.runToFunctionAction,
Constants::RUN_TO_FUNCTION, debuggercontext);
Constants::RUN_TO_FUNCTION, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_FUNCTION_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.jumpToLineAction1,
Constants::JUMP_TO_LINE1, debuggercontext);
Constants::JUMP_TO_LINE1, gdbDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.returnFromFunctionAction,
Constants::RETURN_FROM_FUNCTION, debuggercontext);
Constants::RETURN_FROM_FUNCTION, gdbDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(actions.reverseDirectionAction,
Constants::REVERSE, debuggercontext);
Constants::REVERSE, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::REVERSE_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
......@@ -855,13 +872,15 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
cmd = am->registerAction(actions.snapshotAction,
Constants::SNAPSHOT, debuggercontext);
Constants::SNAPSHOT, gdbDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::SNAPSHOT_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
cmd = am->registerAction(theDebuggerAction(OperateByInstruction),
Constants::OPERATE_BY_INSTRUCTION, debuggercontext);
Constants::OPERATE_BY_INSTRUCTION, gdbDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, Constants::LANG_CPP);
......@@ -889,24 +908,24 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
ActionContainer *editorContextMenu =
am->actionContainer(CppEditor::Constants::M_CONTEXT);
cmd = am->registerAction(sep, _("Debugger.Sep.Views"),
debuggercontext);
gdbDebuggercontext);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
cmd = am->registerAction(actions.watchAction2,
Constants::ADD_TO_WATCH2, debuggercontext);
Constants::ADD_TO_WATCH2, gdbDebuggercontext);
cmd->action()->setEnabled(true);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
cmd = am->registerAction(actions.runToLineAction2,
Constants::RUN_TO_LINE2, debuggercontext);
Constants::RUN_TO_LINE2, gdbDebuggercontext);
cmd->action()->setEnabled(true);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
cmd = am->registerAction(actions.jumpToLineAction2,
Constants::JUMP_TO_LINE2, debuggercontext);
Constants::JUMP_TO_LINE2, gdbDebuggercontext);
cmd->action()->setEnabled(true);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
......
......@@ -58,7 +58,14 @@ struct DebuggerUISwitcherPrivate {
QStackedWidget *m_toolbarStack;
Internal::DebuggerMainWindow *m_mainWindow;
// main debugger context
QList<int> m_debuggercontext;
// global context
QList<int> m_globalContext;
QHash<int, QList<int> > m_contextsForLanguage;
QActionGroup *m_languageActionGroup;
int m_activeLanguage;
......@@ -103,12 +110,16 @@ DebuggerUISwitcher::DebuggerUISwitcher(Core::BaseMode *mode, QObject* parent) :
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
SLOT(modeChanged(Core::IMode*)));
d->m_debugMenu = am->actionContainer(ProjectExplorer::Constants::M_DEBUG);
d->m_viewsMenu = am->createMenu(Debugger::Constants::M_DEBUG_VIEWS);
d->m_languageMenu = am->createMenu(Debugger::Constants::M_DEBUG_LANGUAGES);
d->m_languageActionGroup->setExclusive(true);
d->m_viewsMenu = am->createMenu(Debugger::Constants::M_DEBUG_VIEWS);
d->m_debuggercontext << Core::ICore::instance()->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_GDBDEBUGGER);
d->m_debuggercontext << core->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_BASEDEBUGGER);
d->m_globalContext << Core::Constants::C_GLOBAL_ID;
DebuggerUISwitcherPrivate::m_instance = this;
}
......@@ -190,12 +201,10 @@ void DebuggerUISwitcher::createViewsMenuItems()
d->m_debugMenu->addAction(cmd);
QMenu *mLang = d->m_languageMenu->menu();
mLang->setEnabled(true);
mLang->setTitle(tr("&Languages"));
d->m_debugMenu->addMenu(d->m_languageMenu, Core::Constants::G_DEFAULT_THREE);
QMenu *m = d->m_viewsMenu->menu();
m->setEnabled(true);
m->setTitle(tr("&Views"));
d->m_debugMenu->addMenu(d->m_viewsMenu, Core::Constants::G_DEFAULT_THREE);
......@@ -214,9 +223,10 @@ DebuggerUISwitcher *DebuggerUISwitcher::instance()
return DebuggerUISwitcherPrivate::m_instance;
}
void DebuggerUISwitcher::addLanguage(const QString &langName)
void DebuggerUISwitcher::addLanguage(const QString &langName, const QList<int> &context)
{
d->m_toolBars.insert(langName, 0);
d->m_contextsForLanguage.insert(d->m_languages.count(), context);
d->m_languages.append(langName);
Core::ActionManager *am = Core::ICore::instance()->actionManager();
......@@ -228,9 +238,8 @@ void DebuggerUISwitcher::addLanguage(const QString &langName)
connect(langChange, SIGNAL(triggered()), SLOT(langChangeTriggered()));
Core::Command *cmd = am->registerAction(langChange,
"Debugger.Language" + langName, d->m_debuggercontext);
"Debugger.Language." + langName, d->m_globalContext);
d->m_languageMenu->addAction(cmd);
}
void DebuggerUISwitcher::langChangeTriggered()
......@@ -249,8 +258,6 @@ void DebuggerUISwitcher::changeDebuggerUI(const QString &langName)
int langId = d->m_languages.indexOf(langName);
if (langId != d->m_activeLanguage) {
d->m_languageActionGroup->actions()[langId]->setChecked(true);
d->m_activeLanguage = langId;
d->m_toolbarStack->setCurrentWidget(d->m_toolBars.value(langName));
foreach (DebugToolWindow *window, d->m_dockWidgets) {
......@@ -277,12 +284,19 @@ void DebuggerUISwitcher::changeDebuggerUI(const QString &langName)
d->m_languageMenu->menu()->setTitle(tr("Language") + " (" + langName + ")");
QHashIterator<int, Core::Command *> iter(d->m_menuCommands);
while (iter.hasNext()) {
iter.next();
bool active = (iter.key() == langId);
iter.value()->action()->setVisible(active);
}
Core::ICore *core = Core::ICore::instance();
const QList<int> &oldContexts = d->m_contextsForLanguage.value(d->m_activeLanguage);
const QList<int> &newContexts = d->m_contextsForLanguage.value(langId);
foreach(int ctx, oldContexts)
core->removeAdditionalContext(ctx);
foreach(int ctx, newContexts)
core->addAdditionalContext(ctx);
core->updateContext();
d->m_activeLanguage = langId;
emit languageChanged(langName);
}
......@@ -366,9 +380,12 @@ QDockWidget *DebuggerUISwitcher::createDockWidget(const QString &langName, QWidg
if (d->m_languages.indexOf(langName) != d->m_activeLanguage)
dockWidget->hide();
QList<int> langContext = d->m_contextsForLanguage.value(d->m_languages.indexOf(langName));
Core::ActionManager *am = Core::ICore::instance()->actionManager();
Core::Command *cmd = am->registerAction(dockWidget->toggleViewAction(),
"Debugger." + dockWidget->objectName(), d->m_debuggercontext);
"Debugger." + dockWidget->objectName(), langContext);
cmd->setAttribute(Core::Command::CA_Hide);
d->m_viewsMenu->addAction(cmd);
d->m_viewsMenuItems.append(qMakePair(d->m_languages.indexOf(langName), dockWidget->toggleViewAction()));
......
......@@ -38,8 +38,8 @@ public:
static DebuggerUISwitcher *instance();
// debuggable languages are registered with this function
void addLanguage(const QString &langName);
// debuggable languages are registered with this function.
void addLanguage(const QString &langName, const QList<int> &context);
// debugger toolbars are registered with this function
void setToolbar(const QString &langName, QWidget *widget);
......
......@@ -171,7 +171,13 @@ QmlInspector::QmlInspector(QObject *parent)
{
m_watchTableModel = new WatchTableModel(0, this);
initWidgets();
m_objectTreeWidget = new ObjectTree;
m_propertiesWidget = new ObjectPropertiesView;
m_watchTableView = new WatchTableView(m_watchTableModel);
m_frameRateWidget = new CanvasFrameRate;
m_expressionWidget = new ExpressionQueryWidget(ExpressionQueryWidget::SeparateEntryMode);
m_context = new Internal::InspectorContext(m_expressionWidget);
m_expressionWidget->createCommands(m_context);
}
bool QmlInspector::connectToViewer()
......@@ -291,16 +297,8 @@ void QmlInspector::connectionError()
.arg(m_conn->error()).arg(m_conn->errorString()));
}
void QmlInspector::initWidgets()
void QmlInspector::createDockWidgets()
{
m_objectTreeWidget = new ObjectTree;
m_propertiesWidget = new ObjectPropertiesView;
m_watchTableView = new WatchTableView(m_watchTableModel);
m_frameRateWidget = new CanvasFrameRate;
m_expressionWidget = new ExpressionQueryWidget(ExpressionQueryWidget::SeparateEntryMode);
m_context = new Internal::InspectorContext(m_expressionWidget);
m_expressionWidget->createCommands(m_context);
m_engineSpinBox = new EngineSpinBox;
m_engineSpinBox->setEnabled(false);
......@@ -368,6 +366,7 @@ void QmlInspector::initWidgets()
propSplitter->setWindowTitle(tr("Properties and Watchers"));
InspectorOutputWidget *inspectorOutput = new InspectorOutputWidget();
connect(this, SIGNAL(statusMessage(QString)),
inspectorOutput, SLOT(addInspectorStatus(QString)));
......@@ -387,6 +386,7 @@ void QmlInspector::initWidgets()
m_inspectorOutputDock->setToolTip(tr("Output of the QML inspector, such as information on connecting to the server."));
m_dockWidgets << m_objectTreeDock << m_frameRateDock << m_propertyWatcherDock << m_inspectorOutputDock;
}
void QmlInspector::setSimpleDockWidgetArrangement()
......
......@@ -75,6 +75,7 @@ class QMLINSPECTOR_EXPORT QmlInspector : public QObject
public:
QmlInspector(QObject *parent = 0);
void createDockWidgets();
bool connectToViewer(); // using host, port from widgets
Core::IContext *context() const;
......@@ -96,7 +97,6 @@ private slots:
private:
void resetViews();
void initWidgets();
QDeclarativeDebugConnection *m_conn;
QDeclarativeEngineDebug *m_client;
......
......@@ -103,11 +103,13 @@ bool QmlInspectorPlugin::initialize(const QStringList &arguments, QString *error
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
Debugger::DebuggerUISwitcher *uiSwitcher = pluginManager->getObject<Debugger::DebuggerUISwitcher>();
uiSwitcher->addLanguage(Qml::Constants::LANG_QML);
m_inspector = new QmlInspector;
addObject(m_inspector);
Core::ICore::instance()->addContextObject(m_inspector->context());
uiSwitcher->addLanguage(Qml::Constants::LANG_QML, m_inspector->context()->context());
m_inspector->createDockWidgets();
connect(m_connectionTimer, SIGNAL(timeout()), SLOT(pollInspector()));
......
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