Skip to content

Commit

Permalink
Add 'Exit on last tab closed' option
Browse files Browse the repository at this point in the history
Closes #539
  • Loading branch information
dail8859 committed Apr 7, 2024
1 parent 22a9590 commit 77d0932
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/NotepadNext/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/NotepadNext/ApplicationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions src/NotepadNext/dialogs/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/NotepadNext/dialogs/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions src/NotepadNext/dialogs/PreferencesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxExitOnLastTabClosed">
<property name="text">
<string>Exit on last tab closed</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 77d0932

Please sign in to comment.