www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cageview/+project/ProjectActions.m

    classdef ProjectActions < handle
    %ProjectActions CAGE project actions
    
    %  Copyright 2016 The MathWorks, Inc. 

    properties (Constant)
        %Examples list of examples to be displayed
        Examples = struct('FileName',{'gasolineOneStage.cag','CI_MultiInject.cag','Gasoline_optimization.cag'},...
            'Description',{'Dual CAM gasoline engine with spark optimized during testing','Multi-injection diesel tested with pilot injection on and off','Dual CAM gasoline engine with spark'},...
            'Type',{'One-stage','Point-by-point','Two-Stage'},...
            'HelpTag',{'GasolineOneStage','DieselPtByPt','GasolineTwoStage'},...
            'Icon',{'gloreg.bmp','modelSwitch.bmp','mle2.bmp'});
    end
    
    properties (SetAccess=private)
        %NewProject new project action
        NewProject
        %OpenProject open project action
        OpenProject
        %Browser CAGE browser handle
        Browser
    end
    
    properties (Dependent,SetAccess=private)
        %RecentFiles list of recent files
        RecentFiles
    end
    
    methods
        function obj = ProjectActions(Browser)
        %ProjectActions constructor 
        obj.Browser = Browser;
        obj.NewProject = mbcgui.actions.StatefulAction(@obj.onNewProject,'New Project',...
            '',xregrespath('fileNew.bmp'));
        obj.OpenProject = mbcgui.actions.StatefulAction(@obj.onOpenProject,'Open Project',...
            '',xregrespath('fileOpen.bmp'));
        end
        
        function files = get.RecentFiles(obj) %#ok<MANU>
        %list of recent files from preferences for CAGE 
        AP = mbcprefs('mbc');
        cgbprefs = getpref(AP,'cgbrowser');
        if ~isempty(cgbprefs.FileList)
            files = {cgbprefs.FileList.File};
        else
            files = {};
        end
        end
        
        function open(obj,file,addFile)
        %open open file 
        %   open(obj,file,addFile)
        %    addFile is a boolean flag to add file to recent file
        if nargin<3
            addFile = true;
        end
        % call cgbrowser method
        openproject(obj.Browser,file,false,addFile);
        end
    end
    
    
    methods 
        function onNewProject(obj,~,~) 
        %onNewProject create new project in browser
        % call cgbrowser method
        newproject(obj.Browser);
        
        end
        
        function onOpenProject(obj,~,~) 
        %onBrowse browse for a project
        
        % call cgbrowser method
        openproject(obj.Browser);
        
        end
    end
    
end