mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
Merge pull request #1120 from kiwix/Issue#1073-remember-current-tab-from-prev-session
Remembers Previous Current Tab Index From Last Session
This commit is contained in:
commit
1cad7057b2
@ -207,15 +207,17 @@ void KiwixApp::restoreTabs()
|
||||
{
|
||||
for (const auto &zimUrl : tabsToOpen)
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Throws exception if zim file cannot be found */
|
||||
m_library.getArchive(QUrl(zimUrl).host().split('.')[0]);
|
||||
if (zimUrl == "SettingsTab")
|
||||
getTabWidget()->openOrSwitchToSettingsTab();
|
||||
else if (zimUrl.isEmpty())
|
||||
getTabWidget()->createNewTab(true, true);
|
||||
else
|
||||
openUrl(QUrl(zimUrl));
|
||||
}
|
||||
catch (std::exception &e) { /* Blank */ }
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore current tab index. */
|
||||
getTabWidget()->setCurrentIndex(mp_session->value("currentTabIndex", 0).toInt());
|
||||
}
|
||||
|
||||
KiwixApp *KiwixApp::instance()
|
||||
@ -570,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());
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ public:
|
||||
void saveListOfOpenTabs();
|
||||
void saveWindowState();
|
||||
void restoreWindowState();
|
||||
void saveCurrentTabIndex();
|
||||
|
||||
public slots:
|
||||
void newTab();
|
||||
|
@ -81,6 +81,7 @@ void TabBar::openOrSwitchToSettingsTab()
|
||||
insertTab(index,QIcon(":/icons/settings.svg"), gt("settings"));
|
||||
setCloseTabButton(index);
|
||||
setCurrentIndex(index);
|
||||
KiwixApp::instance()->saveListOfOpenTabs();
|
||||
}
|
||||
|
||||
void TabBar::setStackedWidget(QStackedWidget *widget) {
|
||||
@ -163,6 +164,7 @@ ZimView* TabBar::createNewTab(bool setCurrent, bool nextToCurrentTab)
|
||||
connect(tab, &ZimView::webActionEnabledChanged,
|
||||
this, &TabBar::onWebviewHistoryActionChanged);
|
||||
|
||||
KiwixApp::instance()->saveListOfOpenTabs();
|
||||
return tab;
|
||||
}
|
||||
|
||||
@ -274,6 +276,8 @@ QStringList TabBar::getTabUrls() const {
|
||||
{
|
||||
if (ZimView* zv = qobject_cast<ZimView*>(mp_stackedWidget->widget(index)))
|
||||
idList.push_back(zv->getWebView()->url().url());
|
||||
else if (qobject_cast<SettingsView*>(mp_stackedWidget->widget(index)))
|
||||
idList.push_back("SettingsTab");
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
@ -334,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user