function handleClickSaveProfile(userdata, cbinfo)
    peInstance = cbinfo.Context.Object.AppObject;
    row = peInstance.ProfileBrowser.getCurrentSelection; 
    switch userdata
        case 'save'
            % If profile has open models using it, then offer to
            % save both model and profile
            for profiles = row
                node = peInstance.ProfileBrowser.dataProvider.UUIDtoNameMap(profiles.rowID);
                prfName = strtok(node, '.');
                profile = systemcomposer.profile.Profile.find(prfName).getImpl;
                [profileIsInUse, modelsToSave] = pe.toolstrip.profileHasOpenUsages(profile, peInstance);
                if profileIsInUse
                    dp = DAStudio.DialogProvider;
                    qDlg = dp.questdlg(...
                        DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileAndModelsQuestion', profile.getName()), ...
                        DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileTitle'), ...
                        {DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileAndModels'), ...
                        DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileOnly'), ...
                        DAStudio.message('SystemArchitecture:ProfileDesigner:Cancel')}, ...
                        DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileAndModels'), ...
                        @(resp) handleSaveResponse(resp, modelsToSave, profile));
                else
                    % No profiles are being used - just do the regular
                    % save path
                    handleSaveResponse(...
                        DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileOnly'), modelsToSave, profile);
                end
            end
    
        case 'saveAs'
            for profiles = row
                node = peInstance.ProfileBrowser.dataProvider.UUIDtoNameMap(profiles.rowID);
                prfName = strtok(node, '.');
                profile = systemcomposer.profile.Profile.find(prfName).getImpl;
                pe.toolstrip.profileSaveAs(profile, [], peInstance);
                systemcomposer.loadProfile(prfName);
            end
    
        case 'saveAll'
            pe.toolstrip.saveUnsavedProfiles();
    
        case 'exportToPrevious'
            for profiles = row
                node = peInstance.ProfileBrowser.dataProvider.UUIDtoNameMap(profiles.rowID);
                prfName = strtok(node, '.');
                profile = systemcomposer.profile.Profile.find(prfName).getImpl;
                pe.toolstrip.handleClickExportProfile(profile);
                systemcomposer.loadProfile(prfName);
            end
        otherwise
            assert(false, 'Invalid action tag');
    end
    peInstance.ProfileBrowser.dataModel.refreshView();

        function handleSaveResponse(response, modelsToSave, profile)
    
            prf = profile;
            switch response
                case DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileAndModels')
                    % statusMsg = DAStudio.message('SystemArchitecture:ProfileDesigner:SavedProfileAndModels', prf.getName);
                case DAStudio.message('SystemArchitecture:ProfileDesigner:SaveProfileOnly')
                    modelsToSave = {};
                otherwise
                    return; % cancel => do nothing
            end
    
            % Does profile have a filepath where it came from?
            if ~isempty(prf.filePath)
                s = pe.toolstrip.profileSave(prf, '', []);
                if s % either error or abort
                    return;
                end
            else
                pe.toolstrip.profileSaveAs(prf, [], peInstance);
            end
    
            % Now save any open models or dictionaries
            for idx = 1 : length(modelsToSave)
                [~,name,ext] = fileparts(modelsToSave{idx});
                if ~strcmpi(ext, '.sldd')
                    save_system(name, 'SaveDirtyReferencedModels', true);
                else
                    ddConn = Simulink.data.dictionary.open(modelsToSave{idx});
                    ddConn.saveChanges();
                end
            end
        end
end