forked from qt-creator/qt-creator
MainWindow: ask confirmation before closing Qt Creator
When working with multiple windows, pressing the close button multiple times can close Qt Creator too. This patch adds a system option, asking for a confirmation before closing the IDE. By default it's not enabled. Fixes: QTCREATORBUG-7637 Change-Id: Ifc5e8c97511f9227ce0634c8a7064d95775c76c2 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
70b226144f
commit
6e4ca8b6af
@@ -85,6 +85,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QPrinter>
|
||||
#include <QSettings>
|
||||
#include <QStatusBar>
|
||||
@@ -209,6 +210,16 @@ void MainWindow::setSidebarVisible(bool visible, Side side)
|
||||
navigationWidget(side)->setShown(visible);
|
||||
}
|
||||
|
||||
bool MainWindow::askConfirmationBeforeExit() const
|
||||
{
|
||||
return m_askConfirmationBeforeExit;
|
||||
}
|
||||
|
||||
void MainWindow::setAskConfirmationBeforeExit(bool ask)
|
||||
{
|
||||
m_askConfirmationBeforeExit = ask;
|
||||
}
|
||||
|
||||
void MainWindow::setOverrideColor(const QColor &color)
|
||||
{
|
||||
m_overrideColor = color;
|
||||
@@ -338,6 +349,17 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_askConfirmationBeforeExit &&
|
||||
(QMessageBox::question(this,
|
||||
tr("Exit %1?").arg(Constants::IDE_DISPLAY_NAME),
|
||||
tr("Exit %1?").arg(Constants::IDE_DISPLAY_NAME),
|
||||
QMessageBox::Yes | QMessageBox::No,
|
||||
QMessageBox::No)
|
||||
== QMessageBox::No)) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
ICore::saveSettings(ICore::MainWindowClosing);
|
||||
|
||||
// Save opened files
|
||||
@@ -1001,6 +1023,7 @@ void MainWindow::aboutToShutdown()
|
||||
|
||||
static const char settingsGroup[] = "MainWindow";
|
||||
static const char colorKey[] = "Color";
|
||||
static const char askBeforeExitKey[] = "AskBeforeExit";
|
||||
static const char windowGeometryKey[] = "WindowGeometry";
|
||||
static const char windowStateKey[] = "WindowState";
|
||||
static const char modeSelectorLayoutKey[] = "ModeSelectorLayout";
|
||||
@@ -1019,6 +1042,8 @@ void MainWindow::readSettings()
|
||||
QColor(StyleHelper::DEFAULT_BASE_COLOR)).value<QColor>());
|
||||
}
|
||||
|
||||
m_askConfirmationBeforeExit = settings->value(askBeforeExitKey, false).toBool();
|
||||
|
||||
{
|
||||
ModeManager::Style modeStyle =
|
||||
ModeManager::Style(settings->value(modeSelectorLayoutKey, int(ModeManager::Style::IconsAndText)).toInt());
|
||||
@@ -1050,6 +1075,8 @@ void MainWindow::saveSettings()
|
||||
if (!(m_overrideColor.isValid() && StyleHelper::baseColor() == m_overrideColor))
|
||||
settings->setValue(QLatin1String(colorKey), StyleHelper::requestedBaseColor());
|
||||
|
||||
settings->setValue(askBeforeExitKey, m_askConfirmationBeforeExit);
|
||||
|
||||
settings->endGroup();
|
||||
|
||||
DocumentManager::saveSettings();
|
||||
|
||||
Reference in New Issue
Block a user