X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTApplication.java;h=d2b8f446c4d15a5b519f3c55bdc590d787c884a2;hb=e826b451baf0d1e66d09ce03a6fefee2eb8386f5;hp=35aa32d0d0f5dd4c892ab4a3ae79db949b90effe;hpb=2b9c27db318b916730aa04f2b41bd3bff795a5dc;p=fanfix.git diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index 35aa32d..d2b8f44 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -34,8 +34,10 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import jexer.bits.CellAttributes; import jexer.bits.ColorTheme; @@ -109,6 +111,11 @@ public class TApplication { */ private TMenu activeMenu = null; + /** + * Active keyboard accelerators. + */ + private Map accelerators; + /** * Windows and widgets pull colors from this ColorTheme. */ @@ -204,6 +211,7 @@ public class TApplication { windows = new LinkedList(); menus = new LinkedList(); subMenus = new LinkedList(); + accelerators = new HashMap(); } /** @@ -394,8 +402,8 @@ public class TApplication { private void metaHandleEvent(final TInputEvent event) { /* - System.err.printf(String.format("metaHandleEvents event: %s\n", - event)); System.err.flush(); + System.err.printf(String.format("metaHandleEvents event: %s\n", + event)); System.err.flush(); */ if (quit) { @@ -404,16 +412,6 @@ public class TApplication { return; } - // DEBUG - if (event instanceof TKeypressEvent) { - TKeypressEvent keypress = (TKeypressEvent) event; - if (keypress.equals(kbAltX)) { - quit = true; - return; - } - } - // DEBUG - // Special application-wide events ------------------------------- // Abort everything @@ -530,15 +528,16 @@ public class TApplication { return; } - /* - TODO - if (event instanceof TKeypressEvent) { TKeypressEvent keypress = (TKeypressEvent) event; + // See if this key matches an accelerator, and if so dispatch the // menu event. TKeypress keypressLowercase = keypress.getKey().toLowerCase(); - TMenuItem item = accelerators.get(keypressLowercase); + TMenuItem item = null; + synchronized (accelerators) { + item = accelerators.get(keypressLowercase); + } if (item != null) { // Let the menu item dispatch item.dispatch(); @@ -550,7 +549,6 @@ public class TApplication { } } } - */ if (event instanceof TCommandEvent) { if (onCommand((TCommandEvent) event)) { @@ -1126,11 +1124,13 @@ public class TApplication { */ public final void addAccelerator(final TMenuItem item, final TKeypress keypress) { - /* - TODO - assert((keypress in accelerators) is null); - accelerators[keypress] = item; - */ + + // System.err.printf("addAccelerator: key %s item %s\n", keypress, item); + + synchronized (accelerators) { + assert (accelerators.get(keypress) == null); + accelerators.put(keypress, item); + } } /**