Home > vbmeg > functions > gui > preAnalysis > meeg_processor > signal_processor > vb_signal_processor_confirm_overwrite_files.m

vb_signal_processor_confirm_overwrite_files

PURPOSE ^

Show confirmation message(dialog or text) when

SYNOPSIS ^

function output_ix = vb_signal_processor_confirm_overwrite_files(data, mode)

DESCRIPTION ^

 Show confirmation message(dialog or text) when 
 the candidate output files already exist.
 [USAGE]
    data = vb_signal_processor_confirm_overwrite_files(data, mode);
 [IN]
    data : application data.
    mode : confirm overwrite
         : = 0   : by text.    [default]
         : = 1   : by dialog.
         : = 2   : Yes to all.(with no check)
 [OUT]
    output_ix : Index for data.output_files. 

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function output_ix = vb_signal_processor_confirm_overwrite_files(data, mode)
0002 % Show confirmation message(dialog or text) when
0003 % the candidate output files already exist.
0004 % [USAGE]
0005 %    data = vb_signal_processor_confirm_overwrite_files(data, mode);
0006 % [IN]
0007 %    data : application data.
0008 %    mode : confirm overwrite
0009 %         : = 0   : by text.    [default]
0010 %         : = 1   : by dialog.
0011 %         : = 2   : Yes to all.(with no check)
0012 % [OUT]
0013 %    output_ix : Index for data.output_files.
0014 %
0015 % Copyright (C) 2011, ATR All Rights Reserved.
0016 % License : New BSD License(see VBMEG_LICENSE.txt)
0017 
0018 %
0019 % --- Previous check
0020 %
0021 if ~exist('data', 'var')
0022     error('data is a required parameter.');
0023 end
0024 if ~exist('mode', 'var')
0025     mode = 0; % text
0026 end
0027 
0028 %
0029 % --- Main Procedure
0030 %
0031 output_ix = []; % 1:process, 0: don't process.
0032 
0033 remove_pref;
0034 
0035 if mode == 2
0036     output_ix = [1:1:length(data.output_files)]';
0037 else
0038     Noutput_files = length(data.output_files);
0039 
0040     for k=1:Noutput_files
0041         file = data.output_files{k};
0042         if exist(file, 'file') == 2
0043 % debug
0044 %        if 1
0045             % file already exist.
0046             if mode == 1
0047                 % confirm by dialog
0048                 write = show_dialog(file);
0049             elseif mode == 0
0050                 % confirm by text
0051                 write = show_text(file);
0052             end
0053             if write
0054                 output_ix = [output_ix; k];
0055             end
0056         else
0057             % file not exist. create file.
0058             output_ix = [output_ix; k];
0059         end
0060     end
0061 end
0062 
0063 remove_pref;
0064 
0065 function remove_pref
0066 if ispref('group', PREF_NAME)
0067     rmpref('group', PREF_NAME);
0068 end
0069 
0070 function write = show_text(file)
0071 reply = '';
0072 while(isempty(reply))
0073     if ispref('group', PREF_NAME)
0074         reply = 'yes';
0075     else
0076         reply = input([file ' already exist. overwrite? (Yes/No/All):'], 's');
0077     end
0078     switch(lower(reply))
0079         case {'yes', 'y'}
0080             write = 1;
0081         case {'no', 'n'}
0082             write = 0;
0083         case {'all', 'a'}
0084             write = 1;
0085             setpref('group', PREF_NAME, 1);
0086     end
0087 end
0088 
0089 function write = show_dialog(file)
0090 
0091 % dialog
0092 reply = uigetpref('group', ...
0093                 PREF_NAME, ...
0094                 'Confirmation', ...
0095                 [file ' already exist. overwrite?'],...
0096                 {'Yes', 'No'}, 'DefaultButton', 'No',...
0097                 'CheckboxString', 'Apply to All');
0098 
0099 % Judge
0100 switch(lower(reply))
0101     case {'yes', 'y'}
0102         write = 1;
0103     case {'no', 'n'}
0104         write = 0;
0105     otherwise
0106         error('Unknown choice.');
0107 end
0108 
0109 function name = PREF_NAME
0110 name = 'overwrite_megmat';
0111

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