Changeset View
Changeset View
Standalone View
Standalone View
lib/qml/ResultsView.qml
Show All 18 Lines | |||||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | * | 20 | * | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | import QtQuick 2.1 | 23 | import QtQuick 2.1 | ||
24 | 24 | | |||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | 25 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
26 | import org.kde.plasma.core 2.0 as PlasmaCore | 26 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
27 | import org.kde.milou 0.2 as Milou | 27 | import org.kde.milou 0.3 as Milou | ||
28 | 28 | | |||
29 | ListView { | 29 | ListView { | ||
30 | id: listView | 30 | id: listView | ||
31 | property alias queryString: resultModel.queryString | 31 | property alias queryString: resultModel.queryString | ||
32 | property alias runner: resultModel.runner | 32 | property alias runner: resultModel.runner | ||
33 | | ||||
33 | property alias runnerName: resultModel.runnerName | 34 | property alias runnerName: resultModel.runnerName | ||
34 | property alias runnerIcon: resultModel.runnerIcon | 35 | property alias runnerIcon: resultModel.runnerIcon | ||
36 | property alias querying: resultModel.querying | ||||
35 | property bool reversed | 37 | property bool reversed | ||
36 | signal activated | 38 | signal activated | ||
37 | signal updateQueryString(string text, int cursorPosition) | 39 | signal updateQueryString(string text, int cursorPosition) | ||
38 | 40 | | |||
39 | // NOTE this also flips increment/decrementCurrentIndex (Bug 360789) | 41 | // NOTE this also flips increment/decrementCurrentIndex (Bug 360789) | ||
40 | verticalLayoutDirection: reversed ? ListView.BottomToTop : ListView.TopToBottom | 42 | verticalLayoutDirection: reversed ? ListView.BottomToTop : ListView.TopToBottom | ||
41 | keyNavigationWraps: true | 43 | keyNavigationWraps: true | ||
42 | highlight: PlasmaComponents.Highlight {} | 44 | highlight: PlasmaComponents.Highlight {} | ||
43 | highlightMoveDuration: 0 | 45 | highlightMoveDuration: 0 | ||
44 | activeFocusOnTab: true | 46 | activeFocusOnTab: true | ||
45 | Accessible.role: Accessible.List | 47 | Accessible.role: Accessible.List | ||
46 | 48 | | |||
47 | section { | 49 | section { | ||
48 | criteria: ViewSection.FullString | 50 | criteria: ViewSection.FullString | ||
49 | property: "type" | 51 | property: "category" | ||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | // This is used to keep track if the user has pressed enter before | 54 | // This is used to keep track if the user has pressed enter before | ||
53 | // the first result has been shown, in the case the first result should | 55 | // the first result has been shown, in the case the first result should | ||
54 | // be run when the model is populated | 56 | // be run when the model is populated | ||
55 | property bool runAutomatically | 57 | property bool runAutomatically | ||
56 | 58 | | |||
57 | // This is used to disable mouse selection if the user interacts only with keyboard | 59 | // This is used to disable mouse selection if the user interacts only with keyboard | ||
58 | property bool moved: false | 60 | property bool moved: false | ||
59 | property point savedMousePosition: Milou.MouseHelper.globalMousePosition() | 61 | property point savedMousePosition: Milou.MouseHelper.globalMousePosition() | ||
60 | function mouseMovedGlobally() { | 62 | function mouseMovedGlobally() { | ||
61 | return savedMousePosition != Milou.MouseHelper.globalMousePosition(); | 63 | return savedMousePosition != Milou.MouseHelper.globalMousePosition(); | ||
62 | } | 64 | } | ||
63 | 65 | | |||
64 | Milou.DragHelper { | 66 | Milou.DragHelper { | ||
65 | id: dragHelper | 67 | id: dragHelper | ||
66 | dragIconSize: units.iconSizes.medium | 68 | dragIconSize: units.iconSizes.medium | ||
67 | } | 69 | } | ||
68 | 70 | | |||
69 | model: Milou.SourcesModel { | 71 | model: Milou.ResultsModel { | ||
70 | id: resultModel | 72 | id: resultModel | ||
71 | queryLimit: 20 | 73 | limit: 20 | ||
72 | 74 | onQueryStringChangeRequested: { | |||
73 | 75 | listView.updateQueryString(queryString, pos) | |||
74 | onUpdateSearchTerm: listView.updateQueryString(text, pos) | 76 | } | ||
77 | onQueryStringChanged: resetView() | ||||
78 | onModelReset: resetView() | ||||
79 | | ||||
80 | onRowsInserted: { | ||||
81 | // Keep the selection at the top as items inserted to the beginning will shift it downwards | ||||
82 | // ListView will update its view after this signal is processed and then our callLater will set it back | ||||
83 | if (listView.currentIndex === 0) { | ||||
84 | Qt.callLater(function() { | ||||
85 | listView.currentIndex = 0; | ||||
86 | }); | ||||
75 | } | 87 | } | ||
76 | 88 | | |||
77 | // Internally when the query string changes, the model is reset | | |||
78 | // and the results are presented | | |||
79 | onCountChanged: { | | |||
80 | listView.currentIndex = 0 | | |||
81 | listView.moved = false | | |||
82 | listView.savedMousePosition = Milou.MouseHelper.globalMousePosition() | | |||
83 | | ||||
84 | if (runAutomatically) { | 89 | if (runAutomatically) { | ||
85 | runCurrentIndex(); | 90 | if (resultModel.run(resultModel.index(0, 0))) { | ||
davidedmundson: This recreates the bug I just fixed!
Adding a Qt.callLater round this would also work | |||||
91 | listView.activated(); | ||||
92 | } | ||||
93 | runAutomatically = false; | ||||
94 | } | ||||
95 | } | ||||
96 | | ||||
97 | function resetView() { | ||||
98 | listView.currentIndex = 0; | ||||
99 | listView.moved = false; | ||||
100 | listView.savedMousePosition = Milou.MouseHelper.globalMousePosition(); | ||||
Call it resetView()? Otherwise it seems like you're resetting the model again. apol: Call it `resetView()`? Otherwise it seems like you're resetting the model again. | |||||
86 | } | 101 | } | ||
87 | } | 102 | } | ||
88 | 103 | | |||
89 | delegate: ResultDelegate { | 104 | delegate: ResultDelegate { | ||
90 | id: resultDelegate | 105 | id: resultDelegate | ||
91 | width: listView.width | 106 | width: listView.width | ||
92 | } | 107 | } | ||
93 | 108 | | |||
Show All 17 Lines | 123 | if (event && event.modifiers === Qt.ShiftModifier | |||
111 | return | 126 | return | ||
112 | } | 127 | } | ||
113 | 128 | | |||
114 | if (currentItem.activeAction > -1) { | 129 | if (currentItem.activeAction > -1) { | ||
115 | runAction(currentItem.activeAction) | 130 | runAction(currentItem.activeAction) | ||
116 | return | 131 | return | ||
117 | } | 132 | } | ||
118 | 133 | | |||
119 | if (resultModel.run(currentIndex)) { | 134 | if (resultModel.run(resultModel.index(currentIndex, 0))) { | ||
120 | activated() | 135 | activated() | ||
121 | } | 136 | } | ||
122 | runAutomatically = false | 137 | runAutomatically = false | ||
123 | } | 138 | } | ||
124 | } | 139 | } | ||
125 | 140 | | |||
126 | function runAction(index) { | 141 | function runAction(index) { | ||
127 | if (resultModel.runAction(currentIndex, index)) { | 142 | if (resultModel.runAction(resultModel.index(currentIndex, 0), index)) { | ||
128 | activated() | 143 | activated() | ||
129 | } | 144 | } | ||
130 | } | 145 | } | ||
131 | 146 | | |||
132 | onActiveFocusChanged: { | 147 | onActiveFocusChanged: { | ||
133 | if (!activeFocus && currentIndex == listView.count-1) { | 148 | if (!activeFocus && currentIndex == listView.count-1) { | ||
134 | currentIndex = 0; | 149 | currentIndex = 0; | ||
135 | } | 150 | } | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
180 | Keys.onDownPressed: reversed ? decrementCurrentIndex() : incrementCurrentIndex(); | 195 | Keys.onDownPressed: reversed ? decrementCurrentIndex() : incrementCurrentIndex(); | ||
181 | 196 | | |||
182 | boundsBehavior: Flickable.StopAtBounds | 197 | boundsBehavior: Flickable.StopAtBounds | ||
183 | 198 | | |||
184 | function loadSettings() { | 199 | function loadSettings() { | ||
185 | resultModel.loadSettings() | 200 | resultModel.loadSettings() | ||
186 | } | 201 | } | ||
187 | 202 | | |||
188 | function setQueryString(string) { | 203 | function setQueryString(queryString) { | ||
189 | resultModel.queryString = string | 204 | resultModel.queryString = queryString | ||
190 | runAutomatically = false | 205 | runAutomatically = false | ||
191 | } | 206 | } | ||
192 | } | 207 | } |
This recreates the bug I just fixed!
Adding a Qt.callLater round this would also work