Home > functions > common > utility > @file_dialog > private > fname_edit.m

fname_edit

PURPOSE ^

ファイル名を入力するedit textのCallback関数

SYNOPSIS ^

function [] = fname_edit(obj, eventdata, dialog)

DESCRIPTION ^

 ファイル名を入力するedit textのCallback関数
 この関数はpublic.save_mode = trueの時のみ有効 
 public.save_mode = falseの時はなにもしない。

 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 [] = fname_edit(obj, eventdata, dialog)
0002 % ファイル名を入力するedit textのCallback関数
0003 % この関数はpublic.save_mode = trueの時のみ有効
0004 % public.save_mode = falseの時はなにもしない。
0005 %
0006 % Copyright (C) 2011, ATR All Rights Reserved.
0007 % License : New BSD License(see VBMEG_LICENSE.txt)
0008 
0009 this = get(dialog, 'UserData');
0010 fname = deblank( get(obj, 'String') );
0011 
0012 
0013 % もし入力がディレクトリならカレントディレクトリを変更する
0014 err = false;
0015 current_dir = this.public.current_dir;
0016 f_path = fname;
0017 if isdir([current_dir, filesep, f_path])
0018   % 相対パス入力
0019   f_path = [current_dir, filesep, f_path];
0020 elseif isdir([pwd, filesep, f_path])
0021   % isdirがMATLABのカレントパスを探しにいくとまずいので、ここでキャンセル
0022   err = true;
0023 elseif isdir(f_path)
0024   % 絶対パス入力
0025 else
0026   err = true;
0027 end
0028 
0029 if ~err
0030   % 入力文字列はディレクトリだった
0031   tmp = pwd;
0032   cd(f_path);
0033   f_path = pwd;
0034   cd(tmp); 
0035   if strcmp(f_path(length(f_path)), filesep)
0036       f_path = f_path(1:length(f_path)-1);
0037   end
0038   % set selected directory
0039   this.public.current_dir = f_path;
0040   % set drive(Windows)
0041   if ispc
0042     ix = strfind(f_path, ':');
0043     if ~isempty(ix)
0044       drive = f_path(1:ix);
0045       drive_list = {this.private.drive_info.drive};
0046       ix_list = strmatch(drive, drive_list);
0047       if ~isempty(ix_list)
0048         this.private.current_drive = ix_list;
0049       end
0050     end % if ~isempty(ix)
0051   end
0052   fname = [];
0053 else
0054   % 入力文字列はディレクトリではなかった
0055   [f_path, f_name, f_ext] = fileparts(fname);
0056   fname = [f_name, f_ext];
0057 end
0058 
0059 if this.public.save_mode
0060   current_extension = get(this.private.gui_handles.extension_popup, 'Value');
0061   file_extension = this.public.file_extensions{current_extension};
0062 
0063   this.private.current_file = {};
0064   if length(fname)
0065     % 拡張子をチェックする。
0066     flg = 1;
0067     if strcmp(file_extension, '.*')
0068       flg = 0;    % ワイルドカード(拡張子のチェック不要)
0069     else
0070       if length(fname) > length(file_extension)
0071         tmp = length(fname) - length(file_extension) + 1;
0072           if strcmp(fname(tmp:length(fname)), file_extension)
0073           flg = 0;    % 拡張子がfile_extensionと一致した。
0074         end
0075       end
0076     end
0077     % 入力ファイル名に拡張子を追加する。
0078     if flg == 1,    fname = [fname, file_extension];    end
0079     
0080     this.private.current_file{1} = fname;
0081   end        % <-- end of 'if length(fname)'
0082 end
0083 
0084 % DialogのGUIのpropertyを更新する。
0085 set(dialog, 'UserData', this);
0086 set_gui_property(dialog);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005