Merge lp:~aacid/unity-2d/addshortcutstochangelens into lp:unity-2d

Proposed by Albert Astals Cid
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 1051
Merged at revision: 1052
Proposed branch: lp:~aacid/unity-2d/addshortcutstochangelens
Merge into: lp:unity-2d
Diff against target: 51 lines (+41/-0)
1 file modified
shell/dash/Dash.qml (+41/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/addshortcutstochangelens
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Review via email: mp+100954@code.launchpad.net

Commit message

[Dash] Implement shortcuts to change lenses

Description of the change

UNBLOCK

To post a comment you must log in.
1049. By Albert Astals Cid

Merge lp:unity-2d

1050. By Albert Astals Cid

Not needed after last unity-2d merge

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Would you mind extracting part of the changeLens code that sets activeLens into a new function - getActiveLensIndex or so?

Also, how about having two functions: nextLens(currentIndex) and previousLens(currentIndex) that would wrap changeLens? I don't have strong opinion on this, but I think this could make it more readable than changeLens(lenses.rowCount() - 1). Up to you.

BTW, I confirmed with John Lea that the current Ctrl+PageUp and Ctrl+PageDown mapping you have is correct - and he updated the description of bug report.

review: Needs Fixing
1051. By Albert Astals Cid

code refinement

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Works great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'shell/dash/Dash.qml'
--- shell/dash/Dash.qml 2012-04-05 13:25:46 +0000
+++ shell/dash/Dash.qml 2012-04-10 09:09:19 +0000
@@ -258,6 +258,47 @@
258 necessarily focusing the search bar first. */258 necessarily focusing the search bar first. */
259 /* FIXME: deactivated because it makes the user lose the focus very often */259 /* FIXME: deactivated because it makes the user lose the focus very often */
260 //Keys.forwardTo: [search_entry]260 //Keys.forwardTo: [search_entry]
261 Keys.onPressed: {
262 if ((event.key == Qt.Key_Tab || event.key == Qt.Key_PageDown) && event.modifiers == Qt.ControlModifier) {
263 changeLens(1);
264 event.accepted = true
265 } else if ((event.key == Qt.Key_Backtab && event.modifiers == (Qt.ControlModifier | Qt.ShiftModifier)) ||
266 (event.key == Qt.Key_PageUp && event.modifiers == Qt.ControlModifier)) {
267 changeLens(-1);
268 event.accepted = true
269 }
270 }
271
272 function activeLensIndex() {
273 var count = lenses.rowCount()
274 for (var i = 0; i < count; i++) {
275 if (lenses.get(i).id == shellManager.dashActiveLens) {
276 return i
277 }
278 }
279 return -1
280 }
281
282 function changeLens(step) {
283 var activeLens = activeLensIndex()
284 if (activeLens != -1) {
285 var lensesCount = lenses.rowCount()
286 if (step < 0) {
287 // Can't do lenses.get(negativeNumber) so instead of adding a negative step
288 // we add the positive number that results in the same value when doing the modulus
289 step = lensesCount + step
290 }
291 var nextLensIndex = (activeLens + step) % lensesCount
292 var nextLens = lenses.get(nextLensIndex)
293 while (!nextLens.visible && nextLensIndex != activeLens) {
294 nextLensIndex = (nextLensIndex + step) % lensesCount
295 nextLens = lenses.get(nextLensIndex)
296 }
297 activateLens(nextLens.id)
298 } else {
299 console.log("Could not find the active dash lens")
300 }
301 }
261302
262 Image {303 Image {
263 id: panelBorder304 id: panelBorder

Subscribers

People subscribed via source and target branches