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();
|
||||
|
@@ -102,6 +102,9 @@ public:
|
||||
void updateAdditionalContexts(const Context &remove, const Context &add,
|
||||
ICore::ContextPriority priority);
|
||||
|
||||
bool askConfirmationBeforeExit() const;
|
||||
void setAskConfirmationBeforeExit(bool ask);
|
||||
|
||||
void setOverrideColor(const QColor &color);
|
||||
|
||||
QStringList additionalAboutInformation() const;
|
||||
@@ -194,6 +197,7 @@ private:
|
||||
|
||||
QToolButton *m_toggleLeftSideBarButton = nullptr;
|
||||
QToolButton *m_toggleRightSideBarButton = nullptr;
|
||||
bool m_askConfirmationBeforeExit = false;
|
||||
QColor m_overrideColor;
|
||||
QList<std::function<bool()>> m_preCloseListeners;
|
||||
};
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "fileutils.h"
|
||||
#include "icore.h"
|
||||
#include "iversioncontrol.h"
|
||||
#include "mainwindow.h"
|
||||
#include "patchtool.h"
|
||||
#include "vcsmanager.h"
|
||||
|
||||
@@ -112,6 +113,8 @@ public:
|
||||
m_ui.maxRecentFilesSpinBox->setMinimum(1);
|
||||
m_ui.maxRecentFilesSpinBox->setMaximum(99);
|
||||
m_ui.maxRecentFilesSpinBox->setValue(EditorManagerPrivate::maxRecentFiles());
|
||||
m_ui.askBeforeExitCheckBox->setChecked(
|
||||
static_cast<Core::Internal::MainWindow *>(ICore::mainWindow())->askConfirmationBeforeExit());
|
||||
|
||||
if (HostOsInfo::isAnyUnixHost()) {
|
||||
connect(m_ui.resetTerminalButton, &QAbstractButton::clicked,
|
||||
@@ -191,6 +194,8 @@ void SystemSettingsWidget::apply()
|
||||
m_ui.warnBeforeOpeningBigFiles->isChecked());
|
||||
EditorManagerPrivate::setBigFileSizeLimit(m_ui.bigFilesLimitSpinBox->value());
|
||||
EditorManagerPrivate::setMaxRecentFiles(m_ui.maxRecentFilesSpinBox->value());
|
||||
static_cast<Core::Internal::MainWindow *>(ICore::mainWindow())->setAskConfirmationBeforeExit(
|
||||
m_ui.askBeforeExitCheckBox->isChecked());
|
||||
|
||||
if (HostOsInfo::isMacHost()) {
|
||||
Qt::CaseSensitivity defaultSensitivity
|
||||
|
@@ -390,6 +390,17 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="askBeforeExitCheckBox">
|
||||
<property name="text">
|
||||
<string>Ask for confirmation before exiting</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Reference in New Issue
Block a user