X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTApplication.java;h=91d2e98d7c039da4aeb9d01c84bb33385f762772;hb=55d2b2c2b29ce51f4f910448a115073371deeae8;hp=e9a7a44c62ddb4c9cd53b17a3ca7eee35e8985b8;hpb=1d14ffab43232e04a7d60ac496152510fa47b407;p=fanfix.git diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index e9a7a44..91d2e98 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -370,6 +370,15 @@ public class TApplication implements Runnable { */ private Backend backend; + /** + * Get the Backend. + * + * @return the Backend + */ + public final Backend getBackend() { + return backend; + } + /** * Get the Screen. * @@ -772,6 +781,9 @@ public class TApplication implements Runnable { // wait until either the backend or the consumer threads have // something to do. try { + if (debugThreads) { + System.err.println("sleep " + timeout + " millis"); + } synchronized (this) { this.wait(timeout); } @@ -962,20 +974,35 @@ public class TApplication implements Runnable { 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 = null; - synchronized (accelerators) { - item = accelerators.get(keypressLowercase); + // See if this key matches an accelerator, and is not being + // shortcutted by the active window, and if so dispatch the menu + // event. + boolean windowWillShortcut = false; + for (TWindow window: windows) { + if (window.isActive()) { + if (window.isShortcutKeypress(keypress.getKey())) { + // We do not process this key, it will be passed to + // the window instead. + windowWillShortcut = true; + } + } } - if (item != null) { - if (item.isEnabled()) { - // Let the menu item dispatch - item.dispatch(); - return; + + if (!windowWillShortcut) { + TKeypress keypressLowercase = keypress.getKey().toLowerCase(); + TMenuItem item = null; + synchronized (accelerators) { + item = accelerators.get(keypressLowercase); + } + if (item != null) { + if (item.isEnabled()) { + // Let the menu item dispatch + item.dispatch(); + return; + } } } + // Handle the keypress if (onKeypress(keypress)) { return; @@ -1496,6 +1523,15 @@ public class TApplication implements Runnable { return false; } + /** + * Display the about dialog. + */ + protected void showAboutDialog() { + messageBox("About", "Jexer Version " + + this.getClass().getPackage().getImplementationVersion(), + TMessageBox.Type.OK); + } + /** * Method that TApplication subclasses can override to handle menu * events. @@ -1531,6 +1567,10 @@ public class TApplication implements Runnable { closeAllWindows(); return true; } + if (menu.getId() == TMenu.MID_ABOUT) { + showAboutDialog(); + return true; + } return false; } @@ -1656,7 +1696,7 @@ public class TApplication implements Runnable { * * @param event new event to add to the queue */ - public final void addMenuEvent(final TInputEvent event) { + public final void postMenuEvent(final TInputEvent event) { synchronized (fillEventQueue) { fillEventQueue.add(event); } @@ -1734,6 +1774,24 @@ public class TApplication implements Runnable { return windowMenu; } + /** + * Convenience function to add a default "Help" menu. + * + * @return the new menu + */ + public final TMenu addHelpMenu() { + TMenu helpMenu = addMenu("&Help"); + helpMenu.addDefaultItem(TMenu.MID_HELP_CONTENTS); + helpMenu.addDefaultItem(TMenu.MID_HELP_INDEX); + helpMenu.addDefaultItem(TMenu.MID_HELP_SEARCH); + helpMenu.addDefaultItem(TMenu.MID_HELP_PREVIOUS); + helpMenu.addDefaultItem(TMenu.MID_HELP_HELP); + helpMenu.addDefaultItem(TMenu.MID_HELP_ACTIVE_FILE); + helpMenu.addSeparator(); + helpMenu.addDefaultItem(TMenu.MID_ABOUT); + return helpMenu; + } + /** * Close all open windows. */ @@ -1742,11 +1800,8 @@ public class TApplication implements Runnable { if (activeMenu != null) { return; } - - synchronized (windows) { - for (TWindow window: windows) { - closeWindow(window); - } + while (windows.size() > 0) { + closeWindow(windows.get(0)); } }