SideBySide2: Move [,] event handling into header
The header object knows how to manage the navigation. Instead of digging into there from anonymous Runnables in SideBySide2, let Header create the Runnable, hiding some of the inner details of Header from the event binding code. This shortens the event binding code for a CM3 a bit more, making the table of key bindings slightly easier to read. Change-Id: Ia3c999f37001c51d5c36d8eaff02f8bdc725773a
This commit is contained in:
@@ -255,12 +255,29 @@ class Header extends Composite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasPrev() {
|
Runnable navigate(Direction dir) {
|
||||||
return hasPrev;
|
switch (dir) {
|
||||||
}
|
case PREV:
|
||||||
|
return new Runnable() {
|
||||||
boolean hasNext() {
|
@Override
|
||||||
return hasNext;
|
public void run() {
|
||||||
|
(hasPrev ? prev : up).go();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
case NEXT:
|
||||||
|
return new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
(hasNext ? next : up).go();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getNextPath() {
|
String getNextPath() {
|
||||||
|
|||||||
@@ -348,6 +348,8 @@ public class SideBySide2 extends Screen {
|
|||||||
cm.addKeyMap(KeyMap.create()
|
cm.addKeyMap(KeyMap.create()
|
||||||
.on("'a'", upToChange(true))
|
.on("'a'", upToChange(true))
|
||||||
.on("'u'", upToChange(false))
|
.on("'u'", upToChange(false))
|
||||||
|
.on("[", header.navigate(Direction.PREV))
|
||||||
|
.on("]", header.navigate(Direction.NEXT))
|
||||||
.on("'r'", toggleReviewed())
|
.on("'r'", toggleReviewed())
|
||||||
.on("'o'", toggleOpenBox(cm))
|
.on("'o'", toggleOpenBox(cm))
|
||||||
.on("Enter", toggleOpenBox(cm))
|
.on("Enter", toggleOpenBox(cm))
|
||||||
@@ -369,18 +371,6 @@ public class SideBySide2 extends Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("[", new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
(header.hasPrev() ? header.prev : header.up).go();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("]", new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
(header.hasNext() ? header.next : header.up).go();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("','", new Runnable() {
|
.on("','", new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
Reference in New Issue
Block a user