forked from qt-creator/qt-creator
{Fancy,Debugger}MainWindow: Consolidate dock actions menu population
There are several places where the list of dock actions are shown, and at least two where it was created. Change-Id: Ib2c18e602b5d6f57c1b7471bd75f3b989d536600 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -377,9 +377,9 @@ void FancyMainWindow::showEvent(QShowEvent *event)
|
||||
|
||||
void FancyMainWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu *menu = createPopupMenu();
|
||||
menu->exec(event->globalPos());
|
||||
delete menu;
|
||||
QMenu menu;
|
||||
addDockActionsToMenu(&menu);
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
void FancyMainWindow::handleVisibilityChanged(bool visible)
|
||||
@@ -448,7 +448,7 @@ static bool actionLessThan(const QAction *action1, const QAction *action2)
|
||||
return action1->text().toLower() < action2->text().toLower();
|
||||
}
|
||||
|
||||
QMenu *FancyMainWindow::createPopupMenu()
|
||||
void FancyMainWindow::addDockActionsToMenu(QMenu *menu)
|
||||
{
|
||||
QList<QAction *> actions;
|
||||
QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
|
||||
@@ -460,12 +460,10 @@ QMenu *FancyMainWindow::createPopupMenu()
|
||||
}
|
||||
}
|
||||
qSort(actions.begin(), actions.end(), actionLessThan);
|
||||
QMenu *menu = new QMenu(this);
|
||||
foreach (QAction *action, actions)
|
||||
menu->addAction(action);
|
||||
menu->addAction(&d->m_menuSeparator);
|
||||
menu->addAction(&d->m_resetLayoutAction);
|
||||
return menu;
|
||||
}
|
||||
|
||||
QAction *FancyMainWindow::menuSeparator() const
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
QAction *resetLayoutAction() const;
|
||||
|
||||
// Overwritten to add locked/reset.
|
||||
virtual QMenu *createPopupMenu();
|
||||
void addDockActionsToMenu(QMenu *menu);
|
||||
|
||||
QDockWidget *toolBarDockWidget() const;
|
||||
void setToolBarDockWidget(QDockWidget *dock);
|
||||
|
||||
@@ -128,7 +128,6 @@ public:
|
||||
DebuggerLanguages m_engineDebugLanguages;
|
||||
|
||||
ActionContainer *m_viewsMenu;
|
||||
QList<Command *> m_menuCommandsToAdd;
|
||||
|
||||
Project *m_previousProject;
|
||||
Target *m_previousTarget;
|
||||
@@ -319,10 +318,6 @@ void DebuggerMainWindowPrivate::createViewsMenuItems()
|
||||
"Debugger.Views.Separator", debugcontext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||
cmd = Core::ActionManager::registerAction(q->resetLayoutAction(),
|
||||
"Debugger.Views.ResetSimple", debugcontext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||
}
|
||||
|
||||
void DebuggerMainWindowPrivate::addLanguage(DebuggerLanguage languageId,
|
||||
@@ -410,7 +405,6 @@ QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &langua
|
||||
Command *cmd = Core::ActionManager::registerAction(toggleViewAction,
|
||||
Core::Id("Debugger.").withSuffix(widget->objectName()), globalContext);
|
||||
cmd->setAttribute(Command::CA_Hide);
|
||||
d->m_menuCommandsToAdd.append(cmd);
|
||||
|
||||
dockWidget->installEventFilter(&d->m_resizeEventFilter);
|
||||
|
||||
@@ -426,12 +420,7 @@ QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &langua
|
||||
|
||||
void DebuggerMainWindow::addStagedMenuEntries()
|
||||
{
|
||||
Utils::sort(d->m_menuCommandsToAdd, [](Command *cmd1, Command *cmd2) {
|
||||
return cmd1->action()->text() < cmd2->action()->text();
|
||||
});
|
||||
foreach (Command *cmd, d->m_menuCommandsToAdd)
|
||||
d->m_viewsMenu->addAction(cmd);
|
||||
d->m_menuCommandsToAdd.clear();
|
||||
addDockActionsToMenu(d->m_viewsMenu->menu());
|
||||
}
|
||||
|
||||
QWidget *DebuggerMainWindow::createContents(IMode *mode)
|
||||
@@ -543,9 +532,9 @@ void DebuggerMainWindow::writeSettings() const
|
||||
|
||||
void DebuggerMainWindow::showViewsMenu()
|
||||
{
|
||||
QMenu *menu = createPopupMenu();
|
||||
menu->exec(d->m_viewButton->mapToGlobal(QPoint()));
|
||||
delete menu;
|
||||
QMenu menu;
|
||||
addDockActionsToMenu(&menu);
|
||||
menu.exec(d->m_viewButton->mapToGlobal(QPoint()));
|
||||
}
|
||||
|
||||
void DebuggerMainWindow::readSettings()
|
||||
@@ -613,11 +602,6 @@ bool DebuggerMainWindowPrivate::isQmlActive() const
|
||||
return (m_activeDebugLanguages & QmlLanguage);
|
||||
}
|
||||
|
||||
QMenu *DebuggerMainWindow::createPopupMenu()
|
||||
{
|
||||
return FancyMainWindow::createPopupMenu();
|
||||
}
|
||||
|
||||
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
|
||||
{
|
||||
using namespace Constants;
|
||||
|
||||
@@ -86,7 +86,6 @@ public:
|
||||
void addStagedMenuEntries();
|
||||
|
||||
QWidget *createContents(Core::IMode *mode);
|
||||
QMenu *createPopupMenu();
|
||||
|
||||
void readSettings();
|
||||
void writeSettings() const;
|
||||
|
||||
Reference in New Issue
Block a user