<commit_before>﻿using UnityEngine;
using System;
using System.Collections;
using UnityEditor;
using ATP.ReorderableList;
using SyntaxTree.VisualStudio.Unity.Messaging;

namespace mlogger {

    [CustomEditor(typeof(Logger))]
    public class LoggerEditor : Editor {

        private Logger Script { get; set; }

        #region SERIALIZED PROPERTIES
        private SerializedProperty filePath;
        private SerializedProperty initArraySize;
        private SerializedProperty inGameLabel;
        private SerializedProperty logInRealTime;
        private SerializedProperty echoToConsole;
        private SerializedProperty enableLogCall;
        private SerializedProperty enableLogResult;
        private SerializedProperty enableLogString;
        private SerializedProperty loggingEnabled;
        private SerializedProperty enableOnPlay;
        private SerializedProperty appendClassName;
        private SerializedProperty appendCallerClassName;
        private SerializedProperty fullyQualifiedClassName;
        private SerializedProperty showTimestamp;
        private SerializedProperty indentMessage;
        private SerializedProperty classFilter;
        private SerializedProperty methodFilter;
        #endregion

        #region UNITY MESSAGES
        private void OnEnable() {
            Script = (Logger) target;

            filePath = serializedObject.FindProperty("filePath");
            initArraySize = serializedObject.FindProperty("initArraySize");
            inGameLabel = serializedObject.FindProperty("inGameLabel");
            logInRealTime = serializedObject.FindProperty("logInRealTime");
            echoToConsole = serializedObject.FindProperty("echoToConsole");
            enableLogCall = serializedObject.FindProperty("enableLogCall");
            enableLogResult = serializedObject.FindProperty("enableLogResult");
            enableLogString = serializedObject.FindProperty("enableLogString");
            loggingEnabled = serializedObject.FindProperty("loggingEnabled");
            enableOnPlay = serializedObject.FindProperty("enableOnPlay");
            appendClassName = serializedObject.FindProperty("appendClassName");
            appendCallerClassName =
                serializedObject.FindProperty("appendCallerClassName");
            fullyQualifiedClassName =
                serializedObject.FindProperty("fullyQualifiedClassName");
            showTimestamp = serializedObject.FindProperty("showTimestamp");
            indentMessage = serializedObject.FindProperty("indentMessage");
            classFilter = serializedObject.FindProperty("classFilter");
            methodFilter = serializedObject.FindProperty("methodFilter");
        }

        public override void OnInspectorGUI() {
            serializedObject.Update();

            // TODO Set longer label width.

            DrawFilePathField();

            EditorGUILayout.Space();

            DrawEnableOnPlayToggle();
            DrawLogInRealTimeToggle();
            DrawEchoToConsoleToggle();

            EditorGUILayout.Space();

            DrawIndentLineToggle();
            DrawFullyQualifiedNameToggle();

            EditorGUILayout.Space();

            DrawEnabledMethodsDropdown();
            DrawAppendDropdown();

            EditorGUILayout.Space();

            DrawMyClassHelpBox();
            ReorderableListGUI.Title("Class Filter");
            ReorderableListGUI.ListField(classFilter);

            DrawOnEnableHelpBox();
            ReorderableListGUI.Title("Method Filter");
            ReorderableListGUI.ListField(methodFilter);

            EditorGUILayout.BeginHorizontal();
            HandleDrawingStartStopButton();
            DrawClearLogFileButton();
            EditorGUILayout.EndHorizontal();

            // Save changes
            serializedObject.ApplyModifiedProperties();
        }
        #endregion
        #region INSPECTOR
        private void DrawClearLogFileButton() {
            if (GUILayout.Button("Clear Log File")) {
                Script.ClearLogFile();
            }
        }


        private void HandleDrawingStartStopButton() {
            // todo add button to continue logging after pause
            // todo extract what's inside to DrawDrawStartStopButton()
            if (loggingEnabled.boolValue == false) {
                loggingEnabled.boolValue = GUILayout.Toggle(
                    loggingEnabled.boolValue,
                    "Start Logging",
                    "Button");

                // If value was changed..
                if (loggingEnabled.boolValue != Script.LoggingEnabled) {
                    // Fire event.
                    Utilities.InvokeMethodWithReflection(
                        Script,
                        "OnStateChanged",
                        null);
                }
            }
            else if (Application.isPlaying && enableOnPlay.boolValue) {
                loggingEnabled.boolValue = GUILayout.Toggle(
                    loggingEnabled.boolValue,
                    "Pause Logging",
                    "Button");

                // If value was changed..
                if (loggingEnabled.boolValue != Script.LoggingEnabled) {
                    loggingEnabled.boolValue = false;
                    Script.LogCache.Add("[PAUSE]", true);

                    // Fire event.
                    Utilities.InvokeMethodWithReflection(
                        Script,
                        "OnStateChanged",
                        null);
                }
            }
            else {
                loggingEnabled.boolValue = GUILayout.Toggle(
                    loggingEnabled.boolValue,
                    "Stop Logging",
                    "Button");

                // If value was changed..
                if (loggingEnabled.boolValue != Script.LoggingEnabled) {
                    loggingEnabled.boolValue = false;
                    Script.LogCache.WriteAll(Script.FilePath, false);

                    // Fire event.
                    Utilities.InvokeMethodWithReflection(
                        Script,
                        "OnStateChanged",
                        null);
                }
            }
        }

        private void DrawOnEnableHelpBox() {
            EditorGUILayout.HelpBox(
                "Example: OnEnable",
                UnityEditor.MessageType.Info);
        }

        private void DrawMyClassHelpBox() {

            EditorGUILayout.HelpBox(
                "Example: MyClass",
                UnityEditor.MessageType.Info);
        }

        private void DrawAppendDropdown() {
            Script.AppendOptions = (AppendOptions) EditorGUILayout.EnumMaskField(
                new GUIContent(
                    "Append",
                    ""),
                Script.AppendOptions);
        }

        private void DrawEnabledMethodsDropdown() {
            Script.EnabledMethods = (EnabledMethods) EditorGUILayout.EnumMaskField(
                new GUIContent(
                    "Enabled Methods",
                    "Select Logger methods that should be active. Inactive " +
                    "methods won't product output."),
                Script.EnabledMethods);
        }

        private void DrawFullyQualifiedNameToggle() {

            EditorGUILayout.PropertyField(
                fullyQualifiedClassName,
                new GUIContent(
                    "Qualified Class Name",
                    "If enabled, class name will be fully qualified."));
        }

        private void DrawIndentLineToggle() {

            EditorGUILayout.PropertyField(
                // todo rename to indentLine
                indentMessage,
                new GUIContent(
                    "Indent On",
                    ""));
        }

        private void DrawEchoToConsoleToggle() {

            EditorGUILayout.PropertyField(
                echoToConsole,
                new GUIContent(
                    "Echo To Console",
                    "Echo logged messages also to the Unity's console. " +
                    "It can be really slow."));
        }

        private void DrawLogInRealTimeToggle() {

            EditorGUILayout.PropertyField(
                logInRealTime,
                new GUIContent(
                    "Log In Real Time",
                    "Each log message will be written to the file " +
                    "in real time instead of when logging stops."));
        }

        private void DrawEnableOnPlayToggle() {

            EditorGUILayout.PropertyField(
                enableOnPlay,
                new GUIContent(
                    "Enable On Play",
                    "Start logger when entering play mode."));
        }

        private void DrawFilePathField() {

            EditorGUILayout.PropertyField(
                filePath,
                new GUIContent(
                    "File Path",
                    "File path to save the generated log file."));
        }
        #endregion

    }
}
<commit_msg>Don't allow reseting log file while logging<commit_after>﻿using UnityEngine;
using System;
using System.Collections;
using UnityEditor;
using ATP.ReorderableList;
using SyntaxTree.VisualStudio.Unity.Messaging;

namespace mlogger {

    [CustomEditor(typeof(Logger))]
    public class LoggerEditor : Editor {

        private Logger Script { get; set; }

        #region SERIALIZED PROPERTIES
        private SerializedProperty filePath;
        private SerializedProperty initArraySize;
        private SerializedProperty inGameLabel;
        private SerializedProperty logInRealTime;
        private SerializedProperty echoToConsole;
        private SerializedProperty enableLogCall;
        private SerializedProperty enableLogResult;
        private SerializedProperty enableLogString;
        private SerializedProperty loggingEnabled;
        private SerializedProperty enableOnPlay;
        private SerializedProperty appendClassName;
        private SerializedProperty appendCallerClassName;
        private SerializedProperty fullyQualifiedClassName;
        private SerializedProperty showTimestamp;
        private SerializedProperty indentMessage;
        private SerializedProperty classFilter;
        private SerializedProperty methodFilter;
        #endregion

        #region UNITY MESSAGES
        private void OnEnable() {
            Script = (Logger) target;

            filePath = serializedObject.FindProperty("filePath");
            initArraySize = serializedObject.FindProperty("initArraySize");
            inGameLabel = serializedObject.FindProperty("inGameLabel");
            logInRealTime = serializedObject.FindProperty("logInRealTime");
            echoToConsole = serializedObject.FindProperty("echoToConsole");
            enableLogCall = serializedObject.FindProperty("enableLogCall");
            enableLogResult = serializedObject.FindProperty("enableLogResult");
            enableLogString = serializedObject.FindProperty("enableLogString");
            loggingEnabled = serializedObject.FindProperty("loggingEnabled");
            enableOnPlay = serializedObject.FindProperty("enableOnPlay");
            appendClassName = serializedObject.FindProperty("appendClassName");
            appendCallerClassName =
                serializedObject.FindProperty("appendCallerClassName");
            fullyQualifiedClassName =
                serializedObject.FindProperty("fullyQualifiedClassName");
            showTimestamp = serializedObject.FindProperty("showTimestamp");
            indentMessage = serializedObject.FindProperty("indentMessage");
            classFilter = serializedObject.FindProperty("classFilter");
            methodFilter = serializedObject.FindProperty("methodFilter");
        }

        public override void OnInspectorGUI() {
            serializedObject.Update();

            // TODO Set longer label width.

            DrawFilePathField();

            EditorGUILayout.Space();

            DrawEnableOnPlayToggle();
            DrawLogInRealTimeToggle();
            DrawEchoToConsoleToggle();

            EditorGUILayout.Space();

            DrawIndentLineToggle();
            DrawFullyQualifiedNameToggle();

            EditorGUILayout.Space();

            DrawEnabledMethodsDropdown();
            DrawAppendDropdown();

            EditorGUILayout.Space();

            DrawMyClassHelpBox();
            ReorderableListGUI.Title("Class Filter");
            ReorderableListGUI.ListField(classFilter);

            DrawOnEnableHelpBox();
            ReorderableListGUI.Title("Method Filter");
            ReorderableListGUI.ListField(methodFilter);

            EditorGUILayout.BeginHorizontal();
            HandleDrawingStartStopButton();
            DrawClearLogFileButton();
            EditorGUILayout.EndHorizontal();

            // Save changes
            serializedObject.ApplyModifiedProperties();
        }
        #endregion
        #region INSPECTOR
        private void DrawClearLogFileButton() {
            // Don't allow reseting log file while logging.
            if (Script.LoggingEnabled) return;

            if (GUILayout.Button(
                "Clear Log File",
                GUILayout.Width(100))) {

                Script.ClearLogFile();
            }
        }


        private void HandleDrawingStartStopButton() {
            // todo add button to continue logging after pause
            // todo extract what's inside to DrawDrawStartStopButton()
            if (loggingEnabled.boolValue == false) {
                loggingEnabled.boolValue = GUILayout.Toggle(
                    loggingEnabled.boolValue,
                    "Start Logging",
                    "Button");

                // If value was changed..
                if (loggingEnabled.boolValue != Script.LoggingEnabled) {
                    // Fire event.
                    Utilities.InvokeMethodWithReflection(
                        Script,
                        "OnStateChanged",
                        null);
                }
            }
            else if (Application.isPlaying && enableOnPlay.boolValue) {
                loggingEnabled.boolValue = GUILayout.Toggle(
                    loggingEnabled.boolValue,
                    "Pause Logging",
                    "Button");

                // If value was changed..
                if (loggingEnabled.boolValue != Script.LoggingEnabled) {
                    loggingEnabled.boolValue = false;
                    Script.LogCache.Add("[PAUSE]", true);

                    // Fire event.
                    Utilities.InvokeMethodWithReflection(
                        Script,
                        "OnStateChanged",
                        null);
                }
            }
            else {
                loggingEnabled.boolValue = GUILayout.Toggle(
                    loggingEnabled.boolValue,
                    "Stop Logging",
                    "Button");

                // If value was changed..
                if (loggingEnabled.boolValue != Script.LoggingEnabled) {
                    loggingEnabled.boolValue = false;
                    Script.LogCache.WriteAll(Script.FilePath, false);

                    // Fire event.
                    Utilities.InvokeMethodWithReflection(
                        Script,
                        "OnStateChanged",
                        null);
                }
            }
        }

        private void DrawOnEnableHelpBox() {
            EditorGUILayout.HelpBox(
                "Example: OnEnable",
                UnityEditor.MessageType.Info);
        }

        private void DrawMyClassHelpBox() {

            EditorGUILayout.HelpBox(
                "Example: MyClass",
                UnityEditor.MessageType.Info);
        }

        private void DrawAppendDropdown() {
            Script.AppendOptions = (AppendOptions) EditorGUILayout.EnumMaskField(
                new GUIContent(
                    "Append",
                    ""),
                Script.AppendOptions);
        }

        private void DrawEnabledMethodsDropdown() {
            Script.EnabledMethods = (EnabledMethods) EditorGUILayout.EnumMaskField(
                new GUIContent(
                    "Enabled Methods",
                    "Select Logger methods that should be active. Inactive " +
                    "methods won't product output."),
                Script.EnabledMethods);
        }

        private void DrawFullyQualifiedNameToggle() {

            EditorGUILayout.PropertyField(
                fullyQualifiedClassName,
                new GUIContent(
                    "Qualified Class Name",
                    "If enabled, class name will be fully qualified."));
        }

        private void DrawIndentLineToggle() {

            EditorGUILayout.PropertyField(
                // todo rename to indentLine
                indentMessage,
                new GUIContent(
                    "Indent On",
                    ""));
        }

        private void DrawEchoToConsoleToggle() {

            EditorGUILayout.PropertyField(
                echoToConsole,
                new GUIContent(
                    "Echo To Console",
                    "Echo logged messages also to the Unity's console. " +
                    "It can be really slow."));
        }

        private void DrawLogInRealTimeToggle() {

            EditorGUILayout.PropertyField(
                logInRealTime,
                new GUIContent(
                    "Log In Real Time",
                    "Each log message will be written to the file " +
                    "in real time instead of when logging stops."));
        }

        private void DrawEnableOnPlayToggle() {

            EditorGUILayout.PropertyField(
                enableOnPlay,
                new GUIContent(
                    "Enable On Play",
                    "Start logger when entering play mode."));
        }

        private void DrawFilePathField() {

            EditorGUILayout.PropertyField(
                filePath,
                new GUIContent(
                    "File Path",
                    "File path to save the generated log file."));
        }
        #endregion

    }
}

{'fraction_non_alphanumeric': 0.07102116924426895, 'fraction_numerical': 0.00016452780519907864, 'mean_word_length': 1.6218547807332855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3180857', 'n_tokens_mistral': 4110, 'n_tokens_neox': 3842, 'n_words': 864}