www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+project/ProjectPane.m
classdef ProjectPane < mbcgui.multiview.View %ProjectPane panel containing recent files and examples. % Copyright 2016-2016 The MathWorks, Inc. properties (SetAccess=private) %RecentList list for recent files RecentList %ExamplesList list for example projects ExamplesList %OpenRecentButton open recent files from list OpenRecentButton %Title title text for project pane Title end properties %ProjectActions project actions object ProjectActions end properties (Dependent) %Examples shortcut to ProjectActions.Examples Examples %RecentFiles shortcut to ProjectActions.RecentFiles RecentFiles end methods function obj = ProjectPane(varargin) %ProjectPane constructor obj@mbcgui.multiview.View(varargin{:}) create(obj); end function t = gettitle(obj) %#ok<MANU> t = 'Project Manager'; end function create(obj) %create create layout col = mbcgui.util.SystemColorsDbl.COMMONTASKS; backGround = mbcgui.container.layoutpanel('Parent',obj.Parent, ... 'LayoutBorder',[10 0 10 3],... 'BorderType','etchedin',... 'BackgroundColor', col); obj.Title = uicontrol('Parent',backGround,... 'Style','text',... 'HorizontalAlignment','left',... 'FontSize',10,... 'BackgroundColor',col,... 'FontWeight','bold',... 'String','Projects'); div1 = xregGui.dividerline('Parent',backGround); div2 = xregGui.dividerline('Parent',backGround); div3 = xregGui.dividerline('Parent',backGround); newButton =mbcWorkflowItem('Parent',backGround,... 'Action',obj.ProjectActions.NewProject,... 'TransparentColor', [0 255 0]); openButton =mbcWorkflowItem('Parent',backGround,... 'Action',obj.ProjectActions.OpenProject,... 'TransparentColor', [0 255 0]); % recent files section t = uicontrol('Parent',backGround,...; 'Style','text',... 'HorizontalAlignment','left',... 'BackgroundColor',col,... 'FontSize',10,... 'String','Recent projects:'); obj.RecentList = uicontrol('Parent',backGround,... 'Callback',@obj.onOpenRecent,... 'Style','list'); obj.OpenRecentButton = uicontrol('Parent',backGround,... 'Style','pushbutton',... 'HorizontalAlignment','left',... 'Callback',@obj.onOpenRecentButton,... 'String','Open Recent Project'); % examples section for project pane examplesTitle = uicontrol('Parent',backGround,... 'Style','text',... 'HorizontalAlignment','left',... 'FontSize',10,... 'BackgroundColor',col,... 'FontWeight','bold',... 'String','Case Studies'); obj.ExamplesList = mbcwidgets.List('Parent',backGround,... 'IconLocation',xregrespath,... 'ColumnWidths',250,... 'Tag','ExamplesList',... 'ActionPerformedCallback',@obj.onOpenExample); obj.ExamplesList.setData( {obj.Examples.Description}', {obj.Examples.Icon}'); obj.ExamplesList.ColumnHeaders = {'Examples'}; obj.ExamplesList.SelectedRows = 1; hOpenExample = uicontrol('Parent',backGround,... 'Style','pushbutton',... 'HorizontalAlignment','left',... 'TooltipString','Open example project and help',... 'Callback',@obj.onOpenExampleButton,... 'Tag','OpenExample',.... 'String','Open Example'); hHelp = uicontrol('Parent',backGround,... 'Style','pushbutton',... 'HorizontalAlignment','left',... 'Callback',@obj.onOpenHelp,... 'String','Help'); lyt = xreggridbaglayout(backGround,... 'dimension',[14 2],... 'gapy',5,... 'gapx',10,... 'ColSizes',[-1 -1],... 'rowsizes',[18 3 25 25 3 18 120 25 2 18 2 120 25 -1],... 'elements',{obj.Title,[] div1,[] newButton,[] openButton,[] [] [] t [] obj.RecentList [] [] obj.OpenRecentButton div2 [] examplesTitle [] div3 [] obj.ExamplesList [] hHelp hOpenExample [] []},... 'MergeBlock',{[1 1],[1 2]},... 'MergeBlock',{[2 2],[1 2]},... 'MergeBlock',{[3 3],[1 2]},... 'MergeBlock',{[4 4],[1 2]},... 'MergeBlock',{[7 7],[1 2]},... 'MergeBlock',{[9 9],[1 2]},... 'MergeBlock',{[11 11],[1 2]},... 'MergeBlock',{[12 12],[1 2]}); backGround.LayoutComponent = lyt; obj.ContentHandle = backGround; addMessageServiceListener(obj, 'NodeChanged',@obj.onNodeChanged) end function ex = get.Examples(obj) ex = obj.ProjectActions.Examples; end function files = get.RecentFiles(obj) files = obj.ProjectActions.RecentFiles; end function onNodeChanged(obj,~,~) %onNodeChanged update recent files on load update(obj) end function onOpenRecent(obj,~,~) %onOpenRecent open recent file by double clicking on list fig = ancestor(obj.Parent,'figure'); if strcmp(fig.SelectionType,'open') openRecent(obj) end end function onOpenRecentButton(obj,~,~) %onOpenRecentButton open recent file by double clicking on button openRecent(obj) end function openRecent(obj) %onOpenRecent open recent file file = obj.RecentFiles{obj.RecentList.Value}; open(obj.ProjectActions,file); end function update(obj) %update update list of recent files files = obj.RecentFiles; lbls = files; for i=1:length(files) lbls{i} = displayFileName(files{i}); end set(obj.OpenRecentButton,'Enable',mbconoff(~isempty(files))) set(obj.RecentList,'String',lbls); end function onOpenExample(obj,~,evt) %onOpenExample open example by double clicking on list row = evt.Data.SelectedRows; openExample(obj,row) end function onOpenExampleButton(obj,~,~) %onOpenExample open example by button row = obj.ExamplesList.SelectedRows; if isscalar(row) openExample(obj,row) end end function onOpenHelp(obj,~,~) %onOpenHelp open help callback row = obj.ExamplesList.SelectedRows; openHelp(obj,row) end function openHelp(obj,row) %openHelp open help from help or open button if isscalar(row) ex = obj.Examples(row); mv_helptool(ex.HelpTag); end end function openExample(obj,row) %openExample open example project from list if isscalar(row) ex = obj.Examples(row); file = fullfile(mbcpath,'mbctraining',ex.FileName); open(obj.ProjectActions,file,false); openHelp(obj,row) end end end end function [lbl,file] = displayFileName(file) %displayFileName display name for recent file [~,fname,ext]=fileparts(file); if length(file)>35 % replace inner folder names with ... lbl=[file(1:3) '...',filesep,fname,ext]; else lbl = file; end end