www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@cgbrowser/docreateimportmenu.m

    function docreateimportmenu(h,impH)
%DOCREATEIMPORTMENU Create the Import menu items
%
%  DOCREATEIMPORTMENU(CGB, menuH) creates the import menu items below the
%  given parent menu handle.

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

tpI = cgtools.cgtypecollection;
tps = tpI.TypeObjects;
cats = tpI.CategoryObjects;

for catn = cats'
    for tpn=tps'
        if isa(tpn,class(catn)) && isfield(tpn.Actions,'import')
            % get add structure and create items
            imprt = tpn.Actions.import;
            prnt = impH;
            u = prnt;
            lvlnow = 0;
            for n = 1:length(imprt)
                if isfield(imprt, 'level')
                    if imprt(n).level>lvlnow
                        set(u,'Callback',{@i_doenablestatus,h});
                        prnt = u;
                        lvlnow = imprt(n).level;
                    elseif imprt(n).level==0
                        prnt = impH;
                        lvlnow = 0;
                    end
                else
                    prnt = impH;
                    lvlnow = 0;
                end
                u = i_createmenu( prnt,...
                    imprt(n).name,...
                    {@i_importmenucb,h,imprt(n).fcn},...
                    imprt(n).statusfcn );
            end
        end
    end
end
set(impH,'Callback',{@i_doenablestatus,h});

function u = i_createmenu( prnt, label, callback, enablecheckfcn )
u = uimenu('Parent',prnt,...
    'Label',label,...
    'Callback', callback,...
    'Interruptible','off');

% add a new property to hold the enable status check function!
mbcgui.hgclassesutil.addprop(u,'EnableCheckFcn');
set(u, 'EnableCheckFcn', enablecheckfcn);

function i_importmenucb(srv,evt,h,importfcn)
if h.lock
    PR = xregGui.PointerRepository;
    ptrID = PR.stackSetPointer(h.Figure,'watch');
    feval(importfcn,h.CurrentNode);
    PR.stackRemovePointer(h.Figure,ptrID);
    h.unlock
end


function i_doenablestatus(src,evt,h)
% check enable status of all import items
ch = get(src,'Children');
en = cell(size(ch));
nd = h.CurrentNode;
for n = 1:length(ch)
    stfcn = get(ch(n), 'EnableCheckFcn');
    if ~isempty(stfcn)
        allow = feval(stfcn,nd);
        if allow
            en{n} = 'on';
        else
            en{n} = 'off';
        end
    else
        en{n} = 'on';
    end
end
set(ch,{'Enable'},en);