X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fmenu%2FTMenu.java;h=dbbea82bd1a9509dcd2bdd6a4e576cec84d57176;hb=e23ea53820244957b17a7000c6d3e1ff586f1ef0;hp=3120635996e503fd43feb4bc24d3c031c43911bf;hpb=051e29138b18fb4b731a72f8727475b10e4c74e4;p=fanfix.git diff --git a/src/jexer/menu/TMenu.java b/src/jexer/menu/TMenu.java index 3120635..dbbea82 100644 --- a/src/jexer/menu/TMenu.java +++ b/src/jexer/menu/TMenu.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -58,45 +58,48 @@ public class TMenu extends TWindow { // Reserved menu item IDs public static final int MID_UNUSED = -1; + // Tools menu + public static final int MID_REPAINT = 1; + public static final int MID_VIEW_IMAGE = 2; + public static final int MID_CHANGE_FONT = 3; + // File menu - public static final int MID_EXIT = 1; + public static final int MID_NEW = 10; + public static final int MID_EXIT = 11; public static final int MID_QUIT = MID_EXIT; - public static final int MID_OPEN_FILE = 2; - public static final int MID_SHELL = 3; + public static final int MID_OPEN_FILE = 12; + public static final int MID_SHELL = 13; // Edit menu - public static final int MID_CUT = 10; - public static final int MID_COPY = 11; - public static final int MID_PASTE = 12; - public static final int MID_CLEAR = 13; + public static final int MID_CUT = 20; + public static final int MID_COPY = 21; + public static final int MID_PASTE = 22; + public static final int MID_CLEAR = 23; // Search menu - public static final int MID_FIND = 20; - public static final int MID_REPLACE = 21; - public static final int MID_SEARCH_AGAIN = 22; - public static final int MID_GOTO_LINE = 23; + public static final int MID_FIND = 30; + public static final int MID_REPLACE = 31; + public static final int MID_SEARCH_AGAIN = 32; + public static final int MID_GOTO_LINE = 33; // Window menu - public static final int MID_TILE = 30; - public static final int MID_CASCADE = 31; - public static final int MID_CLOSE_ALL = 32; - public static final int MID_WINDOW_MOVE = 33; - public static final int MID_WINDOW_ZOOM = 34; - public static final int MID_WINDOW_NEXT = 35; - public static final int MID_WINDOW_PREVIOUS = 36; - public static final int MID_WINDOW_CLOSE = 37; + public static final int MID_TILE = 40; + public static final int MID_CASCADE = 41; + public static final int MID_CLOSE_ALL = 42; + public static final int MID_WINDOW_MOVE = 43; + public static final int MID_WINDOW_ZOOM = 44; + public static final int MID_WINDOW_NEXT = 45; + public static final int MID_WINDOW_PREVIOUS = 46; + public static final int MID_WINDOW_CLOSE = 47; // Help menu - public static final int MID_HELP_CONTENTS = 40; - public static final int MID_HELP_INDEX = 41; - public static final int MID_HELP_SEARCH = 42; - public static final int MID_HELP_PREVIOUS = 43; - public static final int MID_HELP_HELP = 44; - public static final int MID_HELP_ACTIVE_FILE = 45; - public static final int MID_ABOUT = 46; - - // Other - public static final int MID_REPAINT = 50; + public static final int MID_HELP_CONTENTS = 50; + public static final int MID_HELP_INDEX = 51; + public static final int MID_HELP_SEARCH = 52; + public static final int MID_HELP_PREVIOUS = 53; + public static final int MID_HELP_HELP = 54; + public static final int MID_HELP_ACTIVE_FILE = 55; + public static final int MID_ABOUT = 56; // ------------------------------------------------------------------------ // Variables -------------------------------------------------------------- @@ -161,6 +164,7 @@ public class TMenu extends TWindow { @Override public void onMouseDown(final TMouseEvent mouse) { this.mouse = mouse; + super.onMouseDown(mouse); // Pass to children for (TWidget widget: getChildren()) { @@ -341,7 +345,7 @@ public class TMenu extends TWindow { hLineXY(1 + 1, getHeight() - 1, getWidth() - 4, cHSide, background); // Draw a shadow - getScreen().drawBoxShadow(0, 0, getWidth(), getHeight()); + drawBoxShadow(0, 0, getWidth(), getHeight()); } // ------------------------------------------------------------------------ @@ -387,6 +391,21 @@ public class TMenu extends TWindow { return addItemInternal(id, label, null); } + /** + * Convenience function to add a menu item. + * + * @param id menu item ID. Must be greater than 1024. + * @param label menu item label + * @param enabled default state for enabled + * @return the new menu item + */ + public TMenuItem addItem(final int id, final String label, + final boolean enabled) { + + assert (id >= 1024); + return addItemInternal(id, label, null, enabled); + } + /** * Convenience function to add a custom menu item. * @@ -492,6 +511,22 @@ public class TMenu extends TWindow { switch (id) { + case MID_REPAINT: + label = i18n.getString("menuRepaintDesktop"); + break; + + case MID_VIEW_IMAGE: + label = i18n.getString("menuViewImage"); + break; + + case MID_CHANGE_FONT: + label = i18n.getString("menuChangeFont"); + break; + + case MID_NEW: + label = i18n.getString("menuNew"); + break; + case MID_EXIT: label = i18n.getString("menuExit"); key = kbAltX; @@ -592,10 +627,6 @@ public class TMenu extends TWindow { label = i18n.getString("menuHelpAbout"); break; - case MID_REPAINT: - label = i18n.getString("menuRepaintDesktop"); - break; - default: throw new IllegalArgumentException("Invalid menu ID: " + id); }