Commit 3d6560a1 authored by Friedemann Kleint's avatar Friedemann Kleint

Move the Debugger/Designer view menus to Window menu.

Move actions into FancyMainWindow. Register them in
DebuggerUISwitcher and FormEditorW. Manually hide
Debugger actions for Non-Debug modes (as they belong
to the language context).
Acked-by: con
parent e6900ff0
......@@ -33,28 +33,50 @@
#include <QtCore/QHash>
#include <QtGui/QAction>
#include <QtGui/QMenu>
#include <QtGui/QDockWidget>
#include <QtCore/QSettings>
static const char lockedKeyC[] = "Locked";
static const char stateKeyC[] = "State";
static const int settingsVersion = 1;
namespace Utils {
struct FancyMainWindowPrivate {
FancyMainWindowPrivate();
explicit FancyMainWindowPrivate(FancyMainWindow *q);
QList<QDockWidget *> m_dockWidgets;
QList<bool> m_dockWidgetActiveState;
bool m_locked;
bool m_handleDockVisibilityChanges; //todo
QAction *m_menuSeparator1;
QAction *m_toggleLockedAction;
QAction *m_menuSeparator2;
QAction *m_resetLayoutAction;
};
FancyMainWindowPrivate::FancyMainWindowPrivate() :
m_locked(true), m_handleDockVisibilityChanges(true)
FancyMainWindowPrivate::FancyMainWindowPrivate(FancyMainWindow *q) :
m_locked(true), m_handleDockVisibilityChanges(true),
m_menuSeparator1(new QAction(q)),
m_toggleLockedAction(new QAction(FancyMainWindow::tr("Locked"), q)),
m_menuSeparator2(new QAction(q)),
m_resetLayoutAction(new QAction(FancyMainWindow::tr("Reset to default layout") ,q))
{
m_toggleLockedAction->setCheckable(true);
m_toggleLockedAction->setChecked(m_locked);
m_menuSeparator1->setSeparator(true);
m_menuSeparator2->setSeparator(true);
}
FancyMainWindow::FancyMainWindow(QWidget *parent) :
QMainWindow(parent), d(new FancyMainWindowPrivate)
QMainWindow(parent), d(new FancyMainWindowPrivate(this))
{
connect(d->m_toggleLockedAction, SIGNAL(toggled(bool)),
this, SLOT(setLocked(bool)));
connect(d->m_resetLayoutAction, SIGNAL(triggered()),
this, SIGNAL(resetLayout()));
}
FancyMainWindow::~FancyMainWindow()
......@@ -190,8 +212,8 @@ void FancyMainWindow::restoreSettings(const QSettings *settings)
QHash<QString, QVariant> FancyMainWindow::saveSettings() const
{
QHash<QString, QVariant> settings;
settings.insert(QLatin1String("State"), saveState(1));
settings.insert(QLatin1String("Locked"), d->m_locked);
settings.insert(QLatin1String(stateKeyC), saveState(settingsVersion));
settings.insert(QLatin1String(lockedKeyC), d->m_locked);
for (int i = 0; i < d->m_dockWidgetActiveState.count(); ++i) {
settings.insert(d->m_dockWidgets.at(i)->objectName(),
d->m_dockWidgetActiveState.at(i));
......@@ -201,10 +223,11 @@ QHash<QString, QVariant> FancyMainWindow::saveSettings() const
void FancyMainWindow::restoreSettings(const QHash<QString, QVariant> &settings)
{
QByteArray ba = settings.value("State", QByteArray()).toByteArray();
QByteArray ba = settings.value(QLatin1String(stateKeyC), QByteArray()).toByteArray();
if (!ba.isEmpty())
restoreState(ba, 1);
d->m_locked = settings.value("Locked", true).toBool();
restoreState(ba, settingsVersion);
d->m_locked = settings.value(QLatin1String("Locked"), true).toBool();
d->m_toggleLockedAction->setChecked(d->m_locked);
for (int i = 0; i < d->m_dockWidgetActiveState.count(); ++i) {
d->m_dockWidgetActiveState[i] = settings.value(d->m_dockWidgets.at(i)->objectName(), false).toBool();
}
......@@ -220,4 +243,44 @@ bool FancyMainWindow::isLocked() const
return d->m_locked;
}
QMenu *FancyMainWindow::createPopupMenu()
{
QMenu *menu = QMainWindow::createPopupMenu();
menu->addAction(d->m_menuSeparator1);
menu->addAction(d->m_toggleLockedAction);
menu->addAction(d->m_menuSeparator2);
menu->addAction(d->m_resetLayoutAction);
return menu;
}
QAction *FancyMainWindow::menuSeparator1() const
{
return d->m_menuSeparator1;
}
QAction *FancyMainWindow::toggleLockedAction() const
{
return d->m_toggleLockedAction;
}
QAction *FancyMainWindow::menuSeparator2() const
{
return d->m_menuSeparator2;
}
QAction *FancyMainWindow::resetLayoutAction() const
{
return d->m_resetLayoutAction;
}
void FancyMainWindow::setDockActionsVisible(bool v)
{
foreach(const QDockWidget *dockWidget, d->m_dockWidgets)
dockWidget->toggleViewAction()->setVisible(v);
d->m_toggleLockedAction->setVisible(v);
d->m_menuSeparator1->setVisible(v);
d->m_menuSeparator2->setVisible(v);
d->m_resetLayoutAction->setVisible(v);
}
} // namespace Utils
......@@ -42,6 +42,10 @@ namespace Utils {
struct FancyMainWindowPrivate;
// MainWindow with dock widgets and additional "lock" functionality
// (locking the dock widgets in place) and "reset layout" functionality.
// The dock actions and the additional actions should be accessible
// in a Window-menu.
class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow
{
Q_OBJECT
......@@ -63,8 +67,23 @@ public:
QHash<QString, QVariant> saveSettings() const;
void restoreSettings(const QHash<QString, QVariant> &settings);
// Additional context menu actions
QAction *menuSeparator1() const;
QAction *toggleLockedAction() const;
QAction *menuSeparator2() const;
QAction *resetLayoutAction() const;
// Overwritten to add locked/reset.
virtual QMenu *createPopupMenu();
signals:
// Emitted by resetLayoutAction(). Connect to a slot
// restoring the default layout.
void resetLayout();
public slots:
void setLocked(bool locked);
void setDockActionsVisible(bool v);
protected:
void hideEvent(QHideEvent *event);
......
......@@ -82,6 +82,7 @@ const char * const M_EDIT_ADVANCED = "QtCreator.Menu.Edit.Advanced";
const char * const M_TOOLS = "QtCreator.Menu.Tools";
const char * const M_WINDOW = "QtCreator.Menu.Window";
const char * const M_WINDOW_PANES = "QtCreator.Menu.Window.Panes";
const char * const M_WINDOW_VIEWS = "QtCreator.Menu.Window.Views";
const char * const M_HELP = "QtCreator.Menu.Help";
//contexts
......@@ -193,6 +194,7 @@ const char * const G_EDIT_EDITOR = "QtCreator.Group.Edit.Editor";
// window menu groups
const char * const G_WINDOW_SIZE = "QtCreator.Group.Window.Size";
const char * const G_WINDOW_PANES = "QtCreator.Group.Window.Panes";
const char * const G_WINDOW_VIEWS = "QtCreator.Group.Window.Views";
const char * const G_WINDOW_SPLIT = "QtCreator.Group.Window.Split";
const char * const G_WINDOW_NAVIGATE = "QtCreator.Group.Window.Navigate";
const char * const G_WINDOW_OTHER = "QtCreator.Group.Window.Other";
......
......@@ -472,6 +472,7 @@ void MainWindow::registerDefaultContainers()
menubar->addMenu(mwindow, Constants::G_WINDOW);
mwindow->menu()->setTitle(tr("&Window"));
mwindow->appendGroup(Constants::G_WINDOW_SIZE);
mwindow->appendGroup(Constants::G_WINDOW_VIEWS);
mwindow->appendGroup(Constants::G_WINDOW_PANES);
mwindow->appendGroup(Constants::G_WINDOW_SPLIT);
mwindow->appendGroup(Constants::G_WINDOW_NAVIGATE);
......@@ -714,7 +715,7 @@ void MainWindow::registerDefaultActions()
#endif
connect(m_toggleSideBarAction, SIGNAL(triggered(bool)), this, SLOT(setSidebarVisible(bool)));
m_toggleSideBarButton->setDefaultAction(cmd->action());
mwindow->addAction(cmd, Constants::G_WINDOW_PANES);
mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
m_toggleSideBarAction->setEnabled(false);
#ifndef Q_WS_MAC
......@@ -727,6 +728,11 @@ void MainWindow::registerDefaultActions()
connect(m_toggleFullScreenAction, SIGNAL(triggered(bool)), this, SLOT(setFullScreen(bool)));
#endif
// Window->Views
ActionContainer *mviews = am->createMenu(Constants::M_WINDOW_VIEWS);
mwindow->addMenu(mviews, Constants::G_WINDOW_VIEWS);
mviews->menu()->setTitle(tr("&Views"));
// About IDE Action
icon = QIcon::fromTheme(QLatin1String("help-about"));
#ifdef Q_WS_MAC
......
......@@ -35,6 +35,7 @@
#include <utils/savedaction.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <coreplugin/actionmanager/command.h>
#include <debugger/debuggerconstants.h>
#include <debugger/debuggeractions.h>
......@@ -96,8 +97,6 @@ struct DebuggerUISwitcherPrivate
bool m_isActiveMode;
bool m_changingUI;
QAction *m_toggleLockedAction;
const static int StackIndexRole = Qt::UserRole + 11;
Core::ActionContainer *m_languageMenu;
......@@ -115,7 +114,6 @@ DebuggerUISwitcherPrivate::DebuggerUISwitcherPrivate(DebuggerUISwitcher *q) :
m_activeLanguage(-1),
m_isActiveMode(false),
m_changingUI(false),
m_toggleLockedAction(0),
m_viewsMenu(0),
m_debugMenu(0)
{
......@@ -134,10 +132,10 @@ 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_viewsMenu = am->actionContainer(QLatin1String(Core::Constants::M_WINDOW_VIEWS));
QTC_ASSERT(d->m_viewsMenu, return)
d->m_languageMenu = am->createMenu(Debugger::Constants::M_DEBUG_LANGUAGES);
d->m_languageActionGroup->setExclusive(true);
......@@ -178,6 +176,7 @@ int DebuggerUISwitcher::activeLanguageId() const
void DebuggerUISwitcher::modeChanged(Core::IMode *mode)
{
d->m_isActiveMode = (mode->id() == Debugger::Constants::MODE_DEBUG);
d->m_mainWindow->setDockActionsVisible(d->m_isActiveMode);
hideInactiveWidgets();
}
......@@ -214,35 +213,19 @@ void DebuggerUISwitcher::createViewsMenuItems()
QList<int> globalcontext;
globalcontext << Core::Constants::C_GLOBAL_ID;
Core::Command *cmd = 0;
d->m_toggleLockedAction = new QAction(tr("Locked"), this);
d->m_toggleLockedAction->setCheckable(true);
d->m_toggleLockedAction->setChecked(true);
connect(d->m_toggleLockedAction, SIGNAL(toggled(bool)),
d->m_mainWindow, SLOT(setLocked(bool)));
QAction *sep = new QAction(this);
sep->setSeparator(true);
cmd = am->registerAction(sep, QLatin1String("Debugger.Sep.Views"), globalcontext);
d->m_debugMenu->addAction(cmd);
QMenu *mLang = d->m_languageMenu->menu();
mLang->setTitle(tr("&Languages"));
d->m_debugMenu->addMenu(d->m_languageMenu, Core::Constants::G_DEFAULT_THREE);
QMenu *m = d->m_viewsMenu->menu();
m->setTitle(tr("&Views"));
d->m_debugMenu->addMenu(d->m_viewsMenu, Core::Constants::G_DEFAULT_THREE);
m->addSeparator();
m->addAction(d->m_toggleLockedAction);
m->addSeparator();
QAction *resetToSimpleAction = d->m_viewsMenu->menu()->addAction(tr("Reset to default layout"));
connect(resetToSimpleAction, SIGNAL(triggered()),
SLOT(resetDebuggerLayout()));
// Add menu items
Core::Command *cmd = am->registerAction(d->m_mainWindow->menuSeparator1(), QLatin1String("Debugger.Views.Separator1"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(d->m_mainWindow->toggleLockedAction(), QLatin1String("Debugger.Views.ToggleLocked"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(d->m_mainWindow->menuSeparator2(), QLatin1String("Debugger.Views.Separator2"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(d->m_mainWindow->resetLayoutAction(), QLatin1String("Debugger.Views.ResetSimple"), globalcontext);
d->m_viewsMenu->addAction(cmd);
}
DebuggerUISwitcher *DebuggerUISwitcher::instance()
......@@ -345,6 +328,8 @@ QWidget *DebuggerUISwitcher::createMainWindow(Core::BaseMode *mode)
d->m_mainWindow = new DebuggerMainWindow(this);
d->m_mainWindow->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
d->m_mainWindow->setDocumentMode(true);
connect(d->m_mainWindow, SIGNAL(resetLayout()),
this, SLOT(resetDebuggerLayout()));
QBoxLayout *editorHolderLayout = new QVBoxLayout;
editorHolderLayout->setMargin(0);
......@@ -407,12 +392,13 @@ QDockWidget *DebuggerUISwitcher::createDockWidget(const QString &langName, QWidg
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(),
QAction *action = dockWidget->toggleViewAction();
Core::Command *cmd = am->registerAction(action,
"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()));
d->m_viewsMenuItems.append(qMakePair(d->m_languages.indexOf(langName), action));
return dockWidget;
}
......@@ -464,7 +450,6 @@ void DebuggerUISwitcher::readSettings()
QSettings *s = Core::ICore::instance()->settings();
s->beginGroup(QLatin1String("DebugMode"));
d->m_mainWindow->restoreSettings(s);
d->m_toggleLockedAction->setChecked(d->m_mainWindow->isLocked());
s->endGroup();
foreach(Internal::DebugToolWindow *toolWindow, d->m_dockWidgets) {
......@@ -483,6 +468,7 @@ void DebuggerUISwitcher::initialize()
changeDebuggerUI(d->m_languages.first());
}
hideInactiveWidgets();
d->m_mainWindow->setDockActionsVisible(false);
}
void DebuggerUISwitcher::resetDebuggerLayout()
......
......@@ -114,6 +114,7 @@ private:
void createViewsMenuItems();
void readSettings();
void writeSettings() const;
QWidget *createContents(Core::BaseMode *mode);
QWidget *createMainWindow(Core::BaseMode *mode);
......
......@@ -145,7 +145,6 @@ FormEditorW::FormEditorW() :
m_fwm(0),
m_core(Core::ICore::instance()),
m_initStage(RegisterPlugins),
m_viewMenu(0),
m_actionGroupEditMode(0),
m_actionPrint(0),
m_actionPreview(0),
......@@ -219,13 +218,15 @@ FormEditorW::~FormEditorW()
// Add an actioon to toggle the view state of a dock window
void FormEditorW::addDockViewAction(Core::ActionManager *am,
Core::ActionContainer *viewMenu,
int index, const QList<int> &context,
const QString &title, const QString &id)
{
if (const QDockWidget *dw = m_editorWidget->designerDockWidgets()[index]) {
QAction *action = dw->toggleViewAction();
action->setText(title);
addToolAction(action, am, context, id, m_viewMenu, QString());
Core::Command *cmd = addToolAction(action, am, context, id, viewMenu, QString());
cmd->setAttribute(Core::Command::CA_Hide);
}
}
......@@ -233,37 +234,36 @@ void FormEditorW::setupViewActions()
{
// Populate "View" menu of form editor menu
Core::ActionManager *am = m_core->actionManager();
QList<int> globalcontext;
globalcontext << m_core->uniqueIDManager()->uniqueIdentifier(Core::Constants::C_GLOBAL);
Core::ActionContainer *viewMenu = am->actionContainer(QLatin1String(Core::Constants::M_WINDOW_VIEWS));
QTC_ASSERT(viewMenu, return)
addDockViewAction(am, WidgetBoxSubWindow, globalcontext,
addDockViewAction(am, viewMenu, WidgetBoxSubWindow, m_contexts,
tr("Widget box"), QLatin1String("FormEditor.WidgetBox"));
addDockViewAction(am, ObjectInspectorSubWindow, globalcontext,
addDockViewAction(am, viewMenu, ObjectInspectorSubWindow, m_contexts,
tr("Object Inspector"), QLatin1String("FormEditor.ObjectInspector"));
addDockViewAction(am, PropertyEditorSubWindow, globalcontext,
addDockViewAction(am, viewMenu, PropertyEditorSubWindow, m_contexts,
tr("Property Editor"), QLatin1String("FormEditor.PropertyEditor"));
addDockViewAction(am, SignalSlotEditorSubWindow, globalcontext,
addDockViewAction(am, viewMenu, SignalSlotEditorSubWindow, m_contexts,
tr("Signals && Slots Editor"), QLatin1String("FormEditor.SignalsAndSlotsEditor"));
addDockViewAction(am, ActionEditorSubWindow, globalcontext,
addDockViewAction(am, viewMenu, ActionEditorSubWindow, m_contexts,
tr("Action Editor"), QLatin1String("FormEditor.ActionEditor"));
// Lock/Reset
Core::Command *cmd = addToolAction(m_editorWidget->menuSeparator1(), am, m_contexts, QLatin1String("FormEditor.SeparatorLock"), viewMenu, QString());
cmd->setAttribute(Core::Command::CA_Hide);
createSeparator(this, am, globalcontext, m_viewMenu, QLatin1String("FormEditor.Menu.Tools.Views.SeparatorLock"));
cmd = addToolAction(m_editorWidget->toggleLockedAction(), am, m_contexts, QLatin1String("FormEditor.Locked"), viewMenu, QString());
cmd->setAttribute(Core::Command::CA_Hide);
m_lockAction = new QAction(tr("Locked"), this);
m_lockAction->setCheckable(true);
addToolAction(m_lockAction, am, globalcontext, QLatin1String("FormEditor.Locked"), m_viewMenu, QString());
connect(m_lockAction, SIGNAL(toggled(bool)), m_editorWidget, SLOT(setLocked(bool)));
cmd = addToolAction(m_editorWidget->menuSeparator2(), am, m_contexts, QLatin1String("FormEditor.SeparatorReset"), viewMenu, QString());
cmd->setAttribute(Core::Command::CA_Hide);
createSeparator(this, am, globalcontext, m_viewMenu, QLatin1String("FormEditor.Menu.Tools.Views.SeparatorReset"));
m_resetLayoutAction = new QAction(tr("Reset to Default Layout"), this);
m_lockAction->setChecked(m_editorWidget->isLocked());
connect(m_resetLayoutAction, SIGNAL(triggered()), m_editorWidget, SLOT(resetToDefaultLayout()));
addToolAction(m_resetLayoutAction, am, globalcontext, QLatin1String("FormEditor.ResetToDefaultLayout"), m_viewMenu, QString());
cmd = addToolAction(m_editorWidget->resetLayoutAction(), am, m_contexts, QLatin1String("FormEditor.ResetToDefaultLayout"), viewMenu, QString());
connect(m_editorWidget, SIGNAL(resetLayout()), m_editorWidget, SLOT(resetToDefaultLayout()));
cmd->setAttribute(Core::Command::CA_Hide);
}
void FormEditorW::fullInit()
......@@ -538,13 +538,6 @@ void FormEditorW::setupActions()
connect(m_actionAboutPlugins, SIGNAL(triggered()), m_fwm, SLOT(aboutPlugins()));
m_actionAboutPlugins->setEnabled(false);
// Views. Populated later on.
createSeparator(this, am, m_contexts, mformtools, QLatin1String("FormEditor.Menu.Tools.SeparatorViews"));
m_viewMenu = am->createMenu(QLatin1String(M_FORMEDITOR_VIEWS));
m_viewMenu->menu()->setTitle(tr("Views"));
mformtools->addMenu(m_viewMenu);
// FWM
connect(m_fwm, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface *)), this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface *)));
}
......@@ -653,18 +646,17 @@ QAction *FormEditorW::createEditModeAction(QActionGroup *ag,
}
// Create a tool action
void FormEditorW::addToolAction(QAction *a,
Core::ActionManager *am,
const QList<int> &context,
const QString &name,
Core::ActionContainer *c1,
const QString &keySequence)
Core::Command *FormEditorW::addToolAction(QAction *a, Core::ActionManager *am,
const QList<int> &context, const QString &name,
Core::ActionContainer *c1, const QString &keySequence)
{
Core::Command *command = am->registerAction(a, name, context);
if (!keySequence.isEmpty())
command->setDefaultKeySequence(QKeySequence(keySequence));
bindShortcut(command, a);
if (!a->isSeparator())
bindShortcut(command, a);
c1->addAction(command);
return command;
}
EditorData FormEditorW::createEditor(QWidget *parent)
......
......@@ -136,7 +136,9 @@ private:
void setupActions();
void setupViewActions();
inline void addDockViewAction(Core::ActionManager *am, int index,
inline void addDockViewAction(Core::ActionManager *am,
Core::ActionContainer *viewMenu,
int index,
const QList<int> &context,
const QString &title, const QString &id);
......@@ -154,12 +156,9 @@ private:
int toolNumber,
const QString &iconName = QString(),
const QString &keySequence = QString());
void addToolAction(QAction *a,
Core::ActionManager *am,
const QList<int> &context,
const QString &name,
Core::ActionContainer *c1,
const QString &keySequence = QString());
Core::Command *addToolAction(QAction *a, Core::ActionManager *am,
const QList<int> &context, const QString &name,
Core::ActionContainer *c1, const QString &keySequence = QString());
QToolBar *createEditorToolBar() const;
static FormEditorW *m_self;
......@@ -171,7 +170,6 @@ private:
InitializationStage m_initStage;
QWidget *m_designerSubWindows[Designer::Constants::DesignerSubWindowCount];
Core::ActionContainer *m_viewMenu;
QAction *m_lockAction;
QAction *m_resetLayoutAction;
......
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