コード例 #1
0
        public void OpenFile(OpenedFile file)
        {
            CodeEditorContent documentContent;

            if (!_codeEditors.TryGetValue(file, out documentContent))
            {
                documentContent         = new CodeEditorContent(this, file);
                documentContent.Closed += content_Closed;
                _codeEditors.Add(file, documentContent);
                ExtensionHost.ControlManager.OpenDocumentContents.Add(documentContent);
            }

            ExtensionHost.ControlManager.SelectedDocumentContent = documentContent;
        }
コード例 #2
0
 public CodeEditor()
 {
     InitializeComponent();
     HiglightContent     = new CodeEditorContent();
     Errors              = new List <SyntaxError>();
     MaxLineCountInBlock = 100;
     LineHeight          = FontSize * 1.3;
     TabSize             = 4;
     totalLineCount      = 1;
     blocks              = new List <InnerTextBlock>();
     ToolTip             = new ToolTip
     {
         IsOpen = false
     };
     Loaded += (s, e) => {
         ApplyTemplate();
         Text                        = Text.Replace("\t", new string(' ', TabSize));
         renderCanvas                = (DrawingControl)Template.FindName("PART_RenderCanvas", this);
         lineNumbersCanvas           = (DrawingControl)Template.FindName("PART_LineNumbersCanvas", this);
         scrollViewer                = (ScrollViewer)Template.FindName("PART_ContentHost", this);
         lineNumbersCanvas.Width     = GetFormattedTextWidth($"{totalLineCount:0000}") + 5;
         scrollViewer.ScrollChanged += OnScrollChanged;
         InvalidateBlocks(0);
         InvalidateVisual();
     };
     SizeChanged += (s, e) => {
         if (e.HeightChanged == false)
         {
             return;
         }
         UpdateBlocks();
         InvalidateVisual();
     };
     TextChanged += (s, e) => {
         UpdateTotalLineCount();
         InvalidateBlocks(e.Changes.First().Offset);
         InvalidateVisual();
         //If navigator exists, update its visuals
         if (navigator == null)
         {
             return;
         }
         navigator.LinkedScrollViewerHeight = scrollViewer.ViewportHeight;
         navigator.UpdateText(GetFormattedText(Text),
                              new Point(2 - HorizontalOffset, VerticalOffset),
                              scrollViewer.VerticalOffset);
     };
     PreviewTextInput += (s, e) => {
         if (e.Text.Contains("{"))
         {
             WaitingForClosingBracket = true;
         }
         if (e.Text.Contains("}"))
         {
             WaitingForClosingBracket = false;
         }
     };
     PreviewKeyDown          += CodeEditor_OnPreviewKeyDown;
     SelectionChanged        += CodeEditor_SelectionChanged;
     PreviewMouseDoubleClick += CodeEditor_MouseDoubleClick;
     MouseMove += (s, e) =>
     {
         ToolTip localtool = ToolTip as ToolTip;
         if (localtool == null)
         {
             return;
         }
         Point          mousePos = Mouse.GetPosition(renderCanvas);
         InnerTextBlock block    = blocks.FirstOrDefault(b =>
                                                         new Rect(b.Position, new Size(b.FormattedText.Width,
                                                                                       b.FormattedText.Height)).Contains(mousePos));
         if (block == null)
         {
             localtool.IsOpen = false;
             return;
         }
         SyntaxError error = Errors.FirstOrDefault(ev =>
         {
             int Line   = ev.Line ?? -1;
             int Column = ev.Column ?? -1;
             int TagPos = CodeHelper.getStartCharOfPos(Text, Line, Column);
             return(TagPos >= block.CharStartIndex && TagPos <= block.CharEndIndex);
         });
         if (error == null)
         {
             localtool.IsOpen = false;
         }
         else
         {
             localtool.HorizontalOffset = e.GetPosition(this).X;
             localtool.VerticalOffset   = e.GetPosition(this).Y;
             localtool.IsOpen           = true;
             localtool.Content          = error.InnerMessage;
         }
     };
 }