diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -304,6 +304,8 @@ bool wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform); bool resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform); + void doubleClickViewBackground(Qt::MouseButton button); + private: bool m_singleClickActivationEnforced; bool m_selectionTogglePressed; diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -23,19 +23,27 @@ #include "kitemlistcontroller.h" +#include "dolphin_generalsettings.h" +#include "dolphinmainwindow.h" #include "kitemlistselectionmanager.h" #include "kitemlistview.h" #include "private/kitemlistkeyboardsearchmanager.h" #include "private/kitemlistrubberband.h" #include "views/draganddrophelper.h" +#include "views/dolphinview.h" + +#include +#include #include #include +#include #include #include #include #include #include +#include #include KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : @@ -795,11 +803,52 @@ return false; } +void KItemListController::doubleClickViewBackground(Qt::MouseButton button) +{ + GeneralSettings* settings = GeneralSettings::self(); + QString clickAction; + QString clickCustomAction; + if (button == Qt::LeftButton) { + clickAction = settings->doubleClickViewAction(); + clickCustomAction = settings->doubleClickViewCustomAction(); + } else { + return; + } + DolphinView *view = qobject_cast(parent()->parent()); + DolphinMainWindow *mainWindow = (DolphinMainWindow *)QApplication::activeWindow(); + if (mainWindow == nullptr || view == nullptr || clickAction == "none") { + return; + } + if (clickAction == "custom") { + // run custom command set by the user + QString path = view->url().toLocalFile(); + // replace {path} with the actual path wrapped in quotes + clickCustomAction.replace("{path}", path.prepend('"').append('"')); + QStringList args = KShell::splitArgs(clickCustomAction); + QString processName = args.takeAt(0); + QProcess *process = new QProcess(); + process->start(processName, args); + } else { + // find the action set by the user and trigger it + QList actions = mainWindow->actionCollection()->actions(); + for (QAction *action : actions) { + if (clickAction == action->objectName()) { + action->trigger(); + break; + } + } + } +} + bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) { const QPointF pos = transform.map(event->pos()); const int index = m_view->itemAt(pos); + if (index == -1) { + doubleClickViewBackground(event->button()); + } + // Expand item if desired - See Bug 295573 if (m_mouseDoubleClickAction != ActivateItemOnly) { if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { diff --git a/src/settings/dolphin_generalsettings.kcfg b/src/settings/dolphin_generalsettings.kcfg --- a/src/settings/dolphin_generalsettings.kcfg +++ b/src/settings/dolphin_generalsettings.kcfg @@ -74,6 +74,12 @@ false + + + + + + true diff --git a/src/settings/navigation/navigationsettingspage.h b/src/settings/navigation/navigationsettingspage.h --- a/src/settings/navigation/navigationsettingspage.h +++ b/src/settings/navigation/navigationsettingspage.h @@ -22,6 +22,9 @@ #include "settings/settingspagebase.h" class QCheckBox; +class QComboBox; +class QLabel; +class QLineEdit; /** * @brief Page for the 'Navigation' settings of the Dolphin settings dialog. @@ -42,10 +45,14 @@ private: void loadSettings(); + void setCustomActionVisibility(); private: QCheckBox* m_openArchivesAsFolder; QCheckBox* m_autoExpandFolders; + QComboBox *m_doubleClickViewComboBox; + QLineEdit *m_doubleClickViewCustomAction; + QLabel *m_doubleClickViewCustomActionInfo; }; #endif diff --git a/src/settings/navigation/navigationsettingspage.cpp b/src/settings/navigation/navigationsettingspage.cpp --- a/src/settings/navigation/navigationsettingspage.cpp +++ b/src/settings/navigation/navigationsettingspage.cpp @@ -20,10 +20,17 @@ #include "navigationsettingspage.h" #include "dolphin_generalsettings.h" +#include "dolphinmainwindow.h" +#include "global.h" +#include #include +#include #include +#include +#include +#include #include NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) : @@ -45,10 +52,88 @@ topLayout->addWidget(vBox); + // --------------------- // + // START double click view background + vBoxLayout->addItem(new QSpacerItem(0, + Dolphin::VERTICAL_SPACER_HEIGHT, + QSizePolicy::Fixed, + QSizePolicy::Fixed)); + + // list of actions allowed to be triggered by double click + QStringList allowedActions; + allowedActions << "new_tab" + << "open_terminal" + << "show_terminal_panel" + << "go_up" + << "go_home" + << "split_view" + << "editable_location" + << "replace_location" + << "show_filter_bar" + << "show_preview" + << "show_hidden_files" + << "view_properties" + << "edit_paste" + << "edit_find" + << "create_dir" + << "show_in_groups" + << "file_new" + << "edit_select_all" + << "go_back"; + + // create actions combo-box and add actions + m_doubleClickViewComboBox = new QComboBox(); + m_doubleClickViewComboBox->addItem(QIcon::fromTheme("empty"), + i18nc("@item:inlistbox", "None"), + QStringLiteral("none")); + m_doubleClickViewComboBox->addItem(QIcon::fromTheme("list-add"), + i18nc("@item:inlistbox", "Custom"), + QStringLiteral("custom")); + m_doubleClickViewComboBox->insertSeparator(2); + + DolphinMainWindow *mainWindow = (DolphinMainWindow *)QApplication::activeWindow(); + if (mainWindow != nullptr) { + QList actions = mainWindow->actionCollection()->actions(); + // find the actions present in both allowedActions and actionCollection + // and add them to the combo-box + for (QAction *action : actions) { + if (!allowedActions.contains(action->objectName())) { + continue; + } + QString actionText = action->text(); + // remove ampersand used to define the action's shortcut + for (int i = 0; i < actionText.size(); i++) { + if (actionText.at(i) == QLatin1Char('&')) { + actionText.remove(i, 1); + } + } + m_doubleClickViewComboBox->addItem(action->icon(), actionText, action->objectName()); + } + } + QLabel *label = new QLabel("View Double Click Action"); + vBoxLayout->addWidget(label); + vBoxLayout->addWidget(m_doubleClickViewComboBox); + + m_doubleClickViewCustomAction = new QLineEdit(); + vBoxLayout->addWidget(m_doubleClickViewCustomAction); + m_doubleClickViewCustomActionInfo = new QLabel(i18nc("@label", "Use %1 if you need the path " + "of the current folder in your script.\n" + "Example: dolphin %1").arg("{path}")); + m_doubleClickViewCustomActionInfo->hide(); + vBoxLayout->addWidget(m_doubleClickViewCustomActionInfo); + // END double click view background + // --------------------- // + loadSettings(); connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &NavigationSettingsPage::changed); connect(m_autoExpandFolders, &QCheckBox::toggled, this, &NavigationSettingsPage::changed); + connect(m_doubleClickViewCustomAction, &QLineEdit::textChanged, + this, &NavigationSettingsPage::changed); + connect(m_doubleClickViewComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &NavigationSettingsPage::changed); + connect(m_doubleClickViewComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, [=]() { setCustomActionVisibility(); }); } NavigationSettingsPage::~NavigationSettingsPage() @@ -60,6 +145,8 @@ GeneralSettings* settings = GeneralSettings::self(); settings->setBrowseThroughArchives(m_openArchivesAsFolder->isChecked()); settings->setAutoExpandFolders(m_autoExpandFolders->isChecked()); + settings->setDoubleClickViewCustomAction(m_doubleClickViewCustomAction->text()); + settings->setDoubleClickViewAction(m_doubleClickViewComboBox->currentData().toString()); settings->save(); } @@ -76,5 +163,19 @@ { m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives()); m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders()); + int index = m_doubleClickViewComboBox->findData(GeneralSettings::doubleClickViewAction()); + (index != -1) ? m_doubleClickViewComboBox->setCurrentIndex(index) : m_doubleClickViewComboBox->setCurrentIndex(0); + m_doubleClickViewCustomAction->setText(GeneralSettings::doubleClickViewCustomAction()); + setCustomActionVisibility(); } +void NavigationSettingsPage::setCustomActionVisibility() +{ + if (m_doubleClickViewComboBox->currentIndex() == 1) { + m_doubleClickViewCustomAction->show(); + m_doubleClickViewCustomActionInfo->show(); + } else { + m_doubleClickViewCustomAction->hide(); + m_doubleClickViewCustomActionInfo->hide(); + } +}