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() {
|
||||
return hasPrev;
|
||||
Runnable navigate(Direction dir) {
|
||||
switch (dir) {
|
||||
case PREV:
|
||||
return new Runnable() {
|
||||
@Override
|
||||
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() {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
boolean hasNext() {
|
||||
return hasNext;
|
||||
}
|
||||
|
||||
String getNextPath() {
|
||||
|
||||
@@ -348,6 +348,8 @@ public class SideBySide2 extends Screen {
|
||||
cm.addKeyMap(KeyMap.create()
|
||||
.on("'a'", upToChange(true))
|
||||
.on("'u'", upToChange(false))
|
||||
.on("[", header.navigate(Direction.PREV))
|
||||
.on("]", header.navigate(Direction.NEXT))
|
||||
.on("'r'", toggleReviewed())
|
||||
.on("'o'", 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() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Reference in New Issue
Block a user