diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index f517fb618d7..aa07c979e45 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -103,6 +103,7 @@ const char TOGGLE_FULLSCREEN[] = "QtCreator.ToggleFullScreen"; const char MINIMIZE_WINDOW[] = "QtCreator.MinimizeWindow"; const char ZOOM_WINDOW[] = "QtCreator.ZoomWindow"; +const char CLOSE_WINDOW[] = "QtCreator.CloseWindow"; const char SPLIT[] = "QtCreator.Split"; const char SPLIT_SIDE_BY_SIDE[] = "QtCreator.SplitSideBySide"; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 8747f55caac..d900c8c5510 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -330,6 +330,7 @@ bool MainWindow::init(QString *errorMessage) void MainWindow::extensionsInitialized() { m_windowSupport = new WindowSupport(this, Context("Core.MainWindow")); + m_windowSupport->setCloseActionEnabled(false); m_editorManager->init(); m_statusBarManager->extensionsInitalized(); OutputPaneManager::instance()->init(); @@ -654,9 +655,18 @@ void MainWindow::registerDefaultActions() cmd->setAttribute(Command::CA_UpdateText); mwindow->addAction(cmd, Constants::G_WINDOW_SIZE); - if (UseMacShortcuts) + if (UseMacShortcuts) { mwindow->addSeparator(globalContext, Constants::G_WINDOW_SIZE); + QAction *closeAction = new QAction(tr("Close Window"), this); + closeAction->setEnabled(false); + cmd = ActionManager::registerAction(closeAction, Constants::CLOSE_WINDOW, globalContext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Meta+W"))); + mwindow->addAction(cmd, Constants::G_WINDOW_SIZE); + + mwindow->addSeparator(globalContext, Constants::G_WINDOW_SIZE); + } + // Show Sidebar Action m_toggleSideBarAction = new QAction(QIcon(QLatin1String(Constants::ICON_TOGGLE_SIDEBAR)), tr("Show Sidebar"), this); diff --git a/src/plugins/coreplugin/windowsupport.cpp b/src/plugins/coreplugin/windowsupport.cpp index be3cf2a01b1..6f8f23881da 100644 --- a/src/plugins/coreplugin/windowsupport.cpp +++ b/src/plugins/coreplugin/windowsupport.cpp @@ -61,6 +61,10 @@ WindowSupport::WindowSupport(QWidget *window, const Context &context) m_zoomAction = new QAction(this); ActionManager::registerAction(m_zoomAction, Constants::ZOOM_WINDOW, context); connect(m_zoomAction, SIGNAL(triggered()), m_window, SLOT(showMaximized())); + + m_closeAction = new QAction(this); + ActionManager::registerAction(m_closeAction, Constants::CLOSE_WINDOW, context); + connect(m_closeAction, SIGNAL(triggered()), m_window, SLOT(close()), Qt::QueuedConnection); } m_toggleFullScreenAction = new QAction(this); @@ -74,6 +78,12 @@ WindowSupport::~WindowSupport() ICore::removeContextObject(m_contextObject); } +void WindowSupport::setCloseActionEnabled(bool enabled) +{ + if (UseMacShortcuts) + m_closeAction->setEnabled(enabled); +} + bool WindowSupport::eventFilter(QObject *obj, QEvent *event) { if (obj != m_window) diff --git a/src/plugins/coreplugin/windowsupport.h b/src/plugins/coreplugin/windowsupport.h index 85d0a6bf718..2fa4bac9646 100644 --- a/src/plugins/coreplugin/windowsupport.h +++ b/src/plugins/coreplugin/windowsupport.h @@ -49,6 +49,8 @@ public: WindowSupport(QWidget *window, const Context &context); ~WindowSupport(); + void setCloseActionEnabled(bool enabled); + protected: bool eventFilter(QObject *obj, QEvent *event); @@ -61,6 +63,7 @@ private: IContext *m_contextObject; QAction *m_minimizeAction; QAction *m_zoomAction; + QAction *m_closeAction; QAction *m_toggleFullScreenAction; };