Пример #1
0
        public void SetOutput(ITextOutput output, IHighlightingDefinition highlighting)
        {
            if (output == null)
            {
                throw new ArgumentNullException();
            }

            HideCancelButton();

            var newLastOutput = new LastOutput(output, highlighting);

            if (lastOutput.Equals(newLastOutput))
            {
                return;
            }
            lastOutput = newLastOutput;

            var avOutput = output as AvalonEditTextOutput;

            Debug.Assert(avOutput != null, "output should be an AvalonEditTextOutput instance");

            TextEditor.LanguageTokens = avOutput == null ? new LanguageTokens() : avOutput.LanguageTokens;
            TextEditor.LanguageTokens.Finish();

            ClearMarkedReferences();
            TextEditor.ScrollToHome();
            TextEditor.Document           = null;
            TextEditor.SyntaxHighlighting = highlighting;
            ClearCustomElementGenerators();

            if (avOutput == null)
            {
                uiElementGenerator.UIElements        = null;
                referenceElementGenerator.References = null;
                references          = new TextSegmentCollection <ReferenceSegment>();
                definitionLookup    = null;
                TextEditor.Document = new TextDocument(output.ToString());
            }
            else
            {
                uiElementGenerator.UIElements        = avOutput.UIElements;
                referenceElementGenerator.References = avOutput.References;
                references       = avOutput.References;
                definitionLookup = avOutput.DefinitionLookup;
                foreach (var elementGenerator in avOutput.ElementGenerators)
                {
                    TextEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);
                    activeCustomElementGenerators.Add(elementGenerator);
                }

                TextEditor.Document = avOutput.GetDocument();
            }
        }