Commit e40477cc authored by Eike Ziller's avatar Eike Ziller
Browse files

ActionManager: transfer ownership from main window to core plugin



Also make a bit less dependent on main window:
- Menus do not need to start with main window as parent.
- Centering the presentation label on the main window is wrong in the
presence of extra windows anyhow. It should be centered on the active
window.

Unfortunately, actions still must be added to the main window, because
actions that are not children of visible widgets do not trigger.

Change-Id: Ibb99644a3723de476db465ebe6a9cdc0820ea692
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent dc860258
......@@ -381,14 +381,16 @@ void ActionContainerPrivate::update()
*/
MenuActionContainer::MenuActionContainer(Id id)
: ActionContainerPrivate(id), m_menu(0)
: ActionContainerPrivate(id),
m_menu(new QMenu)
{
m_menu->setObjectName(id.toString());
setOnAllDisabledBehavior(Disable);
}
void MenuActionContainer::setMenu(QMenu *menu)
MenuActionContainer::~MenuActionContainer()
{
m_menu = menu;
delete m_menu;
}
QMenu *MenuActionContainer::menu() const
......
......@@ -105,8 +105,8 @@ class MenuActionContainer : public ActionContainerPrivate
{
public:
explicit MenuActionContainer(Id id);
~MenuActionContainer();
void setMenu(QMenu *menu);
QMenu *menu() const;
void insertAction(QAction *before, QAction *action);
......@@ -120,7 +120,7 @@ protected:
bool updateInternal();
private:
QMenu *m_menu;
QPointer<QMenu> m_menu;
};
class MenuBarActionContainer : public ActionContainerPrivate
......
......@@ -32,17 +32,19 @@
#include "actionmanager_p.h"
#include "actioncontainer_p.h"
#include "command_p.h"
#include <coreplugin/id.h>
#include <coreplugin/mainwindow.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <utils/qtcassert.h>
#include <QAction>
#include <QApplication>
#include <QDebug>
#include <QSettings>
#include <QDesktopWidget>
#include <QLabel>
#include <QMenu>
#include <QAction>
#include <QMenuBar>
#include <QSettings>
namespace {
enum { warnAboutFindFailures = 0 };
......@@ -200,11 +202,7 @@ ActionContainer *ActionManager::createMenu(Id id)
if (it != d->m_idContainerMap.constEnd())
return it.value();
QMenu *m = new QMenu(ICore::mainWindow());
m->setObjectName(QLatin1String(id.name()));
MenuActionContainer *mc = new MenuActionContainer(id);
mc->setMenu(m);
d->m_idContainerMap.insert(id, mc);
connect(mc, SIGNAL(destroyed()), d, SLOT(containerDestroyed()));
......@@ -327,8 +325,8 @@ void ActionManager::unregisterAction(QAction *action, Id id)
a->removeOverrideAction(action);
if (a->isEmpty()) {
// clean up
// ActionContainers listen to the commands' destroyed signals
ICore::mainWindow()->removeAction(a->action());
// ActionContainers listen to the commands' destroyed signals
delete a->action();
d->m_idCmdMap.remove(id);
delete a;
......@@ -378,8 +376,9 @@ bool ActionManager::isPresentationModeEnabled()
return d->m_presentationLabel;
}
void ActionManager::initialize()
void ActionManager::initialize(QObject *parent)
{
new ActionManager(parent);
d->initialize();
}
......@@ -463,7 +462,17 @@ void ActionManagerPrivate::showShortcutPopup(const QString &shortcut)
m_presentationLabel->setText(shortcut);
m_presentationLabel->adjustSize();
QPoint p = ICore::mainWindow()->mapToGlobal(ICore::mainWindow()->rect().center() - m_presentationLabel->rect().center());
QWidget *window = QApplication::activeWindow();
if (!window && !QApplication::topLevelWidgets().isEmpty())
window = QApplication::topLevelWidgets().first();
QPoint center;
if (window) {
center = window->mapToGlobal(window->rect().center());
} else {
QTC_ASSERT(QApplication::desktop(), return);
center = QApplication::desktop()->screenGeometry().center();
}
QPoint p = center - m_presentationLabel->rect().center();
m_presentationLabel->move(p);
m_presentationLabel->show();
......
......@@ -48,7 +48,10 @@ namespace Core {
class ActionContainer;
namespace Internal { class MainWindow; }
namespace Internal {
class CorePlugin;
class MainWindow;
} // Internal
class CORE_EXPORT ActionManager : public QObject
{
......@@ -78,11 +81,12 @@ signals:
private:
ActionManager(QObject *parent = 0);
~ActionManager();
static void initialize();
void saveSettings(QSettings *settings);
void setContext(const Context &context);
static void initialize(QObject *parent);
static void saveSettings(QSettings *settings);
static void setContext(const Context &context);
friend class Core::Internal::MainWindow;
friend class Core::Internal::CorePlugin; // initialization
friend class Core::Internal::MainWindow; // saving settings and setting context
};
} // namespace Core
......
......@@ -167,6 +167,7 @@ void CorePlugin::parseArguments(const QStringList &arguments)
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
ActionManager::initialize(this);
Theme::initialPalette(); // Initialize palette before setting it
qsrand(QDateTime::currentDateTime().toTime_t());
parseArguments(arguments);
......
......@@ -117,7 +117,6 @@ MainWindow::MainWindow() :
this)),
m_printer(0),
m_windowSupport(0),
m_actionManager(new ActionManager(this)),
m_editorManager(0),
m_externalToolManager(0),
m_progressManager(new ProgressManagerPrivate),
......@@ -146,8 +145,6 @@ MainWindow::MainWindow() :
m_toggleSideBarAction(0),
m_toggleSideBarButton(new QToolButton)
{
ActionManager::initialize(); // must be done before registering any actions
(void) new DocumentManager(this);
OutputPaneManager::create();
......@@ -1000,7 +997,7 @@ void MainWindow::writeSettings()
settings->endGroup();
DocumentManager::saveSettings();
m_actionManager->saveSettings(settings);
ActionManager::saveSettings(settings);
EditorManagerPrivate::saveSettings();
m_navigationWidget->saveSettings(settings);
}
......@@ -1043,7 +1040,7 @@ void MainWindow::updateContext()
uniquecontexts.add(id);
}
m_actionManager->setContext(uniquecontexts);
ActionManager::setContext(uniquecontexts);
emit m_coreImpl->contextChanged(m_activeContext, m_additionalContexts);
}
......
......@@ -49,7 +49,6 @@ QT_END_NAMESPACE
namespace Core {
class ActionManager;
class StatusBarWidget;
class EditorManager;
class ExternalToolManager;
......@@ -69,7 +68,6 @@ class VcsManager;
namespace Internal {
class ActionManagerPrivate;
class FancyTabWidget;
class GeneralSettings;
class ProgressManagerPrivate;
......@@ -168,7 +166,6 @@ private:
SettingsDatabase *m_settingsDatabase;
mutable QPrinter *m_printer;
WindowSupport *m_windowSupport;
ActionManager *m_actionManager;
EditorManager *m_editorManager;
ExternalToolManager *m_externalToolManager;
MessageManager *m_messageManager;
......
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