Esempio n. 1
0
        public void NoCheckFollowedByConvertExample()
        {
            const string inputString =
                @"This is our summary
	BEGIN EX NOCHECK
	 weight  name   layer   lower   upper
	END EX
	 Blend weights blah blah 
	CONVERTEXAMPLE
	BEGIN EX
		animation.weight = 0.5;
	END EX"    ;
            var derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual("This is our summary", derivedModel.Summary);
            Assert.AreEqual(3, derivedModel.TextBlocks.Count);

            var example1 = derivedModel.TextBlocks[0];

            Assert.IsTrue(example1 is ExampleBlock);
            Assert.IsTrue((example1 as ExampleBlock).IsNoCheck);
            VerifyExample(derivedModel, 0, @"	 weight  name   layer   lower   upper
");
            VerifyDescription(derivedModel, 1, @"	 Blend weights blah blah");

            var example2 = derivedModel.TextBlocks[2];

            Assert.IsTrue(example2 is ExampleBlock);
            Assert.IsFalse((example2 as ExampleBlock).IsNoCheck);
            VerifyExample(derivedModel, 2, @"		animation.weight = 0.5;
");
        }
Esempio n. 2
0
        public void EmptyMember()
        {
            const string inputString   = "";
            var          expectedModel = new MemberSubSection(inputString);

            Assert.IsTrue(expectedModel.IsEmpty());
        }
Esempio n. 3
0
        public void MemberWithOnlyParamTabs()
        {
            const string inputString  = @"@param	label	Label in front of the label field";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual(1, derivedModel.Parameters.Count);
            Assert.IsTrue(derivedModel.Parameters[0].Equals("label", "Label in front of the label field"));
        }
Esempio n. 4
0
        public void MemberWithOnlyReturnValueTab()
        {
            const string inputString  = "@return	retval";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.IsNotNull(derivedModel.ReturnDoc);
            Assert.AreEqual("retval", derivedModel.ReturnDoc.Doc);
        }
Esempio n. 5
0
        public void MemberWithOnlySummary()
        {
            const string inputString  = "This is our summary";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual(inputString, derivedModel.Summary);
            Assert.AreEqual(0, derivedModel.TextBlocks.Count);
            Assert.AreEqual(0, derivedModel.Parameters.Count);
        }
Esempio n. 6
0
        public void MemberWithSummaryAndReturn()
        {
            const string inputString  = @"This is our summary
@return stupid stuff";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual("This is our summary", derivedModel.Summary);
            Assert.AreEqual(0, derivedModel.Parameters.Count);
            Assert.AreEqual("stupid stuff", derivedModel.ReturnDoc.Doc);
        }
Esempio n. 7
0
        public void MemberWithSummaryAndParam()
        {
            const string inputString  = @"This is our summary
@param label Label in front of the label field";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual("This is our summary", derivedModel.Summary);
            Assert.AreEqual(1, derivedModel.Parameters.Count);
            Assert.IsTrue(derivedModel.Parameters[0].Equals("label", "Label in front of the label field"));
        }
Esempio n. 8
0
        public void MemberWithSummaryAndDescription()
        {
            const string inputString  = @"This is our summary
Some more text";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual("This is our summary", derivedModel.Summary);
            Assert.AreEqual(1, derivedModel.TextBlocks.Count);
            Assert.AreEqual("Some more text", derivedModel.TextBlocks[0].Text);
        }
Esempio n. 9
0
    void ParametersAndReturnGUI(MemberSession member, int sectionIndex, bool readOnly)
    {
        MemberSubSection section = member.Model.SubSections[sectionIndex];

        // Parameters
        if (section.Parameters.Count > 0)
        {
            GUILayout.Label("Parameters", DocBrowser.styles.docSectionHeader);

            // Handle dragging parameter into first slot
            Rect dragTargetRect = GUILayoutUtility.GetRect(10, 0);
            dragTargetRect.y     -= 6;
            dragTargetRect.height = 14;
            DocBrowser.DragTarget(dragTargetRect, typeof(ParameterWithDoc), section.Parameters, 0);

            ParameterWithDoc paramToRemove = null;
            for (int i = 0; i < section.Parameters.Count; i++)
            {
                ParameterWithDoc p     = section.Parameters[i];
                string           label = "<b>" + p.Name + " : </b>" + (p.HasAsm ? Extensions.GetNiceName(p.TypeString) : "?");
                bool             remove;
                p.Doc = ParamOrReturnGUI(p.HasAsm, p.HasDoc, label, p.Doc, member.Language, readOnly, out remove, section.Parameters, i);
                if (remove)
                {
                    paramToRemove = p;
                }
            }
            if (paramToRemove != null)
            {
                section.Parameters.Remove(paramToRemove);
            }
        }

        // Returns
        if (section.ReturnDoc != null)
        {
            GUILayout.Label("Returns", DocBrowser.styles.docSectionHeader);
            ReturnWithDoc p     = section.ReturnDoc;
            string        label = (p.HasAsm ? Extensions.GetNiceName(p.ReturnType) : "?");
            bool          remove;
            p.Doc = ParamOrReturnGUI(p.HasAsm, p.HasDoc, label, p.Doc, member.Language, readOnly, out remove);
            if (remove)
            {
                section.ReturnDoc = null;
            }
        }

        EditorGUILayout.Space();
    }
Esempio n. 10
0
        public void MemberWithSummaryAndOneExample()
        {
            const string inputString  = @"This is our summary
BEGIN EX
function foo()
{ int k=0;}
END EX";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual("This is our summary", derivedModel.Summary);
            Assert.AreEqual(1, derivedModel.TextBlocks.Count);
            VerifyExample(derivedModel, 0, @"function foo()
{ int k=0;}
");
        }
Esempio n. 11
0
        public void ModifyReturnValue()
        {
            const string input = @"This is our summary
@return stupid stuff";
            var          model = new MemberSubSection(input);

            Assert.AreEqual("This is our summary", model.Summary);
            Assert.AreEqual("stupid stuff", model.ReturnDoc.Doc);

            model.ReturnDoc.Doc = "smart stuff";

            var actualOutput = model.ToString();

            Assert.AreEqual(@"This is our summary
@return smart stuff", actualOutput);
        }
Esempio n. 12
0
        public void MeaningfulBlockWithSignatures()
        {
            const string inputString  = @"<signature>
sig1
sig2
sig3
sig4
</signature>
Summary for all sigs";
            var          derivedModel = new MemberSubSection(inputString, true);

            Assert.AreEqual("Summary for all sigs", derivedModel.Summary);
            Assert.AreEqual(0, derivedModel.TextBlocks.Count);
            Assert.AreEqual(0, derivedModel.Parameters.Count);
            Assert.AreEqual(4, derivedModel.SignatureList.Count);
        }
Esempio n. 13
0
    private void DocEditButtons()
    {
        bool somethingSelected = m_SelectedText >= 0;

        EditorGUI.BeginDisabledGroup(EditMember == null || !EditMember.Loaded || !somethingSelected);
        if (GUILayout.Button("Insert Example", EditorStyles.toolbarButton))
        {
            MemberSubSection section = EditMember.Model.SubSections[m_SelectedSection];
            section.TextBlocks.Insert(m_SelectedText + 1, new ExampleBlock(""));
            EditMember.Model.SanitizeForEditing();
            EditMember.OnModelEdited();
        }
        EditorGUI.EndDisabledGroup();

        if (!m_Browser.translating)
        {
            EditorGUILayout.Space();
            EditGrouping = GUILayout.Toggle(EditGrouping, "Edit Grouping", EditorStyles.toolbarButton);
        }
    }
Esempio n. 14
0
        public void MemberWithSummaryDescriptionAndNoCheckExample()
        {
            const string inputString  = @"This is our summary
hello hello
BEGIN EX NOCHECK
	function foo()
	{ int k=0;}
END EX";
            var          derivedModel = new MemberSubSection(inputString);

            Assert.AreEqual("This is our summary", derivedModel.Summary);
            Assert.AreEqual(2, derivedModel.TextBlocks.Count);

            VerifyExample(derivedModel, 1, @"	function foo()
	{ int k=0;}
");
            var example = derivedModel.TextBlocks[1] as ExampleBlock;

            Assert.IsTrue(example.IsNoCheck);
            Assert.IsFalse(example.IsConvertExample);
        }
Esempio n. 15
0
    private XElement FormattedXML(MemberSubSection section)
    {
        var finalList = new List <XElement>();
        var sigList   = section.SignatureEntryList.Where(sig => sig.Asm != null).Select(sig => FormattedXML(sig.Asm));

        finalList.AddRange(sigList);
        finalList.Add(new XElement("Summary", section.Summary));
        if (section.Parameters != null && section.Parameters.Count > 0)
        {
            var paramsList = section.Parameters.Select(paramWithDoc => FormattedXML(paramWithDoc));
            finalList.AddRange(paramsList);
        }

        if (section.ReturnDoc != null)
        {
            finalList.Add(FormattedXML(section.ReturnDoc));
        }

        var blocks = new List <XElement>();

        foreach (var block in section.TextBlocks)
        {
            XElement         blockXML         = new XElement("dummy");
            DescriptionBlock descriptionBlock = block as DescriptionBlock;
            if (descriptionBlock != null)
            {
                blockXML = FormattedXML(descriptionBlock);
            }

            ExampleBlock exampleBlock = block as ExampleBlock;
            if (exampleBlock != null)
            {
                blockXML = FormattedXML(exampleBlock);
            }
            blocks.Add(blockXML);
        }
        finalList.AddRange(blocks);
        return(new XElement("Section", finalList));
    }
Esempio n. 16
0
    private string TextArea(string text, GUIStyle style, bool readOnly, LanguageUtil.ELanguage language)
    {
        // @TODO: Make SelectableLabel work correctly and then use that,

        /*if (readOnly)
         * {
         *      EditorGUILayout.SelectableLabel (text, style);
         *      return text;
         * }*/

        Rect rect = GUILayoutUtility.GetRect(new GUIContent(text), style);

        // Hack to prevent select all when clicking in a text field
        Event evt            = Event.current;
        Color oldCursorColor = GUI.skin.settings.cursorColor;

        if (evt.type == EventType.MouseDown && rect.Contains(evt.mousePosition))
        {
            GUI.skin.settings.cursorColor = Color.clear;
        }

        //GUI.enabled = !readOnly || Event.current.type == EventType.Repaint;
        EditorGUI.BeginChangeCheck();
        string newText = EditorGUI.TextArea(rect, text, style);

        if (EditorGUI.EndChangeCheck() && !readOnly)
        {
            text = newText;
            if (style != DocBrowser.styles.example && language == LanguageUtil.ELanguage.English)
            {
                text = MemberSubSection.EnforcePunctuation(text);
            }
        }

        GUI.skin.settings.cursorColor = oldCursorColor;

        return(text);
    }
Esempio n. 17
0
 void VerifyDescription(MemberSubSection model, int index, string expectedText)
 {
     Assert.IsFalse(model.TextBlocks[index] is ExampleBlock);
     Assert.AreEqual(expectedText, model.TextBlocks[index].Text);
 }
Esempio n. 18
0
    void SectionHeaderGUI(MemberSession member, int sectionIndex, bool readOnly)
    {
        MemberSubSection section = sectionIndex < 0 ? null : member.Model.SubSections[sectionIndex];

        string headerText;

        if (sectionIndex >= 0)
        {
            headerText = "Section " + (sectionIndex + 1) + " of " + member.Model.SubSections.Count;
        }
        else
        {
            headerText = "New Section";
        }

        EditorGUI.BeginChangeCheck();

        if (EditGrouping && !readOnly)
        {
            // Handle dragging of section
            Rect dragTargetRect = GUILayoutUtility.GetRect(10, 0);
            dragTargetRect.y     -= 4;
            dragTargetRect.height = 16;
            DocBrowser.DragTarget(dragTargetRect, typeof(MemberSubSection), member.Model.SubSections, sectionIndex >= 0 ? sectionIndex : member.Model.SubSections.Count);

            GUILayout.BeginHorizontal(GUILayout.Height(25));

            GUILayout.Space(4);
            Rect rect = GUILayoutUtility.GetRect(14, 14, GUILayout.ExpandWidth(false));
            rect.y += 11;

            if (sectionIndex >= 0)
            {
                if (member.Model.SubSections.Count > 1)
                {
                    DocBrowser.DragHandle(rect, typeof(MemberSubSection), member.Model.SubSections, sectionIndex, DocBrowser.styles.dragHandle);

                    if (section.SignatureList.Count == 0)
                    {
                        GUILayout.Space(4);
                        rect    = GUILayoutUtility.GetRect(14, 14, GUILayout.ExpandWidth(false));
                        rect.y += 11;
                        if (MiniButton(rect, DocBrowser.styles.iconRemove))
                        {
                            member.Model.SubSections.RemoveAt(sectionIndex);
                        }
                    }
                }
            }
            else
            {
                if (MiniButton(rect, DocBrowser.styles.iconAdd))
                {
                    member.Model.SubSections.Add(new MemberSubSection(sTodoText));
                }
            }

            GUILayout.Label(headerText, DocBrowser.styles.docSectionHeader);
            GUILayout.EndHorizontal();
        }
        else
        {
            GUILayout.Label(headerText, DocBrowser.styles.docSectionHeader);
        }

        if (sectionIndex >= 0)
        {
            // Handle dragging of signature
            Rect dragTargetRect = GUILayoutUtility.GetRect(10, 0);
            dragTargetRect.y     -= 3;
            dragTargetRect.height = 14;
            DocBrowser.DragTarget(dragTargetRect, typeof(SignatureEntry), section.SignatureList, 0);
        }

        if (EditorGUI.EndChangeCheck())
        {
            member.OnModelEdited(true);
        }

        if (EditGrouping && section != null && section.SignatureList.Count == 0 && member.Member.MultipleSignaturesPossible && member.Model.SubSections.Count > 1)
        {
            if ((string.IsNullOrEmpty(section.Summary) || section.Summary == sTodoText) && section.Parameters.Count == 0 && section.ReturnDoc == null)
            {
                GUILayout.Label("Section has no documentation. It can safely be deleted.", DocBrowser.styles.docSectionMessage);
            }
            else
            {
                GUILayout.Label("Section has documentation. (Exit 'Edit Grouping' mode to see it.) Deleting this section will delete its docs too.", DocBrowser.styles.docSectionMessageWarning);
            }
        }
        if (section != null && section.SignatureList.Count > 0)
        {
            IEnumerable <SignatureEntry> asmEntries = section.SignatureList.Select(e => member.Member.GetSignature(e, true));
            asmEntries = asmEntries.Where(e => e.InAsm);
            IEnumerable <string> returnTypes = asmEntries.Select(e => e.Asm.ReturnType);
            returnTypes = returnTypes.Distinct();
            if (returnTypes.Count() > 1)
            {
                GUILayout.Label("Section has signatures with multiple different return types: " + string.Join(", ", returnTypes.ToArray()) + ".", DocBrowser.styles.docSectionMessageWarning);
            }
        }
    }
Esempio n. 19
0
    void SubSectionEditGUI(MemberSession member, int sectionIndex, bool readOnly)
    {
        MemberSubSection section = member.Model.SubSections[sectionIndex];

        if ((member.Member.MultipleSignaturesPossible && member.Model.SubSections.Count > 1) || EditGrouping)
        {
            SectionHeaderGUI(member, sectionIndex, readOnly);
        }
        else
        {
            GUILayout.Space(18);
        }

        if (!m_Browser.translating)
        {
            // Toggle for NoDoc
            Rect toggleRect = GUILayoutUtility.GetRect(10, 0);
            toggleRect.height = 16;
            toggleRect.y     -= 16;
            toggleRect.xMin   = toggleRect.xMax - 175;
            EditorGUI.BeginChangeCheck();
            section.IsUndoc = GUI.Toggle(toggleRect, section.IsUndoc, "Exclude section from docs");
            if (EditorGUI.EndChangeCheck())
            {
                member.OnModelEdited();
            }
        }

        // Show signatures
        for (int i = 0; i < section.SignatureList.Count; i++)
        {
            SignatureGUI(member, sectionIndex, section.SignatureList, i, readOnly);
        }

        if (section.IsUndoc)
        {
            if (!m_Browser.translating)
            {
                EditorGUILayout.HelpBox("This section will be excluded from the documentation but it will still show up in intelli-sense etc. Many users may not realize it's not officially supported. Consider either making the API internal or include it in the documentation.", MessageType.Warning);
            }
            else
            {
                EditorGUILayout.HelpBox("This section is not documented. No translation is needed.", MessageType.Info);
            }
        }
        else
        {
            if (!EditGrouping)
            {
                EditorGUI.BeginChangeCheck();
                ParametersAndReturnGUI(member, sectionIndex, readOnly);
                DescriptionAndExamplesGUI(member, sectionIndex, readOnly);
                if (EditorGUI.EndChangeCheck())
                {
                    member.OnModelEdited();
                }
            }
        }

        EditorGUILayout.Space();

        GUI.enabled = true;
    }
Esempio n. 20
0
    void DescriptionAndExamplesGUI(MemberSession member, int sectionIndex, bool readOnly)
    {
        MemberSubSection section = member.Model.SubSections[sectionIndex];

        // Summary
        string controlName = "Section_" + sectionIndex + "_Summary";

        GUI.SetNextControlName(controlName);
        if (GUI.GetNameOfFocusedControl() == controlName)
        {
            m_SelectedSection = sectionIndex;
            m_SelectedText    = 0;
        }
        GUILayout.Label("Description (first line is summary)", DocBrowser.styles.docSectionHeader);
        if (!readOnly)
        {
            GUI.backgroundColor = GetColor(true, m_Browser.translating ? section.Summary != sTodoText : section.Summary != string.Empty);
        }
        section.Summary     = TextArea(section.Summary, DocBrowser.styles.description, readOnly, member.Language);
        GUI.backgroundColor = Color.white;

        // Description and examples
        int i             = 0;
        int removeExample = -1;

        foreach (TextBlock t in section.TextBlocks)
        {
            bool isExample = (t is ExampleBlock);

            controlName = "Section_" + sectionIndex + "_Text_" + i;
            GUI.SetNextControlName(controlName);
            if (GUI.GetNameOfFocusedControl() == controlName && !isExample)
            {
                m_SelectedSection = sectionIndex;
                m_SelectedText    = i;
            }

            if (isExample)
            {
                GUILayout.Space(4);

                EditorGUILayout.BeginHorizontal();
                var example = t as ExampleBlock;

                GUILayout.FlexibleSpace();

                EditorGUI.BeginDisabledGroup(readOnly || m_Browser.translating);
                example.IsConvertExample = GUILayout.Toggle(example.IsConvertExample, "Convert");
                example.IsNoCheck        = GUILayout.Toggle(example.IsNoCheck, "NoCheck");
                if (GUILayout.Button("Delete", EditorStyles.miniButton))
                {
                    removeExample = i;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();

                // Some hackery to show the label nicely, since gui margins don't work inside a horizontal group.
                Rect r = GUILayoutUtility.GetLastRect();
                r.x += 4; r.y += 3;
                GUI.Label(r, "Example", DocBrowser.styles.docSectionHeader);

                t.Text = TextArea(t.Text, DocBrowser.styles.example, readOnly || m_Browser.translating, member.Language);
            }
            else
            {
                if (i > 0)
                {
                    GUILayout.Label("Description (continued)", DocBrowser.styles.docSectionHeader);
                }
                t.Text = TextArea(t.Text, DocBrowser.styles.description, readOnly, member.Language);
            }

            i++;
        }

        if (removeExample >= 0)
        {
            section.TextBlocks.RemoveAt(removeExample);
            EditMember.Model.SanitizeForEditing();
        }
    }
Esempio n. 21
0
    private MemberSession MergeTranslated(MemDocModel english, MemDocModel translatedOld)
    {
        MemberSession translatedNewMember = new MemberSession(m_Browser.docProject, m_Item, translatedOld.Language);
        MemDocModel   translatedNew       = translatedNewMember.Model;

        // If number of sections don't match at all, make new list of sections
        if (english.SubSections.Count != translatedNew.SubSections.Count)
        {
            translatedNew.SubSections.Clear();
            for (int i = 0; i < english.SubSections.Count; i++)
            {
                translatedNew.SubSections.Add(new MemberSubSection(""));
            }
        }

        for (int s = 0; s < english.SubSections.Count; s++)
        {
            MemberSubSection engSec = english.SubSections[s];
            MemberSubSection newSec = translatedNew.SubSections[s];

            // Replace signatures
            newSec.SignatureList = engSec.SignatureList;
            // Replace flags
            newSec.IsCsNone = engSec.IsCsNone;
            newSec.IsUndoc  = engSec.IsUndoc;

            // Merge parameters
            List <ParameterWithDoc> oldParams = newSec.Parameters;
            newSec.Parameters = new List <ParameterWithDoc> ();
            foreach (ParameterWithDoc engParam in engSec.Parameters)
            {
                ParameterWithDoc newParam = new ParameterWithDoc(engParam.Name);
                newParam.Types = engParam.Types;
                ParameterWithDoc oldParam = oldParams.FirstOrDefault(e => e.Name == engParam.Name);
                if (oldParam != null && !string.IsNullOrEmpty(oldParam.Doc))
                {
                    newParam.Doc = oldParam.Doc;
                }
                else
                {
                    newParam.Doc = GetInitialTranslationString(engParam.Doc);
                }
                newSec.Parameters.Add(newParam);
            }

            // Merge return type
            if (engSec.ReturnDoc == null)
            {
                newSec.ReturnDoc = null;
            }
            else
            {
                string returnDocString = newSec.ReturnDoc != null ? newSec.ReturnDoc.Doc : GetInitialTranslationString(engSec.ReturnDoc.Doc);
                newSec.ReturnDoc            = new ReturnWithDoc();
                newSec.ReturnDoc.ReturnType = engSec.ReturnDoc.ReturnType;
                newSec.ReturnDoc.Doc        = returnDocString;
            }

            // Merge text blocks
            bool blockTypesMatch = true;
            if (newSec.TextBlocks.Count != engSec.TextBlocks.Count)
            {
                blockTypesMatch = false;
            }
            else
            {
                for (int i = 0; i < engSec.TextBlocks.Count; i++)
                {
                    if (engSec.TextBlocks[i].GetType() != newSec.TextBlocks[i].GetType())
                    {
                        blockTypesMatch = false;
                    }
                }
            }

            // If block types match, only replace examples
            if (blockTypesMatch)
            {
                for (int i = 0; i < engSec.TextBlocks.Count; i++)
                {
                    TextBlock engBlock = engSec.TextBlocks[i];
                    if (engBlock is ExampleBlock)
                    {
                        newSec.TextBlocks[i] = engBlock;
                    }
                }
            }
            // If block types don't match, replace examples and make all description
            // blocks have TODO in them (except if the English one is empty too).
            else
            {
                newSec.TextBlocks.Clear();
                for (int i = 0; i < engSec.TextBlocks.Count; i++)
                {
                    TextBlock engBlock = engSec.TextBlocks[i];
                    if (engBlock is ExampleBlock)
                    {
                        newSec.TextBlocks.Add(engBlock);
                    }
                    else if (engBlock is DescriptionBlock)
                    {
                        newSec.TextBlocks.Add(new DescriptionBlock(GetInitialTranslationString(engBlock.Text)));
                    }
                }
            }
        }

        translatedNewMember.TextOrig    = translatedOld.ToString();
        translatedNewMember.TextCurrent = translatedNew.ToString();
        translatedNewMember.Diff.Compare(translatedNewMember.TextOrig, translatedNewMember.TextCurrent);
        return(translatedNewMember);
    }