diff options
author | Dan Gudmundsson <[email protected]> | 2012-12-21 14:14:11 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2013-01-09 11:44:30 +0100 |
commit | 4400ec08aaa4c30272f502b5d8450dafec30f5dc (patch) | |
tree | 25e8a986294a7cc1d6793a68aaf3af5522b7a804 /lib/observer/src/observer_wx.erl | |
parent | 60f0eeddd23306efa3d5993c320b31e7ce942464 (diff) | |
download | otp-4400ec08aaa4c30272f502b5d8450dafec30f5dc.tar.gz otp-4400ec08aaa4c30272f502b5d8450dafec30f5dc.tar.bz2 otp-4400ec08aaa4c30272f502b5d8450dafec30f5dc.zip |
wx: Workaround wx-2.9 bugs
Menuhandling in 2.9 is (currently) buggy on mac,
this avoids a crash in menu handling but causes a lot unusable menus.
Diffstat (limited to 'lib/observer/src/observer_wx.erl')
-rw-r--r-- | lib/observer/src/observer_wx.erl | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/lib/observer/src/observer_wx.erl b/lib/observer/src/observer_wx.erl index 5625e69b6e..47740581f0 100644 --- a/lib/observer/src/observer_wx.erl +++ b/lib/observer/src/observer_wx.erl @@ -543,28 +543,36 @@ clean_menus(Menus, MenuBar) -> remove_menu_items(Menus, MenuBar). remove_menu_items([{MenuStr = "File", Menus}|Rest], MenuBar) -> - MenuId = wxMenuBar:findMenu(MenuBar, MenuStr), - Menu = wxMenuBar:getMenu(MenuBar, MenuId), - Items = [wxMenu:findItem(Menu, Tag) || #create_menu{text=Tag} <- Menus], - [wxMenu:delete(Menu, MItem) || MItem <- Items], - case os:type() =:= {unix, darwin} of - true -> - wxMenuBar:remove(MenuBar, MenuId), - wxMenu:destroy(Menu); - false -> - ignore - end, - remove_menu_items(Rest, MenuBar); + case wxMenuBar:findMenu(MenuBar, MenuStr) of + ?wxNOT_FOUND -> + remove_menu_items(Rest, MenuBar); + MenuId -> + Menu = wxMenuBar:getMenu(MenuBar, MenuId), + Items = [wxMenu:findItem(Menu, Tag) || #create_menu{text=Tag} <- Menus], + [wxMenu:delete(Menu, MItem) || MItem <- Items], + case os:type() =:= {unix, darwin} of + true -> + wxMenuBar:remove(MenuBar, MenuId), + wxMenu:destroy(Menu); + false -> + ignore + end, + remove_menu_items(Rest, MenuBar) + end; remove_menu_items([{"Nodes", _}|_], _MB) -> ok; remove_menu_items([{Tag, _Menus}|Rest], MenuBar) -> - MenuId = wxMenuBar:findMenu(MenuBar, Tag), - Menu = wxMenuBar:getMenu(MenuBar, MenuId), - wxMenuBar:remove(MenuBar, MenuId), - Items = wxMenu:getMenuItems(Menu), - [wxMenu:'Destroy'(Menu, Item) || Item <- Items], - wxMenu:destroy(Menu), - remove_menu_items(Rest, MenuBar); + case wxMenuBar:findMenu(MenuBar, Tag) of + ?wxNOT_FOUND -> + remove_menu_items(Rest, MenuBar); + MenuId -> + Menu = wxMenuBar:getMenu(MenuBar, MenuId), + wxMenuBar:remove(MenuBar, MenuId), + Items = wxMenu:getMenuItems(Menu), + [wxMenu:'Destroy'(Menu, Item) || Item <- Items], + wxMenu:destroy(Menu), + remove_menu_items(Rest, MenuBar) + end; remove_menu_items([], _MB) -> ok. @@ -592,15 +600,22 @@ epmd_nodes(Names) -> update_node_list(State = #state{menubar=MenuBar}) -> {Nodes, NodesMenuItems} = get_nodes(), - NodeMenuId = wxMenuBar:findMenu(MenuBar, "Nodes"), - NodeMenu = wxMenuBar:getMenu(MenuBar, NodeMenuId), - wx:foreach(fun(Item) -> wxMenu:'Destroy'(NodeMenu, Item) end, - wxMenu:getMenuItems(NodeMenu)), - + NodeMenu = case wxMenuBar:findMenu(MenuBar, "Nodes") of + ?wxNOT_FOUND -> + Menu = wxMenu:new(), + wxMenuBar:append(MenuBar, Menu, "Nodes"), + Menu; + NodeMenuId -> + Menu = wxMenuBar:getMenu(MenuBar, NodeMenuId), + wx:foreach(fun(Item) -> wxMenu:'Destroy'(Menu, Item) end, + wxMenu:getMenuItems(Menu)), + Menu + end, + Index = wx:foldl(fun(Record, Index) -> observer_lib:create_menu_item(Record, NodeMenu, Index) end, 0, NodesMenuItems), - + Dist = case erlang:is_alive() of true -> #create_menu{id = ?ID_PING, text = "Connect node"}; false -> #create_menu{id = ?ID_CONNECT, text = "Enable distribution"} |