function ext = new_extension_dialog(type)

%----------------------
% HANDLE INPUT
%----------------------

%--
% set and check extension type
%--

types = get_extension_types;

if ~nargin
	type = types{1};
end

if ~ismember(type, types)
	error('Unrecognized extension type input.');
end

%----------------------
% CREATE DIALOG
%----------------------

%--
% create controls
%--

control = empty(control_create);

control(end + 1) = control_create( ...
	'style', 'separator', ...
	'type', 'header', ...
	'min', 1, ...
	'string', 'Extension' ...
);

control(end + 1) = control_create( ...
	'name', 'name', ...
	'style', 'edit', ... 
	'space', 0.75 ...
);

ix = find(strcmp(type, types));

control(end + 1) = control_create( ...
	'name', 'type', ...
	'style', 'popup', ...
	'string', title_caps(types), ... 
	'value', ix ...
);

exts = get_extensions(type); names = {'None', exts.name};

control(end + 1) = control_create( ...
	'name', 'parent', ...
	'style', 'popup', ...
	'string', names, ... 
	'value', ix ...
);

control(end + 1) = control_create( ...
	'name', 'short_description', ...
	'lines', 2, ...
	'style', 'edit', ... 
	'space', 0.75 ...
);

control(end).space = 1.5;

%--
% configure and present dialog
%--

% NOTE: consider using color based on type value and possibly changing label

opt = dialog_group; 

opt.header_color = get_extension_color('root'); opt.text_menu = 1;

out = dialog_group('New ...', control, opt, @new_extension_callback);

% NOTE: return on cancel or abort

values = out.values;

if isempty(values)
	ext = []; return;
end

%--
% generate extension
%--

% TODO: develop a way to inherit using the dialog, dynamic parent popup

values

% ext = generate_extension(values.type{1}, values.name, values.parent{1});


%-------------------------------------
% NEW_EXTENSION_CALLBACK
%-------------------------------------

% TODO: this function must implement the dynamic parent popup

% NOTE: consider that inheritance may jump types, still single inheritance

function new_extension_callback(obj, eventdata);

callback = get_callback_context(obj, 'pack');

pal = callback.pal; control = callback.control; 

switch control.name
	
	case 'name'
		
		% TODO: validate it is proper filename
		
	case 'type'
		
		% TODO: change header color and label and load parent list dynamically
		
	case 'parent'
		
	case 'short_description'
		
end
