From 6b39f24484bb0796f3f383401f95904f85b74d7b Mon Sep 17 00:00:00 2001 From: "Felix \"xq\" Queißner" Date: Sat, 20 Nov 2021 15:16:34 +0100 Subject: Implements #245 --- src/dialogs/settingsdialog.cpp | 15 ++++++ src/dialogs/settingsdialog.hpp | 4 ++ src/dialogs/settingsdialog.ui | 108 ++++++++++++++++++++++++++++++----------- src/kristall.hpp | 1 + src/main.cpp | 4 ++ src/mainwindow.cpp | 11 +++++ src/mainwindow.hpp | 2 + 7 files changed, 118 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp index 19b0fd9..4921d50 100644 --- a/src/dialogs/settingsdialog.cpp +++ b/src/dialogs/settingsdialog.cpp @@ -396,6 +396,9 @@ void SettingsDialog::setOptions(const GenericSettings &options) break; } } + + this->ui->tab_keep_window->setChecked(!this->current_options.close_window_with_last_tab); + this->ui->tab_close_window->setChecked(this->current_options.close_window_with_last_tab); } std::optional SettingsDialog::locale() const @@ -1032,3 +1035,15 @@ void SettingsDialog::on_selected_language_currentIndexChanged(int index) kristall::globals().localization->translate(QLocale(language_id)); } + +void SettingsDialog::on_tab_keep_window_clicked() +{ + this->current_options.close_window_with_last_tab = false; +} + + +void SettingsDialog::on_tab_close_window_clicked() +{ + this->current_options.close_window_with_last_tab = true; +} + diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp index 9176cea..59b4496 100644 --- a/src/dialogs/settingsdialog.hpp +++ b/src/dialogs/settingsdialog.hpp @@ -184,6 +184,10 @@ private slots: void on_selected_language_currentIndexChanged(int index); + void on_tab_keep_window_clicked(); + + void on_tab_close_window_clicked(); + private: void reloadStylePreview(); diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui index 45d9787..f8c3510 100644 --- a/src/dialogs/settingsdialog.ui +++ b/src/dialogs/settingsdialog.ui @@ -276,6 +276,37 @@ + + + + Tab close behaviour + + + + + + + + + Keep window open + + + buttonGroup_10 + + + + + + + Close window + + + buttonGroup_10 + + + + + @@ -698,7 +729,8 @@ Set color... - + + .. @@ -736,7 +768,8 @@ Set font... - + + .. @@ -746,7 +779,8 @@ Set color... - + + .. @@ -777,7 +811,8 @@ Set font... - + + .. @@ -787,7 +822,8 @@ Set color... - + + .. @@ -818,7 +854,8 @@ Set font... - + + .. @@ -828,7 +865,8 @@ Set color... - + + .. @@ -859,7 +897,8 @@ Set font... - + + .. @@ -869,7 +908,8 @@ Set color... - + + .. @@ -906,7 +946,8 @@ Set font... - + + .. @@ -916,7 +957,8 @@ Set color... - + + .. @@ -953,7 +995,8 @@ Set font... - + + .. @@ -963,7 +1006,8 @@ Set color... - + + .. @@ -1036,7 +1080,8 @@ Set color... - + + .. @@ -1060,7 +1105,8 @@ Set color... - + + .. @@ -1084,7 +1130,8 @@ Set color... - + + .. @@ -1394,7 +1441,8 @@ Set color... - + + .. @@ -1430,7 +1478,8 @@ New - + + .. @@ -1443,7 +1492,8 @@ Save - + + .. @@ -1456,7 +1506,8 @@ Load - + + .. @@ -1472,7 +1523,8 @@ Import - + + .. @@ -1485,7 +1537,8 @@ Export - + + .. @@ -1661,14 +1714,15 @@ - - + - - + - + + + + diff --git a/src/kristall.hpp b/src/kristall.hpp index 272525b..e24532c 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -90,6 +90,7 @@ struct GenericSettings bool fancy_quotes = true; bool emojis_enabled = true; bool strip_nav = false; + bool close_window_with_last_tab = false; AnsiEscRenderMode ansi_escapes = AnsiEscRenderMode::render; // This is set automatically diff --git a/src/main.cpp b/src/main.cpp index a86f2bd..d4f7d7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -899,6 +899,8 @@ void GenericSettings::load(QSettings &settings) cache_unlimited_life = settings.value("cache_unlimited_life", true).toBool(); session_restore_behaviour = SessionRestoreBehaviour(settings.value("session_restore_behaviour", int(session_restore_behaviour)).toInt()); + + close_window_with_last_tab = settings.value("close_window_with_last_tab", false).toBool(); } void GenericSettings::save(QSettings &settings) const @@ -965,6 +967,8 @@ void GenericSettings::save(QSettings &settings) const } settings.setValue("session_restore_behaviour", int(session_restore_behaviour)); + + settings.setValue("close_window_with_last_tab", close_window_with_last_tab); } void kristall::applySettings() diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d2eeaf8..32f36c8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -146,6 +146,7 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new, bool load_default) { BrowserTab * tab = new BrowserTab(this); + connect(tab, &BrowserTab::destroyed, this, &MainWindow::on_tab_closed); connect(tab, &BrowserTab::titleChanged, this, &MainWindow::on_tab_titleChanged); connect(tab, &BrowserTab::fileLoaded, this, &MainWindow::on_tab_fileLoaded); connect(tab, &BrowserTab::requestStateChanged, this, &MainWindow::on_tab_requestStateChanged); @@ -366,6 +367,16 @@ void MainWindow::closeEvent(QCloseEvent *event) event->accept(); } +void MainWindow::on_tab_closed() +{ + // If the user wants, we close the window together with the last tab. + // tabCount() might be 1 here, as the tab is still counted as "open" + if(kristall::globals().options.close_window_with_last_tab and (this->tabCount() <= 1)) + { + this->close(); + } +} + void MainWindow::on_browser_tabs_currentChanged(int index) { if(index >= 0) { diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 4f482b8..d81583c 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -61,6 +61,8 @@ public: void closeEvent(QCloseEvent *event) override; private slots: + void on_tab_closed(); + void on_browser_tabs_currentChanged(int index); void on_browser_tabs_tabCloseRequested(int index); -- cgit v1.2.3