Specifications
5 GUI Applications
5-36
else
errordlg('Not a valid Address Book','Address Book Error')
end
The Open Menu Callback
The address book GUI contains a File menu that has an Open submenu for
loading address book MAT-files. When selected,
Open displays a dialog
(
uigetfile) that enables the user to browser for files. The dialog displays only
MAT-files, but users can change the filter to display all files.
The dialog returns both the filename and the path to the file, which is then
passed to
fullfile to ensure the path is properly constructed for any platform.
Check_And_Load validates and load the new address book.
Open_Callback Code Listing
function Open_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile( ...
{'*.mat', 'All MAT-Files (*.mat)'; ...
'*.*','All Files (*.*)'}, ...
'Select Address Book');
% If "Cancel" is selected then return
if isequal([filename,pathname],[0,0])
return
% Otherwise construct the fullfilename and Check and load the file
else
File = fullfile(pathname,filename);
% if the MAT-file is not valid, do not save the name
if Check_And_Load(File,handles)
handles.LastFIle = File;
guidata(hObject, handles)
end
end
See the “Creating Menus — The Menu Editor” on page 3-57 section for
information on creating the menu.
The Contact Name Callback
The Contact Name text box displays the name of the address book entry. If you
type in a new name and press enter, the callback performs these steps: