Fix mouse on menu line
[nikiroo-utils.git] / src / jexer / menu / TMenu.java
index 0e948cee0df2fbb7845a53bcf76e6a64074da37e..b9641e1eab4a31fd0179ffed4cb53e4e040d66e8 100644 (file)
@@ -56,6 +56,29 @@ public final class TMenu extends TWindow {
      */
     boolean isSubMenu = false;
 
+    /**
+     * The X position of the menu's title.
+     */
+    private int titleX;
+
+    /**
+     * Set the menu title X position.
+     *
+     * @param titleX the position
+     */
+    public void setTitleX(final int titleX) {
+        this.titleX = titleX;
+    }
+
+    /**
+     * Get the menu title X position.
+     *
+     * @return the position
+     */
+    public int getTitleX() {
+        return titleX;
+    }
+
     /**
      * The shortcut and title.
      */
@@ -104,6 +127,9 @@ public final class TMenu extends TWindow {
     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 constructor.
      *
@@ -346,6 +372,23 @@ public final class TMenu extends TWindow {
         return addItemInternal(id, label, key);
     }
 
+    /**
+     * Convenience function to add a custom menu item.
+     *
+     * @param id menu item ID.  Must be greater than 1024.
+     * @param label menu item label
+     * @param key global keyboard accelerator
+     * @param enabled default state for enabled
+     * @return the new menu item
+     */
+    public TMenuItem addItem(final int id, final String label,
+        final TKeypress key, final boolean enabled) {
+
+        TMenuItem item = addItem(id, label, key);
+        item.setEnabled(enabled);
+        return item;
+    }
+
     /**
      * Convenience function to add a custom menu item.
      *
@@ -477,6 +520,10 @@ public final 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);
         }