From ddd005b1f5bd802193d9393f68cf2bd1e01dee6d Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sun, 30 Aug 2020 16:19:26 +0000 Subject: [PATCH] Add option to retain prior search FEATURE: 397092 FIXED-IN: 5.20 --- krunner/view.cpp | 12 +++++++++++- krunner/view.h | 5 +++++ lookandfeel/contents/runcommand/RunCommand.qml | 16 ++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/krunner/view.cpp b/krunner/view.cpp index 8ea6a7b56..f0702e774 100644 --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -51,7 +51,8 @@ View::View(QWindow *) : PlasmaQuick::Dialog(), m_offset(.5), - m_floating(false) + m_floating(false), + m_retainPriorSearch(false) { setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); @@ -163,6 +164,11 @@ void View::loadConfig() m_history = history; emit historyChanged(); } + bool retainPriorSearch = m_config.readEntry("RetainPriorSearch", true); + if (retainPriorSearch != m_retainPriorSearch) { + m_retainPriorSearch = retainPriorSearch; + Q_EMIT retainPriorSearchChanged(); + } } bool View::event(QEvent *event) @@ -432,3 +438,7 @@ void View::setVisible(bool visible) PlasmaQuick::Dialog::setVisible(visible); } } + +bool View::retainPriorSearch() const { + return m_retainPriorSearch; +} diff --git a/krunner/view.h b/krunner/view.h index e34509016..1ceb6704e 100644 --- a/krunner/view.h +++ b/krunner/view.h @@ -49,6 +49,7 @@ class View : public PlasmaQuick::Dialog Q_PROPERTY(bool canConfigure READ canConfigure CONSTANT) Q_PROPERTY(QStringList history READ history NOTIFY historyChanged) + Q_PROPERTY(bool retainPriorSearch READ retainPriorSearch NOTIFY retainPriorSearchChanged) public: explicit View(QWindow *parent = nullptr); @@ -65,8 +66,11 @@ public: Q_INVOKABLE void addToHistory(const QString &item); Q_INVOKABLE void removeFromHistory(int index); + bool retainPriorSearch() const; + Q_SIGNALS: void historyChanged(); + void retainPriorSearchChanged(); protected: bool event(QEvent* event) override; @@ -101,6 +105,7 @@ private: bool m_floating : 1; bool m_requestedVisible = false; QStringList m_history; + bool m_retainPriorSearch; }; diff --git a/lookandfeel/contents/runcommand/RunCommand.qml b/lookandfeel/contents/runcommand/RunCommand.qml index ceed20ac9..d5ced36ff 100644 --- a/lookandfeel/contents/runcommand/RunCommand.qml +++ b/lookandfeel/contents/runcommand/RunCommand.qml @@ -29,6 +29,7 @@ ColumnLayout { property string query property string runner property bool showHistory: false + property string priorSearch LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft LayoutMirroring.childrenInherit: true @@ -44,8 +45,13 @@ ColumnLayout { queryField.forceActiveFocus(); listView.currentIndex = -1 } else { - root.query = ""; root.runner = "" + if (runnerWindow.retainPriorSearch) { + root.query = priorSearch + queryField.select(priorSearch.length, 0) + } else { + root.query = "" + } root.showHistory = false } } @@ -56,6 +62,7 @@ ColumnLayout { PlasmaComponents3.ToolButton { icon.name: "configure" onClicked: { + priorSearch = query runnerWindow.visible = false runnerWindow.displayConfiguration() } @@ -165,6 +172,7 @@ ColumnLayout { Keys.onReturnPressed: results.runCurrentIndex(event) Keys.onEscapePressed: { + priorSearch = query runnerWindow.visible = false } @@ -199,7 +207,10 @@ ColumnLayout { } PlasmaComponents3.ToolButton { icon.name: "window-close" - onClicked: runnerWindow.visible = false + onClicked: { + priorSearch = query + runnerWindow.visible = false + } Accessible.name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Close") Accessible.description: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Close Search") PlasmaComponents3.ToolTip { @@ -237,6 +248,7 @@ ColumnLayout { onActivated: { runnerWindow.addToHistory(queryString) + priorSearch = query runnerWindow.visible = false }