Commit 3b7c05b3 authored by Felix Ernst's avatar Felix Ernst 🇺🇦
Browse files

Add Selection Mode

The selection mode action is a checkable toggle action named
"Select Files and Folders" which has "Space" as the default
shortcut.

In selection mode a bottom bar with contextual actions is shown.
These should mostly mirror the actions which are available through
the right-click context menu aka DolphinContextMenu.

Resizing of the window might make a overflow button appear in the
bottom selection mode bar.

This commit makes press and hold in the view activate selection
mode. This behaviour is not triggered if the press and hold is
used to either start a rubberband selection or a drag operation
within a short time. The length of the short timeframe is defined
by a QStyleHint. This is currently not implemented in touch
because I can't test it.

Mix the selection mode bars' background colors using a nice
combination of colors from the current color scheme

BUG: 427202
parent 9dbe4813
......@@ -209,6 +209,7 @@ target_sources(dolphinstatic PRIVATE
dolphinurlnavigatorscontroller.cpp
trash/dolphintrash.cpp
filterbar/filterbar.cpp
kitemviews/kfileitemlisttostring.cpp
panels/places/placespanel.cpp
panels/panel.cpp
panels/folders/foldersitemlistwidget.cpp
......@@ -218,6 +219,10 @@ target_sources(dolphinstatic PRIVATE
search/dolphinfacetswidget.cpp
search/dolphinquery.cpp
search/dolphinsearchbox.cpp
selectionmode/actionwithwidget.cpp
selectionmode/backgroundcolorhelper.cpp
selectionmode/selectionmodebottombar.cpp
selectionmode/selectionmodetopbar.cpp
settings/general/behaviorsettingspage.cpp
settings/general/configurepreviewplugindialog.cpp
settings/general/confirmationssettingspage.cpp
......
......@@ -83,6 +83,8 @@
#include <QToolButton>
#include <QWhatsThisClickedEvent>
#include <iostream>
namespace {
// Used for GeneralSettings::version() to determine whether
// an updated version of Dolphin is running, so as to migrate
......@@ -124,7 +126,7 @@ DolphinMainWindow::DolphinMainWindow() :
setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
setObjectName(QStringLiteral("Dolphin#"));
setStateConfigGroup("State");
//setStateConfigGroup("State"); // TODO: Don't leave this as a comment.
connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage,
this, &DolphinMainWindow::showErrorMessage);
......@@ -165,6 +167,7 @@ DolphinMainWindow::DolphinMainWindow() :
m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar);
connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
connect(m_actionHandler, &DolphinViewActionHandler::setSelectionMode, this, &DolphinMainWindow::slotSetSelectionMode);
m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
connect(this, &DolphinMainWindow::urlChanged,
......@@ -192,6 +195,7 @@ DolphinMainWindow::DolphinMainWindow() :
auto hamburgerMenu = static_cast<KHamburgerMenu *>(actionCollection()->action(
KStandardAction::name(KStandardAction::HamburgerMenu)));
hamburgerMenu->icon();
hamburgerMenu->setMenuBar(menuBar());
hamburgerMenu->setShowMenuBarAction(showMenuBarAction);
connect(hamburgerMenu, &KHamburgerMenu::aboutToShowMenu,
......@@ -713,12 +717,22 @@ void DolphinMainWindow::undo()
void DolphinMainWindow::cut()
{
m_activeViewContainer->view()->cutSelectedItemsToClipboard();
if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CutContents);
} else {
m_activeViewContainer->view()->cutSelectedItemsToClipboard();
m_activeViewContainer->setSelectionModeEnabled(false);
}
}
void DolphinMainWindow::copy()
{
m_activeViewContainer->view()->copySelectedItemsToClipboard();
if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyContents);
} else {
m_activeViewContainer->view()->copySelectedItemsToClipboard();
m_activeViewContainer->setSelectionModeEnabled(false);
}
}
void DolphinMainWindow::paste()
......@@ -845,6 +859,11 @@ void DolphinMainWindow::slotGoForward(QAction* action)
}
}
void DolphinMainWindow::slotSetSelectionMode(bool enabled, SelectionModeBottomBar::Contents bottomBarContents)
{
m_activeViewContainer->setSelectionModeEnabled(enabled, actionCollection(), bottomBarContents);
}
void DolphinMainWindow::selectAll()
{
clearStatusBar();
......@@ -884,6 +903,26 @@ void DolphinMainWindow::toggleSplitStash()
tabPage->setSplitViewEnabled(true, WithAnimation, QUrl("stash:/"));
}
void DolphinMainWindow::copyToInactiveSplitView()
{
if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyToOtherViewContents);
} else {
m_tabWidget->copyToInactiveSplitView();
m_activeViewContainer->setSelectionModeEnabled(false);
}
}
void DolphinMainWindow::moveToInactiveSplitView()
{
if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::MoveToOtherViewContents);
} else {
m_tabWidget->moveToInactiveSplitView();
m_activeViewContainer->setSelectionModeEnabled(false);
}
}
void DolphinMainWindow::reloadView()
{
clearStatusBar();
......@@ -906,6 +945,14 @@ void DolphinMainWindow::disableStopAction()
actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
}
void DolphinMainWindow::toggleSelectionMode()
{
const bool checked = !m_activeViewContainer->isSelectionModeEnabled();
m_activeViewContainer->setSelectionModeEnabled(checked, actionCollection(), SelectionModeBottomBar::Contents::GeneralContents);
actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked);
}
void DolphinMainWindow::showFilterBar()
{
m_activeViewContainer->setFilterBarVisible(true);
......@@ -1283,6 +1330,11 @@ void DolphinMainWindow::updateHamburgerMenu()
menu->addAction(ac->action(QStringLiteral("go_forward")));
menu->addMenu(m_newFileMenu->menu());
if (!toolBar()->isVisible()
|| !toolbarActions.contains(ac->action(QStringLiteral("toggle_selection_mode_with_popup")))
) {
menu->addAction(ac->action(QStringLiteral("toggle_selection_mode")));
}
menu->addAction(ac->action(QStringLiteral("basic_actions")));
menu->addAction(ac->action(KStandardAction::name(KStandardAction::Undo)));
if (!toolBar()->isVisible()
......@@ -1562,7 +1614,7 @@ void DolphinMainWindow::setupActions()
copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5 );
connect(copyToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::copyToInactiveSplitView);
connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
......@@ -1571,7 +1623,7 @@ void DolphinMainWindow::setupActions()
moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6 );
connect(moveToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::moveToInactiveSplitView);
connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter..."));
......@@ -1617,6 +1669,33 @@ void DolphinMainWindow::setupActions()
toggleSearchAction->setWhatsThis(searchAction->whatsThis());
toggleSearchAction->setCheckable(true);
QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
// i18n: This action toggles a selection mode.
toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders"));
// i18n: Opens a selection mode for selecting files/folders and later selecting an action that acts on them.
// So in a way "Select" here is used to mean both "Select files" and also "Select what to do" but mostly the first.
// The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select"));
toggleSelectionModeAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application doesn't know which files or folders should be acted on, "
"unless they are <emphasis>selected</emphasis> first. Press this to toggle the <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as "
"easy as pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows all the available actions for the current "
"selection of items.</para>"));
toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
toggleSelectionModeAction->setCheckable(true);
actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space );
connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
// A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
// with the selectAllAction and invertSelectionAction.
auto *toggleSelectionModeToolBarAction = new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection());
toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text());
toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis());
actionCollection()->addAction(QStringLiteral("toggle_selection_mode_with_popup"), toggleSelectionModeToolBarAction);
toggleSelectionModeToolBarAction->setCheckable(true);
toggleSelectionModeToolBarAction->setPopupMode(QToolButton::DelayedPopup);
connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger);
connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked);
QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
"files and folders in the current location."));
......@@ -1629,6 +1708,11 @@ void DolphinMainWindow::setupActions()
actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
QMenu *toggleSelectionModeActionMenu = new QMenu(this);
toggleSelectionModeActionMenu->addAction(selectAllAction);
toggleSelectionModeActionMenu->addAction(invertSelection);
toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu);
// setup 'View' menu
// (note that most of it is set up in DolphinViewActionHandler)
......@@ -2143,6 +2227,11 @@ void DolphinMainWindow::updateFileAndEditActions()
const KActionCollection* col = actionCollection();
KFileItemListProperties capabilitiesSource(list);
QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
......@@ -2151,20 +2240,19 @@ void DolphinMainWindow::updateFileAndEditActions()
if (list.isEmpty()) {
stateChanged(QStringLiteral("has_no_selection"));
// All actions that need a selection to function can be enabled because they should trigger selection mode.
renameAction->setEnabled(true);
moveToTrashAction->setEnabled(true);
deleteAction->setEnabled(true);
cutAction->setEnabled(true);
duplicateAction->setEnabled(true);
addToPlacesAction->setEnabled(true);
copyToOtherViewAction->setEnabled(false);
moveToOtherViewAction->setEnabled(false);
copyLocation->setEnabled(false);
copyLocation->setEnabled(true);
} else {
stateChanged(QStringLiteral("has_selection"));
QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
QAction* showTarget = col->action(QStringLiteral("show_target"));
QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
if (list.length() == 1 && list.first().isDir()) {
addToPlacesAction->setEnabled(true);
......@@ -2172,23 +2260,6 @@ void DolphinMainWindow::updateFileAndEditActions()
addToPlacesAction->setEnabled(false);
}
if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
KFileItem capabilitiesDestination;
if (tabPage->primaryViewActive()) {
capabilitiesDestination = tabPage->secondaryViewContainer()->url();
} else {
capabilitiesDestination = tabPage->primaryViewContainer()->url();
}
copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving() && capabilitiesDestination.isWritable());
} else {
copyToOtherViewAction->setEnabled(false);
moveToOtherViewAction->setEnabled(false);
}
const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
renameAction->setEnabled(capabilitiesSource.supportsMoving());
......@@ -2200,12 +2271,36 @@ void DolphinMainWindow::updateFileAndEditActions()
showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
}
if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
KFileItem capabilitiesDestination;
if (tabPage->primaryViewActive()) {
capabilitiesDestination = tabPage->secondaryViewContainer()->url();
} else {
capabilitiesDestination = tabPage->primaryViewContainer()->url();
}
copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable());
} else {
copyToOtherViewAction->setEnabled(false);
moveToOtherViewAction->setEnabled(false);
}
}
void DolphinMainWindow::updateViewActions()
{
m_actionHandler->updateViewActions();
QAction *toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode"));
disconnect(nullptr, &DolphinViewContainer::selectionModeChanged,
toggleSelectionModeAction, &QAction::setChecked);
toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled());
connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged,
toggleSelectionModeAction, &QAction::setChecked);
QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
......
......@@ -10,6 +10,7 @@
#define DOLPHIN_MAINWINDOW_H
#include "dolphintabwidget.h"
#include "selectionmode/selectionmodebottombar.h"
#include "config-dolphin.h"
#include <KFileItemActions>
#include <kio/fileundomanager.h>
......@@ -313,6 +314,9 @@ private Q_SLOTS:
*/
void updatePasteAction();
/** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
void slotSetSelectionMode(bool enabled, SelectionModeBottomBar::Contents bottomBarContents);
/** Selects all items from the active view. */
void selectAll();
......@@ -333,6 +337,12 @@ private Q_SLOTS:
/** Dedicated action to open the stash:/ ioslave in split view. */
void toggleSplitStash();
/** Copies all selected items to the inactive view. */
void copyToInactiveSplitView();
/** Moves all selected items to the inactive view. */
void moveToInactiveSplitView();
/** Reloads the currently active view. */
void reloadView();
......@@ -342,6 +352,8 @@ private Q_SLOTS:
void enableStopAction();
void disableStopAction();
void toggleSelectionMode();
void showFilterBar();
void toggleFilterBar();
......
......@@ -9,7 +9,6 @@
#include "dolphin_generalsettings.h"
#include "dolphinviewcontainer.h"
#include "global.h"
#include <QVariantAnimation>
#include <QGridLayout>
......@@ -152,6 +151,8 @@ void DolphinTabPage::setSplitViewEnabled(bool enabled, Animated animated, const
view->setDisabled(true);
startExpandViewAnimation(m_primaryViewContainer);
}
m_primaryViewContainer->slotSplitTabDisabled();
}
}
}
......
......@@ -8,6 +8,8 @@
#ifndef DOLPHIN_TAB_PAGE_H
#define DOLPHIN_TAB_PAGE_H
#include "global.h"
#include <QPointer>
#include <QUrl>
#include <QWidget>
......@@ -19,11 +21,6 @@ class QVariantAnimation;
class KFileItemList;
class DolphinTabPageSplitter;
enum Animated {
WithAnimation,
WithoutAnimation
};
class DolphinTabPage : public QWidget
{
Q_OBJECT
......
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="dolphin" version="36">
<gui name="dolphin" version="38">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
......@@ -31,6 +31,7 @@
<Action name="show_filter_bar" />
<Action name="edit_find" />
<Separator />
<Action name="toggle_selection_mode" />
<Action name="copy_to_inactive_split_view" />
<Action name="move_to_inactive_split_view" />
<Action name="edit_select_all" />
......@@ -80,7 +81,6 @@
<Action name="edit_undo" />
<Action name="edit_redo" />
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="renamefile" />
<Action name="movetotrash" />
<Action name="deletefile" />
......@@ -92,23 +92,11 @@
</State>
<State name="has_selection" >
<enable>
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="renamefile" />
<Action name="duplicate" />
<Action name="movetotrash" />
<Action name="deletefile" />
<Action name="invert_selection" />
</enable>
</State>
<State name="has_no_selection" >
<disable>
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="renamefile" />
<Action name="duplicate" />
<Action name="movetotrash" />
<Action name="deletefile" />
<Action name="delete_shortcut" />
<Action name="invert_selection" />
</disable>
......@@ -125,6 +113,7 @@
<Action name="split_view" />
<Action name="split_stash" />
<Action name="toggle_search" />
<Action name="toggle_selection_mode_with_popup" />
<Action name="hamburger_menu" />
</ToolBar>
<ActionProperties scheme="Default">
......
......@@ -12,11 +12,13 @@
#include "filterbar/filterbar.h"
#include "global.h"
#include "search/dolphinsearchbox.h"
#include "selectionmode/selectionmodetopbar.h"
#include "statusbar/dolphinstatusbar.h"
#include "views/viewmodecontroller.h"
#include "views/viewproperties.h"
#include "dolphin_detailsmodesettings.h"
#include <KActionCollection>
#if HAVE_KACTIVITIES
#include <KActivities/ResourceInstance>
#endif
......@@ -32,14 +34,28 @@
#include <KUrlComboBox>
#include <QDropEvent>
#include <QGridLayout>
#include <QGuiApplication>
#include <QLoggingCategory>
#include <QMimeData>
#include <QTimer>
#include <QUrl>
#include <QVBoxLayout>
#include <QDesktopServices>
#include <iostream>
// An overview of the widgets contained by this ViewContainer
struct LayoutStructure {
int searchBox = 0;
int messageWidget = 1;
int selectionModeTopBar = 2;
int view = 3;
int selectionModeBottomBar = 4;
int filterBar = 5;
int statusBar = 6;
};
constexpr LayoutStructure positionFor;
DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
QWidget(parent),
m_topLayout(nullptr),
......@@ -48,8 +64,10 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
m_searchBox(nullptr),
m_searchModeEnabled(false),
m_messageWidget(nullptr),
m_selectionModeTopBar{nullptr},
m_view(nullptr),
m_filterBar(nullptr),
m_selectionModeBottomBar{nullptr},
m_statusBar(nullptr),
m_statusBarTimer(nullptr),
m_statusBarTimestamp(),
......@@ -60,7 +78,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
{
hide();
m_topLayout = new QVBoxLayout(this);
m_topLayout = new QGridLayout(this);
m_topLayout->setSpacing(0);
m_topLayout->setContentsMargins(0, 0, 0, 0);
......@@ -187,16 +205,16 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished,
this, &DolphinViewContainer::delayedStatusBarUpdate);
m_topLayout->addWidget(m_searchBox);
m_topLayout->addWidget(m_messageWidget);
m_topLayout->addWidget(m_view);
m_topLayout->addWidget(m_filterBar);
m_topLayout->addWidget(m_statusBar);
m_topLayout->addWidget(m_searchBox, positionFor.searchBox, 0);
m_topLayout->addWidget(m_messageWidget, positionFor.messageWidget, 0);
m_topLayout->addWidget(m_view, positionFor.view, 0);
m_topLayout->addWidget(m_filterBar, positionFor.filterBar, 0);
m_topLayout->addWidget(m_statusBar, positionFor.statusBar, 0);
setSearchModeEnabled(isSearchUrl(url));
connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged, this, [=]() {
if (view()->mode() == DolphinView::Mode::DetailsView) {
if (view()->viewMode() == DolphinView::Mode::DetailsView) {
view()->reload();
}
});
......@@ -357,6 +375,78 @@ void DolphinViewContainer::disconnectUrlNavigator()
m_urlNavigatorConnected = nullptr;
}
void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionModeBottomBar::Contents bottomBarContents)
{
std::cout << "DolphinViewContainer::setSelectionModeEnabled(" << enabled << ", " << bottomBarContents << ")\n";
const bool wasEnabled = m_view->selectionMode();
m_view->setSelectionMode(enabled);
if (!enabled) {
Q_CHECK_PTR(m_selectionModeTopBar); // there is no point in disabling selectionMode when it wasn't even enabled once.
Q_CHECK_PTR(m_selectionModeBottomBar);
m_selectionModeTopBar->setVisible(false, WithAnimation);
m_selectionModeBottomBar->setVisible(false, WithAnimation);
if (wasEnabled) {
Q_EMIT selectionModeChanged(false);
}
return;
}
if (!m_selectionModeTopBar) {
// Changing the location will disable selection mode.
connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlChanged, this, [this]() {
setSelectionModeEnabled(false);
});
m_selectionModeTopBar = new SelectionModeTopBar(this); // will be created hidden
connect(m_selectionModeTopBar, &SelectionModeTopBar::leaveSelectionModeRequested, this, [this]() {
setSelectionModeEnabled(false);
});
m_topLayout->addWidget(m_selectionModeTopBar, positionFor.selectionModeTopBar, 0);
}
if (!m_selectionModeBottomBar) {
m_selectionModeBottomBar = new SelectionModeBottomBar(actionCollection, this);
connect(m_view, &DolphinView::selectionChanged, this, [this](const KFileItemList &selection) {
m_selectionModeBottomBar->slotSelectionChanged(selection, m_view->url());
});
connect(m_selectionModeBottomBar, &SelectionModeBottomBar::error, this, [this](const QString &errorMessage) {
showErrorMessage(errorMessage);
});
connect(m_selectionModeBottomBar, &SelectionModeBottomBar::leaveSelectionModeRequested, this, [this]() {
setSelectionModeEnabled(false);
});
m_topLayout->addWidget(m_selectionModeBottomBar, positionFor.selectionModeBottomBar, 0);
}
m_selectionModeBottomBar->resetContents(bottomBarContents);
if (bottomBarContents == SelectionModeBottomBar::GeneralContents) {
m_selectionModeBottomBar->slotSelectionChanged(m_view->selectedItems(), m_view->url());
}
if (!wasEnabled) {
m_selectionModeTopBar->setVisible(true, WithAnimation);
m_selectionModeBottomBar->setVisible(true, WithAnimation);
Q_EMIT selectionModeChanged(true);
}
}
bool DolphinViewContainer::isSelectionModeEnabled() const
{
const bool isEnabled = m_view->selectionMode();
Q_ASSERT( !isEnabled // We cannot assert the invisibility of the bars because of the hide animation.
|| ( isEnabled && m_selectionModeTopBar && m_selectionModeTopBar->isVisible() && m_selectionModeBottomBar && m_selectionModeBottomBar->isVisible()));
return isEnabled;
}
void DolphinViewContainer::slotSplitTabDisabled()
{
if (m_selectionModeBottomBar) {
m_selectionModeBottomBar->slotSplitTabDisabled();
}
}
void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
{
if (msg.isEmpty()) {
......
......@@ -9,6 +9,7 @@
#include "config-dolphin.h"
#include "dolphinurlnavigator.h"
#include "selectionmode/selectionmodebottombar.h"
#include "views/dolphinview.h"
#include <KFileItem>
......@@ -27,9 +28,12 @@ namespace KActivities {
class FilterBar;
class KMessageWidget;