<commit_before>﻿using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using UnityObject = UnityEngine.Object;

namespace UInspectorPlus {
    class InspectorDrawer {
        public object target;
        public List<IReflectorDrawer> drawer;
        public bool shown;
        public bool isInternalType;
        public bool changed;
        public string searchText;
        public event Action OnRequireRedraw;
        Type targetType, elementType;
        HexEdit hexEdit;
        List<MethodPropertyDrawer> arrayContentDrawer;
        ReorderableList arrayHandler;

        public InspectorDrawer(object target, bool shown, bool showProps, bool showPrivateFields, bool showObsolete, bool showMethods) {
            this.target = target;
            this.drawer = new List<IReflectorDrawer>();
            BindingFlags flag = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
            if (showPrivateFields)
                flag |= BindingFlags.NonPublic;
            targetType = target.GetType();
            elementType = Helper.GetGenericListType(targetType);
            var fields = targetType.GetFields(flag);
            var props = !showProps ? null : targetType.GetProperties(flag).Where(prop => prop.GetIndexParameters().Length == 0).ToArray();
            isInternalType = !(target is MonoBehaviour) || Attribute.IsDefined(target.GetType(), typeof(ExecuteInEditMode));
            foreach (var field in fields)
                try {
                    if (!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
                        continue;
                    drawer.Add(new MethodPropertyDrawer(field, target, showPrivateFields, showObsolete) {
                        AllowReferenceMode = false
                    });
                } catch (Exception ex) {
                    Debug.LogException(ex);
                }
            if (showProps) {
                HashSet<string> blacklistedType;
                if(!Helper.blackListedTypes.TryGetValue(targetType, out blacklistedType)) {
                    Helper.blackListedTypes.Add(targetType, blacklistedType = new HashSet<string>());
                    foreach (var kvp in Helper.blackListedTypes)
                        if (kvp.Key.IsAssignableFrom(targetType))
                            blacklistedType.UnionWith(kvp.Value);
                }
                foreach (var prop in props)
                    try {
                        if (blacklistedType != null && blacklistedType.Contains(prop.Name))
                            continue;
                        if (!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
                            continue;
                        drawer.Add(new MethodPropertyDrawer(prop, target, showPrivateFields, showObsolete, prop.CanRead && EditorApplication.isPlaying) {
                            AllowReferenceMode = false,
                            Updatable = isInternalType || Helper.GetState(prop, false),
                            ShowUpdatable = !isInternalType
                        });
                    } catch (Exception ex) {
                        Debug.LogException(ex);
                    }
            }
            if (showMethods)
                drawer.Add(new ComponentMethodDrawer(target) { AllowPrivateFields = showPrivateFields });
            foreach (var d in drawer)
                d.OnRequireRedraw += RequireRedraw;
            this.shown = Helper.GetState(target, shown);
        }

        public void Draw(bool drawHeader = true, bool readOnly = false) {
            if (target == null) {
                EditorGUILayout.InspectorTitlebar(false, null as UnityObject);
                return;
            }
            if (drawHeader) {
                shown = EditorGUILayout.InspectorTitlebar(shown, target as UnityObject);
                Helper.StoreState(target, shown);
                if (!shown)
                    return;
            }
            EditorGUI.indentLevel++;
            EditorGUILayout.BeginVertical();
            if (elementType != null) {
                if (targetType == typeof(byte[])) {
                    if (hexEdit == null)
                        hexEdit = new HexEdit();
                    hexEdit.data = target as byte[];
                    if (hexEdit.data != null)
                        hexEdit.DrawGUI(false, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight), GUILayout.ExpandHeight(true));
                } else {
                    if (arrayHandler == null) {
                        if (arrayContentDrawer == null) {
                            arrayContentDrawer = new List<MethodPropertyDrawer>();
                            for (int i = 0; i < (target as IList).Count; i++)
                                ListAddItem();
                        }
                        arrayHandler = new ReorderableList(target as IList, elementType);
                        arrayHandler.headerHeight = EditorGUIUtility.singleLineHeight;
                        arrayHandler.elementHeight = EditorGUIUtility.singleLineHeight + 2;
                        arrayHandler.drawElementCallback = (r, i, c, d) => {
                            arrayContentDrawer[i].Value = (target as IList)[i];
                            arrayContentDrawer[i].Draw(false, Helper.ScaleRect(r, offsetHeight: -2));
                            if (arrayContentDrawer[i].Changed)
                                (target as IList)[i] = arrayContentDrawer[i].Value;
                        };
                        arrayHandler.drawHeaderCallback = r => GUI.Label(r, target.ToString(), EditorStyles.boldLabel);
                        arrayHandler.onCanAddCallback = l => target != null && !(target as IList).IsFixedSize;
                        arrayHandler.onCanRemoveCallback = arrayHandler.onCanAddCallback.Invoke;<commit_msg>Add folded to array list editor Set minimum height for hex editor<commit_after>﻿using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using UnityObject = UnityEngine.Object;

namespace UInspectorPlus {
    class InspectorDrawer {
        public object target;
        public List<IReflectorDrawer> drawer;
        public bool shown;
        public bool isInternalType;
        public bool changed;
        public string searchText;
        public event Action OnRequireRedraw;
        Type targetType, elementType;
        HexEdit hexEdit;
        List<MethodPropertyDrawer> arrayContentDrawer;
        ReorderableList arrayHandler;
        bool showListEdit;

        public InspectorDrawer(object target, bool shown, bool showProps, bool showPrivateFields, bool showObsolete, bool showMethods) {
            this.target = target;
            this.drawer = new List<IReflectorDrawer>();
            BindingFlags flag = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
            if (showPrivateFields)
                flag |= BindingFlags.NonPublic;
            targetType = target.GetType();
            elementType = Helper.GetGenericListType(targetType);
            var fields = targetType.GetFields(flag);
            var props = !showProps ? null : targetType.GetProperties(flag).Where(prop => prop.GetIndexParameters().Length == 0).ToArray();
            isInternalType = !(target is MonoBehaviour) || Attribute.IsDefined(target.GetType(), typeof(ExecuteInEditMode));
            foreach (var field in fields)
                try {
                    if (!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
                        continue;
                    drawer.Add(new MethodPropertyDrawer(field, target, showPrivateFields, showObsolete) {
                        AllowReferenceMode = false
                    });
                } catch (Exception ex) {
                    Debug.LogException(ex);
                }
            if (showProps) {
                HashSet<string> blacklistedType;
                if(!Helper.blackListedTypes.TryGetValue(targetType, out blacklistedType)) {
                    Helper.blackListedTypes.Add(targetType, blacklistedType = new HashSet<string>());
                    foreach (var kvp in Helper.blackListedTypes)
                        if (kvp.Key.IsAssignableFrom(targetType))
                            blacklistedType.UnionWith(kvp.Value);
                }
                foreach (var prop in props)
                    try {
                        if (blacklistedType != null && blacklistedType.Contains(prop.Name))
                            continue;
                        if (!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
                            continue;
                        drawer.Add(new MethodPropertyDrawer(prop, target, showPrivateFields, showObsolete, prop.CanRead && EditorApplication.isPlaying) {
                            AllowReferenceMode = false,
                            Updatable = isInternalType || Helper.GetState(prop, false),
                            ShowUpdatable = !isInternalType
                        });
                    } catch (Exception ex) {
                        Debug.LogException(ex);
                    }
            }
            if (showMethods)
                drawer.Add(new ComponentMethodDrawer(target) { AllowPrivateFields = showPrivateFields });
            foreach (var d in drawer)
                d.OnRequireRedraw += RequireRedraw;
            this.shown = Helper.GetState(target, shown);
        }

        public void Draw(bool drawHeader = true, bool readOnly = false) {
            if (target == null) {
                EditorGUILayout.InspectorTitlebar(false, null as UnityObject);
                return;
            }
            if (drawHeader) {
                shown = EditorGUILayout.InspectorTitlebar(shown, target as UnityObject);
                Helper.StoreState(target, shown);
                if (!shown)
                    return;
            }
            EditorGUI.indentLevel++;
            EditorGUILayout.BeginVertical();
            if (elementType != null) {
                if (targetType == typeof(byte[])) {
                    if (hexEdit == null)
                        hexEdit = new HexEdit();
                    hexEdit.data = target as byte[];
                    if (hexEdit.data != null)
                        hexEdit.DrawGUI(false, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 3), GUILayout.ExpandHeight(true));
                } else if (showListEdit = EditorGUILayout.Foldout(showListEdit, string.Format("Edit List [{0} Items]", (target as IList).Count))) {
                    if (arrayHandler == null) {
                        if (arrayContentDrawer == null) {
                            arrayContentDrawer = new List<MethodPropertyDrawer>();
                            for (int i = 0; i < (target as IList).Count; i++)
                                ListAddItem();
                        }
                        arrayHandler = new ReorderableList(target as IList, elementType);
                        arrayHandler.headerHeight = EditorGUIUtility.singleLineHeight;
                        arrayHandler.elementHeight = EditorGUIUtility.singleLineHeight + 2;
                        arrayHandler.drawElementCallback = (r, i, c, d) => {
                            arrayContentDrawer[i].Value = (target as IList)[i];
                            arrayContentDrawer[i].Draw(false, Helper.ScaleRect(r, offsetHeight: -2));
                            if (arrayContentDrawer[i].Changed)
                                (target as IList)[i] = arrayContentDrawer[i].Value;
                        };
                        arrayHandler.drawHeaderCallback = r => GUI.Label(r, target.ToString(), EditorStyles.boldLabel);
                        arrayHandler.onCanAddCallback = l => target != null && !(target as IList).IsFixedSize;
                        arrayHandler.onCanRemoveCallback = arrayHandler.onCanAddCallback.Invoke;
{'fraction_non_alphanumeric': 0.0844240837696335, 'fraction_numerical': 0.0008180628272251309, 'mean_word_length': 1.6703800786369594, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '4717937', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2803, 'n_words': 641}