diff --git a/krunner/view.cpp b/krunner/view.cpp index 208c88c06..2b9c1e715 100644 --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -56,7 +56,7 @@ View::View(QWindow *) m_config = KConfigGroup(KSharedConfig::openConfig("krunnerrc"), "General"); - setFreeFloating(m_config.readEntry("FreeFloating", false)); + reloadConfig(); new AppAdaptor(this); QDBusConnection::sessionBus().registerObject(QLatin1String("/App"), this); @@ -173,6 +173,12 @@ void View::reloadConfig() { m_config.config()->reparseConfiguration(); setFreeFloating(m_config.readEntry("FreeFloating", false)); + + const QStringList history = m_config.readEntry("history", QStringList()); + if (m_history != history) { + m_history = history; + emit historyChanged(); + } } bool View::event(QEvent *event) @@ -322,4 +328,28 @@ void View::displayConfiguration() QProcess::startDetached(QStringLiteral("kcmshell5"), QStringList() << QStringLiteral("plasmasearch")); } +QStringList View::history() const +{ + return m_history; +} + +void View::addToHistory(const QString &item) +{ + if (item == QLatin1String("SESSIONS")) { + return; + } + + m_history.removeOne(item); + m_history.prepend(item); + + while (m_history.count() > 10) { // make configurable? + m_history.removeLast(); + } + + emit historyChanged(); + + m_config.writeEntry("history", m_history); + m_config.sync(); +} + #include "moc_view.cpp" diff --git a/krunner/view.h b/krunner/view.h index 45f4d2841..e73a4197a 100644 --- a/krunner/view.h +++ b/krunner/view.h @@ -34,6 +34,8 @@ class View : public PlasmaQuick::Dialog Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.krunner.App") + Q_PROPERTY(QStringList history READ history NOTIFY historyChanged) + public: explicit View(QWindow *parent = 0); virtual ~View(); @@ -43,6 +45,12 @@ public: bool freeFloating() const; void setFreeFloating(bool floating); + QStringList history() const; + Q_INVOKABLE void addToHistory(const QString &item); + +Q_SIGNALS: + void historyChanged(); + protected: virtual bool event(QEvent* event); virtual void showEvent(QShowEvent *event); @@ -70,6 +78,7 @@ private: KConfigGroup m_config; qreal m_offset; bool m_floating : 1; + QStringList m_history; }; diff --git a/lookandfeel/contents/runcommand/RunCommand.qml b/lookandfeel/contents/runcommand/RunCommand.qml index 4c6eb3036..4650da7b3 100644 --- a/lookandfeel/contents/runcommand/RunCommand.qml +++ b/lookandfeel/contents/runcommand/RunCommand.qml @@ -37,6 +37,7 @@ ColumnLayout { onVisibleChanged: { if (runnerWindow.visible) { queryField.forceActiveFocus(); + listView.currentIndex = -1 } else { root.query = ""; } @@ -58,13 +59,16 @@ ColumnLayout { id: queryField clearButtonShown: true Layout.minimumWidth: units.gridUnit * 25 + + activeFocusOnPress: true + onTextChanged: { root.query = queryField.text } Keys.onEscapePressed: { runnerWindow.visible = false } - Keys.forwardTo: results + Keys.forwardTo: [listView, results] } PlasmaComponents.ToolButton { iconSource: "window-close" @@ -77,6 +81,7 @@ ColumnLayout { PlasmaExtras.ScrollArea { Layout.alignment: Qt.AlignTop visible: results.count > 0 + enabled: visible Layout.fillWidth: true Layout.preferredHeight: Math.min(Screen.height, results.contentHeight) @@ -86,6 +91,7 @@ ColumnLayout { runner: root.runner onActivated: { + runnerWindow.addToHistory(queryString) runnerWindow.visible = false } @@ -95,4 +101,39 @@ ColumnLayout { } } } + + PlasmaExtras.ScrollArea { + Layout.alignment: Qt.AlignTop + Layout.fillWidth: true + visible: root.query.length === 0 && listView.count > 0 + // don't accept keyboard input when not visible so the keys propagate to the other list + enabled: visible + Layout.preferredHeight: Math.min(Screen.height, listView.contentHeight) + + ListView { + id: listView // needs this id so the delegate can access it + keyNavigationWraps: true + highlight: PlasmaComponents.Highlight {} + highlightMoveDuration: 0 + model: runnerWindow.history + delegate: Milou.ResultDelegate { + id: resultDelegate + width: listView.width + typeText: index === 0 ? i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Recent Queries") : "" + } + + Keys.onReturnPressed: runCurrentIndex() + Keys.onEnterPressed: runCurrentIndex() + + Keys.onTabPressed: incrementCurrentIndex() + Keys.onBacktabPressed: decrementCurrentIndex() + Keys.onUpPressed: decrementCurrentIndex() + Keys.onDownPressed: incrementCurrentIndex() + + function runCurrentIndex() { + queryField.text = runnerWindow.history[currentIndex] + } + } + + } }