aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/mainwindow.cpp')
-rw-r--r--src/plugins/coreplugin/mainwindow.cpp64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index ea2e8db147..ed90caea2d 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -76,6 +76,7 @@
#include <utils/stringutils.h>
#include <utils/utilsicons.h>
+#include <QActionGroup>
#include <QApplication>
#include <QCloseEvent>
#include <QColorDialog>
@@ -424,6 +425,12 @@ void MainWindow::registerDefaultContainers()
medit->appendGroup(Constants::G_EDIT_FIND);
medit->appendGroup(Constants::G_EDIT_OTHER);
+ ActionContainer *mview = ActionManager::createMenu(Constants::M_VIEW);
+ menubar->addMenu(mview, Constants::G_VIEW);
+ mview->menu()->setTitle(tr("&View"));
+ mview->appendGroup(Constants::G_VIEW_VIEWS);
+ mview->appendGroup(Constants::G_VIEW_PANES);
+
// Tools Menu
ActionContainer *ac = ActionManager::createMenu(Constants::M_TOOLS);
menubar->addMenu(ac, Constants::G_TOOLS);
@@ -434,8 +441,6 @@ 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);
mwindow->appendGroup(Constants::G_WINDOW_LIST);
@@ -465,6 +470,7 @@ void MainWindow::registerDefaultActions()
{
ActionContainer *mfile = ActionManager::actionContainer(Constants::M_FILE);
ActionContainer *medit = ActionManager::actionContainer(Constants::M_EDIT);
+ ActionContainer *mview = ActionManager::actionContainer(Constants::M_VIEW);
ActionContainer *mtools = ActionManager::actionContainer(Constants::M_TOOLS);
ActionContainer *mwindow = ActionManager::actionContainer(Constants::M_WINDOW);
ActionContainer *mhelp = ActionManager::actionContainer(Constants::M_HELP);
@@ -544,11 +550,7 @@ void MainWindow::registerDefaultActions()
mfile->addAction(cmd, Constants::G_FILE_SAVE);
// SaveAll Action
- m_saveAllAction = new QAction(tr("Save A&ll"), this);
- cmd = ActionManager::registerAction(m_saveAllAction, Constants::SAVEALL);
- cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? QString() : tr("Ctrl+Shift+S")));
- mfile->addAction(cmd, Constants::G_FILE_SAVE);
- connect(m_saveAllAction, &QAction::triggered, this, &MainWindow::saveAll);
+ DocumentManager::registerSaveAllAction();
// Print Action
icon = QIcon::fromTheme(QLatin1String("document-print"));
@@ -640,7 +642,10 @@ void MainWindow::registerDefaultActions()
: Utils::Icons::ZOOMOUT_TOOLBAR.icon();
tmpaction = new QAction(icon, tr("Zoom Out"), this);
cmd = ActionManager::registerAction(tmpaction, Constants::ZOOM_OUT);
- cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
+ if (useMacShortcuts)
+ cmd->setDefaultKeySequences({QKeySequence(tr("Ctrl+-")), QKeySequence(tr("Ctrl+Shift+-"))});
+ else
+ cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
tmpaction->setEnabled(false);
// Zoom Reset Action
@@ -714,7 +719,7 @@ void MainWindow::registerDefaultActions()
ProxyAction *toggleLeftSideBarProxyAction =
ProxyAction::proxyActionWithIcon(cmd->action(), Utils::Icons::TOGGLE_LEFT_SIDEBAR_TOOLBAR.icon());
m_toggleLeftSideBarButton->setDefaultAction(toggleLeftSideBarProxyAction);
- mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
+ mview->addAction(cmd, Constants::G_VIEW_VIEWS);
m_toggleLeftSideBarAction->setEnabled(false);
// Show Right Sidebar Action
@@ -730,14 +735,14 @@ void MainWindow::registerDefaultActions()
ProxyAction *toggleRightSideBarProxyAction =
ProxyAction::proxyActionWithIcon(cmd->action(), Utils::Icons::TOGGLE_RIGHT_SIDEBAR_TOOLBAR.icon());
m_toggleRightSideBarButton->setDefaultAction(toggleRightSideBarProxyAction);
- mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
+ mview->addAction(cmd, Constants::G_VIEW_VIEWS);
m_toggleRightSideBarButton->setEnabled(false);
registerModeSelectorStyleActions();
// Window->Views
- ActionContainer *mviews = ActionManager::createMenu(Constants::M_WINDOW_VIEWS);
- mwindow->addMenu(mviews, Constants::G_WINDOW_VIEWS);
+ ActionContainer *mviews = ActionManager::createMenu(Constants::M_VIEW_VIEWS);
+ mview->addMenu(mviews, Constants::G_VIEW_VIEWS);
mviews->menu()->setTitle(tr("&Views"));
// "Help" separators
@@ -781,7 +786,7 @@ void MainWindow::registerDefaultActions()
void MainWindow::registerModeSelectorStyleActions()
{
- ActionContainer *mwindow = ActionManager::actionContainer(Constants::M_WINDOW);
+ ActionContainer *mview = ActionManager::actionContainer(Constants::M_VIEW);
// Cycle Mode Selector Styles
m_cycleModeSelectorStyleAction = new QAction(tr("Cycle Mode Selector Styles"), this);
@@ -792,8 +797,8 @@ void MainWindow::registerModeSelectorStyleActions()
});
// Mode Selector Styles
- ActionContainer *mmodeLayouts = ActionManager::createMenu(Constants::M_WINDOW_MODESTYLES);
- mwindow->addMenu(mmodeLayouts, Constants::G_WINDOW_VIEWS);
+ ActionContainer *mmodeLayouts = ActionManager::createMenu(Constants::M_VIEW_MODESTYLES);
+ mview->addMenu(mmodeLayouts, Constants::G_VIEW_VIEWS);
QMenu *styleMenu = mmodeLayouts->menu();
styleMenu->setTitle(tr("Mode Selector Style"));
auto *stylesGroup = new QActionGroup(styleMenu);
@@ -889,11 +894,6 @@ void MainWindow::setFocusToEditor()
EditorManagerPrivate::doEscapeKeyFocusMoveMagic();
}
-void MainWindow::saveAll()
-{
- DocumentManager::saveAllModifiedDocumentsSilently();
-}
-
void MainWindow::exit()
{
// this function is most likely called from a user action
@@ -918,9 +918,10 @@ void MainWindow::openFileWith()
}
}
-IContext *MainWindow::contextObject(QWidget *widget)
+IContext *MainWindow::contextObject(QWidget *widget) const
{
- return m_contextWidgets.value(widget);
+ const auto it = m_contextWidgets.find(widget);
+ return it == m_contextWidgets.end() ? nullptr : it->second;
}
void MainWindow::addContextObject(IContext *context)
@@ -928,10 +929,11 @@ void MainWindow::addContextObject(IContext *context)
if (!context)
return;
QWidget *widget = context->widget();
- if (m_contextWidgets.contains(widget))
+ if (m_contextWidgets.find(widget) != m_contextWidgets.end())
return;
- m_contextWidgets.insert(widget, context);
+ m_contextWidgets.insert(std::make_pair(widget, context));
+ connect(context, &QObject::destroyed, this, [this, context] { removeContextObject(context); });
}
void MainWindow::removeContextObject(IContext *context)
@@ -939,11 +941,17 @@ void MainWindow::removeContextObject(IContext *context)
if (!context)
return;
- QWidget *widget = context->widget();
- if (!m_contextWidgets.contains(widget))
+ disconnect(context, &QObject::destroyed, this, nullptr);
+
+ const auto it = std::find_if(m_contextWidgets.cbegin(),
+ m_contextWidgets.cend(),
+ [context](const std::pair<QWidget *, IContext *> &v) {
+ return v.second == context;
+ });
+ if (it == m_contextWidgets.cend())
return;
- m_contextWidgets.remove(widget);
+ m_contextWidgets.erase(it);
if (m_activeContext.removeAll(context) > 0)
updateContextObject(m_activeContext);
}
@@ -960,7 +968,7 @@ void MainWindow::updateFocusWidget(QWidget *old, QWidget *now)
if (QWidget *p = QApplication::focusWidget()) {
IContext *context = nullptr;
while (p) {
- context = m_contextWidgets.value(p);
+ context = contextObject(p);
if (context)
newContext.append(context);
p = p->parentWidget();