diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -47,6 +47,7 @@ class QIcon; class PlacesPanel; class TerminalPanel; +enum class DolphinTabPlacement; /** * @short Main window for Dolphin. @@ -327,7 +328,7 @@ /** * Opens a new tab in the background showing the URL \a url. */ - void openNewTab(const QUrl& url); + void openNewTab(const QUrl& url, DolphinTabPlacement tabPlacement); /** * Opens the selected folder in a new tab. diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -315,9 +315,9 @@ m_tabWidget->openNewActivatedTab(); } -void DolphinMainWindow::openNewTab(const QUrl& url) +void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabPlacement tabPlacement) { - m_tabWidget->openNewTab(url); + m_tabWidget->openNewTab(url, QUrl(), tabPlacement); } void DolphinMainWindow::openInNewTab() @@ -328,15 +328,15 @@ foreach (const KFileItem& item, list) { const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (!url.isEmpty()) { - m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterCurrentTab); + m_tabWidget->openNewTab(url, QUrl(), DolphinTabPlacement::AfterCurrentTab); tabCreated = true; } } // if no new tab has been created from the selection // open the current directory in a new tab if (!tabCreated) { - m_tabWidget->openNewTab(m_activeViewContainer->url(), QUrl(), DolphinTabWidget::AfterCurrentTab); + m_tabWidget->openNewTab(m_activeViewContainer->url(), QUrl(), DolphinTabPlacement::AfterCurrentTab); } } @@ -740,25 +740,25 @@ { KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); const int index = urlNavigator->historyIndex() + 1; - openNewTab(urlNavigator->locationUrl(index)); + openNewTab(urlNavigator->locationUrl(index), DolphinTabPlacement::AfterLastTab); } void DolphinMainWindow::goForwardInNewTab() { KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); const int index = urlNavigator->historyIndex() - 1; - openNewTab(urlNavigator->locationUrl(index)); + openNewTab(urlNavigator->locationUrl(index), DolphinTabPlacement::AfterLastTab); } void DolphinMainWindow::goUpInNewTab() { const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl(); - openNewTab(KIO::upUrl(currentUrl)); + openNewTab(KIO::upUrl(currentUrl), DolphinTabPlacement::AfterLastTab); } void DolphinMainWindow::goHomeInNewTab() { - openNewTab(Dolphin::homeUrl()); + openNewTab(Dolphin::homeUrl(), DolphinTabPlacement::AfterLastTab); } void DolphinMainWindow::compareFiles() @@ -889,7 +889,7 @@ break; case DolphinContextMenu::OpenParentFolderInNewTab: - openNewTab(KIO::upUrl(item.url())); + openNewTab(KIO::upUrl(item.url()), DolphinTabPlacement::AfterLastTab); break; case DolphinContextMenu::None: @@ -1328,7 +1328,7 @@ connect(foldersPanel, &FoldersPanel::folderActivated, this, &DolphinMainWindow::changeUrl); connect(foldersPanel, &FoldersPanel::folderMiddleClicked, - this, &DolphinMainWindow::openNewTab); + this, [this](const QUrl& url){this->openNewTab(url, DolphinTabPlacement::AfterCurrentTab); }); connect(foldersPanel, &FoldersPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage); @@ -1384,7 +1384,7 @@ connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated); connect(m_placesPanel, &PlacesPanel::placeMiddleClicked, - this, &DolphinMainWindow::openNewTab); + this, [this](const QUrl& url) { this->openNewTab(url, DolphinTabPlacement::AfterCurrentTab); }); connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage); connect(this, &DolphinMainWindow::urlChanged, @@ -1598,7 +1598,7 @@ connect(navigator, &KUrlNavigator::editableStateChanged, this, &DolphinMainWindow::slotEditableStateChanged); connect(navigator, &KUrlNavigator::tabRequested, - this, &DolphinMainWindow::openNewTab); + this, [this](const QUrl& url) { this->openNewTab(url, DolphinTabPlacement::AfterLastTab); }); } void DolphinMainWindow::updateSplitAction() diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -94,7 +94,7 @@ connect(m_view, &DolphinView::itemsActivated, this, &DolphinPart::slotItemsActivated); connect(m_view, &DolphinView::tabRequested, - this, &DolphinPart::createNewWindow); + this, [this](const QUrl& url, DolphinTabPlacement) { this->createNewWindow(url); }); connect(m_view, &DolphinView::requestContextMenu, this, &DolphinPart::slotOpenContextMenu); connect(m_view, &DolphinView::selectionChanged, diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -27,24 +27,25 @@ class DolphinTabPage; class KConfigGroup; +/** + * @brief Controls where tabs are placed + */ +enum class DolphinTabPlacement { + /** + * The new tab is placed after the current tab + */ + AfterCurrentTab, + /** + * The new tab is placed after the last tab + */ + AfterLastTab +}; + class DolphinTabWidget : public QTabWidget { Q_OBJECT public: - /** - * @brief Controls where tabs are placed - */ - enum TabPlacement { - /** - * The new tab is placed after the current tab - */ - AfterCurrentTab, - /** - * The new tab is placed after the last tab - */ - AfterLastTab - }; explicit DolphinTabWidget(QWidget* parent); /** @@ -122,7 +123,7 @@ * is placed. */ void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = QUrl(), - TabPlacement tabPlacement = AfterLastTab); + DolphinTabPlacement tabPlacement = DolphinTabPlacement::AfterLastTab); /** * Opens each directory in \p dirs in a separate tab. If \a splitView is set, diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -147,7 +147,7 @@ setCurrentIndex(count() - 1); } -void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement) +void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, DolphinTabPlacement tabPlacement) { QWidget* focusWidget = QApplication::focusWidget(); @@ -158,7 +158,7 @@ connect(tabPage, &DolphinTabPage::activeViewUrlChanged, this, &DolphinTabWidget::tabUrlChanged); int newTabIndex = -1; - if (tabPlacement == AfterCurrentTab) { + if (tabPlacement == DolphinTabPlacement::AfterCurrentTab) { newTabIndex = currentIndex() + 1; } insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage)); diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -45,6 +45,7 @@ class ViewProperties; class QGraphicsSceneDragDropEvent; class QRegExp; +enum class DolphinTabPlacement; /** * @short Represents a view for the directory content. @@ -400,7 +401,7 @@ /** * Is emitted if a new tab should be opened for the URL \a url. */ - void tabRequested(const QUrl& url); + void tabRequested(const QUrl& url, DolphinTabPlacement tabPlacement); /** * Is emitted if the view mode (IconsView, DetailsView, diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -24,6 +24,7 @@ #include "dolphin_generalsettings.h" #include "dolphinitemlistview.h" #include "dolphinnewfilemenuobserver.h" +#include "dolphintabwidget.h" #include "draganddrophelper.h" #include "kitemviews/kfileitemlistview.h" #include "kitemviews/kfileitemmodel.h" @@ -853,7 +854,7 @@ const QUrl& url = openItemAsFolderUrl(item); if (!url.isEmpty()) { // Open folders in new tabs - emit tabRequested(url); + emit tabRequested(url, DolphinTabPlacement::AfterLastTab); } else { items.append(item); } @@ -871,9 +872,9 @@ const KFileItem& item = m_model->fileItem(index); const QUrl& url = openItemAsFolderUrl(item); if (!url.isEmpty()) { - emit tabRequested(url); + emit tabRequested(url, DolphinTabPlacement::AfterCurrentTab); } else if (isTabsForFilesEnabled()) { - emit tabRequested(item.url()); + emit tabRequested(item.url(), DolphinTabPlacement::AfterCurrentTab); } }