function extension_menus(pal)

% extension_menus - add extension menus to palettes
% -------------------------------------------------
%
% extension_menus(pal)
%
% Input:
% ------
%  pal - palette handle

%--
% check palette is extension palette and get extension
%--

[value, ext] = is_extension_palette(pal);

%--
% add extension menus
%--

if value
	
	%--
	% add extension user menus
	%--
	
	preset_menu(pal, ext);
	
	help_menu(pal, ext);
	
	% EXPERIMENTAL CODE
	
	% NOTE: the state query required for the state is expensive
	
	par = get_palette_parent(pal);
	
	if ~isempty(par)
		toggle_menu(pal, ext, get_extension_active_state(par, ext));
	end
	
	%--
	% add extension developer menus
	%--
	
	pal_menu(pal, '', ext.subtype);
	
end


%-------------------------------------------
% GET_EXTENSION_ACTIVE_STATE
%-------------------------------------------

function state = get_extension_active_state(par, ext, data)

%--
% get browser state if needed
%--

if nargin < 3
	data = get_browser(par);
end

%--
% get active extension of relevant type and test
%--

active = data.browser.(ext.subtype).active;

if isempty(active)
	state = 0;
else
	state = strcmp(active, ext.name);
end

