Esempio n. 1
0
        static public void GetStrategyFromName2(this TextEditor editor, IEditorContext control)
        {
            FoldingManager.Uninstall(control.FoldingManager);
            AbstractFoldingStrategy NewFoldingStrategy     = null;
            IIndentationStrategy    NewIndentationStrategy = null;

            if (editor.SyntaxHighlighting == null)
            {
            }                                                    //control.FoldingStrategy = null;
            else
            {
                switch (editor.SyntaxHighlighting.Name)
                {
                case "XML":
                    NewFoldingStrategy     = new XmlFoldingStrategy();
                    NewIndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                    break;

                case "C#":
                case "C++":
                case "PHP":
                case "Java":
                    NewFoldingStrategy     = new CSharpPragmaRegionFoldingStrategy();
                    NewIndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy();
                    break;

                default:
                    NewFoldingStrategy     = new CSharpPragmaRegionFoldingStrategy();
                    NewIndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                    break;
                }
            }
            //control.FoldingStrategy is not assigned
            //control.FoldingStrategy,editor.TextArea.IndentationStrategy
            if (NewFoldingStrategy != null)
            {
                control.FoldingStrategy = NewFoldingStrategy;
                if (control.FoldingManager == null)
                {
                    control.FoldingManager = FoldingManager.Install(editor.TextArea);
                }

                control.FoldingStrategy.UpdateFoldings(control.FoldingManager, editor.Document);
            }
            else
            {
                if (control.FoldingManager != null)
                {
                    FoldingManager.Uninstall(control.FoldingManager);
                    control.FoldingManager = null;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CsTextEditor"/> class.
        /// </summary>
        public CsTextEditor()
        {
            // Adjust appearance
            FontFamily = new System.Windows.Media.FontFamily("Consolas");
            FontSize   = 14;
            Options.IndentationSize      = 4;
            Options.HighlightCurrentLine = true;
            SyntaxHighlighting           = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinition("C#");

            var indentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(Options);

            indentationStrategy.IndentationString = "    ";
            TextArea.IndentationStrategy          = indentationStrategy;

            // Add event handlers
            TextArea.TextEntering += TextArea_TextEntering;
            TextArea.TextEntered  += TextArea_TextEntered;

            // Remove binding for Enter (we want to do something else :))
            InputBinding newLineBinding = null;

            foreach (var binding in TextArea.InputBindings)
            {
                var keyBinding = binding as KeyBinding;

                if (keyBinding != null)
                {
                    if (keyBinding.Key == Key.Enter)
                    {
                        newLineBinding = keyBinding;
                        break;
                    }
                }
            }

            TextArea.InputBindings.Remove(newLineBinding);

            // Add special commands
            AddKeyGesture(ModifierKeys.Control, Key.Space, TextArea_ControlSpace);
            AddKeyGesture(ModifierKeys.None, Key.Enter, TextArea_ExecuteCSharpScript);
            AddKeyGesture(ModifierKeys.Control, Key.Enter, TextArea_ExecuteWinDbgCommand);
            AddKeyGesture(ModifierKeys.Shift, Key.Enter, TextArea_RegularNewLine);

            // Initialize project content
            projectContent = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent();

            // Initialize images
            CompletionData testData = new CompletionData(CompletionDataType.Unknown, "");
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CsTextEditor"/> class.
        /// </summary>
        public CsTextEditor()
        {
            // Adjust appearance
            FontFamily = new System.Windows.Media.FontFamily("Consolas");
            FontSize = 14;
            Options.IndentationSize = 4;
            Options.HighlightCurrentLine = true;
            SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinition("C#");

            var indentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(Options);
            indentationStrategy.IndentationString = "    ";
            TextArea.IndentationStrategy = indentationStrategy;

            // Add event handlers
            TextArea.TextEntering += TextArea_TextEntering;
            TextArea.TextEntered += TextArea_TextEntered;

            // Remove binding for Enter (we want to do something else :))
            InputBinding newLineBinding = null;

            foreach (var binding in TextArea.InputBindings)
            {
                var keyBinding = binding as KeyBinding;

                if (keyBinding != null)
                {
                    if (keyBinding.Key == Key.Enter)
                    {
                        newLineBinding = keyBinding;
                        break;
                    }
                }
            }

            TextArea.InputBindings.Remove(newLineBinding);

            // Add special commands
            AddKeyGesture(ModifierKeys.Control, Key.Space, TextArea_ControlSpace);
            AddKeyGesture(ModifierKeys.None, Key.Enter, TextArea_ExecuteCSharpScript);
            AddKeyGesture(ModifierKeys.Control, Key.Enter, TextArea_ExecuteWinDbgCommand);
            AddKeyGesture(ModifierKeys.Shift, Key.Enter, TextArea_RegularNewLine);

            // Initialize project content
            projectContent = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent();

            // Initialize images
            CompletionData testData = new CompletionData(CompletionDataType.Unknown, "");
        }
        public CodeEditorViewAdapterCSharp(AltaxoWorkspaceBase workspace, Microsoft.CodeAnalysis.DocumentId documentID, RoslynSourceTextContainerAdapter sourceText)
        {
            Workspace                      = workspace ?? throw new ArgumentNullException(nameof(workspace));
            DocumentId                     = documentID ?? throw new ArgumentNullException(nameof(documentID));
            SourceTextAdapter              = sourceText ?? throw new ArgumentNullException(nameof(sourceText));
            _roslynHost                    = workspace.RoslynHost;
            SourceTextAdapter.TextChanged += EhSourceTextAdapter_TextChanged;

            HighlightingColorizer     = new SemanticHighlighting.SemanticHighlightingColorizer(Workspace, DocumentId);
            QuickInfoProvider         = _roslynHost.GetService <QuickInfo.IQuickInfoProvider>();
            FoldingStrategy           = new SyntaxTreeFoldingStrategy();
            BraceMatchingService      = _roslynHost.GetService <IBraceMatchingService>();
            ReferenceHighlightService = new ReferenceHighlighting.CSharp.CSharpDocumentHighlightsService();
            CompletionProvider        = new Completion.CodeEditorCompletionProvider(_roslynHost, Workspace, DocumentId);
            RenamingService           = new Renaming.RenamingService();
            IndentationStrategy       = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy();
            LiveDocumentFormatter     = new LiveDocumentFormatterCSharp();
            ExternalHelpProvider      = new ExternalHelp.ExternalHelpProvider();

            Workspace.SubscribeToDiagnosticsUpdateNotification(DocumentId, EhDiagnosticsUpdated);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CsTextEditor"/> class.
        /// </summary>
        /// <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 CsTextEditor(string fontFamily, double fontSize, int indentationSize, params ICSharpCode.AvalonEdit.Highlighting.HighlightingColor[] highlightingColors)
        {
            // Adjust appearance
            FontFamily = new FontFamily(fontFamily);
            FontSize   = fontSize;
            Options.IndentationSize      = indentationSize;
            Options.HighlightCurrentLine = true;
            SyntaxHighlighting           = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinition("C#");
            foreach (var color in highlightingColors)
            {
                foreach (var color2 in SyntaxHighlighting.NamedHighlightingColors)
                {
                    if (color.Name == color2.Name)
                    {
                        color2.Background = color.Background;
                        color2.FontStyle  = color.FontStyle;
                        color2.FontWeight = color.FontWeight;
                        color2.Foreground = color.Foreground;
                        color2.Underline  = color.Underline;
                    }
                }
            }

            var regularText = highlightingColors.FirstOrDefault(c => c.Name == "#RegularText#");

            if (regularText != null)
            {
                Background = regularText.Background.GetBrush(null);
                Foreground = regularText.Foreground.GetBrush(null);
                FontStyle  = regularText.FontStyle.Value;
                FontWeight = regularText.FontWeight.Value;
            }

            var currentLine = highlightingColors.FirstOrDefault(c => c.Name == "#CurrentLine#");

            if (currentLine != null)
            {
                TextArea.TextView.SetValue(
                    ICSharpCode.AvalonEdit.Rendering.TextView.CurrentLineBackgroundProperty,
                    currentLine.Background.GetBrush(null));
                TextArea.TextView.SetValue(
                    ICSharpCode.AvalonEdit.Rendering.TextView.CurrentLineBorderProperty,
                    new Pen(currentLine.Foreground.GetBrush(null), 1));
            }

            var tooltipText = highlightingColors.FirstOrDefault(c => c.Name == "#TooltipText#");

            if (tooltipText != null)
            {
                tooltipTextColor      = tooltipText.Foreground.GetBrush(null);
                tooltipTextBackground = tooltipText.Background.GetBrush(null);
            }
            else
            {
                tooltipTextColor      = Foreground;
                tooltipTextBackground = Background;
            }

            var completionText = highlightingColors.FirstOrDefault(c => c.Name == "#CompletionText#");

            if (completionText != null)
            {
                completionTextColor      = completionText.Foreground.GetBrush(null);
                completionTextBackground = completionText.Background.GetBrush(null);
            }
            else
            {
                completionTextColor      = Foreground;
                completionTextBackground = Background;
            }

            var indentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(Options);

            indentationStrategy.IndentationString = new string(' ', indentationSize);
            TextArea.IndentationStrategy          = indentationStrategy;

            // Add event handlers
            TextArea.TextEntering += TextArea_TextEntering;
            TextArea.TextEntered  += TextArea_TextEntered;

            // Remove binding for Enter (we want to do something else :))
            InputBinding newLineBinding = null;

            foreach (var binding in TextArea.InputBindings)
            {
                var keyBinding = binding as KeyBinding;

                if (keyBinding != null)
                {
                    if (keyBinding.Key == Key.Enter)
                    {
                        newLineBinding = keyBinding;
                        break;
                    }
                }
            }

            TextArea.InputBindings.Remove(newLineBinding);

            // Add special commands
            AddKeyGesture(ModifierKeys.Control, Key.Space, TextArea_ControlSpace);
            AddKeyGesture(ModifierKeys.None, Key.Enter, TextArea_ExecuteCSharpScript);
            AddKeyGesture(ModifierKeys.Control, Key.Enter, TextArea_ExecuteWinDbgCommand);
            AddKeyGesture(ModifierKeys.Shift, Key.Enter, TextArea_RegularNewLine);

            // Initialize project content
            projectContent = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent();

            // Initialize images
            CompletionData testData = new CompletionData(CompletionDataType.Unknown, "");

            // Start timer to find tooltips
            var timer = new System.Windows.Threading.DispatcherTimer();

            timer.Tick += (a, b) =>
            {
                if (autoCompletePopup != null && autoCompletePopup != fixedToolTipPopup)
                {
                    var tooltip = System.Windows.PresentationSource.CurrentSources.OfType <System.Windows.Interop.HwndSource>()
                                  .Select(h => h.RootVisual)
                                  .Select(v => System.Windows.LogicalTreeHelper.GetParent(v))
                                  .OfType <System.Windows.Controls.Primitives.Popup>()
                                  .Select(p => p.Child)
                                  .OfType <System.Windows.Controls.ToolTip>()
                                  .Where(t => t.PlacementTarget == autoCompletePopup)
                                  .FirstOrDefault();

                    if (tooltip != null)
                    {
                        fixedToolTipPopup = autoCompletePopup;
                        if (tooltipTextBackground != null)
                        {
                            tooltip.Background      = tooltipTextBackground;
                            tooltip.BorderThickness = new System.Windows.Thickness(1);
                        }
                    }
                }
            };
            timer.Interval = TimeSpan.FromSeconds(0.1);
            timer.Start();
        }