www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@xregtools/@MBrowser/OpenProject.m

    function OK = OpenProject(h,FILE,addToRecent)
%OPENPROJECT Open a new project file
%
%  MB.OpenProject;
%  MB.OpenProject(FILE);

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

if nargin<3
    addToRecent = true;
end
ProjectPtr= h.RootNode;
cnode= h.CurrentNode;
msgID=h.addStatusMsg('Closing current project...');
OK=h.SelectNode(xregpointer);
if OK
    h.GUILocked= true;
    if nargin<2
        [Filename,Pathname] = uigetfile( mbcGetPath('mbcmodel', 'Projects', '*.mat'), 'Open Project');
    else
        [Pathname,Filename,ext] = fileparts(FILE);
        if isempty(Pathname)
            FILE = which(FILE);
            [Pathname,Filename,ext] = fileparts(FILE);
        end
        Filename=[Filename ext];
    end
    OK=0;
    if Filename~=0
        ProjectPtr.setmodified(h.FileModified);

        % close without delete
        [OldMP,msg,cancel]= close(ProjectPtr.info,0,cnode);
        if isempty(msg) && ~cancel
            h.removeStatusMsg(msgID);
            msgID=h.addStatusMsg(sprintf('Opening file: %s', fullfile(Pathname,Filename)));
            set(h.Figure,'Pointer','watch');

            [MP,msg]= load(OldMP, fullfile(Pathname,Filename));
            if isempty(msg)
                % delete old project
                delete(OldMP);

                h.FileModified(1);
                p= address(MP);
                h.RootNode= p;

                % update treeview
                treeview(MP,'refresh',h.Hand.Figure.TreeView,4);

                LastNode = getLastNode(MP);
                if ~isempty(LastNode) && isvalid(LastNode)
                    p = LastNode;
                end
                
                h.SelectNode(p,1);

                if addToRecent
                    % update file list	 (is this an mdevproject operation)
                    h.addToFileList(MP);
                end
                OK=1;
            else
                % reselect current node
                h.SelectNode(cnode, 1);
                errordlg(sprintf('Failed to load project %s\n%s',Filename,msg), 'Error', 'modal');
            end

            set(h.Figure,'Pointer',get(0,'DefaultFigurePointer'));

        else
            % reselect current node
            h.SelectNode(cnode,1);
        end
    else
        h.SelectNode(cnode,1);
    end
else
    h.SelectNode(h.CurrentNode,1);
    errordlg('Failed to close current project', 'Error', 'modal');
end
h.GUILocked=false;
h.removeStatusMsg(msgID);