-void DolphinMainWindow::setActiveTab(int index)
-{
- Q_ASSERT(index >= 0);
- Q_ASSERT(index < m_viewTab.count());
- if (index == m_tabIndex) {
- return;
- }
-
- // hide current tab content
- ViewTab& hiddenTab = m_viewTab[m_tabIndex];
- hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
- hiddenTab.primaryView->setActive(false);
- if (hiddenTab.secondaryView) {
- hiddenTab.secondaryView->setActive(false);
- }
- QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
- splitter->hide();
- m_centralWidgetLayout->removeWidget(splitter);
-
- // show active tab content
- m_tabIndex = index;
-
- ViewTab& viewTab = m_viewTab[index];
- m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
- viewTab.primaryView->show();
- if (viewTab.secondaryView) {
- viewTab.secondaryView->show();
- }
- viewTab.splitter->show();
-
- if (!viewTab.wasActive) {
- viewTab.wasActive = true;
-
- // If the tab has not been activated yet the size of the KItemListView is
- // undefined and results in an unwanted animation. To prevent this a
- // reloading of the directory gets triggered.
- viewTab.primaryView->view()->reload();
- if (viewTab.secondaryView) {
- viewTab.secondaryView->view()->reload();
- }
- }
-
- setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
- viewTab.secondaryView);
-}
-
-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);
- }
- rememberClosedTab(index);
-
- // delete tab
- m_viewTab[index].primaryView->deleteLater();
- if (m_viewTab[index].secondaryView) {
- m_viewTab[index].secondaryView->deleteLater();
- }
- m_viewTab[index].splitter->deleteLater();
- m_viewTab.erase(m_viewTab.begin() + index);
-
- 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() == 1) {
- m_tabBar->removeTab(0);
- actionCollection()->action("close_tab")->setEnabled(false);
- actionCollection()->action("activate_prev_tab")->setEnabled(false);
- actionCollection()->action("activate_next_tab")->setEnabled(false);
- } else {
- m_tabBar->blockSignals(false);
- }
-}
-
-void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
-{
- KMenu menu(this);
-
- QAction* newTabAction = menu.addAction(QIcon::fromTheme("tab-new"), i18nc("@action:inmenu", "New Tab"));
- newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
-
- QAction* detachTabAction = menu.addAction(QIcon::fromTheme("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
-
- QAction* closeOtherTabsAction = menu.addAction(QIcon::fromTheme("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
-
- QAction* closeTabAction = menu.addAction(QIcon::fromTheme("tab-close"), i18nc("@action:inmenu", "Close Tab"));
- closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
- QAction* selectedAction = menu.exec(pos);
- if (selectedAction == newTabAction) {
- const ViewTab& tab = m_viewTab[index];
- Q_ASSERT(tab.primaryView);
- const KUrl url = tab.secondaryView && tab.secondaryView->isActive() ?
- tab.secondaryView->url() : tab.primaryView->url();
- openNewTab(url);
- m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
- } else if (selectedAction == detachTabAction) {
- const QString separator(QLatin1Char(' '));
- QString command = QLatin1String("dolphin");
-
- const ViewTab& tab = m_viewTab[index];
- Q_ASSERT(tab.primaryView);
-
- command += separator + tab.primaryView->url().url();
- if (tab.secondaryView) {
- command += separator + tab.secondaryView->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)