mirror of
https://github.com/electron/electron.git
synced 2026-01-26 15:58:07 -05:00
cocoa: Enable modifying initialized menu
This commit is contained in:
@@ -39,6 +39,9 @@ class MenuModel;
|
||||
// to the contents of the model after calling this will not be noticed.
|
||||
- (id)initWithModel:(ui::MenuModel*)model;
|
||||
|
||||
// Populate current NSMenu with |model|.
|
||||
- (void)populateWithModel:(ui::MenuModel*)model;
|
||||
|
||||
// Programmatically close the constructed menu.
|
||||
- (void)cancel;
|
||||
|
||||
|
||||
@@ -93,6 +93,22 @@ int EventFlagsFromNSEvent(NSEvent* event) {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)populateWithModel:(ui::MenuModel*)model {
|
||||
if (!menu_)
|
||||
return;
|
||||
|
||||
model_ = model;
|
||||
[menu_ removeAllItems];
|
||||
|
||||
const int count = model->GetItemCount();
|
||||
for (int index = 0; index < count; index++) {
|
||||
if (model->GetTypeAt(index) == ui::MenuModel::TYPE_SEPARATOR)
|
||||
[self addSeparatorToMenu:menu_ atIndex:index];
|
||||
else
|
||||
[self addItemToMenu:menu_ atIndex:index fromModel:model];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancel {
|
||||
if (isMenuOpen_) {
|
||||
[menu_ cancelTracking];
|
||||
|
||||
Reference in New Issue
Block a user