function lf_updateBlockCallbackStruct(~,~)
%lf_updateBlockCallbackStruct Listener called after completion of Ctrl+D.

% Copyright 2008-2014 The MathWorks, Inc.


modelHandle = get_param(bdroot,'Handle');

%Uncomment code below to enable access to block handles after Ctrl+D
global modelBlockStruct
global modelHandleStruct

if ~isempty(modelBlockStruct)
    if isfield(modelBlockStruct,'handles')
        modelHandleStruct = modelBlockStruct.handles;
        if isfield(modelBlockStruct.callbacks,'enginePostBlockListener')
            lf_invokeBlockCallback(modelBlockStruct.callbacks.enginePostBlockListener, modelBlockStruct);
        end
    else
        clear global modelHandleStruct;
    end
else
    clear global modelHandleStruct;
end
if loc_isCoderTarget(bdroot)
    codertarget.resourcemanager.resetAllResources(getActiveConfigSet(modelHandle));
end

clear global modelBlockStruct;
clear global modelHandleStruct;

lf_removeEngineEventListener(modelHandle, 'EnginePostBlock',  @lf_updateBlockCallbackStruct);
lf_removeEngineEventListener(modelHandle, 'EngineCompFailed', @lf_clearBlockCallbackStruct);
end


% -------------------------------------------------------------------------
function ret = loc_isCoderTarget(modelName)
cs = getActiveConfigSet(modelName);
ret = cs.isValidParam('CoderTargetData') && ...
   codertarget.data.getParameterValue(cs, 'UseCoderTarget');
end
