www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcmultiview/@ActionMenuPlaceHolder/displayActions.m

    function displayActions(obj)
%DISPLAYACTIONS Put new actions into the managed menu point
%
%  DISPLAYACTIONS(OBJ) replaces the menu items that are currently being
%  displayed at this placeholder's menu point with a new set of Actions
%  taken from the current ActionGroup.

%  Copyright 2005-2013 The MathWorks, Inc. and Ford Global Technologies, Inc.


if isempty(obj.hPlaceHolder) || ~isgraphics(obj.hPlaceHolder)
    return
end

AG = obj.ActionGroup;

nMenusMade = length(obj.hActionMenus);
if nMenusMade>0
    % Reclaim all current menus
    set(obj.hActionMenus, 'Parent', obj.hPlaceHolder, 'UserData', [], 'Separator', 'off');
end

if ~isempty(AG)
    % Check whether more menus will need to be created
    hPlace = obj.hPlaceHolder;
    hParent = get(hPlace, 'Parent');
    nMenus = AG.numRequiredMenus;
    if nMenus>0
        if nMenus>nMenusMade
            for n = nMenusMade+1:nMenus
                uimenu('Parent', hPlace);
            end
            obj.hActionMenus = get(hPlace, 'Children');
        end

        mns = obj.hActionMenus(1:nMenus);

        ch_initial = get(hParent, 'Children');
        place_idx = find(ch_initial==hPlace);

        set(mns, 'Parent', hParent);

        % Reorder child list to get the menus in the correct place
        set(hParent, 'Children', [ch_initial(1:place_idx); mns(:); ch_initial(place_idx+1:end)]);

        AG.attachToMenu(mns(end:-1:1));
    end
end