<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityUI;
using UnityUI.Binding;
using UnityUI_Editor;

namespace UnityTools.UnityUI_Editor
{
    [CustomEditor(typeof(CollectionBinding))]
    class CollectionBindingEditor : Editor
    {

        public override void OnInspectorGUI()
        {
            // Initialise everything
            var targetScript = (CollectionBinding)target;

            var bindableCollections = GetBindableViewModelCollections(targetScript);
            ShowCollectionSelector(targetScript, bindableCollections);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Collection template");

            EditorGUILayout.ObjectField(targetScript.template, typeof(TemplateBinding), true);

            EditorGUILayout.EndHorizontal();
        }

        private PropertyInfo[] GetBindableViewModelCollections(CollectionBinding target)
        {
            return target.GetAvailableViewModelTypes()
                .SelectMany(type => type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                .Where(property => typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                .Where(property => !typeof(string).IsAssignableFrom(property.PropertyType))
                .ToArray();
        }

        /// <summary>
        /// Show dropdown for selecting a collection to bind to.
        /// </summary>
        private void ShowCollectionSelector(CollectionBinding targetScript, PropertyInfo[] bindableCollections)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Collection to bind to");

            var dropdownPosition = GUILayoutUtility.GetLastRect();
            dropdownPosition.x += dropdownPosition.width;

            if (GUILayout.Button(new GUIContent(targetScript.viewModelPropertyName), EditorStyles.popup))
            {<commit_msg>Fixed an issue with the CollectionBindingEditor that was preventing it from being linked to the template.<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityUI;
using UnityUI.Binding;
using UnityUI_Editor;

namespace UnityTools.UnityUI_Editor
{
    [CustomEditor(typeof(CollectionBinding))]
    class CollectionBindingEditor : Editor
    {

        public override void OnInspectorGUI()
        {
            // Initialise everything
            var targetScript = (CollectionBinding)target;

            var bindableCollections = GetBindableViewModelCollections(targetScript);
            ShowCollectionSelector(targetScript, bindableCollections);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Collection template");

            targetScript.template = (TemplateBinding)EditorGUILayout.ObjectField(targetScript.template, typeof(TemplateBinding), true);

            EditorGUILayout.EndHorizontal();
        }

        private PropertyInfo[] GetBindableViewModelCollections(CollectionBinding target)
        {
            return target.GetAvailableViewModelTypes()
                .SelectMany(type => type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                .Where(property => typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                .Where(property => !typeof(string).IsAssignableFrom(property.PropertyType))
                .ToArray();
        }

        /// <summary>
        /// Show dropdown for selecting a collection to bind to.
        /// </summary>
        private void ShowCollectionSelector(CollectionBinding targetScript, PropertyInfo[] bindableCollections)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Collection to bind to");

            var dropdownPosition = GUILayoutUtility.GetLastRect();
            dropdownPosition.x += dropdownPosition.width;

            if (GUILayout.Button(new GUIContent(targetScript.viewModelPropertyName), EditorStyles.popup))
            {
{'fraction_non_alphanumeric': 0.08268182895048566, 'fraction_numerical': 0.0, 'mean_word_length': 3.0286259541984735, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3618005', 'n_tokens_mistral': 1005, 'n_tokens_neox': 958, 'n_words': 204}