www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/mv_helpmenu.m

    function h = mv_helpmenu(fig,extras)
%MV_HELPMENU Add a help menu to a figure
%
%  MV_HELPMENU(FIG) adds a Model-Based Calibration Toolbox help menu to the
%  figure fig.
%
%  MV_HELPMENU(FIG,str) where str is a M*2 cell array of strings and
%  corresponding help destination codes adds M additional entries to the
%  Help menu with callbacks pointing to the correct destination.

%  Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.


if fig==0
    % dispatcher
    i_helpCB([],[],extras);
    h = [];
else
    if nargin>1
        % create menu items
        h = i_createmenus(fig,extras);
    else
        h = i_createmenus(fig);
    end
end


function hm = i_createmenus(fig,extras)

% search for pre-existing one to alter
hm = findobj(fig,'Type','uimenu','Tag','MBC_Help');

if isempty(hm)
    % Top level "Help" on menu bar
    hm = uimenu('Parent',fig,'Label','&Help','Interruptible','off','Tag','MBC_Help');

    % Add basic help entry
    acc = uimenu('Parent',hm,'Label','Model-Based Calibration &Help',...
        'Callback',{@i_helpCB,''},...
        'Interruptible','off');

    % add any extras
    if nargin>1
        for n = 1:size(extras,1)
            uim = uimenu('Parent',hm,'Label',extras{n,1},...
                'Interruptible','off','Callback',{@i_helpCB,extras{n,2}});
            if n==1
                set(uim,'Separator','on');
                acc = uim;
            end
        end
    end

    % add about box link
    uimenu('Parent',hm,'Label','&About Model-Based Calibration',...
        'Callback','xregabout;','Separator','on','Interruptible','off');

    set(acc,'Accelerator','H');
else
    % alter current menu list
    hc = get(hm,'Children');
    if nargin<2
        extras = {};
    end

    % first and last are standard ones.  Any central ones are center options
    numnow = (length(hc)-2);
    numwant = size(extras,1);

    if numnow>numwant
        % delete some menus
        delete(hc((end-(numnow-numwant)):(end-1)));
        hc = get(hm,'Children');
    elseif numnow<numwant
        % add some menus
        for n = 1:(numwant-numnow)
            uimenu('Parent',hm,'Interruptible','off');
        end
        % reorder menus so new ones are in the middle
        hc = get(hm,'Children');
        hc = hc([(numwant-numnow)+1 1:(numwant-numnow) (numwant-numnow)+2:end]);
        set(hm,'Children',hc);
    end
    hc = hc(end-1:-1:2);
    % set labels, callbacks on center ones
    for n = 1:numwant
        set(hc(n),'Label',extras{n,1},'Callback',{@i_helpCB,extras{n,2}},'Separator','off');
        if n==1
            set(hc(n),'Separator','on');
        end
    end
    % set up accelerator
    hc = get(hm,'Children');
    if numwant==0
        set(hc(end),'Accelerator','H');
    else
        set(hc,'Accelerator','');
        set(hc(2),'Accelerator','H');
    end
end


function i_helpCB(src, evt, helpTag)
hFig = mbcfindfigure(src);
if ~isempty(hFig) && strcmp(get(hFig, 'WindowStyle'), 'modal');
    mv_helptool(helpTag, hFig);
else
    mv_helptool(helpTag);
end