Beispiel #1
0
        private bool ValidateNaming()
        {
            var typeNames = TypeSafeUtil.GetTypeSafeClassNames();

            string errorMessage;

            for (var i = 0; i < typeNames.Count; i++)
            {
                if (
                    !TypeSafeUtil.ValidateTypeName(typeNames[i], _newNamespace, _newPrefix, _newSuffix, out errorMessage))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        public void OnGUI()
        {
            GUILayout.Label("Naming Scheme", EditorStyles.boldLabel);

            GUILayout.Label(
                "The naming scheme of the generated code can be adjusted here. Edit the namespace, prefix and suffix settings then press Apply to save and trigger a regeneration.",
                Styles.ParagraphLabel);

            var validationFailed = false;

            var width = (Screen.width - 8) / 3;

            EditorGUILayout.BeginHorizontal(Styles.NamingPreviewHeaderGroupStyle);

            string errorMessage;

            EditorGUILayout.BeginHorizontal(GUILayout.Width(width));
            GUILayout.Label("Namespace", Styles.NamingHeaderNamespaceLabel);

            if (!string.IsNullOrEmpty(_newNamespace) &&
                !TypeSafeUtil.ValidateNamespaceName(_newNamespace, out errorMessage))
            {
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal(GUILayout.Width(width));

            GUILayout.Label("Prefix", Styles.NamingHeaderPrefixLabel);

            if (!string.IsNullOrEmpty(_newPrefix) && !TypeSafeUtil.ValidateTypeName(_newPrefix, out errorMessage))
            {
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal(GUILayout.Width(width));

            GUILayout.Label("Suffix", Styles.NamingHeaderSuffixLabel);

            if (!string.IsNullOrEmpty(_newSuffix) && !TypeSafeUtil.ValidateTypeName(_newSuffix, out errorMessage))
            {
                GUILayout.Label(new GUIContent(_errorIcon, errorMessage), GUILayout.Height(ErrorIconHeight));
                validationFailed = true;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal(Styles.NamingPreviewGroupStyle);

            _newNamespace = EditorGUILayout.TextField(_newNamespace, Styles.NamingHeaderTextBox);
            _newPrefix    = EditorGUILayout.TextField(_newPrefix, Styles.NamingHeaderTextBox);
            _newSuffix    = EditorGUILayout.TextField(_newSuffix, Styles.NamingHeaderTextBox);

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginVertical(Styles.NamingPreviewTable);

            var typeNames = TypeSafeUtil.GetTypeSafeClassNames();

            for (var i = 0; i < typeNames.Count; i++)
            {
                DrawNamingPreview(typeNames[i], i, ref validationFailed);
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(!HasChangedNaming() || validationFailed);

            if (GUILayout.Button("Apply"))
            {
                Apply();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(!HasChangedNaming());

            if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
            {
                Reset();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
        }