function dialogCallback(hObj, hDlg, tag, hCLI, action)
%DIALOGCALLBACK - Callback for the HDLCC dialog.

% Author(s): P. Costa, Jie Sun
% Copyright 2005-2013 The MathWorks, Inc.
%

% For the use by event handler to enable the Apply button
if isempty(tag) && strcmpi(action, 'enableApply')
EnableApplyButton(hDlg);
return;
end

% Object name
ObjProp = tag(length('ConfigSet_HDLCoder_TestBenchPanel_')+1:end);
setting_unchanged = true;
% Execute all dynamic-dialog callbacks. Note that the NAG controller is
% called
try
% Need to clear because closing nag controller does not clear all nags info

setting_unchanged = feval([ObjProp '_callback'], hObj, hDlg, hCLI, action);
catch e
% update code to use new message viewer instead of the simulink viewer.
Simulink.output.Stage('HDLCoder', 'ModelName', gcs(), 'UIMode', true);
Simulink.output.error( e,'Component','HDLCoder','Category','HDL');
end

if isequal(action, 'enableApply') && setting_unchanged == false
EnableApplyButton(hDlg);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function unchanged_flag = Browse_callback(hObj, hDlg, hCLI, action) %#ok

tdir = uigetdir('',DAStudio.message('HDLShared:hdldialog:hdlccSelectTargetDir'));
if tdir ~= 0
set(hCLI, 'SimulationLibPath', tdir);
unchanged_flag = false;
else
unchanged_flag = true;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function EnableApplyButton(hDlg)
% Forcing Apply button to be enabled, bug in Dynamic Dialog
if ~isempty(hDlg) && isa(hDlg, 'DAStudio.Dialog')
hDlg.enableApplyButton(true);
end

% [EOF]