file select dialog [USAGE] [dir, fnames] = vb_file_select(<ext> [,caption] [,save_mode]); [IN] ext : file extension (ex. {'.img', '.txt'}) {Nx1} caption : dialog title(string) [string] save_mode : = true : save file selection mode. = false : load file selection mode. <<DEFAULT>> [OUT] dir : selected directory. fnames{n} : selected filenames. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [dir, fnames] = vb_file_select(ext, caption, save_mode) 0002 % file select dialog 0003 % [USAGE] 0004 % [dir, fnames] = vb_file_select(<ext> [,caption] [,save_mode]); 0005 % [IN] 0006 % ext : file extension (ex. {'.img', '.txt'}) {Nx1} 0007 % caption : dialog title(string) [string] 0008 % save_mode : = true : save file selection mode. 0009 % = false : load file selection mode. <<DEFAULT>> 0010 % 0011 % [OUT] dir : selected directory. 0012 % fnames{n} : selected filenames. 0013 % 0014 % 0015 % Copyright (C) 2011, ATR All Rights Reserved. 0016 % License : New BSD License(see VBMEG_LICENSE.txt) 0017 persistent HISTORY; % file choice history 0018 0019 dir = []; 0020 fnames= []; 0021 0022 if ~exist('save_mode', 'var') 0023 save_mode = false; 0024 end 0025 0026 h = file_dialog; 0027 % Set extension 0028 h = set(h, 'file_extensions', ext); 0029 0030 % Set caption 0031 if exist('caption', 'var') && ~isempty(caption) 0032 h.dialog_title = caption; 0033 end 0034 0035 % Set Save mode 0036 h = set(h, 'save_mode', save_mode); 0037 0038 % Add history to dialog 0039 hist_num = length(HISTORY); 0040 if ~isempty(HISTORY) 0041 h = set(h, 'hist_dir', HISTORY); 0042 h = set(h, 'current_dir', char(HISTORY{hist_num})); 0043 end 0044 0045 [dir fnames] = visible(h); 0046 0047 % Save history 0048 if ~isempty(dir) 0049 % Duplication check 0050 idx = strmatch(dir, HISTORY, 'exact'); 0051 if isempty(idx) 0052 HISTORY{hist_num+1} = dir; 0053 else 0054 HISTORY(idx) = []; 0055 HISTORY{end+1} = dir; 0056 end 0057 end