Home > vbmeg > functions > gui > preAnalysis > utility > pa_prjfile_select.m

pa_prjfile_select

PURPOSE ^

file select dialog

SYNOPSIS ^

function [dirname, fnames, canceled] = pa_prjfile_select(proj_root, ext, caption)

DESCRIPTION ^

 file select dialog 
  - The file is in under the project directory

 [IN]  proj_root : Top of the selectable directory.
       ext{n}    : file extension (ex. '.img', '.txt')
         caption : dialog title(string)                  [string]
 [OUT] dirname   : relative directory name from proj_root
       fnames{n} : selected filenames.
       canceled  : true/false (true means dialog closed by cancel)


 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dirname, fnames, canceled] = pa_prjfile_select(proj_root, ext, caption)
0002 % file select dialog
0003 %  - The file is in under the project directory
0004 %
0005 % [IN]  proj_root : Top of the selectable directory.
0006 %       ext{n}    : file extension (ex. '.img', '.txt')
0007 %         caption : dialog title(string)                  [string]
0008 % [OUT] dirname   : relative directory name from proj_root
0009 %       fnames{n} : selected filenames.
0010 %       canceled  : true/false (true means dialog closed by cancel)
0011 %
0012 %
0013 % Copyright (C) 2011, ATR All Rights Reserved.
0014 % License : New BSD License(see VBMEG_LICENSE.txt)
0015 persistent h;       % for singleton check
0016 persistent HISTORY; % file choice history
0017 
0018 dirname = [];
0019 fnames= [];
0020 canceled = false;
0021 
0022 % dialog can open 1 at a same time.
0023 if ~isempty(h)
0024     canceled = true;
0025     return;
0026 end  
0027 
0028 h = file_dialog;
0029 h = set(h, 'file_extensions', ext);
0030 if exist('caption', 'var')
0031     h.dialog_title = caption;
0032 end
0033 h = set(h, 'current_dir', proj_root);
0034 
0035 % ディレクトリの履歴の追加
0036 hist_num = size(HISTORY, 2);
0037 if ~isempty(HISTORY)
0038     ix = [];
0039     k=1;
0040     for k=1:hist_num
0041          for j=1:size(ext,2)
0042             if ~isempty(strmatch(ext{j}, HISTORY{k}{2}, 'exact'))
0043                 ix = [ix;k];
0044             end
0045             h = set(h, 'hist_dir', {HISTORY{k}{1}});
0046         end
0047     end
0048     if ~isempty(ix)
0049        current_dir = HISTORY{ix(end)}{1};
0050     else
0051        current_dir = HISTORY{k}{1};
0052     end
0053     h = set(h, 'current_dir', char(current_dir));
0054 end
0055 [dirname fnames] = visible(h);
0056 
0057 % CANCEL押下かどうか判断
0058 if isempty(dirname)
0059     canceled = true;
0060 end
0061 
0062 % save history
0063 if ~isempty(dirname)
0064     HISTORY{hist_num+1} = {dirname, ext};
0065 end
0066 
0067 % パスをproj_rootからの相対パスにする
0068 if ~isempty(dirname) & ~isempty(proj_root)
0069     dirname = vb_relativepath(dirname, proj_root);
0070     dirname = dirname(1:length(dirname)-1);
0071 end
0072 
0073 h = [];

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005