Commit 4f8a3415 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Implement type-ahead-find

parent a4f57023
......@@ -17,6 +17,7 @@
*****************************************************************************/
import QtQuick 1.1
import org.kde.sal.fixes 0.1 as SalFixes
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.qtextracomponents 0.1 as QtExtra
......@@ -39,7 +40,7 @@ FocusScope {
property variant favoriteModels
property alias model: gridView.model
property alias model: proxyModel.sourceModel
property string path: model.path ? model.path : "/"
onPathChanged: pathModel.update(path)
......@@ -48,6 +49,10 @@ FocusScope {
id: pathModel
}
SalFixes.SortFilterModel {
id: proxyModel
}
// Components
Component {
id: highlight
......@@ -77,7 +82,7 @@ FocusScope {
}
}
onClicked: indexClicked(model.index)
onClicked: emitIndexClicked(model.index)
onFavoriteClicked: {
var favoriteModel = favoriteModelForFavoriteId(model.favoriteId);
......@@ -97,10 +102,19 @@ FocusScope {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
text: model.name
width: parent.width
}
PlasmaComponents.Label {
id: typeAheadLabel
anchors {
bottom: headerLabel.bottom
left: headerLabel.right
leftMargin: 6
}
text: proxyModel.filterRegExp + "|"
opacity: proxyModel.filterRegExp == "" ? 0 : 0.6
}
Row {
......@@ -130,6 +144,7 @@ FocusScope {
right: parent.right
}
model: proxyModel
focus: true
/*
......@@ -172,13 +187,31 @@ FocusScope {
} else if (event.key == Qt.Key_Down) {
moveCurrentIndexDown();
}
// Only accept the event if the index actually moved. Not accepting
// it will cause parent items to move the focus to the next ResultsView,
// which is what we want
event.accepted = currentIndex != oldIndex;
if (currentIndex != oldIndex) {
// Only accept the event if the index actually moved. Not accepting
// it will cause parent items to move the focus to the next ResultsView,
// which is what we want
event.accepted = true;
return;
}
switch (event.key) {
case Qt.Key_Backspace:
proxyModel.filterRegExp = proxyModel.filterRegExp.slice(0, -1);
event.accepted = true;
break;
case Qt.Key_Tab:
break;
default:
if (event.text != "") {
proxyModel.filterRegExp += event.text;
event.accepted = true;
}
break;
}
}
Keys.onReturnPressed: indexClicked(currentIndex)
Keys.onReturnPressed: emitIndexClicked(currentIndex)
}
PlasmaCore.FrameSvgItem {
......@@ -241,4 +274,10 @@ FocusScope {
return model;
}
}
function emitIndexClicked(index) {
var sourceIndex = proxyModel.mapRowToSource(index);
proxyModel.filterRegExp = "";
indexClicked(sourceIndex);
}
}
......@@ -112,7 +112,6 @@ Item {
id: resultsViewComponent
ResultsView {
width: parent.width
visible: model.count > 0
onIndexClicked: {
if (model.trigger(index)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment