| 470 | } |
| 471 | |
| 472 | void MainWindowPrivate::aboutToRemoveView(Sublime::AreaIndex *index, Sublime::View *view) |
| 473 | { |
| 474 | QSplitter *splitter = m_indexSplitters[index]; |
| 475 | if (!splitter) |
| 476 | return; |
| 477 | |
| 478 | qCDebug(SUBLIME) << "index " << index << " root " << area->rootIndex(); |
| 479 | qCDebug(SUBLIME) << "splitter " << splitter << " container " << splitter->widget(0); |
| 480 | qCDebug(SUBLIME) << "structure: " << index->print() << " whole structure: " << area->rootIndex()->print(); |
| 481 | //find the container for the view and remove the widget |
| 482 | auto *container = qobject_cast<Container*>(splitter->widget(0)); |
| 483 | if (!container) { |
| 484 | qCWarning(SUBLIME) << "Splitter does not have a left widget!"; |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | emit m_mainWindow->aboutToRemoveView( view ); |
| 489 | |
| 490 | viewContainers.remove(view); |
| 491 | |
| 492 | const bool wasActive = m_mainWindow->activeView() == view; |
| 493 | |
| 494 | if (auto* const viewWidget = view->widget()) { |
| 495 | widgetToView.remove(viewWidget); |
| 496 | container->removeWidget(viewWidget); |
| 497 | viewWidget->setParent(nullptr); |
| 498 | } else { |
| 499 | qCWarning(SUBLIME) << "the view" << view->document()->documentSpecifier() << "does not have a widget"; |
| 500 | } |
| 501 | |
| 502 | if (container->count() > 0) { |
| 503 | // container is not empty or this is a root index, so keep the container |
| 504 | |
| 505 | //activate what is visible currently in the container if the removed view was active |
| 506 | if (wasActive) { |
| 507 | m_mainWindow->setActiveView(container->viewForWidget(container->currentWidget())); |
| 508 | return; |
| 509 | } |
| 510 | } |
| 511 | else |
| 512 | { |
| 513 | // We have just removed the last view from this container. The container is now empty, so destroy it as well. |
| 514 | |
| 515 | // If we have a container, then it should be the only child of |
| 516 | // the splitter. |
| 517 | Q_ASSERT(splitter->count() == 1); |
| 518 | |
| 519 | // We can be called from signal handler of container |
| 520 | // (which is tab widget), so defer deleting it. |
| 521 | container->deleteLater(); |
| 522 | container->setParent(nullptr); |
| 523 | |
| 524 | /* If we're not at the top level, we get to collapse split views. */ |
| 525 | if (index->parent()) |
| 526 | { |
| 527 | /* The splitter used to have container as the only child, now it's |
| 528 | time to get rid of it. Make sure deleting splitter does not |
| 529 | delete container -- per above comment, we'll delete it later. */ |
nothing calls this directly
no test coverage detected