mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Fully fool-proof TabBar::closeTab()
Made `TabBar::closeTab()` responsible for all the checks so that none of them have to be performed before calling that function.
This commit is contained in:
parent
94d95b68ca
commit
f62fc3b626
@ -39,16 +39,7 @@ TabBar::TabBar(QWidget *parent) :
|
|||||||
});
|
});
|
||||||
connect(app->getAction(KiwixApp::CloseTabAction), &QAction::triggered,
|
connect(app->getAction(KiwixApp::CloseTabAction), &QAction::triggered,
|
||||||
this, [=]() {
|
this, [=]() {
|
||||||
auto index = currentIndex();
|
this->closeTab(currentIndex());
|
||||||
if (index < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// library tab cannot be closed
|
|
||||||
QWidget *w = mp_stackedWidget->widget(index);
|
|
||||||
if (qobject_cast<ContentManagerView*>(w)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this->closeTab(index);
|
|
||||||
});
|
});
|
||||||
connect(app->getAction(KiwixApp::OpenHomePageAction), &QAction::triggered,
|
connect(app->getAction(KiwixApp::OpenHomePageAction), &QAction::triggered,
|
||||||
this, [=]() {
|
this, [=]() {
|
||||||
@ -278,21 +269,16 @@ void TabBar::closeTabsByZimId(const QString &id)
|
|||||||
|
|
||||||
void TabBar::closeTab(int index)
|
void TabBar::closeTab(int index)
|
||||||
{
|
{
|
||||||
// the last tab is + button, cannot be closed
|
// The first and last tabs (i.e. the library tab and the + (new tab) button)
|
||||||
if (index == this->realTabCount())
|
// cannot be closed
|
||||||
|
if (index <= 0 || index >= this->realTabCount())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QWidget *view = mp_stackedWidget->widget(index);
|
|
||||||
|
|
||||||
// library tab cannot be closed
|
|
||||||
if (qobject_cast<ContentManagerView*>(view)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( index == currentIndex() ) {
|
if ( index == currentIndex() ) {
|
||||||
setCurrentIndex(index + 1 == realTabCount() ? index - 1 : index + 1);
|
setCurrentIndex(index + 1 == realTabCount() ? index - 1 : index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *view = mp_stackedWidget->widget(index);
|
||||||
mp_stackedWidget->removeWidget(view);
|
mp_stackedWidget->removeWidget(view);
|
||||||
view->setParent(nullptr);
|
view->setParent(nullptr);
|
||||||
removeTab(index);
|
removeTab(index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user