Helper class that represents UIElement to be created as result of executing interactive script. This class is needed since UI operations must be done in STA thread, so it will be lazily evaluated in UI thread.
Ejemplo n.º 1
0
        private void TextEditor_CommandExecuted(bool csharpCode, string textOutput, IEnumerable <object> objectsOutput)
        {
            int initialLength   = resultsPanel.Children.Count;
            int textEditorIndex = initialLength - 1;

            foreach (var objectOutput in objectsOutput.Reverse())
            {
                if (objectOutput != null)
                {
                    LazyUIResult lazyUI        = objectOutput as LazyUIResult;
                    UIElement    elementOutput = objectOutput as UIElement ?? lazyUI?.UIElement;

                    if (elementOutput != null)
                    {
                        resultsPanel.Children.Insert(textEditorIndex, elementOutput);
                    }
                    else
                    {
                        resultsPanel.Children.Insert(textEditorIndex, CreateTextOutput(objectOutput.ToString()));
                    }
                }
            }

            if (!string.IsNullOrEmpty(textOutput))
            {
                resultsPanel.Children.Insert(textEditorIndex, CreateTextOutput(textOutput));
            }

            resultsPanel.Children.Insert(textEditorIndex, csharpCode ? CreateCSharpCode(textEditor.Text) : CreateDbgCode(textEditor.Text));
            AddSpacing(resultsPanel.Children[textEditorIndex]);
            if (resultsPanel.Children.Count - initialLength > 1)
            {
                AddSpacing(resultsPanel.Children[textEditorIndex + resultsPanel.Children.Count - initialLength - 1]);
            }
        }
Ejemplo n.º 2
0
        private void TextEditor_CommandExecuted(bool csharpCode, string textOutput, IEnumerable <object> objectsOutput)
        {
            if (clearAfterExecution)
            {
                resultsPanel.Children.RemoveRange(0, resultsPanel.Children.Count - 1);
                clearAfterExecution = false;
            }
            else
            {
                int initialLength   = resultsPanel.Children.Count;
                int textEditorIndex = initialLength - 1;

                foreach (var objectOutput in objectsOutput.Reverse())
                {
                    if (objectOutput != null)
                    {
                        LazyUIResult lazyUI        = objectOutput as LazyUIResult;
                        UIElement    elementOutput = objectOutput as UIElement ?? lazyUI?.UIElement;

                        if (elementOutput != null)
                        {
                            resultsPanel.Children.Insert(textEditorIndex, elementOutput);
                        }
                        else
                        {
                            resultsPanel.Children.Insert(textEditorIndex, CreateTextOutput(objectOutput.ToString()));
                        }
                    }
                }

                if (!string.IsNullOrEmpty(textOutput))
                {
                    resultsPanel.Children.Insert(textEditorIndex, CreateTextOutput(textOutput));
                }

                resultsPanel.Children.Insert(textEditorIndex, csharpCode ? CreateCSharpCode(TextEditor.Text) : CreateDbgCode(TextEditor.Text));
                AddSpacing(resultsPanel.Children[textEditorIndex]);
                if (resultsPanel.Children.Count - initialLength > 1)
                {
                    AddSpacing(resultsPanel.Children[textEditorIndex + resultsPanel.Children.Count - initialLength - 1]);
                }
            }

            if (executingDroppedFile)
            {
                executingDroppedFile = false;
                Dispatcher.InvokeAsync(() =>
                {
                    TextEditor.Text            = savedTextBeforeExecutingDroppedFile;
                    TextEditor.SelectionStart  = savedTextBeforeExecutingDroppedFile.Length;
                    TextEditor.SelectionLength = 0;
                });
            }
        }