X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a4292cf0680237719b32cb3ad8cc58540f7701b2..d3617c06d47df25f70675e0f051fd7c7f38402bc:/src/dolphintabwidget.cpp diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 5586c9df2..6caaf174f 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -117,6 +117,11 @@ bool DolphinTabWidget::isUrlOpen(const QUrl &url) const return indexByUrl(url).first >= 0; } +bool DolphinTabWidget::isUrlOrParentOpen(const QUrl &url) const +{ + return indexByUrl(url, ReturnIndexForOpenedParentAlso).first >= 0; +} + void DolphinTabWidget::openNewActivatedTab() { std::unique_ptr oldNavigatorState; @@ -152,7 +157,7 @@ void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& s } } -void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl) +void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, DolphinTabWidget::NewTabPosition position) { QWidget* focusWidget = QApplication::focusWidget(); @@ -168,8 +173,16 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU tabBar()->setTabText(tabIndex, tabName(tabPage)); }); + if (position == NewTabPosition::FollowSetting) { + if (GeneralSettings::openNewTabAfterLastTab()) { + position = NewTabPosition::AtEnd; + } else { + position = NewTabPosition::AfterCurrent; + } + } + int newTabIndex = -1; - if (!GeneralSettings::openNewTabAfterLastTab()) { + if (position == NewTabPosition::AfterCurrent || (position == NewTabPosition::FollowSetting && !GeneralSettings::openNewTabAfterLastTab())) { newTabIndex = currentIndex() + 1; } @@ -182,7 +195,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU } } -void DolphinTabWidget::openDirectories(const QList& dirs, bool splitView) +void DolphinTabWidget::openDirectories(const QList& dirs, bool splitView, bool skipChildUrls) { Q_ASSERT(dirs.size() > 0); @@ -191,12 +204,12 @@ void DolphinTabWidget::openDirectories(const QList& dirs, bool splitView) QList::const_iterator it = dirs.constBegin(); while (it != dirs.constEnd()) { const QUrl& primaryUrl = *(it++); - const QPair indexInfo = indexByUrl(primaryUrl); + const QPair indexInfo = indexByUrl(primaryUrl, skipChildUrls ? ReturnIndexForOpenedParentAlso : ReturnIndexForOpenedUrlOnly); const int index = indexInfo.first; const bool isInPrimaryView = indexInfo.second; - // When the user asks for a URL that's already open, activate it instead - // of opening a second copy + // When the user asks for a URL that's already open (or it's parent is open if skipChildUrls is set), + // activate it instead of opening a new tab if (index >= 0) { somethingWasAlreadyOpen = true; activateTab(index); @@ -243,7 +256,7 @@ void DolphinTabWidget::openFiles(const QList& files, bool splitView) } const int oldTabCount = count(); - openDirectories(dirs, splitView); + openDirectories(dirs, splitView, true); const int tabCount = count(); // Select the files. Although the files can be split between several @@ -380,6 +393,17 @@ void DolphinTabWidget::tabDropEvent(int index, QDropEvent* event) if (index >= 0) { DolphinView* view = tabPageAt(index)->activeViewContainer()->view(); view->dropUrls(view->url(), event, view); + } else { + const auto urls = event->mimeData()->urls(); + + for (const QUrl &url : urls) { + auto *job = KIO::statDetails(url, KIO::StatJob::SourceSide, KIO::StatDetail::StatBasic, KIO::JobFlag::HideProgressInfo); + connect(job, &KJob::result, this, [this, job]() { + if (!job->error() && job->statResult().isDir()) { + openNewTab(job->url(), QUrl(), NewTabPosition::AtEnd); + } + }); + } } } @@ -475,17 +499,29 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const return name.replace('&', QLatin1String("&&")); } -QPair DolphinTabWidget::indexByUrl(const QUrl& url) const +QPair DolphinTabWidget::indexByUrl(const QUrl& url, ChildUrlBehavior childUrlBehavior) const { - for (int i = 0; i < count(); i++) { + int i = currentIndex(); + if (i < 0) { + return qMakePair(-1, false); + } + // loop over the tabs starting from the current one + do { const auto tabPage = tabPageAt(i); - if (url == tabPage->primaryViewContainer()->url()) { + if (tabPage->primaryViewContainer()->url() == url || + (childUrlBehavior == ReturnIndexForOpenedParentAlso && tabPage->primaryViewContainer()->url().isParentOf(url))) { return qMakePair(i, true); } - if (tabPage->splitViewEnabled() && url == tabPage->secondaryViewContainer()->url()) { + if (tabPage->splitViewEnabled() && + (url == tabPage->secondaryViewContainer()->url() || + (childUrlBehavior == ReturnIndexForOpenedParentAlso && tabPage->secondaryViewContainer()->url().isParentOf(url)))) { return qMakePair(i, false); } + + i = (i + 1) % count(); } + while (i != currentIndex()); + return qMakePair(-1, false); }