Bring back KRunner history

When a result is invoked, the query string is prepended to the history, query strings
are only added once. When KRunner is opened, the history will be displayed right away.
The old ComboBox approach caused bad usability because of two vertical lists conflicting
with each other.

REVIEW: 123888
wilder-5.14
Kai Uwe Broulik 11 years ago
parent cf9c02629e
commit 2d2a79390d
  1. 32
      krunner/view.cpp
  2. 9
      krunner/view.h
  3. 43
      lookandfeel/contents/runcommand/RunCommand.qml

@ -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"

@ -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;
};

@ -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]
}
}
}
}

Loading…
Cancel
Save