From 65fe4b4997709f40ecfd55c791137c860aa2b0aa Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Sun, 16 Jun 2024 17:19:59 -0400 Subject: [PATCH] Restores the previous current tab index on startup Current tab index will be saved now and will be reset with respect to the reopened tabs upon startup --- src/kiwixapp.cpp | 8 ++++++++ src/kiwixapp.h | 1 + src/tabbar.cpp | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index f50e262..b32f57d 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -215,6 +215,9 @@ void KiwixApp::restoreTabs() openUrl(QUrl(zimUrl)); } } + + /* Restore current tab index. */ + getTabWidget()->setCurrentIndex(mp_session->value("currentTabIndex", 0).toInt()); } KiwixApp *KiwixApp::instance() @@ -569,3 +572,8 @@ void KiwixApp::restoreWindowState() getMainWindow()->restoreGeometry(mp_session->value("geometry").toByteArray()); getMainWindow()->restoreState(mp_session->value("windowState").toByteArray()); } + +void KiwixApp::saveCurrentTabIndex() +{ + return mp_session->setValue("currentTabIndex", getTabWidget()->currentIndex()); +} diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 209b05c..bcecd0a 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -91,6 +91,7 @@ public: void saveListOfOpenTabs(); void saveWindowState(); void restoreWindowState(); + void saveCurrentTabIndex(); public slots: void newTab(); diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 25f9c6f..f5456cd 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -338,6 +338,8 @@ void TabBar::onCurrentChanged(int index) // In the future, other types of tabs can be added. // For example, About dialog, or Kiwix Server control panel. } + + KiwixApp::instance()->saveCurrentTabIndex(); } void TabBar::fullScreenRequested(QWebEngineFullScreenRequest request)