| Contents | Index |
pref_value = uigetpref(group,pref,title,question,pref_choices)
[pref_value,dlgshown]
= uigetpref(...)
[...] = uigetpref(... 'Name',value)
pref_value = uigetpref(group,pref,title,question,pref_choices) returns one of the strings in pref_choices in either of two ways:
Displays a multiple-choice dialog box that prompts you to answer a question. The dialog box includes a check box with the label Do not show this dialog again.
Retrieves a previous answer from the preferences data base and returns it without displaying a dialog. No dialog is displayed if you previously selected the check box Do not show this dialog again.
[pref_value,dlgshown] = uigetpref(...) also returns in dlgshown whether or not the dialog displayed.
[...] = uigetpref(... 'Name',value) specify optional name-value pairs to control how dialogs display.
You must supply all input arguments up to and including pref_choices.
uigetpref creates specified groups and preferences, if they do not currently exist. To delete a preference group you no longer need, use rmpref.
The string returned in pref_value is a preference name (as specified in pref), not its button label (as specified in pref_choices).
After you select the check box Do not show this dialog again and close the dialog box, the dialog box does not display again for the same preference. To reenable dialogs that are being suppressed by preferences, use the command:
uisetpref('clearall')Executing uisetpref with this command re-enables all preference dialogs you have defined with uigetpref, not just the most recent one.
Specify optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
Preferences provide the ability to specify how applications behave and how users interact with them. For example, you can set a preference for which products display their documentation in the Help browser, or which messages the Code Analyzer displays. In MathWorks software products, preferences persist across sessions and are stored in a preference data base, the location of which is system-dependent. Use the Preferences option on the File menu to access all built-in preferences.
uigetpref uses the same preference data base as addpref, getpref, ispref, rmpref, and setpref. However, uigetpref registers the preferences it sets as a separate list, so that it and uisetpref can manage those preferences.
To modify preferences registered with uigetpref, you can use setpref and uisetpref to explicitly change preference values to 'ask'. If you specify a preference that does not already exist in the preference data base, uigetpref creates it.
Create a preference dialog for the 'savefigurebeforeclosing' preference in the 'mygraphics' group of preferences.

Call uigetpref to display the dialog (or not) from a figure window CloseRequestFcn callback. The callback code takes action via a switch statement. The action (to delete or not to delete the figure) depends on whether the answer returned by uigetpref was 'always' or 'never':
function save_figure_perhaps
% Closes figure conditionally, asking whether to save it first.
% User can suppress the dialog from UIGETPREF permanently by selecting
% "Do not show this dialog again".
fig = gcf;
[selectedButton dlgshown] = uigetpref(...
'mygraphics',... % Group
'savefigurebeforeclosing',... % Preference
'Closing Figure',... % Window title
{'Do you want to save your figure before closing?'
''
'You can save your figure manually by typing ''hgsave(gcf)'''},...
{'always','never';'Yes','No'},... % Values and button strings
'ExtraOptions','Cancel',... % Additional button
'DefaultButton','Cancel',... % Default choice
'HelpString','Help',... % String for Help button
'HelpFcn','doc(''closereq'');'); % Callback for Help button
switch selectedButton
case 'always' % Open a Save dialog (without testing if saved before)
[fileName,pathName,filterIndex] = uiputfile('fig', ...
'Save current figure', ...
'untitled.fig');
if filterIndex == 0 % User cancelled save or named no file
delete(fig);
else % Use filename returned from UIPUTFILE
saveas(fig,[pathName fileName])
delete(fig);
end
case 'never' % Close the figure without saving it
delete(fig);
case 'cancel' % Do not close the figure
return
endTo execute the example, copy it and paste the code into a new program file. Name the file save_figure_perhaps.m and place it on your search path. To use the function as a CloseRequestFcn, create a figure as follows:
figure('CloseRequestFcn','save_figure_perhaps');
Clicking the figure close box or selecting File > Close displays the dialog box until you select Do not show this dialog again.
addpref | getpref | ispref | prefdir | rmpref | setpref | uisetpref

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |