Exemplo n.º 1
0
        private void SetHighlightBracketBackground(SolidColorBrush brush)
        {
            try
            {
                var oldRenderer = null as BracketHighlightRenderer;

                foreach (var item in this.TextArea.TextView.BackgroundRenderers)
                {
                    if (item != null && item is BracketHighlightRenderer)
                    {
                        oldRenderer = item as BracketHighlightRenderer;
                    }
                }

                this.TextArea.TextView.BackgroundRenderers.Remove(oldRenderer);

                if (this._bracketRenderer != null)
                {
                    if (this.TextArea.TextView.BackgroundRenderers.Contains(this._bracketRenderer))
                    {
                        this.TextArea.TextView.BackgroundRenderers.Remove(this._bracketRenderer);
                    }
                    this._bracketRenderer = null;
                }

                this._bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView, brush);
                this.TextArea.TextView.BackgroundRenderers.Add(this._bracketRenderer);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reset the <seealso cref="SolidColorBrush"/> to be used for highlighting the current editor line.
        /// </summary>
        /// <param name="newValue"></param>
        private void AdjustCurrentLineBackground(SolidColorBrush newValue)
        {
            if (newValue != null)
            {
                HighlightCurrentLineBackgroundRenderer oldRenderer = null;

                // Make sure there is only one of this type of background renderer
                // Otherwise, we might keep adding and WPF keeps drawing them on top of each other
                foreach (var item in this.TextArea.TextView.BackgroundRenderers)
                {
                    if (item != null)
                    {
                        if (item is HighlightCurrentLineBackgroundRenderer)
                        {
                            oldRenderer = item as HighlightCurrentLineBackgroundRenderer;
                        }
                    }
                }

                this.TextArea.TextView.BackgroundRenderers.Remove(oldRenderer);

                this.TextArea.TextView.BackgroundRenderers.Add(new HighlightCurrentLineBackgroundRenderer(this, newValue.Clone()));

                // Remove reference to old background renderer instance (if any) and construct BracketRenderer from scratch
                if (this.mBracketRenderer != null)
                {
                    this.TextArea.TextView.BackgroundRenderers.Remove(this.mBracketRenderer);
                    this.mBracketRenderer = null;
                }

                this.mBracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView);
                this.TextArea.TextView.BackgroundRenderers.Add(this.mBracketRenderer);
            }
        }
        private void InitializeTextEditor()
        {
            textEditor.TextArea.PreviewKeyDown        += TextEditor_TextArea_PreviewKeyDown;
            textEditor.TextArea.Caret.PositionChanged += TextEditor_TextArea_Caret_PositionChanged;

            _bracketHighlightRenderer = new BracketHighlightRenderer(textEditor.TextArea.TextView);
            textEditor.TextArea.Options.HighlightCurrentLine = true;

            _braceMatcher = new HlslBraceMatcher();
        }
Exemplo n.º 4
0
        public CodeEditorView(TextEditorOptions options)
        {
            _syncContext = SynchronizationContext.Current;
            Options      = options ?? new TextEditorOptions
            {
                ConvertTabsToSpaces      = true,
                AllowScrollBelowDocument = true,
                IndentationSize          = 4,
                EnableEmailHyperlinks    = false,
            };

            ShowLineNumbers = true;

            MouseHover        += OnMouseHover;
            MouseHoverStopped += OnMouseHoverStopped;
            TextArea.TextView.VisualLinesChanged += OnVisualLinesChanged;
            TextArea.TextEntering += OnTextEntering;
            TextArea.TextEntered  += OnTextEntered;

            TextArea.MouseWheel += OnTextArea_MouseWheel;

            ToolTipService.SetInitialShowDelay(this, 0);
            // SearchReplacePanel.Install(this);

            var commandBindings   = TextArea.CommandBindings;
            var deleteLineCommand = commandBindings.OfType <CommandBinding>().FirstOrDefault(x => x.Command == AvalonEditCommands.DeleteLine);

            if (deleteLineCommand != null)
            {
                commandBindings.Remove(deleteLineCommand);
            }

            _foldingManager = FoldingManager.Install(TextArea);

            AsyncToolTipRequest = AsyncToolTipRequestDefaultImpl;

            {
                // responsible for rendering brace matches
                _bracketHighlightRenderer       = new BracketHighlightRenderer(TextArea.TextView);
                TextArea.Caret.PositionChanged += HighlightBrackets;
            }

            _textMarkerService = new TextMarkerService(this);
            // _errorMargin = new ErrorMargin { Visibility = Visibility.Collapsed, MarkerBrush = TryFindResource("ExceptionMarker") as Brush, Width = 10 };
            TextArea.TextView.BackgroundRenderers.Add(_textMarkerService);
            TextArea.TextView.LineTransformers.Add(_textMarkerService);
            //this.TextArea.LeftMargins.Insert(0, _errorMargin);
            //this.PreviewMouseWheel += EditorOnPreviewMouseWheel;
            //this.TextArea.Caret.PositionChanged += CaretOnPositionChanged;

            ReferencesHighlightRenderer_Initialize();

            BuildTextAreaContextMenu();
        }
Exemplo n.º 5
0
		public HighlightingOptions()
		{
			// ensure all definitions from AddIns are registered so that they are available for the example view
			AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();
			
			InitializeComponent();
			textEditor.Document.UndoStack.SizeLimit = 0;
			textEditor.Options = CodeEditorOptions.Instance;
			bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
			foldingManager = FoldingManager.Install(textEditor.TextArea);
			CodeEditorOptions.Instance.BindToTextEditor(textEditor);
		}
Exemplo n.º 6
0
        private void HighlightBrackets()
        {
            CSharpBracketSearcher BracketSearcher = new CSharpBracketSearcher();
            var bracketSearchResult = BracketSearcher.SearchBracket(this.txtEditor.Document, this.txtEditor.TextArea.Caret.Offset);

            if (bracketSearchResult != null)
            {
                BracketHighlightRenderer br = new BracketHighlightRenderer(txtEditor.TextArea.TextView);
                br.SetHighlight(bracketSearchResult);
                BracketHighlightRenderer.ApplyCustomizationsToRendering(br, CustomizedHighlightingColor.FetchCustomizations(this.txtEditor.SyntaxHighlighting.Name));
            }
        }
Exemplo n.º 7
0
        public HighlightingOptions()
        {
            // ensure all definitions from AddIns are registered so that they are available for the example view
            AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();

            InitializeComponent();
            textEditor.Document.UndoStack.SizeLimit = 0;
            textEditor.Options = CodeEditorOptions.Instance;
            bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
            foldingManager     = FoldingManager.Install(textEditor.TextArea);
            CodeEditorOptions.Instance.BindToTextEditor(textEditor);
        }
Exemplo n.º 8
0
        public LuaCodeEditor()
            : base(new TextArea() { Document = new TextDocument() })
        {
            Options.ShowTabs            = true;
            Options.ConvertTabsToSpaces = true;

            InstallFoldingManager();
            InstallHighlighting();

            SearchPanel.Install(TextArea);
            BracketHighlightRenderer.Install(TextArea);

            TextArea.IndentationStrategy = new LuaIndentationStrategy(this);
        }
		public HighlightingOptions()
		{
			// ensure all definitions from AddIns are registered so that they are available for the example view
			AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();
			
			InitializeComponent();
			textEditor.Document.UndoStack.SizeLimit = 0;
			CodeEditorOptions.Instance.BindToTextEditor(textEditor);
			textEditor.Options = new TextEditorOptions(CodeEditorOptions.Instance);
			bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
			foldingManager = FoldingManager.Install(textEditor.TextArea);
			textMarkerService = new TextMarkerService(textEditor.Document);
			textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
			textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
			textEditor.Document.GetRequiredService<IServiceContainer>().AddService(typeof(ITextMarkerService), textMarkerService);
		}
        public HighlightingOptions()
        {
            // ensure all definitions from AddIns are registered so that they are available for the example view
            AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();

            InitializeComponent();
            textEditor.Document.UndoStack.SizeLimit = 0;
            CodeEditorOptions.Instance.BindToTextEditor(textEditor);
            textEditor.Options = new TextEditorOptions(CodeEditorOptions.Instance);
            bracketHighlighter = new BracketHighlightRenderer(textEditor.TextArea.TextView);
            foldingManager     = FoldingManager.Install(textEditor.TextArea);
            textMarkerService  = new TextMarkerService(textEditor.Document);
            textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
            textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
            textEditor.Document.GetRequiredService <IServiceContainer>().AddService(typeof(ITextMarkerService), textMarkerService);
        }
Exemplo n.º 11
0
        public CodeEditor()
        {
            _keystrokeTimer          = new System.Timers.Timer(2000);
            _keystrokeTimer.Elapsed += KeystrokeTimeElapsed;

            _languageContext = new LanguageContext();

            FontFamily      = new FontFamily("Consolas");
            FontSize        = 12;
            ShowLineNumbers = true;
            Options         = new TextEditorOptions
            {
                ConvertTabsToSpaces      = true,
                HighlightCurrentLine     = true,
                IndentationSize          = 4,
                AllowScrollBelowDocument = true
            };

            MouseHover        += OnMouseHover;
            MouseHoverStopped += OnMouseHoverStopped;
            TextArea.Caret.PositionChanged += HighlightBrackets;

            _foldingStrategy = new PowershellFoldingStrategy();

            var foldingUpdateTimer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(4)
            };

            foldingUpdateTimer.Tick += delegate { UpdateFoldings(); };
            foldingUpdateTimer.Start();

            _bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView, _languageContext);
            TextArea.TextView.BackgroundRenderers.Add(_bracketRenderer);

            _inlineScriptTransformer = new InlineScriptDocumentTransformer(this.TextArea.TextView, _languageContext);
            TextArea.TextView.BackgroundRenderers.Add(_inlineScriptTransformer);

            InitializeColorizer();
        }
        void CreateDefaultEntries(string language, out IHighlightingItem defaultText, IList <IHighlightingItem> items)
        {
            // Create entry for "default text/background"
            defaultText = new SimpleHighlightingItem(CustomizingHighlighter.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text")
            {
                Foreground = SystemColors.WindowTextColor,
                Background = SystemColors.WindowColor
            };
            defaultText = new CustomizedHighlightingItem(customizationList, defaultText, language, canSetFont: false);
            defaultText.PropertyChanged += item_PropertyChanged;
            items.Add(defaultText);

            // Create entry for "Selected text"
            IHighlightingItem selectedText = new SimpleHighlightingItem(
                CustomizingHighlighter.SelectedText,
                ta => {
                ta.Document.Text = "Selected text";
                ta.Selection     = Selection.Create(ta, 0, 13);
            })
            {
                Foreground = SystemColors.HighlightTextColor,
                Background = SystemColors.HighlightColor
            };

            selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false);
            selectedText.PropertyChanged += item_PropertyChanged;
            items.Add(selectedText);

            // Create entry for "Non-printable characters"
            IHighlightingItem nonPrintChars = new SimpleHighlightingItem(
                CustomizingHighlighter.NonPrintableCharacters,
                ta => {
                ta.Document.Text = "	    \r \r\n \n";
            })
            {
                Foreground = Colors.LightGray
            };

            nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, language, canSetFont: false, canSetBackground: false);
            nonPrintChars.PropertyChanged += item_PropertyChanged;
            items.Add(nonPrintChars);

            // Create entry for "Line numbers"
            IHighlightingItem lineNumbers = new SimpleHighlightingItem(
                CustomizingHighlighter.LineNumbers,
                ta => {
                ta.Document.Text = "These are just" + Environment.NewLine +
                                   "multiple" + Environment.NewLine +
                                   "lines of" + Environment.NewLine +
                                   "text";
            })
            {
                Foreground = Colors.Gray
            };

            lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, language, canSetFont: false, canSetBackground: false);
            lineNumbers.PropertyChanged += item_PropertyChanged;
            items.Add(lineNumbers);

            // Create entry for "Bracket highlight"
            IHighlightingItem bracketHighlight = new SimpleHighlightingItem(
                BracketHighlightRenderer.BracketHighlight,
                ta => {
                ta.Document.Text          = "(simple) example";
                XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
                if (xshd == null)
                {
                    return;
                }
                var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
                BracketHighlightRenderer.ApplyCustomizationsToRendering(bracketHighlighter, customizationsForCurrentLanguage);
                bracketHighlighter.SetHighlight(new BracketSearchResult(0, 1, 7, 1));
            })
            {
                Foreground = BracketHighlightRenderer.DefaultBorder,
                Background = BracketHighlightRenderer.DefaultBackground
            };

            bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false);
            bracketHighlight.PropertyChanged += item_PropertyChanged;
            items.Add(bracketHighlight);

            // Create entry for "Current Line highlight"
            IHighlightingItem currentLineHighlight = new SimpleHighlightingItem(
                CustomizingHighlighter.CurrentLineHighlighter,
                ta => {
                ta.Document.Text = "example text line";
                ta.TextView.Options.HighlightCurrentLine = true;
            })
            {
                Foreground = Color.FromArgb(52, 0, 255, 110),
                Background = Color.FromArgb(22, 20, 220, 224)
            };

            currentLineHighlight = new CustomizedHighlightingItem(customizationList, currentLineHighlight, language, canSetFont: false);
            currentLineHighlight.PropertyChanged += item_PropertyChanged;
            items.Add(currentLineHighlight);

            // Create entry for "Folding controls"
            IHighlightingItem foldingControls = new SimpleHighlightingItem(
                FoldingControls,
                ta => {
                ta.Document.Text = "This" + Environment.NewLine +
                                   "is a folding" + Environment.NewLine +
                                   "example";
                foldingManager.CreateFolding(0, 10);
            })
            {
                Foreground = Colors.Gray,
                Background = Colors.White
            };

            foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, language, canSetFont: false);
            foldingControls.PropertyChanged += item_PropertyChanged;
            items.Add(foldingControls);

            // Create entry for "Selected folding controls"
            IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem(
                FoldingSelectedControls,
                ta => {
                ta.Document.Text = "This" + Environment.NewLine +
                                   "is a folding" + Environment.NewLine +
                                   "example";
                foldingManager.CreateFolding(0, 10);
            })
            {
                Foreground = Colors.Black,
                Background = Colors.White
            };

            selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, language, canSetFont: false);
            selectedFoldingControls.PropertyChanged += item_PropertyChanged;
            items.Add(selectedFoldingControls);

            // Create entry for "Folding text markers"
            IHighlightingItem foldingTextMarker = new SimpleHighlightingItem(
                FoldingTextMarkers,
                ta => {
                ta.Document.Text = "This" + Environment.NewLine +
                                   "is a folding" + Environment.NewLine +
                                   "example";
                foldingManager.CreateFolding(0, 10).IsFolded = true;
            })
            {
                Foreground = Colors.Gray
            };

            foldingTextMarker = new CustomizedHighlightingItem(customizationList, foldingTextMarker, language, canSetFont: false, canSetBackground: false);
            foldingTextMarker.PropertyChanged += item_PropertyChanged;
            items.Add(foldingTextMarker);

            IHighlightingItem linkText = new SimpleHighlightingItem(
                CustomizingHighlighter.LinkText,
                ta => {
                ta.Document.Text = "http://icsharpcode.net" + Environment.NewLine + "*****@*****.**";
            })
            {
                Foreground = Colors.Blue,
                Background = Colors.Transparent
            };

            linkText = new CustomizedHighlightingItem(customizationList, linkText, language, canSetFont: false);
            linkText.PropertyChanged += item_PropertyChanged;
            items.Add(linkText);

            IHighlightingItem errorMarker = new SimpleHighlightingItem(
                ErrorPainter.ErrorColorName,
                ta => {
                ta.Document.Text   = "some error";
                ITextMarker marker = textMarkerService.Create(0, 5);
                marker.Tag         = (Action <IHighlightingItem, ITextMarker>) delegate(IHighlightingItem item, ITextMarker m) {
                    m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                    m.MarkerColor = item.Foreground;
                };
            })
            {
                Foreground = Colors.Red
            };

            errorMarker = new CustomizedHighlightingItem(customizationList, errorMarker, language, canSetFont: false, canSetBackground: false);
            errorMarker.PropertyChanged += item_PropertyChanged;
            items.Add(errorMarker);

            IHighlightingItem warningMarker = new SimpleHighlightingItem(
                ErrorPainter.WarningColorName,
                ta => {
                ta.Document.Text   = "some warning";
                ITextMarker marker = textMarkerService.Create(0, 5);
                marker.Tag         = (Action <IHighlightingItem, ITextMarker>) delegate(IHighlightingItem item, ITextMarker m) {
                    m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                    m.MarkerColor = item.Foreground;
                };
            })
            {
                Foreground = Colors.Orange
            };

            warningMarker = new CustomizedHighlightingItem(customizationList, warningMarker, language, canSetFont: false, canSetBackground: false);
            warningMarker.PropertyChanged += item_PropertyChanged;
            items.Add(warningMarker);

            IHighlightingItem messageMarker = new SimpleHighlightingItem(
                ErrorPainter.MessageColorName,
                ta => {
                ta.Document.Text   = "some message";
                ITextMarker marker = textMarkerService.Create(0, 5);
                marker.Tag         = (Action <IHighlightingItem, ITextMarker>) delegate(IHighlightingItem item, ITextMarker m) {
                    m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                    m.MarkerColor = item.Foreground;
                };
            })
            {
                Foreground = Colors.Blue
            };

            messageMarker = new CustomizedHighlightingItem(customizationList, messageMarker, language, canSetFont: false, canSetBackground: false);
            messageMarker.PropertyChanged += item_PropertyChanged;
            items.Add(messageMarker);

            IHighlightingItem breakpointMarker = new SimpleHighlightingItem(
                BookmarkBase.BreakpointMarkerName,
                ta => {
                ta.Document.Text   = "some code with a breakpoint";
                ITextMarker marker = textMarkerService.Create(0, ta.Document.TextLength);
                marker.Tag         = (Action <IHighlightingItem, ITextMarker>) delegate(IHighlightingItem item, ITextMarker m) {
                    m.BackgroundColor = item.Background;
                    m.ForegroundColor = item.Foreground;
                };
            })
            {
                Background = BookmarkBase.BreakpointDefaultBackground,
                Foreground = BookmarkBase.BreakpointDefaultForeground
            };

            breakpointMarker = new CustomizedHighlightingItem(customizationList, breakpointMarker, language, canSetFont: false);
            breakpointMarker.PropertyChanged += item_PropertyChanged;
            items.Add(breakpointMarker);

            IHighlightingItem currentStatementMarker = new SimpleHighlightingItem(
                BookmarkBase.CurrentLineBookmarkName,
                ta => {
                ta.Document.Text   = "current statement line";
                ITextMarker marker = textMarkerService.Create(0, ta.Document.TextLength);
                marker.Tag         = (Action <IHighlightingItem, ITextMarker>) delegate(IHighlightingItem item, ITextMarker m) {
                    m.BackgroundColor = item.Background;
                    m.ForegroundColor = item.Foreground;
                };
            })
            {
                Background = BookmarkBase.CurrentLineDefaultBackground,
                Foreground = BookmarkBase.CurrentLineDefaultForeground
            };

            currentStatementMarker = new CustomizedHighlightingItem(customizationList, currentStatementMarker, language, canSetFont: false);
            currentStatementMarker.PropertyChanged += item_PropertyChanged;
            items.Add(currentStatementMarker);

            IHighlightingItem columnRuler = new SimpleHighlightingItem(
                CustomizingHighlighter.ColumnRuler,
                ta => {
                ta.Document.Text = "some line with a lot of text";
                ta.TextView.Options.ColumnRulerPosition = 15;
                ta.TextView.Options.ShowColumnRuler     = true;
            })
            {
                Foreground = Colors.LightGray
            };

            columnRuler = new CustomizedHighlightingItem(customizationList, columnRuler, language, canSetFont: false, canSetBackground: false);
            columnRuler.PropertyChanged += item_PropertyChanged;
            items.Add(columnRuler);
        }
Exemplo n.º 13
0
        public QueryPage(IQueryEngineFacade engine)
        {
            InitializeComponent();

            this.engine = engine;
            textEditor.SyntaxHighlighting = 
                HighlightingManager.Instance.GetDefinitionByExtension(engine.DefaultExt);

            height1 = layout.RowDefinitions[3].Height;
            height2 = layout.RowDefinitions[4].Height;
            
            filePath = String.Empty;
            fileName = String.Empty;
            HasContent = false;
            ShowResultPane = false;
            hasModified = false;
            
            xmlGrid = new EmbeddedGrid();
            xmlGrid.Dock = System.Windows.Forms.DockStyle.Fill;
            xmlGrid.Location = new System.Drawing.Point(0, 100);
            xmlGrid.Name = "xmlGridView1";
            xmlGrid.Size = new System.Drawing.Size(100, 100);
            xmlGrid.TabIndex = 0;
            xmlGrid.AutoHeightCells = true;            
            windowsFormsHost.Child = xmlGrid;

            // see http://community.sharpdevelop.net/forums/t/10312.aspx          
            bracketSearcher = new BracketSearcher();
            bracketRenderer = new BracketHighlightRenderer(textEditor.TextArea.TextView);
            textEditor.TextArea.Caret.PositionChanged += new EventHandler(Caret_PositionChanged);            
        }
Exemplo n.º 14
0
        void Init()
        {
            // Apply common editor settings to this instance
            CommonEditorSettings.Instance.AssignToEditor(Editor);

            // If Ctrl+MouseWheel was pressed/turned, increase/decrease font size
            Editor.PreviewMouseWheel += new MouseWheelEventHandler((object sender, MouseWheelEventArgs e) =>
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    CommonEditorSettings.Instance.FontSize = CommonEditorSettings.Instance.FontSize + (e.Delta > 0 ? 1 : -1);
                    CommonEditorSettings.Instance.AssignAllOpenEditors();
                    e.Handled = true;
                }
            });

            /*
             * HACK: To re-focus the editor when this document is activated (the user chose this document tab page)
             * , it's simply needed to catch the Loaded-Event which calls Focus on the editor instance then!
             */
            Editor.Loaded += new RoutedEventHandler((object sender, RoutedEventArgs e) => {
                DoOutsideModificationCheck();
                Editor.Focus();
            });

            #region UI Command registration

            /*
             * UI Command hack - delete the DeleteLine command (which is bound statically to Ctrl-D)
             * and override it with our line duplication event
             */
            var commandBindings = Editor.TextArea.CommandBindings;
            foreach (CommandBinding cb in commandBindings)
            {
                if (cb.Command == AvalonEditCommands.DeleteLine)
                {
                    // Note: We have to break the for-loop because we change the commandBinding's contents!
                    commandBindings.Remove(cb);
                    break;
                }
            }
            CommandBindings.Add(new CommandBinding(IDEUICommands.DoubleLine, DoubleLine));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_event));
            CommandBindings.Add(new CommandBinding(IDEUICommands.ToggleBreakpoint, ToggleBreakpoint_event));
            #endregion

            // Setup editor overlay

            // Let a grid own the entire control
            // - this enables us in EditorDocument derivates to insert additional controls
            var gr = new Grid();
            MainEditorContainer = gr;
            AddChild(gr);
            gr.Children.Add(Editor);

            // Let there be no border
            Editor.Margin      = new System.Windows.Thickness(0);
            Editor.BorderBrush = null;

            // Init bracket hightlighter
            bracketHightlighter = new BracketHighlightRenderer(Editor.TextArea.TextView);

            //TODO: More editor settings
            Editor.ShowLineNumbers = true;
            Editor.TextChanged    += new EventHandler(Editor_TextChanged);

            Editor.Document.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Document_PropertyChanged);

            // Register Marker strategy
            MarkerStrategy = new TextMarkerService(Editor);

            Editor.TextArea.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(TextArea_MouseRightButtonDown);

            // Make UTF-8 encoding default
            Editor.Encoding = Encoding.UTF8;

            // Enhance text rendering
            TextOptions.SetTextFormattingMode(Editor.TextArea.TextView, TextFormattingMode.Display);
            TextOptions.SetTextRenderingMode(Editor.TextArea.TextView, TextRenderingMode.ClearType);

            // Load file contents if file path given
            Reload();

            // Initially draw all probably required text markers
            RefreshErrorHighlightings();
            RefreshBreakpointHighlightings();
            RefreshDebugHighlightings();
        }
Exemplo n.º 15
0
        void CreateDefaultEntries(string language, out IHighlightingItem defaultText)
        {
            // Create entry for "default text/background"
            defaultText = new SimpleHighlightingItem(CustomizableHighlightingColorizer.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text")
            {
                Foreground = SystemColors.WindowTextColor,
                Background = SystemColors.WindowColor
            };
            defaultText = new CustomizedHighlightingItem(customizationList, defaultText, null, canSetFont: false);
            if (language != null)
            {
                defaultText = new CustomizedHighlightingItem(customizationList, defaultText, language, canSetFont: false);
            }
            defaultText.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(defaultText);

            // Create entry for "Selected text"
            IHighlightingItem selectedText = new SimpleHighlightingItem(
                CustomizableHighlightingColorizer.SelectedText,
                ta => {
                ta.Document.Text = "Selected text";
                ta.Selection     = Selection.Create(ta, 0, 13);
            })
            {
                Foreground = SystemColors.HighlightTextColor,
                Background = SystemColors.HighlightColor
            };

            selectedText = new CustomizedHighlightingItem(customizationList, selectedText, null, canSetFont: false);
            if (language != null)
            {
                selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false);
            }
            selectedText.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(selectedText);

            // Create entry for "Non-printable characters"
            IHighlightingItem nonPrintChars = new SimpleHighlightingItem(
                CustomizableHighlightingColorizer.NonPrintableCharacters,
                ta => {
                ta.Document.Text = "	    \r \r\n \n";
            })
            {
                Foreground = Colors.LightGray
            };

            nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, null, canSetFont: false, canSetBackground: false);
            if (language != null)
            {
                nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, language, canSetFont: false);
            }
            nonPrintChars.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(nonPrintChars);

            // Create entry for "Line numbers"
            IHighlightingItem lineNumbers = new SimpleHighlightingItem(
                CustomizableHighlightingColorizer.LineNumbers,
                ta => {
                ta.Document.Text = "These are just" + Environment.NewLine +
                                   "multiple" + Environment.NewLine +
                                   "lines of" + Environment.NewLine +
                                   "text";
            })
            {
                Foreground = Colors.Gray
            };

            lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, null, canSetFont: false, canSetBackground: false);
            if (language != null)
            {
                lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, language, canSetFont: false);
            }
            lineNumbers.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(lineNumbers);

            // Create entry for "Bracket highlight"
            IHighlightingItem bracketHighlight = new SimpleHighlightingItem(
                BracketHighlightRenderer.BracketHighlight,
                ta => {
                ta.Document.Text          = "(simple) example";
                XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
                if (xshd == null)
                {
                    return;
                }
                var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
                BracketHighlightRenderer.ApplyCustomizationsToRendering(bracketHighlighter, customizationsForCurrentLanguage);
                bracketHighlighter.SetHighlight(new BracketSearchResult(0, 1, 7, 1));
            })
            {
                Foreground = BracketHighlightRenderer.DefaultBorder,
                Background = BracketHighlightRenderer.DefaultBackground
            };

            bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, null, canSetFont: false);
            if (language != null)
            {
                bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false);
            }
            bracketHighlight.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(bracketHighlight);

            // Create entry for "Folding controls"
            IHighlightingItem foldingControls = new SimpleHighlightingItem(
                FoldingControls,
                ta => {
                ta.Document.Text = "This" + Environment.NewLine +
                                   "is a folding" + Environment.NewLine +
                                   "example";
                foldingManager.CreateFolding(0, 10);
            })
            {
                Foreground = Colors.Gray,
                Background = Colors.White
            };

            foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, null, canSetFont: false);
            if (language != null)
            {
                foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, language, canSetFont: false);
            }
            foldingControls.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(foldingControls);

            // Create entry for "Selected folding controls"
            IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem(
                FoldingSelectedControls,
                ta => {
                ta.Document.Text = "This" + Environment.NewLine +
                                   "is a folding" + Environment.NewLine +
                                   "example";
                foldingManager.CreateFolding(0, 10);
            })
            {
                Foreground = Colors.Black,
                Background = Colors.White
            };

            selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, null, canSetFont: false);
            if (language != null)
            {
                selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, language, canSetFont: false);
            }
            selectedFoldingControls.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(selectedFoldingControls);

            // Create entry for "Folding text markers"
            IHighlightingItem foldingTextMarker = new SimpleHighlightingItem(
                FoldingTextMarkers,
                ta => {
                ta.Document.Text = "This" + Environment.NewLine +
                                   "is a folding" + Environment.NewLine +
                                   "example";
                foldingManager.CreateFolding(0, 10).IsFolded = true;
            })
            {
                Foreground = Colors.Gray
            };

            foldingTextMarker = new CustomizedHighlightingItem(customizationList, foldingTextMarker, null, canSetFont: false, canSetBackground: false);
            if (language != null)
            {
                foldingControls = new CustomizedHighlightingItem(customizationList, foldingTextMarker, language, canSetFont: false, canSetBackground: false);
            }
            foldingTextMarker.PropertyChanged += item_PropertyChanged;
            listBox.Items.Add(foldingTextMarker);
        }