else
errordlg('Input must be a valid directory','Input Argument Error!')
return
end
else
errordlg('Unrecognized input argument','Input Argument Error!');
return;
end
end
If nargin==3, then the only input arguments to lbox2_OpeningFcn are hObject,
eventdata, and handles. Therefore, the user did not specify a path when they called
lbox2, so the list box shows the contents of the current folder. If nargin>4, then the
varargin input argument contains two additional items (suggesting that the user did
specify a path). Thus, subsequent if statements check to see whether the path is valid.
listbox1_callback
The callback function listbox1_callback executes when the user clicks a list box item.
This statement, near the beginning of the function, returns true whenever the user
double-clicks an item in the list box:
if strcmp(get(handles.figure1,'SelectionType'),'open')
If that condition is true, then listbox1_callback determines which list box item the
user selected:
index_selected = get(handles.listbox1,'Value');
file_list = get(handles.listbox1,'String');
filename = file_list{index_selected};
The rest of the code in this callback function determines how to open the selected item
based on whether the item is a folder, FIG file, or another type of file:
if handles.is_dir(handles.sorted_index(index_selected))
cd (filename)
load_listbox(pwd,handles)
else
[path,name,ext] = fileparts(filename);
switch ext
case '.fig'
guide (filename)
otherwise
try
8 Examples of GUIDE UIs