-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::openTabContextMenu(int index, const QPoint& pos)
-{
- KMenu menu(this);
-
- QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
- newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
-
- QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
-
- QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
-
- QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
- closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
- QAction* selectedAction = menu.exec(pos);
- if (selectedAction == newTabAction) {
- const KUrl url = m_viewTab.at(index)->activeViewContainer()->url();
- openNewTab(url);
- m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
- } else if (selectedAction == detachTabAction) {
- 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);
- } else if (selectedAction == closeOtherTabsAction) {
- const int count = m_tabBar->count();
- for (int i = 0; i < index; ++i) {
- closeTab(0);
- }
- for (int i = index + 1; i < count; ++i) {
- closeTab(1);
- }
- } else if (selectedAction == closeTabAction) {
- closeTab(index);
- }
-}
-
-void DolphinMainWindow::slotTabMoved(int from, int to)
-{
- m_viewTab.move(from, to);
- m_tabIndex = m_tabBar->currentIndex();
-}
-
-void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
-{
- canDecode = KUrl::List::canDecode(event->mimeData());
-}
-
-void DolphinMainWindow::handleUrl(const KUrl& url)