function studios = getStudiosForModels(modelList)
% cvi.Informer.getStudiosForModels
% Get all of the studios with an open editor displaying one of the
% specified models.

% Copyright 2019 The MathWorks, Inc.

    studios = [];
    allStudios = DAS.Studio.getAllStudiosSortedByMostRecentlyActive;
    if isempty(allStudios)
        return;
    end
    
    % Remove blanks
    modelListIdx = ~cellfun(@isempty, modelList);
    modelList = modelList(modelListIdx);
    if isempty(modelList)
        return;
    end
    
    % Convert model list to handles
    modelListH = get_param(modelList, 'handle');
    modelListH = [modelListH{:}];
    
    matchingStudiosIdx = zeros(size(allStudios),'logical');
    for sIdx=1:length(allStudios)
        curStudio = allStudios(sIdx);
        editors = curStudio.App.getAllEditors;
        editorHandles = [editors.blockDiagramHandle];
        
        if any(ismember(editorHandles,modelListH))
            matchingStudiosIdx(sIdx) = true;
        end
    end
    studios = allStudios(matchingStudiosIdx);
end
