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 new_dir = fullfile(char(handles.mypath), char(dir_name));
0120 mkdir(new_dir);
0121 handles.mypath = new_dir;
0122 handles = update_listbox(handles);
0123
0124 guidata(handles.browser, handles);
0125 end
0126
0127
0128 function varargout = drive_popup_Callback(h, eventdata, handles, varargin)
0129
0130 val = get(handles.drive_popup, 'Value');
0131 select_list = get(handles.drive_popup, 'String');
0132 handles.mypath = select_list{val};
0133 set(handles.txtInfo, 'String', handles.mypath);
0134 handles = update_listbox(handles);
0135
0136
0137 guidata(handles.browser, handles);
0138
0139
0140 function varargout = close_function(h, eventdata, handles, varargin)
0141 btnCancel_Callback(h, eventdata, handles, varargin);
0142
0143
0144 function handles = update_listbox(handles)
0145
0146 if IsdirOK(handles.mypath) == false
0147 return;
0148 end
0149
0150 items = dir([handles.mypath, filesep]);
0151 n_items = max(size(items));
0152
0153 if strcmp(handles.mypath, handles.START_DIR)
0154 root = true;
0155 else
0156 root = false;
0157 end
0158
0159 handles.file_path = [];
0160 k=0;
0161
0162
0163 for i = 1 : n_items
0164 if items(i).isdir
0165 dir_name = items(i).name;
0166 if root & (handles.move_mode == false) &...
0167 (strcmp(dir_name, '.') | strcmp(dir_name, '..'))
0168
0169 continue;
0170 else
0171 k = k+1;
0172 handles.file_path{k} = dir_name;
0173 end
0174 end
0175 end
0176
0177 set(handles.List, 'String', handles.file_path, 'Value', 1);
0178 set(handles.txtInfo, 'String', handles.mypath);
0179
0180
0181 function set_drive_info(handles, current_dir)
0182
0183 drive_name = drive_search;
0184 num_drive = length(drive_name);
0185 current_drive = 1;
0186
0187 for k=1:num_drive
0188 if strncmp( upper(current_dir),...
0189 drive_name{k}, ...
0190 length(drive_name{k}) )
0191 current_drive = k;
0192 break;
0193 end
0194 end
0195
0196 set(handles.drive_popup, 'String', drive_name);
0197 set(handles.drive_popup, 'Value', current_drive);
0198
0199
0200 function [drive_name] = drive_search
0201
0202 if ispc
0203
0204 cnt = 0;
0205 for drive = [real('C'):real('Z')]
0206 str = sprintf('%c:', drive);
0207 if length( dir(str) )
0208
0209 cnt = cnt+1;
0210 drive_name{cnt} = str;
0211 end
0212 end
0213 end
0214
0215
0216 function [result] = IsdirOK(path_name)
0217 items = dir([path_name, filesep]);
0218 n_items = max(size(items));
0219 n_dir = 0;
0220 result = false;
0221
0222 try
0223 for j = 1 : n_items
0224 if items(j).isdir
0225 n_dir = n_dir+1;
0226 end
0227 end
0228 catch
0229
0230 result = false;
0231 return;
0232 end
0233
0234 if n_dir < 1
0235
0236 result = false;
0237 elseif n_dir == 2
0238
0239 result = true;
0240 else
0241 result = true;
0242 end
0243