diff --git a/src/NotepadNext/ApplicationSettings.cpp b/src/NotepadNext/ApplicationSettings.cpp index 8a54156cd..09feebe1d 100644 --- a/src/NotepadNext/ApplicationSettings.cpp +++ b/src/NotepadNext/ApplicationSettings.cpp @@ -44,6 +44,7 @@ CREATE_SETTING(Gui, ShowTabBar, showTabBar, bool, true) CREATE_SETTING(Gui, ShowStatusBar, showStatusBar, bool, true) CREATE_SETTING(Gui, TabsClosable, tabsClosable, bool, true) +CREATE_SETTING(Gui, ExitOnLastTabClosed, exitOnLastTabClosed, bool, false) CREATE_SETTING(Gui, CombineSearchResults, combineSearchResults, bool, false) diff --git a/src/NotepadNext/ApplicationSettings.h b/src/NotepadNext/ApplicationSettings.h index 779a995ea..a9aeee858 100644 --- a/src/NotepadNext/ApplicationSettings.h +++ b/src/NotepadNext/ApplicationSettings.h @@ -78,6 +78,7 @@ class ApplicationSettings : public QSettings DEFINE_SETTING(ShowStatusBar, showStatusBar, bool) DEFINE_SETTING(TabsClosable, tabsClosable, bool) + DEFINE_SETTING(ExitOnLastTabClosed, exitOnLastTabClosed, bool) DEFINE_SETTING(CombineSearchResults, combineSearchResults, bool) diff --git a/src/NotepadNext/dialogs/MainWindow.cpp b/src/NotepadNext/dialogs/MainWindow.cpp index 7d61b1eae..e793d69f6 100644 --- a/src/NotepadNext/dialogs/MainWindow.cpp +++ b/src/NotepadNext/dialogs/MainWindow.cpp @@ -1041,8 +1041,8 @@ void MainWindow::closeCurrentFile() void MainWindow::closeFile(ScintillaNext *editor) { - if (getInitialEditor() != Q_NULLPTR) { - // Don't close the last file + // Early out. If we aren't exiting on last tab closed, and it exists, there's no point in continuing + if (!app->getSettings()->exitOnLastTabClosed() && getInitialEditor() != Q_NULLPTR) { return; } @@ -1071,9 +1071,14 @@ void MainWindow::closeFile(ScintillaNext *editor) editor->close(); } - // If the last document was closed, start with a new one + // If the last document was closed, figure out what to do next if (editorCount() == 0) { - newFile(); + if (app->getSettings()->exitOnLastTabClosed()) { + close(); + } + else { + newFile(); + } } } diff --git a/src/NotepadNext/dialogs/PreferencesDialog.cpp b/src/NotepadNext/dialogs/PreferencesDialog.cpp index a7c71e953..e07546cfe 100644 --- a/src/NotepadNext/dialogs/PreferencesDialog.cpp +++ b/src/NotepadNext/dialogs/PreferencesDialog.cpp @@ -63,6 +63,8 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par settings->setTranslation(ui->comboBoxTranslation->itemData(index).toString()); showApplicationRestartRequired(); }); + + MapSettingToCheckBox(ui->checkBoxExitOnLastTabClosed, &ApplicationSettings::exitOnLastTabClosed, &ApplicationSettings::setExitOnLastTabClosed, &ApplicationSettings::exitOnLastTabClosedChanged); } PreferencesDialog::~PreferencesDialog() diff --git a/src/NotepadNext/dialogs/PreferencesDialog.ui b/src/NotepadNext/dialogs/PreferencesDialog.ui index 2ddf7c821..fabaab54d 100644 --- a/src/NotepadNext/dialogs/PreferencesDialog.ui +++ b/src/NotepadNext/dialogs/PreferencesDialog.ui @@ -95,6 +95,13 @@ + + + + Exit on last tab closed + + +