0001 function [] = set_gui_property(dialog)
0002
0003
0004
0005
0006
0007 this = get(dialog,'UserData');
0008
0009
0010 if isempty(this.public.dialog_title)
0011 if this.public.save_mode
0012 dialog_title = 'select SAVE file';
0013 else
0014 dialog_title = 'select LOAD file';
0015 end
0016 set(this.private.gui_handles.dialog, 'Name', dialog_title);
0017 else
0018 set(this.private.gui_handles.dialog, 'Name', this.public.dialog_title);
0019 end
0020
0021
0022 current = 0;
0023 hist_num = length( this.public.hist_dir );
0024 hist_dir = cell(1,hist_num+1);
0025 for ii=1:hist_num
0026 hist_dir{ii+1} = this.public.hist_dir{ii};
0027 if strcmp( this.public.current_dir, deblank(this.public.hist_dir{ii}) )
0028 current = ii;
0029 end
0030 end
0031 if ~current
0032 current = 1;
0033 hist_dir{1} = this.public.current_dir;
0034 this.public.hist_dir = hist_dir;
0035 end
0036
0037
0038 str = sprintf('|%s', this.public.hist_dir{:}); str(1) = [];
0039 set(this.private.gui_handles.current_dir_popup,...
0040 'String', str, 'Value', current);
0041
0042
0043 if length( this.private.drive_info )
0044 str = sprintf('|%s', this.private.drive_info(:).drive);
0045 str(1) = [];
0046 set(this.private.gui_handles.drive_text, 'Enable', 'on');
0047 set(this.private.gui_handles.drive_popup,...
0048 'Enable', 'on', 'String', str, 'Value', this.private.current_drive);
0049 else
0050 set(this.private.gui_handles.drive_text, 'Enable', 'off');
0051 set(this.private.gui_handles.drive_popup, 'Enable', 'off');
0052 end
0053
0054
0055
0056
0057 current_extension = get(this.private.gui_handles.extension_popup, 'Value');
0058 this.public.filter_str = get(this.private.gui_handles.filter_str_edit, 'String');
0059 [files, dirs] = list_files(this.public.current_dir,...
0060 this.public.file_extensions{current_extension},...
0061 this.public.filter_str);
0062
0063
0064
0065 if length(dirs)
0066 str = sprintf('|%s', dirs{:}); str(1) = [];
0067 active_dir = find( strcmp(dirs, '.') );
0068 if isempty( active_dir )
0069 str = sprintf('.|%s', str);
0070 active_dir = 1;
0071 end
0072 set(this.private.gui_handles.dir_listbox, 'String', str,...
0073 'Min',0, 'Max',1, 'Value',active_dir, 'Enable','on');
0074 else
0075 set(this.private.gui_handles.dir_listbox, 'String', '',...
0076 'Min',0, 'Max', 0, 'Value',[], 'Enable', 'off');
0077 end
0078
0079
0080
0081 current_file = [];
0082 if length(files)
0083 str = sprintf('%s|', files{:}); str(length(str)) = '';
0084 for ii=1:length(this.private.current_file)
0085 tmp = find( strcmp(files, this.private.current_file{ii}) );
0086 if length(tmp)
0087 current_file = [current_file, tmp];
0088 end
0089 end
0090
0091 set(this.private.gui_handles.fname_listbox, 'String', str,...
0092 'Min',0, 'Max', 2, 'Value', current_file, 'Enable', 'on');
0093 else
0094 set(this.private.gui_handles.fname_listbox, 'String', '',...
0095 'Min',0, 'Max', 0, 'Value', current_file, 'Enable', 'off');
0096 end
0097
0098
0099
0100 if isempty(this.private.current_file)
0101 filename = '';
0102 elseif length(this.private.current_file) == 1
0103 if this.public.save_mode
0104 filename = this.private.current_file{1};
0105 else
0106 filename =...
0107 fullfile( this.public.current_dir, this.private.current_file{1} );
0108 end
0109 else
0110 filename = '';
0111 for ii=1:length(this.private.current_file)
0112 filename = sprintf('%s ''%s''', filename, this.private.current_file{ii});
0113 end
0114 end
0115 set(this.private.gui_handles.sel_fname_edit, 'String', filename);
0116 set_horizontal_alignment( this.private.gui_handles.sel_fname_edit );
0117
0118
0119
0120 if isempty( this.private.current_file )
0121 set(this.private.gui_handles.done_push,...
0122 'FontWeight','normal', 'Enable','off');
0123 else
0124 set(this.private.gui_handles.done_push,...
0125 'FontWeight','bold', 'Enable','on');
0126 end
0127
0128 set(dialog, 'UserData', this);
0129
0130
0131
0132 function [files,dirs] = list_files(wdir, file_extension, filter_str)
0133
0134
0135
0136
0137
0138 if isempty(filter_str)
0139 filter_str = '*';
0140 end
0141 filter_str = strrep(filter_str, '.', '\.');
0142 filter_str = strrep(filter_str, '*', '.*');
0143 filter_str = ['^', filter_str, '.*'];
0144
0145 d = dir(wdir);
0146 files = {}; files_num = 0;
0147 dirs = {}; dirs_num = 0;
0148 for ii=1:length(d)
0149 if d(ii).isdir
0150 dirs_num = dirs_num+1;
0151 dirs{dirs_num} = d(ii).name;
0152 else
0153 if strcmp(file_extension, '.*')
0154 append = 1;
0155 else
0156 p = findstr(d(ii).name, file_extension);
0157 f = regexp(d(ii).name, filter_str);
0158 if ~isempty(f) & ...
0159 ~isempty(p) &...
0160 p(length(p))==length(d(ii).name)-(length(file_extension)-1)
0161 append = 1;
0162 else
0163 append = 0;
0164 end
0165 end
0166
0167 if append
0168 files_num = files_num+1;
0169 files{files_num} = d(ii).name;
0170 end
0171
0172 end
0173 end
0174
0175
0176
0177 function set_horizontal_alignment(handle)
0178
0179 if isunix
0180 p = get(handle, 'Position');
0181 ext = get(handle,'Extent');
0182 if p(3) < ext(3) set(handle,'HorizontalAlignment','right');
0183 else set(handle,'HorizontalAlignment','left');
0184 end
0185 else
0186 set(handle,'HorizontalAlignment','left');
0187 end
0188