GUI MenuItem/menuBar fixes:
- ensure createItem returns the item - add an accessor for text() - don't do lazy view creation for now - skip aboutToShow until item iteration works for me
This commit is contained in:
parent
ba5fb926a2
commit
ede0844631
4 changed files with 23 additions and 15 deletions
|
@ -153,6 +153,10 @@ gui.MenuItem = {
|
|||
return me.update();
|
||||
},
|
||||
|
||||
text: func {
|
||||
return me._text;
|
||||
},
|
||||
|
||||
setShortcut: func(shortcut) {
|
||||
me._shortcut = keyboard.Shortcut.new(shortcut);
|
||||
if (me._parent_menu != nil and me._parent_menu._canvas_item != nil and me._cb != nil) {
|
||||
|
@ -165,9 +169,10 @@ gui.MenuItem = {
|
|||
_setParentMenu: func(m) {
|
||||
me._parent_menu = m;
|
||||
if (me._parent_menu != nil and me._parent_menu._canvas_item != nil and me._cb != nil) {
|
||||
if (me._shortcut != nil) {
|
||||
me._parent_menu._canvas_item.bindShortcut(me._shortcut, me._cb);
|
||||
}
|
||||
# fixme: add window-level shortcurt handling
|
||||
# if (me._shortcut != nil) {
|
||||
# me._parent_menu._canvas_item.bindShortcut(me._shortcut, me._cb);
|
||||
# }
|
||||
if (me._menu != nil) {
|
||||
for (var i = 0; i < me._menu.count(); i += 1) {
|
||||
me._menu.getItem(i).setCanvasItem(me._parent_menu._canvas_item);
|
||||
|
@ -178,7 +183,7 @@ gui.MenuItem = {
|
|||
|
||||
setIcon: func(icon) {
|
||||
me._icon = icon;
|
||||
me._view.setIcon(icon);
|
||||
me._view.setIcon(me, icon);
|
||||
return me.update();
|
||||
},
|
||||
|
||||
|
@ -190,6 +195,7 @@ gui.MenuItem = {
|
|||
update: func {
|
||||
if (me._view != nil) {
|
||||
me._view.update(me);
|
||||
me._view._updateLayoutSizes(me);
|
||||
}
|
||||
return me;
|
||||
},
|
||||
|
@ -253,7 +259,7 @@ gui.Menu = {
|
|||
}
|
||||
var item = gui.MenuItem.new(me._root, me.style, {text: text, cb: cb, shortcut: shortcut, icon: icon, enabled: enabled});
|
||||
me.addItem(item);
|
||||
return me;
|
||||
return item;
|
||||
},
|
||||
|
||||
# @description Create, insert and return a `canvas.gui.MenuItem with the given text and assign the given submenu to it,
|
||||
|
|
|
@ -18,9 +18,10 @@ var WidgetsFactoryDialog = {
|
|||
m.menubar.setCanvasItem(m.root);
|
||||
m.menubar.createMenu("File")
|
||||
.createItem(text: "Quit", cb: func m.del(), shortcut: "<Ctrl>+Q");
|
||||
m.menubar.createMenu("Tabs")
|
||||
.createItem(text: "Select first tab", cb: func m.tabs.setCurrentTab("tab-1"))
|
||||
.createItem(text: "Select second tab", cb: func m.tabs.setCurrentTab("tab-2"));
|
||||
var tabsMenu = m.menubar.createMenu("Tabs");
|
||||
tabsMenu.createItem(text: "Select first tab", cb: func m.tabs.setCurrentTab("tab-1"));
|
||||
tabsMenu.createItem(text: "Select second tab", cb: func m.tabs.setCurrentTab("tab-2"));
|
||||
|
||||
m.menubar.createMenu("Widgets")
|
||||
.createItem(text: "Benchmark label", cb: func {
|
||||
m.benchmark_widget(canvas.gui.widgets.Label, func(w, i) {
|
||||
|
|
|
@ -911,11 +911,13 @@ DefaultStyle.widgets["menu-item"] = {
|
|||
},
|
||||
|
||||
setShortcut: func(model, shortcut) {
|
||||
me._shortcut.setText(shortcut.repr());
|
||||
if (shortcut != nil) {
|
||||
me._shortcut.setText(shortcut.repr());
|
||||
}
|
||||
return me._updateLayoutSizes(model);
|
||||
},
|
||||
|
||||
setIcon: func(icon) {
|
||||
setIcon: func(model, icon) {
|
||||
if (!icon) {
|
||||
me._icon.hide();
|
||||
} else {
|
||||
|
|
|
@ -44,13 +44,12 @@ gui.widgets.MenuBar = {
|
|||
die("cannot create a submenu item without submenu");
|
||||
}
|
||||
var item = gui.MenuItem.new(me._view._items, style,
|
||||
{
|
||||
text: text, cb: nil, shortcut: nil, icon: nil, enabled: enabled,
|
||||
menu_position: gui.MenuItem.MenuPosition.Below,
|
||||
}
|
||||
{
|
||||
text: text, cb: nil, shortcut: nil, icon: nil, enabled: enabled,
|
||||
menu_position: gui.MenuItem.MenuPosition.Below,
|
||||
}
|
||||
);
|
||||
item._is_menubar_item = 1;
|
||||
item._view._updateLayoutSizes(item);
|
||||
item._setParentMenu(me);
|
||||
item.setMenu(menu);
|
||||
me._layout.addItem(item);
|
||||
|
|
Loading…
Add table
Reference in a new issue