Bug fixes
[fanfix.git] / src / jexer / TWindow.java
index 26bd8c453a1922bfd8f79b47c61b35f1470ae429..73026953eaa2aa5ffaa5985f6489d9fb1170e2e8 100644 (file)
@@ -28,6 +28,8 @@
  */
 package jexer;
 
+import java.util.HashSet;
+
 import jexer.bits.Cell;
 import jexer.bits.CellAttributes;
 import jexer.bits.GraphicsChars;
@@ -137,6 +139,48 @@ public class TWindow extends TWidget {
         this.z = z;
     }
 
+    /**
+     * Window's keyboard shortcuts.  Any key in this set will be passed to
+     * the window directly rather than processed through the menu
+     * accelerators.
+     */
+    private HashSet<TKeypress> keyboardShortcuts = new HashSet<TKeypress>();
+
+    /**
+     * Add a keypress to be overridden for this window.
+     *
+     * @param key the key to start taking control of
+     */
+    protected void addShortcutKeypress(final TKeypress key) {
+        keyboardShortcuts.add(key);
+    }
+
+    /**
+     * Remove a keypress to be overridden for this window.
+     *
+     * @param key the key to stop taking control of
+     */
+    protected void removeShortcutKeypress(final TKeypress key) {
+        keyboardShortcuts.remove(key);
+    }
+
+    /**
+     * Remove all keypresses to be overridden for this window.
+     */
+    protected void clearShortcutKeypresses() {
+        keyboardShortcuts.clear();
+    }
+
+    /**
+     * Determine if a keypress is overridden for this window.
+     *
+     * @param key the key to check
+     * @return true if this window wants to process this key on its own
+     */
+    public boolean isShortcutKeypress(final TKeypress key) {
+        return keyboardShortcuts.contains(key);
+    }
+
     /**
      * If true, then the user clicked on the title bar and is moving the
      * window.