예제 #1
0
 /// <summary>
 /// Initializes the <see cref="VSContext"/> class.
 /// </summary>
 static VSContext()
 {
     InitializeDTE();
     DesignModeCacheInvalidator         = new CacheInvalidator();
     InteractiveExecutionInitialization = new InteractiveExecutionInitialization(new VSInteractiveExecutionBehavior(), DesignModeCacheInvalidator);
     DebuggerEnteredDesignMode         += () => DesignModeCacheInvalidator.InvalidateCache();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="InteractiveWindowContent"/> class.
        /// </summary>
        /// <param name="interactiveExecutionInitialization">Interactive execution initialization.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="indentationSize">Size of the indentation.</param>
        /// <param name="highlightingColors">The highlighting colors.</param>
        public InteractiveWindowContent(InteractiveExecutionInitialization interactiveExecutionInitialization, string fontFamily, double fontSize, int indentationSize, params ICSharpCode.AvalonEdit.Highlighting.HighlightingColor[] highlightingColors)
        {
            this.fontFamily         = fontFamily;
            this.fontSize           = fontSize;
            this.indentationSize    = indentationSize;
            this.highlightingColors = highlightingColors;

            // Add results panel
            scrollViewer = new ScrollViewer();
            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            scrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
            scrollViewer.Margin                = new Thickness(0);
            scrollViewer.Padding               = new Thickness(5);
            resultsPanel                       = new StackPanel();
            resultsPanel.Orientation           = Orientation.Vertical;
            resultsPanel.CanVerticallyScroll   = true;
            resultsPanel.CanHorizontallyScroll = true;
            scrollViewer.Content               = resultsPanel;
            interactiveExecutionInitialization.InteractiveExecutionBehavior.ClearDone += () => clearAfterExecution = true;

            // Add prompt for text editor
            var panel = new Grid();

            resultsPanel.Children.Add(panel);

            promptBlock = new TextBlock();
            promptBlock.HorizontalAlignment = HorizontalAlignment.Left;
            promptBlock.VerticalAlignment   = VerticalAlignment.Top;
            promptBlock.FontFamily          = new FontFamily(fontFamily);
            promptBlock.FontSize            = fontSize;
            promptBlock.Text         = interactiveExecutionInitialization.InteractiveExecutionBehavior.GetReplExecutingPrompt();
            promptBlock.SizeChanged += PromptBlock_SizeChanged;
            panel.Children.Add(promptBlock);

            // Add text editor
            TextEditor = new InteractiveCodeEditor(new InteractiveResultVisualizer(this), interactiveExecutionInitialization.InteractiveExecutionCache, fontFamily, fontSize, indentationSize, highlightingColors);
            TextEditor.HorizontalAlignment           = HorizontalAlignment.Stretch;
            TextEditor.Background                    = Brushes.Transparent;
            TextEditor.CommandExecuted              += TextEditor_CommandExecuted;
            TextEditor.CommandFailed                += TextEditor_CommandFailed;
            TextEditor.Executing                    += TextEditor_Executing;
            TextEditor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            TextEditor.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;
            TextEditor.TextArea.PreviewKeyDown      += TextEditor_PreviewKeyDown;
            TextEditor.TextArea.SizeChanged         += TextArea_SizeChanged;
            panel.Children.Add(TextEditor);

            Content = scrollViewer;

            // Enable drag and drop
            AllowDrop  = true;
            DragEnter += (s, e) => e.Effects = GetFilename(e) != null ? DragDropEffects.Link : DragDropEffects.None;
            Drop      += (s, e) => FileDropped(GetFilename(e));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VSInteractiveWindowControl"/> class.
        /// </summary>
        /// <param name="interactiveExecutionInitialization">Interactive execution initialization.</param>
        public VSInteractiveWindowControl(InteractiveExecutionInitialization interactiveExecutionInitialization)
        {
            this.InitializeComponent();

            Grid grid = new Grid();

            ContentControl = CreateInteractiveWindowContent(interactiveExecutionInitialization);
            grid.Children.Add(ContentControl);
            this.Content = grid;

            MakeEnabled(VSContext.CurrentDebugMode == EnvDTE.dbgDebugMode.dbgBreakMode);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InteractiveWindowContent" /> class.
 /// </summary>
 /// <param name="interactiveExecutionInitialization">Interactive execution initialization.</param>
 /// <param name="highlightingColors">The highlighting colors.</param>
 public InteractiveWindowContent(InteractiveExecutionInitialization interactiveExecutionInitialization, params ICSharpCode.AvalonEdit.Highlighting.HighlightingColor[] highlightingColors)
     : this(interactiveExecutionInitialization, "Consolas", 14, 4, highlightingColors)
 {
 }
        private static InteractiveWindowContent CreateInteractiveWindowContent(InteractiveExecutionInitialization interactiveExecutionInitialization)
        {
            try
            {
                var    result     = new List <HighlightingColor>();
                var    properties = VSContext.DTE.Properties["FontsAndColors", "TextEditor"];
                var    colors     = properties.Item("FontsAndColorsItems").Object as EnvDTE.FontsAndColorsItems;
                string fontFamily = properties.Item("FontFamily").Value.ToString();
                double fontSize   = double.Parse(properties.Item("FontSize").Value.ToString());
                DictionaryCache <string, EnvDTE.ColorableItems> colorsCache = new DictionaryCache <string, EnvDTE.ColorableItems>((name) => colors.Item(name));
                int indentationSize = 4; // TODO:

                result.Add(CreateColor("#RegularText#", colorsCache["Plain Text"]));
                result.Add(CreateColor("#CurrentLine#", colorsCache["CurrentLineActiveFormat"], colorsCache["Plain Text"]));
                result.Add(CreateColor("#TooltipText#", colorsCache["Plain Text"], colorsCache["Peek Highlighted Text Unfocused"]));
                result.Add(CreateColor("#CompletionText#", colorsCache["Plain Text"], colorsCache["Peek Background Unfocused"]));

                Dictionary <string, string> colorMap = new Dictionary <string, string>()
                {
                    { "Comment", "Comment" },
                    { "String", "String" },
                    { "StringInterpolation", "Plain Text" },
                    { "Char", "String" },
                    { "Preprocessor", "Preprocessor Keyword" },
                    { "Punctuation", "Punctuation" },
                    { "ValueTypeKeywords", "Keyword" },
                    { "ReferenceTypeKeywords", "Keyword" },
                    { "MethodCall", "Plain Text" },
                    { "NumberLiteral", "Number" },
                    { "ThisOrBaseReference", "Keyword" },
                    { "NullOrValueKeywords", "Keyword" },
                    { "Keywords", "Keyword" },
                    { "GotoKeywords", "Keyword" },
                    { "ContextKeywords", "Keyword" },
                    { "ExceptionKeywords", "Keyword" },
                    { "CheckedKeyword", "Keyword" },
                    { "UnsafeKeywords", "Keyword" },
                    { "OperatorKeywords", "Keyword" },
                    { "ParameterModifiers", "Keyword" },
                    { "Modifiers", "Keyword" },
                    { "Visibility", "Keyword" },
                    { "NamespaceKeywords", "Keyword" },
                    { "GetSetAddRemove", "Keyword" },
                    { "TrueFalse", "Keyword" },
                    { "TypeKeywords", "Keyword" },
                    { "SemanticKeywords", "Keyword" },
                };

                foreach (var kvp in colorMap)
                {
                    var color = CreateColor(kvp.Key, colorsCache[kvp.Value]);

                    color.Background = null;
                    result.Add(color);
                }

#if false
                System.Drawing.Color cc = System.Drawing.Color.FromArgb(37, 37, 38);

                IEnumerable <EnvDTE.ColorableItems> sorted = colors.Cast <EnvDTE.ColorableItems>()
                                                             .OrderBy(color =>
                {
                    var c = System.Drawing.ColorTranslator.FromOle((int)color.Background);

                    return(System.Math.Abs(c.B - cc.B) + System.Math.Abs(c.G - cc.G) + System.Math.Abs(c.R - cc.R));
                });

                var sb = new System.Text.StringBuilder();

                foreach (var color in sorted.Take(10))
                {
                    var c    = System.Drawing.ColorTranslator.FromOle((int)color.Background);
                    int diff = System.Math.Abs(c.B - cc.B) + System.Math.Abs(c.G - cc.G) + System.Math.Abs(c.R - cc.R);

                    sb.AppendLine($"({diff}) [{c.R}, {c.G}, {c.B}] '{color.Name}'");
                }

                MessageBox.Show(sb.ToString());
#endif

                return(new InteractiveWindowContent(interactiveExecutionInitialization, fontFamily, fontSize * 1.4, indentationSize, result.ToArray()));
            }
            catch
            {
                return(new InteractiveWindowContent(interactiveExecutionInitialization));
            }
        }
예제 #6
0
 public INativeHandleContract CreateControl(InteractiveExecutionInitialization interactiveExecutionInitialization)
 {
     control = new VSInteractiveWindowControl(interactiveExecutionInitialization);
     return(FrameworkElementAdapters.ViewToContractAdapter(control));
 }