-void DolphinMainWindow::setActiveTab(int index)
-{
- Q_ASSERT(index >= 0);
- Q_ASSERT(index < m_viewTab.count());
- if (index == m_tabIndex) {
- return;
- }
-
- m_tabBar->setCurrentIndex(index);
-
- // hide current tab content
- if (m_tabIndex >= 0) {
- DolphinTabPage* hiddenTabPage = m_viewTab.at(m_tabIndex);
- hiddenTabPage->hide();
- m_centralWidgetLayout->removeWidget(hiddenTabPage);
- }
-
- // show active tab content
- m_tabIndex = index;
-
- DolphinTabPage* tabPage = m_viewTab.at(index);
- m_centralWidgetLayout->addWidget(tabPage, 1);
- tabPage->show();
-
- setActiveViewContainer(tabPage->activeViewContainer());
-}
-
-void DolphinMainWindow::closeTab()
-{
- closeTab(m_tabBar->currentIndex());
-}
-
-void DolphinMainWindow::closeTab(int index)
-{
- Q_ASSERT(index >= 0);
- Q_ASSERT(index < m_viewTab.count());
- if (m_viewTab.count() == 1) {
- // the last tab may never get closed
- return;
- }
-
- if (index == m_tabIndex) {
- // The tab that should be closed is the active tab. Activate the
- // previous tab before closing the tab.
- m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
- }
-
- DolphinTabPage* tabPage = m_viewTab.at(index);
-
- if (tabPage->splitViewEnabled()) {
- emit rememberClosedTab(tabPage->primaryViewContainer()->url(),
- tabPage->secondaryViewContainer()->url());
- } else {
- emit rememberClosedTab(tabPage->primaryViewContainer()->url(), KUrl());
- }
-
- // delete tab
- m_viewTab.removeAt(index);
- tabPage->deleteLater();
-
- m_tabBar->blockSignals(true);
- m_tabBar->removeTab(index);
-
- if (m_tabIndex > index) {
- m_tabIndex--;
- Q_ASSERT(m_tabIndex >= 0);
- }
-
- // if only one tab is left, also remove the tab entry so that
- // closing the last tab is not possible
- if (m_viewTab.count() < 2) {
- actionCollection()->action("close_tab")->setEnabled(false);
- actionCollection()->action("activate_prev_tab")->setEnabled(false);
- actionCollection()->action("activate_next_tab")->setEnabled(false);
- m_tabBar->hide();
- } else {
- m_tabBar->blockSignals(false);
- }
-}
-
-void DolphinMainWindow::detachTab(int index)
-{
- Q_ASSERT(index >= 0);
-
- const QString separator(QLatin1Char(' '));
- QString command = QLatin1String("dolphin");
-
- const DolphinTabPage* tabPage = m_viewTab.at(index);
- command += separator + tabPage->primaryViewContainer()->url().url();
- if (tabPage->splitViewEnabled()) {
- command += separator + tabPage->secondaryViewContainer()->url().url();
- command += separator + QLatin1String("-split");
- }
-
- KRun::runCommand(command, this);
-
- closeTab(index);
-}
-
-void DolphinMainWindow::slotTabMoved(int from, int to)
-{
- m_viewTab.move(from, to);
- m_tabIndex = m_tabBar->currentIndex();
-}
-
-void DolphinMainWindow::handleUrl(const KUrl& url)