┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Florea Bănuș <[email protected]>2024-05-08 08:11:56 +0000
committerMéven Car <[email protected]>2024-05-08 08:11:56 +0000
commit65d7ef184acf97e7881050df88ddace97bde4b93 (patch)
tree867a15204eca1e88420e7e707389936ac0bed3c7 /src
parentd42fec2315f4b32f7dbc74a00155f7e6abff7738 (diff)
view: Add setting to trigger user set action with double click
Default action is select-all.
Diffstat (limited to 'src')
-rw-r--r--src/dolphinmainwindow.cpp37
-rw-r--r--src/dolphinmainwindow.h11
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp5
-rw-r--r--src/kitemviews/kitemlistcontroller.h6
-rw-r--r--src/settings/dolphin_generalsettings.kcfg7
-rw-r--r--src/settings/viewmodes/generalviewsettingspage.cpp105
-rw-r--r--src/settings/viewmodes/generalviewsettingspage.h6
-rw-r--r--src/views/dolphinview.cpp1
-rw-r--r--src/views/dolphinview.h6
9 files changed, 184 insertions, 0 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 05fbb41b2..10dc9375d 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -40,6 +40,7 @@
#include <KColorSchemeManager>
#include <KConfig>
#include <KConfigGui>
+#include <KDialogJobUiDelegate>
#include <KDualAction>
#include <KFileItemListProperties>
#include <KIO/CommandLauncherJob>
@@ -81,6 +82,7 @@
#include <QTimer>
#include <QToolButton>
#include <QtConcurrentRun>
+#include <dolphindebug.h>
#include <algorithm>
@@ -2586,6 +2588,7 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container)
connect(view, &DolphinView::goForwardRequested, this, &DolphinMainWindow::goForward);
connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl);
connect(view, &DolphinView::goUpRequested, this, &DolphinMainWindow::goUp);
+ connect(view, &DolphinView::doubleClickViewBackground, this, &DolphinMainWindow::slotDoubleClickViewBackground);
connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged, this, &DolphinMainWindow::changeUrl);
connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged, this, &DolphinMainWindow::updateHistory);
@@ -2902,4 +2905,38 @@ bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem)
return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
}
+void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button)
+{
+ Q_UNUSED(button) // might be of use later
+
+ GeneralSettings *settings = GeneralSettings::self();
+ QString clickAction = settings->doubleClickViewAction();
+
+ DolphinView *view = activeViewContainer()->view();
+ if (view == nullptr || clickAction == "none") {
+ return;
+ }
+
+ if (clickAction == customCommand) {
+ // run custom command set by the user
+ QString path = view->url().toLocalFile();
+ QString clickCustomAction = settings->doubleClickViewCustomAction();
+ clickCustomAction.replace("{path}", path.prepend('"').append('"'));
+
+ m_job = new KIO::CommandLauncherJob(clickCustomAction);
+ m_job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
+ m_job->start();
+
+ } else {
+ // get the action set by the user and trigger it
+ const KActionCollection *actions = actionCollection();
+ QAction *action = actions->action(clickAction);
+ if (action == nullptr) {
+ qCWarning(DolphinDebug) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction);
+ return;
+ }
+ action->trigger();
+ }
+}
+
#include "moc_dolphinmainwindow.cpp"
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h
index 9a1582c1f..5f96ca3b6 100644
--- a/src/dolphinmainwindow.h
+++ b/src/dolphinmainwindow.h
@@ -47,9 +47,13 @@ class QToolButton;
class PlacesPanel;
class TerminalPanel;
+/** Used to identify that a custom command should be triggered on a view background double-click.*/
+constexpr QLatin1String customCommand{"CUSTOM_COMMAND"};
+
namespace KIO
{
class OpenUrlJob;
+class CommandLauncherJob;
}
namespace SelectionMode
{
@@ -131,6 +135,11 @@ public:
bool isInformationPanelEnabled() const;
bool isSplitViewEnabledInCurrentTab() const;
+ /**
+ * Activates a user set action when double clicking the view's background.
+ */
+ void slotDoubleClickViewBackground(Qt::MouseButton button);
+
public Q_SLOTS:
/**
* Opens each directory in \p dirs in a separate tab. If \a splitView is set,
@@ -748,6 +757,8 @@ private:
QFutureWatcher<void> *m_sessionSaveWatcher;
bool m_sessionSaveScheduled;
+ KIO::CommandLauncherJob *m_job;
+
friend class DolphinMainWindowTest;
};
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp
index 2cda2987b..b25c73843 100644
--- a/src/kitemviews/kitemlistcontroller.cpp
+++ b/src/kitemviews/kitemlistcontroller.cpp
@@ -700,6 +700,11 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event,
const QPointF pos = transform.map(event->pos());
const std::optional<int> index = m_view->itemAt(pos);
+ if (!index.has_value()) {
+ Q_EMIT doubleClickViewBackground(event->button());
+ return false;
+ }
+
// Expand item if desired - See Bug 295573
if (m_mouseDoubleClickAction != ActivateItemOnly) {
if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index.value_or(-1))) {
diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h
index ccfc76267..fcb971fb7 100644
--- a/src/kitemviews/kitemlistcontroller.h
+++ b/src/kitemviews/kitemlistcontroller.h
@@ -230,6 +230,12 @@ Q_SIGNALS:
void decreaseZoom();
void swipeUp();
+ /**
+ * Emitted when the view's background is double-clicked.
+ * Used to trigger an user configured action.
+ */
+ void doubleClickViewBackground(Qt::MouseButton button);
+
public Q_SLOTS:
void slotStateChanged(QScroller::State newState);
diff --git a/src/settings/dolphin_generalsettings.kcfg b/src/settings/dolphin_generalsettings.kcfg
index dbb7dcd2c..c800eadb8 100644
--- a/src/settings/dolphin_generalsettings.kcfg
+++ b/src/settings/dolphin_generalsettings.kcfg
@@ -14,6 +14,13 @@
<argument type="Bool">showStatusBar</argument>
</signal>
<group name="General">
+ <entry name="DoubleClickViewAction" type="String">
+ <label>Select Action</label>
+ <default>edit_select_all</default>
+ </entry>
+ <entry name="DoubleClickViewCustomAction" type="String">
+ <label>Custom Action</label>
+ </entry>
<entry name="EditableUrl" type="Bool">
<label>Should the URL be editable for the user</label>
<default>false</default>
diff --git a/src/settings/viewmodes/generalviewsettingspage.cpp b/src/settings/viewmodes/generalviewsettingspage.cpp
index cd68cdaeb..51ab664f1 100644
--- a/src/settings/viewmodes/generalviewsettingspage.cpp
+++ b/src/settings/viewmodes/generalviewsettingspage.cpp
@@ -6,16 +6,21 @@
#include "generalviewsettingspage.h"
#include "dolphin_generalsettings.h"
+#include "dolphindebug.h"
#include "dolphinmainwindow.h"
#include "views/viewproperties.h"
+#include <KActionCollection>
#include <KLocalizedString>
+#include <QApplication>
#include <QButtonGroup>
#include <QCheckBox>
+#include <QComboBox>
#include <QFontDatabase>
#include <QFormLayout>
#include <QLabel>
+#include <QLineEdit>
#include <QMimeDatabase>
#include <QVBoxLayout>
@@ -85,6 +90,90 @@ GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl &url, QWidget *paren
(mime.globPatterns().join(", "))));
topLayout->addRow(QString(), m_hideXtrashFiles);
+ // --------------------- //
+ // START double click view background
+
+ // list of actions allowed to be triggered by double click
+ // actions were selected based on their usefulness of being triggered with the mouse
+ QStringList allowedActions{"new_tab",
+ "file_new",
+ "show_places_panel",
+ "show_information_panel",
+ "show_folders_panel",
+ "show_terminal_panel",
+ "open_terminal",
+ "go_up",
+ "go_back",
+ "go_home",
+ "view_redisplay",
+ "split_view",
+ "edit_select_all",
+ "toggle_selection_mode",
+ "create_dir",
+ "show_preview",
+ "show_hidden_files",
+ "show_in_groups",
+ "view_properties"};
+
+ // create actions combo-box and add actions
+ m_doubleClickViewComboBox = new QComboBox();
+ m_doubleClickViewComboBox->setAccessibleDescription(i18nc("Accessible description for combobox with actions of double click view background setting",
+ "Action to trigger when double clicking view background"));
+ // i18n: Completes the sentence "Double-click triggers [Nothing]".
+ m_doubleClickViewComboBox->addItem(QIcon::fromTheme("empty"), i18nc("@item:inlistbox", "Nothing"), QStringLiteral("none"));
+ m_doubleClickViewComboBox->addItem(QIcon::fromTheme("list-add"), i18nc("@item:inlistbox", "Custom Command"), customCommand);
+ m_doubleClickViewComboBox->insertSeparator(2);
+
+ DolphinMainWindow *mainWindow = static_cast<DolphinMainWindow *>(QApplication::activeWindow());
+ if (mainWindow != nullptr) {
+ KActionCollection *actions = mainWindow->actionCollection();
+ // get the allowed actions from actionCollection and add them to the combobox
+ for (const QString &actionName : allowedActions) {
+ QAction *action = actions->action(actionName);
+ if (action == nullptr) {
+ qCWarning(DolphinDebug) << QStringLiteral("Double click view: action `%1` was not found").arg(actionName);
+ continue;
+ }
+
+ QString actionText = action->text();
+ // remove ampersand used to define the action's shortcut
+ actionText.remove(QLatin1Char('&'));
+ m_doubleClickViewComboBox->addItem(action->icon(), actionText, action->objectName());
+ }
+ }
+ // i18n: This sentence is incomplete because the user can choose an action that is triggered in a combobox that will appear directly after "triggers".
+ // (While using a left-to-right language it will be to the right of "triggers", in a right-to-left layout it will be to the left.)
+ // So please try to keep this translation in a way that it is a complete sentence when reading the content of the combobox as part of the sentence.
+ // There can be many possible actions in the combobox. The default is "Nothing". Other actions are "New Tab", "Create Folder", "Show Hidden Files", …
+ QLabel *doubleClickViewLabel{new QLabel(i18nc("@info", "Double-click triggers"))};
+ QHBoxLayout *doubleClickViewHLayout{new QHBoxLayout()};
+ QWidget *doubleClickViewWidget{new QWidget()};
+ doubleClickViewWidget->setLayout(doubleClickViewHLayout);
+ doubleClickViewHLayout->addWidget(doubleClickViewLabel);
+ doubleClickViewHLayout->setContentsMargins(0, 0, 0, 0);
+ doubleClickViewHLayout->addWidget(m_doubleClickViewComboBox);
+ topLayout->addRow(i18nc("@title:group", "Background: "), doubleClickViewWidget);
+
+ m_doubleClickViewCustomAction = new QLineEdit();
+ m_doubleClickViewCustomAction->setAccessibleDescription(
+ i18nc("Accessible description for custom command text field of double click view background setting",
+ "Enter custom command to trigger when double clicking view background"));
+ m_doubleClickViewCustomAction->setPlaceholderText(i18nc("@info:placeholder for terminal command", "Command…"));
+ topLayout->addRow(QString(), m_doubleClickViewCustomAction);
+
+ m_doubleClickViewCustomActionInfo = new QLabel(i18nc("@label",
+ "Use {path} to get the path of the current folder. "
+ "Example: dolphin {path}"));
+ m_doubleClickViewCustomActionInfo->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
+ m_doubleClickViewCustomActionInfo->setWordWrap(true);
+ m_doubleClickViewCustomActionInfo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ m_doubleClickViewCustomActionInfo->hide();
+ m_doubleClickViewCustomActionInfo->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard
+ | Qt::LinksAccessibleByKeyboard); // for accessibility
+ topLayout->addRow(QString(), m_doubleClickViewCustomActionInfo);
+ // END double click view background
+ // --------------------- //
+
loadSettings();
connect(m_localViewProps, &QRadioButton::toggled, this, &GeneralViewSettingsPage::changed);
@@ -98,6 +187,9 @@ GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl &url, QWidget *paren
connect(m_showSelectionToggle, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
connect(m_renameInline, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
connect(m_hideXtrashFiles, &QCheckBox::toggled, this, &GeneralViewSettingsPage::changed);
+ connect(m_doubleClickViewCustomAction, &QLineEdit::textChanged, this, &GeneralViewSettingsPage::changed);
+ connect(m_doubleClickViewComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &GeneralViewSettingsPage::changed);
+ connect(m_doubleClickViewComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &GeneralViewSettingsPage::updateCustomActionVisibility);
}
GeneralViewSettingsPage::~GeneralViewSettingsPage()
@@ -118,6 +210,8 @@ void GeneralViewSettingsPage::applySettings()
settings->setHideXTrashFile(m_hideXtrashFiles->isChecked());
settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
settings->setBrowseThroughArchives(m_openArchivesAsFolder->isChecked());
+ settings->setDoubleClickViewCustomAction(m_doubleClickViewCustomAction->text());
+ settings->setDoubleClickViewAction(m_doubleClickViewComboBox->currentData().toString());
settings->save();
if (useGlobalViewProps) {
// Remember the global view properties by applying the current view properties.
@@ -151,6 +245,17 @@ void GeneralViewSettingsPage::loadSettings()
m_localViewProps->setChecked(!useGlobalViewProps);
m_globalViewProps->setChecked(useGlobalViewProps);
+ int index = m_doubleClickViewComboBox->findData(GeneralSettings::doubleClickViewAction());
+ m_doubleClickViewComboBox->setCurrentIndex((index == -1) ? 0 : index);
+ m_doubleClickViewCustomAction->setText(GeneralSettings::doubleClickViewCustomAction());
+ updateCustomActionVisibility(m_doubleClickViewComboBox->currentIndex());
+}
+
+void GeneralViewSettingsPage::updateCustomActionVisibility(int doubleClickViewComboBoxCurrentIndex)
+{
+ auto data = m_doubleClickViewComboBox->itemData(doubleClickViewComboBoxCurrentIndex, Qt::UserRole);
+ m_doubleClickViewCustomAction->setVisible(data == customCommand);
+ m_doubleClickViewCustomActionInfo->setVisible(data == customCommand);
}
#include "moc_generalviewsettingspage.cpp"
diff --git a/src/settings/viewmodes/generalviewsettingspage.h b/src/settings/viewmodes/generalviewsettingspage.h
index 234fb03cb..1d4caab65 100644
--- a/src/settings/viewmodes/generalviewsettingspage.h
+++ b/src/settings/viewmodes/generalviewsettingspage.h
@@ -13,7 +13,9 @@
#include <QUrl>
class QCheckBox;
+class QComboBox;
class QLabel;
+class QLineEdit;
class QRadioButton;
/**
@@ -35,6 +37,7 @@ public:
private:
void loadSettings();
+ void updateCustomActionVisibility(int doubleClickViewComboBoxCurrentIndex);
private:
QUrl m_url;
@@ -48,6 +51,9 @@ private:
QCheckBox *m_openArchivesAsFolder = nullptr;
QCheckBox *m_autoExpandFolders = nullptr;
QCheckBox *m_hideXtrashFiles = nullptr;
+ QComboBox *m_doubleClickViewComboBox = nullptr;
+ QLineEdit *m_doubleClickViewCustomAction = nullptr;
+ QLabel *m_doubleClickViewCustomActionInfo = nullptr;
};
#endif
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 1bbcd5998..d42d9cfcd 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -119,6 +119,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
KItemListController *controller = new KItemListController(m_model, m_view, this);
const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1;
controller->setAutoActivationDelay(delay);
+ connect(controller, &KItemListController::doubleClickViewBackground, this, &DolphinView::doubleClickViewBackground);
// The EnlargeSmallPreviews setting can only be changed after the model
// has been set in the view by KItemListController.
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index d4f82ae2f..b55e2ee9b 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -665,6 +665,12 @@ Q_SIGNALS:
*/
void currentDirectoryRemoved();
+ /**
+ * Emitted when the view's background is double-clicked.
+ * Used to trigger an user configured action.
+ */
+ void doubleClickViewBackground(Qt::MouseButton button);
+
protected:
/** Changes the zoom level if Control is pressed during a wheel event. */
void wheelEvent(QWheelEvent *event) override;