From 78a3cd3e4bc75fc299a6b05b266bdd58fe7f8dcf Mon Sep 17 00:00:00 2001 From: Eugene Popov Date: Fri, 21 Apr 2023 15:15:31 +0300 Subject: Improve copying and moving items between panels Currently, copying the selected items between panels is performed by the active panel, which is wrong, because the inactive panel cannot select the copied items after the operation is completed (as it happens when drag'n'dropping or copying using keyboard shortcuts). --- src/dolphintabwidget.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/dolphintabwidget.cpp') diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index bb3680f58..9ee80160a 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -325,36 +325,44 @@ void DolphinTabWidget::restoreClosedTab(const QByteArray &state) void DolphinTabWidget::copyToInactiveSplitView() { - const DolphinTabPage *tabPage = tabPageAt(currentIndex()); - DolphinViewContainer *activeViewContainer = currentTabPage()->activeViewContainer(); - if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) { + const DolphinTabPage *tabPage = currentTabPage(); + if (!tabPage->splitViewEnabled()) { return; } + const KFileItemList selectedItems = tabPage->activeViewContainer()->view()->selectedItems(); + if (selectedItems.isEmpty()) { + return; + } + + DolphinView *inactiveView; if (tabPage->primaryViewActive()) { - // copy from left panel to right - activeViewContainer->view()->copySelectedItems(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url()); + inactiveView = tabPage->secondaryViewContainer()->view(); } else { - // copy from right panel to left - activeViewContainer->view()->copySelectedItems(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url()); + inactiveView = tabPage->primaryViewContainer()->view(); } + inactiveView->copySelectedItems(selectedItems, inactiveView->url()); } void DolphinTabWidget::moveToInactiveSplitView() { - const DolphinTabPage *tabPage = tabPageAt(currentIndex()); - DolphinViewContainer *activeViewContainer = currentTabPage()->activeViewContainer(); - if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) { + const DolphinTabPage *tabPage = currentTabPage(); + if (!tabPage->splitViewEnabled()) { + return; + } + + const KFileItemList selectedItems = tabPage->activeViewContainer()->view()->selectedItems(); + if (selectedItems.isEmpty()) { return; } + DolphinView *inactiveView; if (tabPage->primaryViewActive()) { - // move from left panel to right - activeViewContainer->view()->moveSelectedItems(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url()); + inactiveView = tabPage->secondaryViewContainer()->view(); } else { - // move from right panel to left - activeViewContainer->view()->moveSelectedItems(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url()); + inactiveView = tabPage->primaryViewContainer()->view(); } + inactiveView->moveSelectedItems(selectedItems, inactiveView->url()); } void DolphinTabWidget::detachTab(int index) -- cgit v1.3 From 215923b33f22396c5122d47192a8a933fd4290ae Mon Sep 17 00:00:00 2001 From: Eugene Popov Date: Sat, 22 Apr 2023 22:21:44 +0300 Subject: Add DolphinTabPage::inactiveViewContainer() --- src/dolphintabpage.cpp | 9 +++++++++ src/dolphintabpage.h | 6 ++++++ src/dolphintabwidget.cpp | 14 ++------------ 3 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src/dolphintabwidget.cpp') diff --git a/src/dolphintabpage.cpp b/src/dolphintabpage.cpp index c8da707df..2979cb568 100644 --- a/src/dolphintabpage.cpp +++ b/src/dolphintabpage.cpp @@ -164,6 +164,15 @@ DolphinViewContainer *DolphinTabPage::activeViewContainer() const return m_primaryViewActive ? m_primaryViewContainer : m_secondaryViewContainer; } +DolphinViewContainer *DolphinTabPage::inactiveViewContainer() const +{ + if (!splitViewEnabled()) { + return nullptr; + } + + return primaryViewActive() ? secondaryViewContainer() : primaryViewContainer(); +} + KFileItemList DolphinTabPage::selectedItems() const { KFileItemList items = m_primaryViewContainer->view()->selectedItems(); diff --git a/src/dolphintabpage.h b/src/dolphintabpage.h index 1c8ae094b..4e89d22ee 100644 --- a/src/dolphintabpage.h +++ b/src/dolphintabpage.h @@ -66,6 +66,12 @@ public: */ DolphinViewContainer *activeViewContainer() const; + /** + * @return DolphinViewContainer of the inactive view + * if split view is enabled, or nullptr otherwise. + */ + DolphinViewContainer *inactiveViewContainer() const; + /** * Returns the selected items. The list is empty if no item has been * selected. diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 9ee80160a..d4271847f 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -335,12 +335,7 @@ void DolphinTabWidget::copyToInactiveSplitView() return; } - DolphinView *inactiveView; - if (tabPage->primaryViewActive()) { - inactiveView = tabPage->secondaryViewContainer()->view(); - } else { - inactiveView = tabPage->primaryViewContainer()->view(); - } + DolphinView *const inactiveView = tabPage->inactiveViewContainer()->view(); inactiveView->copySelectedItems(selectedItems, inactiveView->url()); } @@ -356,12 +351,7 @@ void DolphinTabWidget::moveToInactiveSplitView() return; } - DolphinView *inactiveView; - if (tabPage->primaryViewActive()) { - inactiveView = tabPage->secondaryViewContainer()->view(); - } else { - inactiveView = tabPage->primaryViewContainer()->view(); - } + DolphinView *const inactiveView = tabPage->inactiveViewContainer()->view(); inactiveView->moveSelectedItems(selectedItems, inactiveView->url()); } -- cgit v1.3