📄 helpwindow.m
字号:
function helpwindow(topic,pagetitle,helptitle,varargin)
%HELPWIN On-line help, separate window for navigation.
% HELPWIN TOPIC opens a help window and displays the help text for the
% given TOPIC. Links are created to functions referenced in the 'See Also'
% line of the help text.
%
% HELPWIN(HELP_STR,TITLE) displays the string HELP_STR in the help
% window. HELP_STR may be passed in as a string with each line separated
% by carriage returns, a column vector cell array of strings with each cell
% (row) representing a line or as a string matrix with each row representing
% a line. The optional string TITLE will appear in the title edit box.
%
% HELPWIN({TITLE1 HELP_STR1;TITLE2 HELP_STR2;...},PAGE) displays one page
% of multi-page help text. The multi-page help text is passed in as a
% cell array of strings or cells containing TITLE and HELP_STR pairs.
% Each row of the multi-page help text cell array (dimensioned number of
% pages by 2) consists of a title string paired with a string, cell array
% or string matrix of help text. The second argument PAGE is a string
% which must match one of the TITLE entries in the multi-page help text.
% The matching TITLE represents the page that is to be displayed first.
% If no second argument is given, the first page is displayed.
%
% A third argument may be passed to HELPWIN which is a string that becomes
% the title of the help window figure.
%
% Additional arguments, after the window title, will be interpreted as
% Handle Graphics parameter-value pairs to be applied to the text displayed
% in the help window.
%
% Examples.
% helpwin plot
% helpwin('Help String','title')
% helpwin(['Help text for' sprintf('\n') 'my m-file.'],'title')
% helpwin({'Help String for';'my m-file'},'title')
% helpwin(str,'Topic 2','My Title')
% where,
% str = { 'Topic 1' 'Help string for Topic 1';
% 'Topic 2' 'Help string for Topic 2';
% 'Topic 3' 'Help string for Topic 3' }
%
% See also DOC, DOCOPT, HELP, WEB.
% Copyright (c) 1984-98 by The MathWorks, Inc.
% $Revision: 1.30 $
% If no arguments are given, load up the Home help page.
if nargin==0
topic = 'HelpwinHome';
end
% Switchyard on 'topic'. It is either a command or a help entry.
if iscell(topic),
cmd = char(topic(1,1));
else
cmd = char(topic(1,:));
end
switch cmd
%-----------------------------------------------------------------------
case 'HelpwinPage'
% This case is used to link a page to others pages in the text entry.
TopicPop = gcbo;
val = get(TopicPop,'value');
if val~=1
refstr = get(TopicPop,'string');
ref = deblank(refstr{val});
topic = get(TopicPop,'userdata');
helpwindow(topic,ref);
end
%-----------------------------------------------------------------------
case 'HelpwinSeealso'
% This case is used to link a page to others referenced in the
% See Also text.
SeeAlsoPop = gcbo;
val = get(SeeAlsoPop,'value');
if val~=1
set(SeeAlsoPop,'value',1);
refstr = get(SeeAlsoPop,'string');
ref = deblank(refstr{val});
if length(ref) >= 5
if strcmp(ref(1:5),'More ')
ind = max(findstr(ref,' help'));
if ~isempty(ind)
doc(ref(6:ind-1));
end
else
helpwindow(ref);
end
else
helpwindow(ref);
end
end
%-----------------------------------------------------------------------
case 'HelpwinBack'
% This case is used to go back one page in the stack.
BackBtn = gcbo;
fig = gcbf;
fud = get(fig,'UserData');
pgtitle = get(findobj(fig,'tag','CurHelpEdit'),'string');
if pgtitle(1) == ' ', pgtitle(1) = []; end % remove first char if space
match = max(strmatch(pgtitle,{fud.pagetitle},'exact'));
ref = fud(match+1);
set(BackBtn,'UserData',1); % set flag to indicate Back call
helpwindow(ref.topic,ref.pagetitle,ref.helptitle);
%-----------------------------------------------------------------------
case 'HelpwinForward'
% This case is used to go forward one page in the stack.
fig = gcbf;
BackBtn = findobj(fig,'Tag','BackBtn');
fud = get(fig,'UserData');
pgtitle = get(findobj(fig,'tag','CurHelpEdit'),'string');
if pgtitle(1) == ' ', pgtitle(1) = []; end % remove first char if space
match = min(strmatch(pgtitle,{fud.pagetitle},'exact'));
ref = fud(match-1);
set(BackBtn,'UserData',1); % set flag to indicate Back/Forw call to
helpwindow(ref.topic,ref.pagetitle,ref.helptitle);
%-----------------------------------------------------------------------
case 'HelpwinHome'
% This case is used to go to the Home help screen.
str = help;
helpwindow({str},'MATLAB Help Topics');
%-----------------------------------------------------------------------
case 'HelpwinOpen'
% This case is used to open another link from a double-click in
% the list box.
% Determine whether this is a double click.
fig = gcbf;
if strcmp(get(fig,'SelectionType'),'open')
ListBox = findobj(fig,'Tag','ListBox');
SeeAlsoPop = findobj(fig,'tag','SeeAlsoPop');
ln = get(ListBox,'value');
helpstr = get(ListBox,'string');
% Find the function link index or the See Also index.
hstr = helpstr';
hstr = lower(hstr(:)');
cols = size(helpstr,2);
seealso = floor((findstr('see also',hstr)/cols) + 1);
dash = floor((findstr(' - ',hstr)/cols) + 1);
% If there is a 'See Also', follow the 'See also' index
if ~isempty(seealso)
if ln == seealso
% Determine which item in the list is a the first in the
% 'See also' text list.
poplist = get(SeeAlsoPop,'string');
if length(poplist{2}) >= 5
if strcmp(poplist{2}(1:5),'More ')
val = 3;
else
val = 2;
end
else
val = 2;
end
helpwindow(poplist{val}); % gets first reference in 'See also' list.
end
end
% If there are dashes follow the function link.
if ~isempty(dash)
if any(ln == dash)
loc = min(findstr('-',helpstr(ln,:)));
ref = deblank(helpstr(ln,1:loc-1));
ind = min(find(isletter(ref)));
ref = ref(ind:end);
% Process a 'Readme' tag.
if strcmp(ref,'Readme')
CurHelpEdit = findobj(fig,'Tag','CurHelpEdit');
pre = deblank(get(CurHelpEdit,'string'));
if (pre(1)==' '), pre(1) = []; end
helpwindow([pre filesep ref]);
% Else, just follow the link.
else
helpwindow(ref);
end
end
end
end
%-----------------------------------------------------------------------
case 'HelpwinHelpDesk'
% This case is used to link HTML-based documentaion.
doc;
%-----------------------------------------------------------------------
case 'HelpwinMoreHelp'
% This case is used to link HTML-based documentaion.
nexttopic = get(findobj(gcbf,'tag','CurHelpEdit'),'string');
if nexttopic(1) == ' ', nexttopic(1) = []; end % remove first char if space
doc(nexttopic);
%-----------------------------------------------------------------------
case 'HelpwinResize'
% This case is used to reset the position of the buttons and the
% frames is the helpwin figure is resized.
% Get the new figure position in points.
fig = gcbf;
pos = get(fig,'Position');
figwidth = pos(3);
% Get all of the necessary handles.
ListBox = findobj(fig,'tag','ListBox');
CurHelpEdit = findobj(fig,'tag','CurHelpEdit');
SeeAlsoPop = findobj(fig,'tag','SeeAlsoPop');
HomeBtn = findobj(fig,'tag','HomeBtn');
BackBtn = findobj(fig,'tag','BackBtn');
ForwardBtn = findobj(fig,'tag','ForwardBtn');
HelpDeskBtn = findobj(fig,'tag','HelpDeskBtn');
HelpBtn = findobj(fig,'tag','HelpBtn');
CloseBtn = findobj(fig,'tag','CloseBtn');
% Set the top frame and buttons to their correct positions.
wid = 170; wid2 = 60; spc = 8;
ht = 21; frmht = 54;
[fname,fsize,bdr] = goodfonts(computer);
set(CurHelpEdit,'Position',[spc pos(4)-frmht+ht+8 2*wid2+spc ht]);
set(SeeAlsoPop,'Position',[2*wid2+3*spc pos(4)-frmht+ht+8 2*wid2+spc ht]);
set(HomeBtn,'Position',[2*wid2+3*spc pos(4)-frmht+4 wid2 ht]);
set(BackBtn,'Position',[spc pos(4)-frmht+4 wid2 ht]);
set(ForwardBtn,'Position',[wid2+2*spc pos(4)-frmht+4 wid2 ht]);
set(HelpDeskBtn,'Position',[figwidth-2*(wid2+spc) pos(4)-frmht+ht+8 2*wid2+spc ht]);
set(HelpBtn,'Position',[figwidth-2*(wid2+spc) pos(4)-frmht+4 wid2 ht]);
set(CloseBtn,'Position',[figwidth-(wid2+spc) pos(4)-frmht+4 wid2 ht]);
% Set the list box to fill the rest of the figure.
set(ListBox,'Position',[bdr 0 pos(3) pos(4)-frmht]);
%-----------------------------------------------------------------------
otherwise
% Try to find the figure. Note the awkward spelling of the tag to prevent
% others from accidentally grabing this hidden figure.
fig = findobj(allchild(0),'tag','MiniHelPFigurE');
CR = sprintf('\n');
% Determine if the input consists of a cell array or paged help text.
topic_is_cell = iscell(topic);
multi_page_text = topic_is_cell & (size(topic,2) > 1);
% Strip off the first character if it is a space. The space is inserted
% on purpose for better display in the edit box.
if ~topic_is_cell & size(topic,1) == 1 & topic(1)==' ' , topic(1) = []; end
% Create the figure if it doesn't exist.
if isempty(fig),
% Params.
wid = 170; wid2 = 60; spc = 8;
ht = 21; frmht = 54;
% Get a good font and figure size for this platform.
[fname,fsize,bdr] = goodfonts(computer);
% Create the figure.
fig = figure( ...
'Visible','off', ...
'HandleVisibility','off', ...
'MenuBar','none', ...
'Name','MATLAB Help Window', ...
'Color',get(0,'defaultuicontrolbackgroundcolor'), ...
'NumberTitle','off', ...
'IntegerHandle','off', ...
'Units','Points', ...
'ResizeFcn','helpwindow(''HelpwinResize'')', ...
'Tag','MiniHelPFigurE');
% Test the chosen font to get the best figure width.
str = ['01234567890123456789012345678901234567890123456789012345678901234567890123456789'];
t = uicontrol('Parent',fig, ...
'Units','points', ...
'FontName',fname, ...
'FontSize',fsize, ...
'String',str);
figwidth = get(t,'extent');
figwidth = figwidth(3);
delete(t);
pos = get(fig,'position'); % Gets default figure position in points.
bdr = bdr * get(0,'ScreenPixelsPerInch') / 72; % Convert Pixels to Points.
figpos = [(2*pos(1) + pos(3) - figwidth)/2 pos(2) figwidth pos(4)] + ...
[-bdr 0 bdr 0];
% Set the best figure position.
set(fig,'Position',figpos);
% Create the rest of the UIs.
ListBox = uicontrol('Parent',fig, ...
'BackgroundColor',[1 1 1], ...
'CallBack','helpwindow(''HelpwinOpen'');', ...
'FontName',fname, ...
'FontSize',fsize, ...
'Max',2, ...
'Units','Points', ...
'Position',[bdr 0 figwidth pos(4)-frmht], ...
'String',' ', ...
'Style','listbox', ...
'Tag','ListBox', ...
'Value',[]);
CurHelpEdit = uicontrol('Parent',fig, ...
'BackgroundColor',[1 1 1], ...
'Units','Points', ...
'Position',[spc pos(4)-frmht+ht+8 2*wid2+spc ht], ...
'Style','edit', ...
'HorizontalAlignment','left', ...
'Tag','CurHelpEdit', ...
'Callback','helpwindow(get(gcbo,''string''));');
SeeAlsoPop = uicontrol('Parent',fig, ...
'BackgroundColor',[1 1 1], ...
'CallBack','helpwindow(''HelpwinSeealso'');', ...
'Min',1, ...
'Units','Points', ...
'Position',[2*wid2+3*spc pos(4)-frmht+ht+8 2*wid2+spc ht], ...
'String','See also', ...
'Style','popupmenu', ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -