m_actionHandler = new DolphinViewActionHandler(actionCollection(), m_actionTextHelper, 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);
+ connect(m_actionHandler, &DolphinViewActionHandler::selectionModeChangeTriggered, this, &DolphinMainWindow::slotSetSelectionMode);
m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
connect(this, &DolphinMainWindow::urlChanged,
void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionMode::BottomBar::Contents bottomBarContents)
{
const bool wasEnabled = m_view->selectionMode();
- m_view->setSelectionMode(enabled);
+ m_view->setSelectionModeEnabled(enabled);
if (!enabled) {
Q_CHECK_PTR(m_selectionModeTopBar); // there is no point in disabling selectionMode when it wasn't even enabled once.
});
m_selectionModeTopBar = new SelectionMode::TopBar(this); // will be created hidden
- connect(m_selectionModeTopBar, &SelectionMode::TopBar::leaveSelectionModeRequested, this, [this]() {
+ connect(m_selectionModeTopBar, &SelectionMode::TopBar::selectionModeLeavingRequested, this, [this]() {
setSelectionModeEnabled(false);
});
m_topLayout->addWidget(m_selectionModeTopBar, positionFor.selectionModeTopBar, 0);
connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, [this](const QString &errorMessage) {
showErrorMessage(errorMessage);
});
- connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::leaveSelectionModeRequested, this, [this]() {
+ connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::selectionModeLeavingRequested, this, [this]() {
setSelectionModeEnabled(false);
});
m_topLayout->addWidget(m_selectionModeBottomBar, positionFor.selectionModeBottomBar, 0);
*/
void disconnectUrlNavigator();
+ /**
+ * Sets a selection mode that is useful for quick and easy selecting or deselecting of files.
+ * This method is the central authority about enabling or disabling selection mode:
+ * All other classes that want to enable or disable selection mode should trigger a call of this method.
+ *
+ * This method sets the selection mode for the view of this viewContainer and sets the visibility of the
+ * selection mode top and bottom bar which also belong to this viewContainer.
+ *
+ * @param enabled Whether to enable or disable selection mode.
+ * @param actionCollection The collection of actions from which the actions on the bottom bar are retrieved.
+ * @param bottomBarContents The contents the bar is supposed to show after this call.
+ */
void setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection = nullptr, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents);
+ /** @see setSelectionModeEnabled() */
bool isSelectionModeEnabled() const;
/**
m_longPressDetectionTimer->setInterval(QGuiApplication::styleHints()->mousePressAndHoldInterval());
connect(m_longPressDetectionTimer, &QTimer::timeout, this, [this]() {
if (!m_selectionMode) {
- Q_EMIT selectionModeRequested();
+ Q_EMIT selectionModeChangeRequested(true);
}
});
return m_singleClickActivationEnforced;
}
-void KItemListController::setSelectionMode(bool enabled)
+void KItemListController::setSelectionModeEnabled(bool enabled)
{
m_selectionMode = enabled;
}
}
case Qt::Key_Escape:
+ if (m_selectionMode && m_selectionManager->selectedItems().count() < 1) {
+ Q_EMIT selectionModeChangeRequested(false);
+ }
if (m_selectionBehavior != SingleSelection) {
m_selectionManager->clearSelection();
}
void setSingleClickActivationEnforced(bool singleClick);
bool singleClickActivationEnforced() const;
- void setSelectionMode(bool enabled);
+ /**
+ * Setting the selection mode to enabled will make selecting and deselecting easier by acting
+ * kind of similar to when the Control Key is held down.
+ */
+ void setSelectionModeEnabled(bool enabled);
bool selectionMode() const;
bool processEvent(QEvent* event, const QTransform& transform);
void escapePressed();
/**
- * Is emitted if left click is pressed down for a long time without moving the cursor too much.
+ * Used to request either entering or leaving of selection mode
+ * Leaving is requested by pressing Escape when no item is selected.
+ *
+ * Entering is requested if left click is pressed down for a long time without moving the cursor too much.
* Moving the cursor would either trigger an item drag if the click was initiated on top of an item
* or a selection rectangle if the click was not initiated on top of an item.
* So long press is only emitted if there wasn't a lot of cursor movement.
*/
- void selectionModeRequested();
+ void selectionModeChangeRequested(bool enabled);
void modelChanged(KItemModelBase* current, KItemModelBase* previous);
void viewChanged(KItemListView* current, KItemListView* previous);
}
setVisibleInternal(visible, WithAnimation);
});
- connect(m_contentsContainer, &BottomBarContentsContainer::leaveSelectionModeRequested, this, &BottomBar::leaveSelectionModeRequested);
+ connect(m_contentsContainer, &BottomBarContentsContainer::selectionModeLeavingRequested, this, &BottomBar::selectionModeLeavingRequested);
BackgroundColorHelper::instance()->controlBackgroundColor(this);
}
switch (contents()) {
case CopyToOtherViewContents:
case MoveToOtherViewContents:
- Q_EMIT leaveSelectionModeRequested();
+ Q_EMIT selectionModeLeavingRequested();
default:
return;
}
*/
void error(const QString &errorMessage);
- void leaveSelectionModeRequested();
+ void selectionModeLeavingRequested();
protected:
/** Is installed on an internal widget to make sure that the height of the bar is adjusted to its contents. */
// i18n: Aborts the current step-by-step process to copy files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Copying"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *copyButton = new QPushButton(this);
resetContents(BottomBar::Contents::PasteContents); // resetContents() needs to be connected last because
// it instantly deletes the button and then the other slots won't be called.
}
- Q_EMIT leaveSelectionModeRequested();
+ Q_EMIT selectionModeLeavingRequested();
});
updateMainActionButton(KFileItemList());
m_layout->addWidget(copyButton);
// i18n: Aborts the current step-by-step process to copy the location of files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Copying"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *copyLocationButton = new QPushButton(this);
// i18n: Aborts the current step-by-step process to copy the location of files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Copying"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *copyToOtherViewButton = new QPushButton(this);
// i18n: Aborts the current step-by-step process to cut files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Cutting"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *cutButton = new QPushButton(this);
resetContents(BottomBar::Contents::PasteContents); // resetContents() needs to be connected last because
// it instantly deletes the button and then the other slots won't be called.
}
- Q_EMIT leaveSelectionModeRequested();
+ Q_EMIT selectionModeLeavingRequested();
});
updateMainActionButton(KFileItemList());
m_layout->addWidget(cutButton);
// i18n: Aborts the current step-by-step process to delete files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *deleteButton = new QPushButton(this);
// i18n: Aborts the current step-by-step process to duplicate files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Duplicating"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *duplicateButton = new QPushButton(this);
// i18n: Aborts the current step-by-step process to copy the location of files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Moving"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *moveToOtherViewButton = new QPushButton(this);
// i18n: Aborts the current step-by-step process of moving files to the trash by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *moveToTrashButton = new QPushButton(this);
* So we first have to claim that we have different contents before requesting to leave selection mode. */
auto actuallyLeaveSelectionMode = [this]() {
m_contents = BottomBar::Contents::CopyLocationContents;
- Q_EMIT leaveSelectionModeRequested();
+ Q_EMIT selectionModeLeavingRequested();
};
auto *pasteButton = new QPushButton(this);
// i18n: Aborts the current step-by-step process to delete files by leaving the selection mode.
auto *cancelButton = new QPushButton(i18nc("@action:button", "Stop Renaming"), this);
- connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+ connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
m_layout->addWidget(cancelButton);
auto *renameButton = new QPushButton(this);
*/
void barVisibilityChangeRequested(bool visible);
- void leaveSelectionModeRequested();
+ void selectionModeLeavingRequested();
private:
void addCopyContents();
m_closeButton->setAccessibleName(m_closeButton->toolTip());
m_closeButton->setFlat(true);
connect(m_closeButton, &QAbstractButton::pressed,
- this, &TopBar::leaveSelectionModeRequested);
+ this, &TopBar::selectionModeLeavingRequested);
QHBoxLayout *layout = new QHBoxLayout(contentsContainer);
auto contentsMargins = layout->contentsMargins();
void setVisible(bool visible, Animated animated);
Q_SIGNALS:
- void leaveSelectionModeRequested();
+ void selectionModeLeavingRequested();
protected:
/** Calls updateLabelString() */
connect(controller, &KItemListController::increaseZoom, this, &DolphinView::slotIncreaseZoom);
connect(controller, &KItemListController::decreaseZoom, this, &DolphinView::slotDecreaseZoom);
connect(controller, &KItemListController::swipeUp, this, &DolphinView::slotSwipeUp);
- connect(controller, &KItemListController::selectionModeRequested, this, &DolphinView::selectionModeRequested);
+ connect(controller, &KItemListController::selectionModeChangeRequested, this, &DolphinView::selectionModeChangeRequested);
connect(m_model, &KFileItemModel::directoryLoadingStarted, this, &DolphinView::slotDirectoryLoadingStarted);
connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted);
return m_mode;
}
-void DolphinView::setSelectionMode(const bool enabled)
+void DolphinView::setSelectionModeEnabled(const bool enabled)
{
if (enabled) {
m_proxyStyle = std::make_unique<SelectionMode::SingleClickSelectionProxyStyle>();
setStyle(QApplication::style());
m_view->setStyle(QApplication::style());
}
- m_container->controller()->setSelectionMode(enabled);
+ m_container->controller()->setSelectionModeEnabled(enabled);
}
bool DolphinView::selectionMode() const
/**
* Enables or disables a mode for quick and easy selection of items.
*/
- void setSelectionMode(bool enabled);
+ void setSelectionModeEnabled(bool enabled);
bool selectionMode() const;
/**
void goForwardRequested();
/**
- * Is emitted when the selection mode is requested for the current view.
- * This typically happens on press and hold.
- * @see KItemListController::longPress()
+ * Used to request either entering or leaving of selection mode
+ * Entering is typically requested on press and hold.
+ * Leaving by pressing Escape when no item is selected.
*/
- void selectionModeRequested();
+ void selectionModeChangeRequested(bool enabled);
/**
* Is emitted when the user wants to move the focus to another view.
this, &DolphinViewActionHandler::slotZoomLevelChanged);
connect(view, &DolphinView::writeStateChanged,
this, &DolphinViewActionHandler::slotWriteStateChanged);
- connect(view, &DolphinView::selectionModeRequested,
- this, [this]() { Q_EMIT setSelectionMode(true); });
+ connect(view, &DolphinView::selectionModeChangeRequested,
+ this, [this](bool enabled) { Q_EMIT selectionModeChangeTriggered(enabled); });
connect(view, &DolphinView::selectionChanged,
this, &DolphinViewActionHandler::slotSelectionChanged);
slotSelectionChanged(m_currentView->selectedItems());
void DolphinViewActionHandler::slotRename()
{
if (m_currentView->selectedItemsCount() == 0) {
- Q_EMIT setSelectionMode(true, SelectionMode::BottomBar::Contents::RenameContents);
+ Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::RenameContents);
} else {
Q_EMIT actionBeingHandled();
m_currentView->renameSelectedItems();
void DolphinViewActionHandler::slotTrashActivated()
{
if (m_currentView->selectedItemsCount() == 0) {
- Q_EMIT setSelectionMode(true, SelectionMode::BottomBar::Contents::MoveToTrashContents);
+ Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::MoveToTrashContents);
} else {
Q_EMIT actionBeingHandled();
m_currentView->trashSelectedItems();
- Q_EMIT setSelectionMode(false);
+ Q_EMIT selectionModeChangeTriggered(false);
}
}
void DolphinViewActionHandler::slotDeleteItems()
{
if (m_currentView->selectedItemsCount() == 0) {
- Q_EMIT setSelectionMode(true, SelectionMode::BottomBar::Contents::DeleteContents);
+ Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::DeleteContents);
} else {
Q_EMIT actionBeingHandled();
m_currentView->deleteSelectedItems();
- Q_EMIT setSelectionMode(false);
+ Q_EMIT selectionModeChangeTriggered(false);
}
}
void DolphinViewActionHandler::slotDuplicate()
{
if (m_currentView->selectedItemsCount() == 0) {
- Q_EMIT setSelectionMode(true, SelectionMode::BottomBar::Contents::DuplicateContents);
+ Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::DuplicateContents);
} else {
Q_EMIT actionBeingHandled();
m_currentView->duplicateSelectedItems();
- Q_EMIT setSelectionMode(false);
+ Q_EMIT selectionModeChangeTriggered(false);
}
}
void DolphinViewActionHandler::slotCopyPath()
{
if (m_currentView->selectedItemsCount() == 0) {
- Q_EMIT setSelectionMode(true, SelectionMode::BottomBar::Contents::CopyLocationContents);
+ Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::CopyLocationContents);
} else {
m_currentView->copyPathToClipboard();
- Q_EMIT setSelectionMode(false);
+ Q_EMIT selectionModeChangeTriggered(false);
}
}
*/
void createDirectoryTriggered();
- /** Used to request selection mode */
- void setSelectionMode(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents);
+ /** Used to request either entering or leaving of selection mode */
+ void selectionModeChangeTriggered(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents);
private Q_SLOTS:
/**