}
/**
- * Convenience function to add a custom menu item.
+ * Convenience function to add a menu item.
*
* @param id menu item ID. Must be greater than 1024.
* @param label menu item label
- * @param key global keyboard accelerator
* @return the new menu item
*/
- public final TMenuItem addItem(final int id, final String label,
- final TKeypress key) {
-
+ public final TMenuItem addItem(final int id, final String label) {
assert (id >= 1024);
- return addItemInternal(id, label, key);
+ return addItemInternal(id, label, null);
}
/**
* @param key global keyboard accelerator
* @return the new menu item
*/
- private TMenuItem addItemInternal(final int id, final String label,
+ public final TMenuItem addItem(final int id, final String label,
final TKeypress key) {
- int newY = getChildren().size() + 1;
- assert (newY < getHeight());
-
- TMenuItem menuItem = new TMenuItem(this, id, 1, newY, label);
- menuItem.setKey(key);
- setHeight(getHeight() + 1);
- if (menuItem.getWidth() + 2 > getWidth()) {
- setWidth(menuItem.getWidth() + 2);
- }
- for (TWidget widget: getChildren()) {
- widget.setWidth(getWidth() - 2);
- }
- getApplication().addAccelerator(menuItem, key.toLowerCase());
- getApplication().recomputeMenuX();
- activate(0);
- return menuItem;
+ assert (id >= 1024);
+ return addItemInternal(id, label, key);
}
/**
- * Convenience function to add a menu item.
+ * 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
* @return the new menu item
*/
- public final TMenuItem addItem(final int id, final String label) {
- assert (id >= 1024);
- return addItemInternal(id, label);
- }
+ private TMenuItem addItemInternal(final int id, final String label,
+ final TKeypress key) {
- /**
- * Convenience function to add a menu item.
- *
- * @param id menu item ID
- * @param label menu item label
- * @return the new menu item
- */
- private TMenuItem addItemInternal(final int id, final String label) {
int newY = getChildren().size() + 1;
assert (newY < getHeight());
TMenuItem menuItem = new TMenuItem(this, id, 1, newY, label);
+ menuItem.setKey(key);
setHeight(getHeight() + 1);
if (menuItem.getWidth() + 2 > getWidth()) {
setWidth(menuItem.getWidth() + 2);
for (TWidget widget: getChildren()) {
widget.setWidth(getWidth() - 2);
}
+ getApplication().addMenuItem(menuItem);
getApplication().recomputeMenuX();
activate(0);
return menuItem;
String label;
TKeypress key = null;
- boolean hasKey = true;
switch (id) {
case MID_SHELL:
label = "O&S Shell";
- hasKey = false;
break;
case MID_OPEN_FILE:
break;
case MID_CLEAR:
label = "C&lear";
- hasKey = false;
// key = kbDel;
break;
case MID_TILE:
label = "&Tile";
- hasKey = false;
break;
case MID_CASCADE:
label = "C&ascade";
- hasKey = false;
break;
case MID_CLOSE_ALL:
label = "Cl&ose All";
- hasKey = false;
break;
case MID_WINDOW_MOVE:
label = "&Size/Move";
break;
case MID_WINDOW_CLOSE:
label = "&Close";
- hasKey = false;
// key = kbCtrlW;
break;
throw new IllegalArgumentException("Invalid menu ID: " + id);
}
- if (hasKey) {
- return addItemInternal(id, label, key);
- }
- return addItemInternal(id, label);
+ return addItemInternal(id, label, key);
}
/**