X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a6403716439ae72bfdf86a14af94ea9d212f08ee..a291c5999035bb17fe764c1910c3e78ba041f8ac:/src/dolphintabwidget.cpp diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 7928c510e..9fd600567 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -25,9 +25,10 @@ #include "dolphinviewcontainer.h" #include -#include #include #include +#include +#include #include #include @@ -37,6 +38,8 @@ DolphinTabWidget::DolphinTabWidget(QWidget* parent) : m_placesSelectorVisible(true), m_lastViewedTab(0) { + KAcceleratorManager::setNoAccel(this); + connect(this, &DolphinTabWidget::tabCloseRequested, this, QOverload::of(&DolphinTabWidget::closeTab)); connect(this, &DolphinTabWidget::currentChanged, @@ -130,6 +133,11 @@ void DolphinTabWidget::refreshViews() } } +bool DolphinTabWidget::isUrlOpen(const QUrl &url) const +{ + return indexByUrl(url).first >= 0; +} + void DolphinTabWidget::openNewActivatedTab() { const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer(); @@ -161,6 +169,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU QWidget* focusWidget = QApplication::focusWidget(); DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this); + tabPage->setActive(false); tabPage->setPlacesSelectorVisible(m_placesSelectorVisible); connect(tabPage, &DolphinTabPage::activeViewChanged, this, &DolphinTabWidget::activeViewChanged); @@ -170,7 +179,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU if (tabPlacement == AfterCurrentTab) { newTabIndex = currentIndex() + 1; } - insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage)); + insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage)); if (focusWidget) { // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened @@ -186,15 +195,21 @@ void DolphinTabWidget::openDirectories(const QList& dirs, bool splitView) QList::const_iterator it = dirs.constBegin(); while (it != dirs.constEnd()) { const QUrl& primaryUrl = *(it++); - const QPair viewLocation = getIndexByUrl(primaryUrl); - if (viewLocation.first >= 0) { - setCurrentIndex(viewLocation.first); - const auto tabPage = tabPageAt(viewLocation.first); - if (viewLocation.second) { + const QPair indexInfo = indexByUrl(primaryUrl); + const int index = indexInfo.first; + const bool isInPrimaryView = indexInfo.second; + if (index >= 0) { + setCurrentIndex(index); + const auto tabPage = tabPageAt(index); + if (isInPrimaryView) { tabPage->primaryViewContainer()->setActive(true); } else { tabPage->secondaryViewContainer()->setActive(true); } + // BUG: 417230 + // Required for updateViewState() call in openFiles() to work as expected + // If there is a selection, updateViewState() calls are effectively a no-op + tabPage->activeViewContainer()->view()->clearSelection(); continue; } if (splitView && (it != dirs.constEnd())) { @@ -228,10 +243,14 @@ void DolphinTabWidget::openFiles(const QList& files, bool splitView) // Select the files. Although the files can be split between several // tabs, there is no need to split 'files' accordingly, as // the DolphinView will just ignore invalid selections. - for (int i = oldTabCount; i < tabCount; ++i) { + for (int i = 0; i < tabCount; ++i) { DolphinTabPage* tabPage = tabPageAt(i); tabPage->markUrlsAsSelected(files); tabPage->markUrlAsCurrent(files.first()); + if (i < oldTabCount) { + // Force selection of file if directory was already open, BUG: 417230 + tabPage->activeViewContainer()->view()->updateViewState(); + } } } @@ -258,6 +277,18 @@ void DolphinTabWidget::closeTab(const int index) tabPage->deleteLater(); } +void DolphinTabWidget::activateTab(const int index) +{ + if (index < count()) { + setCurrentIndex(index); + } +} + +void DolphinTabWidget::activateLastTab() +{ + setCurrentIndex(count() - 1); +} + void DolphinTabWidget::activateNextTab() { const int index = currentIndex() + 1; @@ -289,6 +320,40 @@ void DolphinTabWidget::restoreClosedTab(const QByteArray& state) currentTabPage()->restoreState(state); } +void DolphinTabWidget::copyToInactiveSplitView() +{ + const DolphinTabPage* tabPage = tabPageAt(currentIndex()); + DolphinViewContainer* activeViewContainer = currentTabPage()->activeViewContainer(); + if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) { + return; + } + + if (tabPage->primaryViewActive()) { + // copy from left panel to right + activeViewContainer->view()->copySelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url()); + } else { + // copy from right panel to left + activeViewContainer->view()->copySelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url()); + } +} + +void DolphinTabWidget::moveToInactiveSplitView() +{ + const DolphinTabPage* tabPage = tabPageAt(currentIndex()); + DolphinViewContainer* activeViewContainer = currentTabPage()->activeViewContainer(); + if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) { + return; + } + + if (tabPage->primaryViewActive()) { + // move from left panel to right + activeViewContainer->view()->moveSelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url()); + } else { + // move from right panel to left + activeViewContainer->view()->moveSelectedItemsToInactiveSplitView(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url()); + } +} + void DolphinTabWidget::detachTab(int index) { Q_ASSERT(index >= 0); @@ -303,8 +368,9 @@ void DolphinTabWidget::detachTab(int index) } args << QStringLiteral("--new-window"); - const QString command = QStringLiteral("dolphin %1").arg(KShell::joinArgs(args)); - KRun::runCommand(command, this); + KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob("dolphin", args, this); + job->setDesktopName(QStringLiteral("org.kde.dolphin")); + job->start(); closeTab(index); } @@ -329,7 +395,12 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url) const int index = indexOf(qobject_cast(sender())); if (index >= 0) { tabBar()->setTabText(index, tabName(tabPageAt(index))); - tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); + if (tabBar()->isVisible()) { + tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); + } else { + // Mark as dirty, actually load once the tab bar actually gets shown + tabBar()->setTabIcon(index, QIcon()); + } // Emit the currentUrlChanged signal if the url of the current tab has been changed. if (index == currentIndex()) { @@ -357,6 +428,13 @@ void DolphinTabWidget::tabInserted(int index) QTabWidget::tabInserted(index); if (count() > 1) { + // Resolve all pending tab icons + for (int i = 0; i < count(); ++i) { + if (tabBar()->tabIcon(i).isNull()) { + tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(tabPageAt(i)->activeViewContainer()->url()))); + } + } + tabBar()->show(); } @@ -387,7 +465,7 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const return name.replace('&', QLatin1String("&&")); } -QPair DolphinTabWidget::getIndexByUrl(const QUrl& url) const +QPair DolphinTabWidget::indexByUrl(const QUrl& url) const { for (int i = 0; i < count(); i++) { const auto tabPage = tabPageAt(i);