a b/functions/adminfunc/eeglab_new.m
1
  % EEGLAB_NEW - script called when a new dataset is created and require 
2
%              input from user. Use workspace variables EEG, ALLEEG,
3
%              CURRENTSET, LASTCOM
4
%
5
% Author: Arnaud Delorme, SCCN/INC/UCSD, 2022
6
%
7
% See also: EEGLAB
8
9
% Copyright (C) 2022 Arnaud Delorme
10
%
11
% This file is part of EEGLAB, see http://www.eeglab.org
12
% for the documentation and details.
13
%
14
% Redistribution and use in source and binary forms, with or without
15
% modification, are permitted provided that the following conditions are met:
16
%
17
% 1. Redistributions of source code must retain the above copyright notice,
18
% this list of conditions and the following disclaimer.
19
%
20
% 2. Redistributions in binary form must reproduce the above copyright notice,
21
% this list of conditions and the following disclaimer in the documentation
22
% and/or other materials provided with the distribution.
23
%
24
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34
% THE POSSIBILITY OF SUCH DAMAGE.
35
36
% functions below modify the current dataset, but should not create new datasets
37
functionsEEGLAB = { 'pop_chanedit' 'pop_editset' 'pop_comment' 'pop_headplot' 'pop_selectcomps' ...
38
              'pop_runica'   'pop_editeventfield' 'pop_editeventvals' 'pop_adjustevents' ...
39
              'pop_saveset'  'pop_importepoch'    'pop_importevent'   'pop_chanevent' ...
40
              'pop_importpres' 'pop_importerplab' 'pop_iclabel' 'pop_icflag' 'pop_dipfit_headmodel' ...
41
              'pop_dipfit_settings' 'pop_dipfit_gridsearch' 'pop_dipfit_nonlinear' 'pop_multifit' 'pop_leadfield' 'topoplot' ';;;' ...
42
              'pop_roi_connect' 'pop_importmff' 'pop_roi_activity' 'pop_eegstats' };
43
44
posEqual = find('=' == LASTCOM);
45
if ~isempty(LASTCOM) && ~isempty(EEG) ...
46
        && ~isempty(posEqual) ...
47
        && contains(LASTCOM(1:posEqual(1)), 'EEG') ... % when no equal sign found, do not create new datasets
48
        && ~contains(LASTCOM, functionsEEGLAB) ... % when using one of the functions in the list, do not create new datasets
49
        && ~exist('DEBUG_EEGLAB_MENUS', 'var') % when in debug menu mode, do not create new datasets (see eeglab_execmenu)
50
51
    % Here the dataset was modified 
52
    EEG = eegh(LASTCOM, EEG); 
53
    [ALLEEG, EEG, CURRENTSET, LASTCOM] = pop_newset(ALLEEG, EEG, CURRENTSET, 'study', ~isempty(STUDY)+0);
54
    eegh(LASTCOM);
55
    disp('Done');
56
    eeglab('redraw');
57
58
elseif ~isempty(LASTCOM)
59
60
    % Here the dataset was not modified (plotting only) 
61
    EEG = eegh(LASTCOM, EEG); 
62
    [ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);
63
    if ~isempty(posEqual) && contains(LASTCOM(1:posEqual(1)), 'EEG')
64
        % dataset modified, store in history
65
        eegh('[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET);');
66
    end
67
    eeglab('redraw');
68
    % even though EEG is modified by eegh call, do not keep eeg_store in history
69
    % so the history does not reflect modifications to EEG.history for
70
    % better redeability
71
72
end
73
74
clear functionsEEGLAB posEqual;