protected Selection RenderEnumSelection(Rect rect, int selected)
        {
            var originalEnumNames = m_EnumInfoHelper.GetAllNames();

            selected = Mathf.Clamp(selected, 0, originalEnumNames.Count() - 1);
            originalEnumNames.Add("► Add enum...");
            originalEnumNames.Add("► Update or delete enum...");
            string[] enumNames           = originalEnumNames.ToArray();
            int      addIndex            = enumNames.Count() - 2;
            int      deleteOrUpdateIndex = enumNames.Count() - 1;
            int      newSelected         = EditorGUI.Popup(rect, selected, enumNames);

            if (newSelected == addIndex)
            {
                NewEnumWindow.ShowNewEnumWindow(m_ProtoFile, m_EnumInfoHelper);
                return(new Selection(selected, enumNames[selected]));
            }

            if (newSelected == deleteOrUpdateIndex)
            {
                DeleteEnumWindow.ShowWindow(m_ProtoFile, m_Descriptor.File, m_EnumInfoHelper);
                return(new Selection(selected, enumNames[selected]));
            }

            return(new Selection(newSelected, enumNames[newSelected]));
        }
Ejemplo n.º 2
0
        void OnGUI()
        {
            var enumNames = m_EnumInfoHelper.GetAllEditableNames().ToArray();

            if (enumNames.Length == 0)
            {
                EditorGUILayout.LabelField(
                    "Fidelity and Annotation messages don't contain any enums you can update or delete.",
                    EditorStyles.wordWrappedLabel);
                return;
            }

            if (m_EnumToDelete < 0)
            {
                m_EnumToDelete = 0;
                m_ErrorMessage = CheckForDeleteErrors(enumNames[m_EnumToDelete]);
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("Select enum to update or delete");
            m_EnumToDelete = EditorGUILayout.Popup(m_EnumToDelete, enumNames);
            if (EditorGUI.EndChangeCheck())
            {
                m_ErrorMessage = CheckForDeleteErrors(enumNames[m_EnumToDelete]);
            }


            GUILayout.Space(10);
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Update Enum", Styles.button, GUILayout.ExpandWidth(false)))
                {
                    EnumInfo?enumInfoToUpdate = m_EnumInfoHelper.GetInfo(enumNames[m_EnumToDelete]);
                    if (enumInfoToUpdate.HasValue)
                    {
                        NewEnumWindow.ShowWindow(m_ProtoFile, m_EnumInfoHelper, enumInfoToUpdate.Value);
                    }
                    else
                    {
                        Debug.LogErrorFormat("Information for [{0}] enum was not found", enumNames[m_EnumToDelete]);
                        NewEnumWindow.ShowNewEnumWindow(m_ProtoFile, m_EnumInfoHelper);
                    }

                    this.Close();
                }
            }

            GUILayout.Space(10);

            if (!string.IsNullOrEmpty(m_ErrorMessage))
            {
                EditorGUILayout.HelpBox(m_ErrorMessage, MessageType.Error);
            }

            EditorGUI.BeginDisabledGroup(!string.IsNullOrEmpty(m_ErrorMessage));
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Delete Enum", Styles.button, GUILayout.ExpandWidth(false)))
                {
                    m_ProtoFile.DeleteEnum(enumNames[m_EnumToDelete]);
                    this.Close();
                }
            }

            EditorGUI.EndDisabledGroup();
        }