X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTApplication.java;h=28e35091ded6e1ef006190574e945c0426c41057;hb=c4cefaa04ec122fc02efb6542451a31fdf722c32;hp=e7ba0f853af5e2e087bc9c25d0384bb1a3d06a38;hpb=3d3e09e625a95ca9b005166f4a9924c9aadfc65c;p=fanfix.git diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index e7ba0f8..28e3509 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -29,6 +29,7 @@ package jexer; import java.io.File; +import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; @@ -62,6 +63,8 @@ import jexer.backend.Screen; import jexer.backend.SwingBackend; import jexer.backend.ECMA48Backend; import jexer.backend.TWindowBackend; +import jexer.help.HelpFile; +import jexer.help.Topic; import jexer.menu.TMenu; import jexer.menu.TMenuItem; import jexer.menu.TSubMenu; @@ -346,6 +349,16 @@ public class TApplication implements Runnable { */ private int screenSelectionY1; + /** + * The help file data. Note package private access. + */ + HelpFile helpFile; + + /** + * The stack of help topics. Note package private access. + */ + ArrayList helpTopics = new ArrayList(); + /** * WidgetEventHandler is the main event consumer loop. There are at most * two such threads in existence: the primary for normal case and a @@ -794,6 +807,27 @@ public class TApplication implements Runnable { } } + // Load the help system + invokeLater(new Runnable() { + /* + * This isn't the best solution. But basically if a TApplication + * subclass constructor throws and needs to use TExceptionDialog, + * it may end up at the bottom of the window stack with a bunch + * of modal windows on top of it if said constructors spawn their + * windows also via invokeLater(). But if they don't do that, + * and instead just conventionally construct their windows, then + * this exception dialog will end up on top where it should be. + */ + public void run() { + try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + helpFile = new HelpFile(); + helpFile.load(loader.getResourceAsStream("help.xml")); + } catch (Exception e) { + new TExceptionDialog(TApplication.this, e); + } + } + }); } // ------------------------------------------------------------------------ @@ -925,6 +959,15 @@ public class TApplication implements Runnable { return true; } + if (command.equals(cmHelp)) { + if (getActiveWindow() != null) { + new THelpWindow(this, getActiveWindow().getHelpTopic()); + } else { + new THelpWindow(this); + } + return true; + } + if (command.equals(cmShell)) { openTerminal(0, 0, TWindow.RESIZABLE); return true; @@ -976,6 +1019,62 @@ public class TApplication implements Runnable { return true; } + if (menu.getId() == TMenu.MID_HELP_HELP) { + new THelpWindow(this, THelpWindow.HELP_HELP); + return true; + } + + if (menu.getId() == TMenu.MID_HELP_CONTENTS) { + new THelpWindow(this, helpFile.getTableOfContents()); + return true; + } + + if (menu.getId() == TMenu.MID_HELP_INDEX) { + new THelpWindow(this, helpFile.getIndex()); + return true; + } + + if (menu.getId() == TMenu.MID_HELP_SEARCH) { + TInputBox inputBox = inputBox(i18n. + getString("searchHelpInputBoxTitle"), + i18n.getString("searchHelpInputBoxCaption"), "", + TInputBox.Type.OKCANCEL); + if (inputBox.isOk()) { + new THelpWindow(this, + helpFile.getSearchResults(inputBox.getText())); + } + return true; + } + + if (menu.getId() == TMenu.MID_HELP_PREVIOUS) { + if (helpTopics.size() > 1) { + Topic previous = helpTopics.remove(helpTopics.size() - 2); + helpTopics.remove(helpTopics.size() - 1); + new THelpWindow(this, previous); + } else { + new THelpWindow(this, helpFile.getTableOfContents()); + } + return true; + } + + if (menu.getId() == TMenu.MID_HELP_ACTIVE_FILE) { + try { + List filters = new ArrayList(); + filters.add("^.*\\.[Xx][Mm][Ll]$"); + String filename = fileOpenBox(".", TFileOpenBox.Type.OPEN, + filters); + if (filename != null) { + helpTopics = new ArrayList(); + helpFile = new HelpFile(); + helpFile.load(new FileInputStream(filename)); + } + } catch (Exception e) { + // Show this exception to the user. + new TExceptionDialog(this, e); + } + return true; + } + if (menu.getId() == TMenu.MID_SHELL) { openTerminal(0, 0, TWindow.RESIZABLE); return true; @@ -3331,6 +3430,9 @@ public class TApplication implements Runnable { */ public final TMenu addEditMenu() { TMenu editMenu = addMenu(i18n.getString("editMenuTitle")); + editMenu.addDefaultItem(TMenu.MID_UNDO, false); + editMenu.addDefaultItem(TMenu.MID_REDO, false); + editMenu.addSeparator(); editMenu.addDefaultItem(TMenu.MID_CUT, false); editMenu.addDefaultItem(TMenu.MID_COPY, false); editMenu.addDefaultItem(TMenu.MID_PASTE, false);