www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@cgbrowser/openproject.m
function OK= openproject(h, FILE, forceflag,addFile) %OPENPROJECT Open a new project file % % OPENPROJECT(CGB) asks the user for a file to open using the standard % file chooser dialog and then opens it. The function returns true if a % new project has been correctly opened, false otherwise. % OPENPROJECT(CGB, FILE) opens the specified file. % OPENPROJECT(CGB, FILE, true) opens the specified file and closes the % current project without saving it. % % In all cases, the file will not be opened if the current project is not % correctly closed for any reason. % Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin < 3 forceflag = false; end if nargin < 4 addFile = true; end if h.GUIExists ProjectPtr = h.RootNode; cnode = h.CurrentNode; csubitem = h.CurrentSubItem; msgID = h.addStatusMsg('Closing current project...'); h.setnewnode(xregpointer, xregpointer); if nargin<2 [Filename,Pathname] = uigetfile(mbcGetPath('cage', 'Projects', '*.cag'),'Open Project'); else [Pathname, Filename, ext] = fileparts(FILE); if isempty(Pathname) % Look for file on path FILE = which(FILE); [Pathname, Filename, ext] = fileparts(FILE); end Filename = [Filename ext]; end OK = false; if Filename~=0 % close without delete [OldMP,msg] = close(ProjectPtr.info, forceflag,[cnode csubitem]); if isempty(msg) h.removeStatusMsg(msgID); msgID = h.addStatusMsg(sprintf('Opening file: %s', fullfile(Pathname,Filename))); % allow the project to be renamed if it is open, but prompt the user first: [MP,msg] = load(OldMP,fullfile(Pathname,Filename),1,1,addFile); if isempty(msg) && ~isempty(MP) % delete old project deleteproject(OldMP); setmodified(MP,1); p = address(MP); h.RootNode = p; mbcutils.GenericTableProvider.Instance.addTableProvider(cgtools.CageTableProvider(address(MP))); if addFile && strcmp(fullfile(Pathname,Filename),projectfile(MP)) % if the project has been loaded under a different name, we won't % add it to the file list until it is saved. h.addToFileList(MP); end OK = 1; else % reselect current node h.setnewnode(cnode, csubitem); if ~forceflag && ~isempty(msg) errordlg(['Failed to load project ',Filename ': ' msg], 'Error', 'modal'); end end else % reselect current node h.setnewnode(cnode, csubitem); end else h.setnewnode(cnode, csubitem); end h.removeStatusMsg(msgID); end