function mRoot = addTSMenu(this,menuType,varargin)
%ADDSIMMENU  Install @timeplot-specific menus.

%  Author(s):  
%  Copyright 1986-2002 The MathWorks, Inc.
%  $Revision: 1.1.6.1 $ $Date: 2004/12/26 21:45:28 $

AxGrid = this.AxesGrid;
mRoot = AxGrid.findMenu(menuType);  % search for specified menu (HOLD support)
if ~isempty(mRoot)
    return
end

switch menuType
    case 'selectrule'
        % Show input signal
        mRoot = uimenu('Parent',AxGrid.UIcontextMenu,...
        'Label','Select data...','Tag','selectrule',...
        'Callback',@(es,ed) openselectdlg(this),varargin{:});
    case 'merge'
        % Show input signal
        mRoot = uimenu('Parent',AxGrid.UIcontextMenu,...
        'Label','Merge/resample...','Tag','merge',...
        'Callback',@(es,ed) openmergedlg(this,'modal'));   
    case 'preproc'
        mRoot = uimenu('Parent',AxGrid.UIcontextMenu,...
        'Label','Pre-process data...','Tag','preproc',...
        'Callback',@(es,ed) openpreprocdlg(this));
    case {'remove','delete','keep','newevent'}
        this.addlisteners(handle.listener(this,this.findprop('Responses'),'PropertyPostSet',...
            {@localSyncSelectionMenus this menuType}));
end


function localSyncSelectionMenus(eventSrc, eventData, h, menutype)

%% Listener callback which installs context menus for selected curves on
%% each wave. Note that this listener must be managed at the top level
%% (i.e., can't just be at the view level) since the menu callback needs
%% access to both the data and the view handles 
for k=1:length(h.Responses)
    h.Responses(k).View.addMenu(h,menutype);
end




