0001 function varargout = dir_dialog_callback(varargin)
0002
0003
0004
0005
0006 if ischar(varargin{1})
0007 try
0008 if nargout == 0
0009 feval(varargin{:})
0010 else
0011
0012 [varargout{1:nargout}] = feval(varargin{:});
0013 end
0014 catch
0015 disp(lasterr);
0016 end
0017 end
0018
0019
0020 function varargout = txtInfo_Callback(h, eventdata, handles, varargin)
0021 dir_ = get(handles.txtInfo, 'String');
0022 err = false;
0023 if isdir([handles.mypath, filesep, dir_])
0024
0025 dir_ = [handles.mypath, filesep, dir_];
0026 elseif isdir([pwd, filesep, dir_])
0027
0028 err = true;
0029 elseif isdir(dir_)
0030
0031 else
0032 err = true;
0033 end
0034 if err
0035 set(handles.txtInfo, 'String', handles.mypath);
0036 return;
0037 else
0038
0039 current_dir = pwd;
0040 cd(dir_);
0041 dir_ = pwd;
0042 cd(current_dir);
0043 if strcmp(dir_(length(dir_)), filesep)
0044 dir_ = dir_(1:length(dir_)-1);
0045 end
0046
0047 handles.mypath = dir_;
0048 handles = update_listbox(handles);
0049
0050
0051 if ispc
0052 ix = strfind(dir_, ':');
0053 if ~isempty(ix)
0054 drive = dir_(1:ix);
0055 drive_list = get(handles.drive_popup, 'String');
0056 ix_list = strmatch(drive, drive_list);
0057 if ~isempty(ix_list)
0058 set(handles.drive_popup, 'Value', ix_list);
0059 end
0060 end
0061 end
0062
0063 guidata(handles.browser, handles);
0064 end
0065
0066
0067 function varargout = List_Callback(h, eventdata, handles, varargin)
0068
0069 index_selected = get(handles.List,'Value');
0070 path_name = handles.file_path{index_selected};
0071 new_path = [handles.mypath filesep path_name];
0072
0073 if strcmp(path_name, '.')
0074 return;
0075 elseif strcmp(path_name, '..')
0076
0077 tmp = pwd;
0078 cd(new_path);
0079 new_path = pwd;
0080 cd(tmp);
0081 if strcmp(new_path(length(new_path)), filesep)
0082 new_path = new_path(1:length(new_path)-1);
0083 end
0084 handles.mypath = new_path;
0085 elseif IsdirOK(new_path) == true
0086
0087 handles.mypath = new_path;
0088 else
0089
0090 return;
0091 end
0092
0093 set(handles.txtInfo, 'String', handles.mypath);
0094 handles = update_listbox(handles);
0095
0096
0097 guidata(handles.browser, handles);
0098
0099
0100 function varargout = btnApply_Callback(h, eventdata, handles, varargin)
0101 handles.mypath = get(handles.txtInfo, 'String');
0102 guidata(handles.browser, handles);
0103
0104
0105 set(handles.browser, 'Visible', 'off');
0106
0107
0108 function varargout = btnCancel_Callback(h, eventdata, handles, varargin)
0109 handles.mypath = [];
0110 guidata(handles.browser, handles);
0111
0112
0113 set(handles.browser, 'Visible', 'off');
0114
0115
0116 function varargout = mkdir_button_Callback(hObject, eventdata, handles, varargin)
0117 dir_name = inputdlg('', 'input directory name');
0118 if ~isempty(dir_name)
0119 mkdir(char(handles.mypath), char(dir_name));
0120 handles = update_listbox(handles);
0121
0122 guidata(handles.browser, handles);
0123 end
0124
0125
0126 function varargout = drive_popup_Callback(h, eventdata, handles, varargin)
0127
0128 val = get(handles.drive_popup, 'Value');
0129 select_list = get(handles.drive_popup, 'String');
0130 handles.mypath = select_list{val};
0131 set(handles.txtInfo, 'String', handles.mypath);
0132 handles = update_listbox(handles);
0133
0134
0135 guidata(handles.browser, handles);
0136
0137
0138 function varargout = close_function(h, eventdata, handles, varargin)
0139 btnCancel_Callback(h, eventdata, handles, varargin);
0140
0141
0142 function handles = update_listbox(handles)
0143
0144 if IsdirOK(handles.mypath) == false
0145 return;
0146 end
0147
0148 items = dir([handles.mypath, filesep]);
0149 n_items = max(size(items));
0150
0151 if strcmp(handles.mypath, handles.START_DIR)
0152 root = true;
0153 else
0154 root = false;
0155 end
0156
0157 handles.file_path = [];
0158 k=0;
0159
0160
0161 for i = 1 : n_items
0162 if items(i).isdir
0163 dir_name = items(i).name;
0164 if root & (handles.move_mode == false) &...
0165 (strcmp(dir_name, '.') | strcmp(dir_name, '..'))
0166
0167 continue;
0168 else
0169 k = k+1;
0170 handles.file_path{k} = dir_name;
0171 end
0172 end
0173 end
0174
0175 set(handles.List, 'String', handles.file_path, 'Value', 1);
0176 set(handles.txtInfo, 'String', handles.mypath);
0177
0178
0179 function set_drive_info(handles, current_dir)
0180
0181 drive_name = drive_search;
0182 num_drive = length(drive_name);
0183 current_drive = 1;
0184
0185 for k=1:num_drive
0186 if strncmp( upper(current_dir),...
0187 drive_name{k}, ...
0188 length(drive_name{k}) )
0189 current_drive = k;
0190 break;
0191 end
0192 end
0193
0194 set(handles.drive_popup, 'String', drive_name);
0195 set(handles.drive_popup, 'Value', current_drive);
0196
0197
0198 function [drive_name] = drive_search
0199
0200 if strcmp( lower(computer), 'pcwin' )
0201
0202 cnt = 0;
0203 for drive = [real('C'):real('Z')]
0204 str = sprintf('%c:', drive);
0205 if length( dir(str) )
0206
0207 cnt = cnt+1;
0208 drive_name{cnt} = str;
0209 end
0210 end
0211 end
0212
0213
0214 function [result] = IsdirOK(path_name)
0215 items = dir([path_name, filesep]);
0216 n_items = max(size(items));
0217 n_dir = 0;
0218 result = false;
0219
0220 try
0221 for j = 1 : n_items
0222 if items(j).isdir
0223 n_dir = n_dir+1;
0224 end
0225 end
0226 catch
0227
0228 result = false;
0229 return;
0230 end
0231
0232 if n_dir < 2
0233
0234 result = false;
0235 elseif n_dir == 2
0236
0237 result = true;
0238 else
0239 result = true;
0240 end
0241