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)
|
void FancyMainWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QMenu *menu = createPopupMenu();
|
QMenu menu;
|
||||||
menu->exec(event->globalPos());
|
addDockActionsToMenu(&menu);
|
||||||
delete menu;
|
menu.exec(event->globalPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyMainWindow::handleVisibilityChanged(bool visible)
|
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();
|
return action1->text().toLower() < action2->text().toLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu *FancyMainWindow::createPopupMenu()
|
void FancyMainWindow::addDockActionsToMenu(QMenu *menu)
|
||||||
{
|
{
|
||||||
QList<QAction *> actions;
|
QList<QAction *> actions;
|
||||||
QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
|
QList<QDockWidget *> dockwidgets = findChildren<QDockWidget *>();
|
||||||
@@ -460,12 +460,10 @@ QMenu *FancyMainWindow::createPopupMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
qSort(actions.begin(), actions.end(), actionLessThan);
|
qSort(actions.begin(), actions.end(), actionLessThan);
|
||||||
QMenu *menu = new QMenu(this);
|
|
||||||
foreach (QAction *action, actions)
|
foreach (QAction *action, actions)
|
||||||
menu->addAction(action);
|
menu->addAction(action);
|
||||||
menu->addAction(&d->m_menuSeparator);
|
menu->addAction(&d->m_menuSeparator);
|
||||||
menu->addAction(&d->m_resetLayoutAction);
|
menu->addAction(&d->m_resetLayoutAction);
|
||||||
return menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *FancyMainWindow::menuSeparator() const
|
QAction *FancyMainWindow::menuSeparator() const
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
QAction *resetLayoutAction() const;
|
QAction *resetLayoutAction() const;
|
||||||
|
|
||||||
// Overwritten to add locked/reset.
|
// Overwritten to add locked/reset.
|
||||||
virtual QMenu *createPopupMenu();
|
void addDockActionsToMenu(QMenu *menu);
|
||||||
|
|
||||||
QDockWidget *toolBarDockWidget() const;
|
QDockWidget *toolBarDockWidget() const;
|
||||||
void setToolBarDockWidget(QDockWidget *dock);
|
void setToolBarDockWidget(QDockWidget *dock);
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ public:
|
|||||||
DebuggerLanguages m_engineDebugLanguages;
|
DebuggerLanguages m_engineDebugLanguages;
|
||||||
|
|
||||||
ActionContainer *m_viewsMenu;
|
ActionContainer *m_viewsMenu;
|
||||||
QList<Command *> m_menuCommandsToAdd;
|
|
||||||
|
|
||||||
Project *m_previousProject;
|
Project *m_previousProject;
|
||||||
Target *m_previousTarget;
|
Target *m_previousTarget;
|
||||||
@@ -319,10 +318,6 @@ void DebuggerMainWindowPrivate::createViewsMenuItems()
|
|||||||
"Debugger.Views.Separator", debugcontext);
|
"Debugger.Views.Separator", debugcontext);
|
||||||
cmd->setAttribute(Command::CA_Hide);
|
cmd->setAttribute(Command::CA_Hide);
|
||||||
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
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,
|
void DebuggerMainWindowPrivate::addLanguage(DebuggerLanguage languageId,
|
||||||
@@ -410,7 +405,6 @@ QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &langua
|
|||||||
Command *cmd = Core::ActionManager::registerAction(toggleViewAction,
|
Command *cmd = Core::ActionManager::registerAction(toggleViewAction,
|
||||||
Core::Id("Debugger.").withSuffix(widget->objectName()), globalContext);
|
Core::Id("Debugger.").withSuffix(widget->objectName()), globalContext);
|
||||||
cmd->setAttribute(Command::CA_Hide);
|
cmd->setAttribute(Command::CA_Hide);
|
||||||
d->m_menuCommandsToAdd.append(cmd);
|
|
||||||
|
|
||||||
dockWidget->installEventFilter(&d->m_resizeEventFilter);
|
dockWidget->installEventFilter(&d->m_resizeEventFilter);
|
||||||
|
|
||||||
@@ -426,12 +420,7 @@ QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &langua
|
|||||||
|
|
||||||
void DebuggerMainWindow::addStagedMenuEntries()
|
void DebuggerMainWindow::addStagedMenuEntries()
|
||||||
{
|
{
|
||||||
Utils::sort(d->m_menuCommandsToAdd, [](Command *cmd1, Command *cmd2) {
|
addDockActionsToMenu(d->m_viewsMenu->menu());
|
||||||
return cmd1->action()->text() < cmd2->action()->text();
|
|
||||||
});
|
|
||||||
foreach (Command *cmd, d->m_menuCommandsToAdd)
|
|
||||||
d->m_viewsMenu->addAction(cmd);
|
|
||||||
d->m_menuCommandsToAdd.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *DebuggerMainWindow::createContents(IMode *mode)
|
QWidget *DebuggerMainWindow::createContents(IMode *mode)
|
||||||
@@ -543,9 +532,9 @@ void DebuggerMainWindow::writeSettings() const
|
|||||||
|
|
||||||
void DebuggerMainWindow::showViewsMenu()
|
void DebuggerMainWindow::showViewsMenu()
|
||||||
{
|
{
|
||||||
QMenu *menu = createPopupMenu();
|
QMenu menu;
|
||||||
menu->exec(d->m_viewButton->mapToGlobal(QPoint()));
|
addDockActionsToMenu(&menu);
|
||||||
delete menu;
|
menu.exec(d->m_viewButton->mapToGlobal(QPoint()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebuggerMainWindow::readSettings()
|
void DebuggerMainWindow::readSettings()
|
||||||
@@ -613,11 +602,6 @@ bool DebuggerMainWindowPrivate::isQmlActive() const
|
|||||||
return (m_activeDebugLanguages & QmlLanguage);
|
return (m_activeDebugLanguages & QmlLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu *DebuggerMainWindow::createPopupMenu()
|
|
||||||
{
|
|
||||||
return FancyMainWindow::createPopupMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
|
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
|
||||||
{
|
{
|
||||||
using namespace Constants;
|
using namespace Constants;
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ public:
|
|||||||
void addStagedMenuEntries();
|
void addStagedMenuEntries();
|
||||||
|
|
||||||
QWidget *createContents(Core::IMode *mode);
|
QWidget *createContents(Core::IMode *mode);
|
||||||
QMenu *createPopupMenu();
|
|
||||||
|
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings() const;
|
void writeSettings() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user