if (x.key !== undefined)
Armin Ronacher , кажется уже, имеет , бьет меня к нему , но:
Object.prototype.hasOwnProperty = function(property) { return this[property] !== undefined; }; x = {'key': 1}; if (x.hasOwnProperty('key')) { alert('have key!'); } if (!x.hasOwnProperty('bar')) { alert('no bar!'); }
А более безопасное, но более медленное решение, , как указано Konrad Rudolph и Armin Ronacher был бы:
Object.prototype.hasOwnProperty = function(property) { return typeof this[property] !== 'undefined'; };
Вы можете получить Меню из MenuManager и затем изменить вклады. Этот фрагмент показывает, как получить доступ к диспетчеру меню и удалить именованный элемент.
Вам нужно будет отслеживать удаленные элементы и индексы элементов, чтобы восстановить их. Единственная проблема в том, что метод indexOf не виден. Добавление этого фрагмента к типу в том же пакете, что и MenuManager, и добавление его к фрагменту - это один из способов решения этой проблемы.
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
//TODO you may need to remove items from the coolbar as well
ICoolBarManager coolBarManager = null;
if(((WorkbenchWindow) window).getCoolBarVisible()) {
coolBarManager = ((WorkbenchWindow)window).getCoolBarManager2();
}
Menu menu = menuManager.getMenu();
//you'll need to find the id for the item
String itemId = "menuId";
IContributionItem item = menuManager.find(itemId);
// remember position, TODO this is protected
int controlIdx = menu.indexOf(mySaveAction.getId());
if (item != null) {
// clean old one
menuManager.remove(item);
// refresh menu gui
menuManager.update();
}
}