www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/xregwinlist.m
function xregwinlist(fig) %XREGWINLIST Create submenu for "Window" menu item. % XREGWINLIST constructs a submenu under the "Window" menu item % of the current figure. The submenu can then be used to % change the current figure. To use WINLIST, the "Window" % menu item must have its 'Tag' property set to a string which is % common between all of the windows being gathered together % % XREGWINLIST(FIG) constructs the "Window" menu and it's subitems for figure % FIG. If a window menu exists then it is used as the base and it's tag is % used for searching for other windows. The default tag is 'xregWinList'. % % % Example: % fig_handle = figure; % xregwinlist(fig_handle); % Initialize the submenu % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. if (nargin == 0) fig = gcf; end h=findobj(allchild(fig),'flat','Type','uimenu', 'Tag','xregWinList'); if isempty(h) h=uimenu('Parent',fig,'Label','&Window','Callback',@i_createsublist,.... 'Tag','xregWinList'); % Menu item to make it work first time uimenu('Parent',h,'Label','init'); end return function i_createsublist(h,~) tg=get(h,'Tag'); % only get items from figures with similar window menus figs=get(findobj(allchild(0),'Type','uimenu','Tag',tg,'Label','&Window'),{'Parent'}); figs=[figs{:}]; figs=findobj(figs,'flat','Visible','on'); % figs=-sort(-figs); % get list of text and filter out blanks etc figName = get(figs,{'Name'}); intHandle = get(figs,{'IntegerHandle'}); numTitle = get(figs,{'NumberTitle'}); N=length(figs); lbls=cell(N,1); for k=1:N if (strcmp(numTitle{k},'on')) if strcmp(intHandle{k},'on'), if (isempty(figName)) lbls(k)={sprintf('&%d Figure No. %d',N-k+1,figs(k))}; else lbls(k)= {sprintf('&%d Figure No. %d: %s',N-k+1,figs(k),i_detokenise(figName{k}))}; end else if (isempty(figName)) lbls(k)={sprintf('&%d Figure No. %.8f',N-k+1,figs(k))}; else lbls(k)= {sprintf('&%d Figure No. %.8f: %s',N-k+1,figs(k),i_detokenise(figName{k}))}; end end else % numTitle is off. if (isempty(figName{k})) lbls(k)={''}; else % Filter names for the string ' - ' and only take everything before this lbls(k)={sprintf('&%d %s',N-k+1,i_detokenise(figName{k}))}; end end end FigsToDo=find(~cellfun('isempty',lbls)); % Create/delete sub-uimenus as needed N=length(FigsToDo); winds=get(h,'Children'); if N>length(winds) for k=N:-1:(length(winds)+1) uimenu('Parent',h); end winds=get(h,'Children'); elseif N<length(winds) delete(winds(N+1:end)); winds=winds(1:N); end MyPrnt=get(h,'Parent'); for k=FigsToDo(:)' set(winds(k),'Label',lbls{k},'Callback',{@iBringToFront,figs(k)}); if figs(k)==MyPrnt set(winds(k),'Checked','on'); else set(winds(k),'Checked','off'); end end return function str=i_detokenise(str) tok=strfind(str,' - '); if ~isempty(tok) str= str(1:tok(1)-1); end return function iBringToFront(~,~,hFig) figure(hFig)