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
1=== modified file 'shell/dash/Dash.qml'
2--- shell/dash/Dash.qml 2012-04-05 13:25:46 +0000
3+++ shell/dash/Dash.qml 2012-04-10 09:09:19 +0000
4@@ -258,6 +258,47 @@
5 necessarily focusing the search bar first. */
6 /* FIXME: deactivated because it makes the user lose the focus very often */
7 //Keys.forwardTo: [search_entry]
8+ Keys.onPressed: {
9+ if ((event.key == Qt.Key_Tab || event.key == Qt.Key_PageDown) && event.modifiers == Qt.ControlModifier) {
10+ changeLens(1);
11+ event.accepted = true
12+ } else if ((event.key == Qt.Key_Backtab && event.modifiers == (Qt.ControlModifier | Qt.ShiftModifier)) ||
13+ (event.key == Qt.Key_PageUp && event.modifiers == Qt.ControlModifier)) {
14+ changeLens(-1);
15+ event.accepted = true
16+ }
17+ }
18+
19+ function activeLensIndex() {
20+ var count = lenses.rowCount()
21+ for (var i = 0; i < count; i++) {
22+ if (lenses.get(i).id == shellManager.dashActiveLens) {
23+ return i
24+ }
25+ }
26+ return -1
27+ }
28+
29+ function changeLens(step) {
30+ var activeLens = activeLensIndex()
31+ if (activeLens != -1) {
32+ var lensesCount = lenses.rowCount()
33+ if (step < 0) {
34+ // Can't do lenses.get(negativeNumber) so instead of adding a negative step
35+ // we add the positive number that results in the same value when doing the modulus
36+ step = lensesCount + step
37+ }
38+ var nextLensIndex = (activeLens + step) % lensesCount
39+ var nextLens = lenses.get(nextLensIndex)
40+ while (!nextLens.visible && nextLensIndex != activeLens) {
41+ nextLensIndex = (nextLensIndex + step) % lensesCount
42+ nextLens = lenses.get(nextLensIndex)
43+ }
44+ activateLens(nextLens.id)
45+ } else {
46+ console.log("Could not find the active dash lens")
47+ }
48+ }
49
50 Image {
51 id: panelBorder

Subscribers

People subscribed via source and target branches