Skip to content

Commit 77d0932

Browse files
committed
Add 'Exit on last tab closed' option
Closes #539
1 parent 22a9590 commit 77d0932

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/NotepadNext/ApplicationSettings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CREATE_SETTING(Gui, ShowTabBar, showTabBar, bool, true)
4444
CREATE_SETTING(Gui, ShowStatusBar, showStatusBar, bool, true)
4545

4646
CREATE_SETTING(Gui, TabsClosable, tabsClosable, bool, true)
47+
CREATE_SETTING(Gui, ExitOnLastTabClosed, exitOnLastTabClosed, bool, false)
4748

4849
CREATE_SETTING(Gui, CombineSearchResults, combineSearchResults, bool, false)
4950

src/NotepadNext/ApplicationSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class ApplicationSettings : public QSettings
7878
DEFINE_SETTING(ShowStatusBar, showStatusBar, bool)
7979

8080
DEFINE_SETTING(TabsClosable, tabsClosable, bool)
81+
DEFINE_SETTING(ExitOnLastTabClosed, exitOnLastTabClosed, bool)
8182

8283
DEFINE_SETTING(CombineSearchResults, combineSearchResults, bool)
8384

src/NotepadNext/dialogs/MainWindow.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,8 @@ void MainWindow::closeCurrentFile()
10411041

10421042
void MainWindow::closeFile(ScintillaNext *editor)
10431043
{
1044-
if (getInitialEditor() != Q_NULLPTR) {
1045-
// Don't close the last file
1044+
// Early out. If we aren't exiting on last tab closed, and it exists, there's no point in continuing
1045+
if (!app->getSettings()->exitOnLastTabClosed() && getInitialEditor() != Q_NULLPTR) {
10461046
return;
10471047
}
10481048

@@ -1071,9 +1071,14 @@ void MainWindow::closeFile(ScintillaNext *editor)
10711071
editor->close();
10721072
}
10731073

1074-
// If the last document was closed, start with a new one
1074+
// If the last document was closed, figure out what to do next
10751075
if (editorCount() == 0) {
1076-
newFile();
1076+
if (app->getSettings()->exitOnLastTabClosed()) {
1077+
close();
1078+
}
1079+
else {
1080+
newFile();
1081+
}
10771082
}
10781083
}
10791084

src/NotepadNext/dialogs/PreferencesDialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par
6363
settings->setTranslation(ui->comboBoxTranslation->itemData(index).toString());
6464
showApplicationRestartRequired();
6565
});
66+
67+
MapSettingToCheckBox(ui->checkBoxExitOnLastTabClosed, &ApplicationSettings::exitOnLastTabClosed, &ApplicationSettings::setExitOnLastTabClosed, &ApplicationSettings::exitOnLastTabClosedChanged);
6668
}
6769

6870
PreferencesDialog::~PreferencesDialog()

src/NotepadNext/dialogs/PreferencesDialog.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@
9595
</item>
9696
</layout>
9797
</item>
98+
<item>
99+
<widget class="QCheckBox" name="checkBoxExitOnLastTabClosed">
100+
<property name="text">
101+
<string>Exit on last tab closed</string>
102+
</property>
103+
</widget>
104+
</item>
98105
<item>
99106
<spacer name="verticalSpacer">
100107
<property name="orientation">

0 commit comments

Comments
 (0)