public void UnregisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file)
        {
            var association = GetAssociatedData(file);

            editor.TextInput -= association.TextInputHandler;

            association.Solution = null;
            dataAssociations.Remove(file);
        }
        public void RegisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file, TextDocument doc)
        {
            CSharpDataAssociation association = null;

            if (dataAssociations.TryGetValue(file, out association))
            {
                throw new Exception("Source file already registered with language service.");
            }

            IndentationStrategy = new CSharpIndentationStrategy(editor.Options);

            association          = new CSharpDataAssociation();
            association.Solution = file.Project.Solution as OmniSharpSolution; // CanHandle has checked this.

            dataAssociations.Add(file, association);

            association.TextInputHandler = (sender, e) =>
            {
                if (editor.Document == doc)
                {
                    editor.BeginChange();
                    OpenBracket(editor, editor.Document, e.Text);
                    CloseBracket(editor, editor.Document, e.Text);

                    switch (e.Text)
                    {
                    case "}":
                    case ";":
                        editor.CaretOffset = Format(editor.Document, 0, (uint)editor.Document.TextLength, editor.CaretOffset);
                        break;

                    case "{":
                        var lineCount = editor.Document.LineCount;
                        var offset    = Format(editor.Document, 0, (uint)editor.Document.TextLength, editor.CaretOffset);

                        // suggests clang format didnt do anything, so we can assume not moving to new line.
                        if (lineCount != editor.Document.LineCount)
                        {
                            if (offset <= editor.Document.TextLength)
                            {
                                var newLine = editor.Document.GetLineByOffset(offset);
                                editor.CaretOffset = newLine.PreviousLine.EndOffset;
                            }
                        }
                        else
                        {
                            editor.CaretOffset = offset;
                        }
                        break;
                    }

                    editor.EndChange();
                }
            };

            editor.TextArea.TextEntered += association.TextInputHandler;
        }
Exemplo n.º 3
0
        protected override void OnAttached()
        {
            editor = AssociatedObject as AvaloniaEdit.TextEditor;

            if (editor != null)
            {
                editor.DataContextChanged += Editor_DataContextChanged;
            }

            base.OnAttached();
        }
Exemplo n.º 4
0
        protected override void OnDetaching()
        {
            editorVm = null;

            if (editor != null)
            {
                editor.DataContextChanged -= Editor_DataContextChanged;

                editor = null;
            }

            base.OnDetaching();
        }
Exemplo n.º 5
0
        public void UnregisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file)
        {
            var association = GetAssociatedData(file);

            editor.TextInput -= association.TextInputHandler;

            var tu = association.TranslationUnit;

            clangAccessJobRunner.InvokeAsync(() =>
            {
                tu?.Dispose();
            });

            dataAssociations.Remove(file);
        }
Exemplo n.º 6
0
        public void RegisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file,
                                       TextDocument textDocument)
        {
            _typeScriptContext = _typeScriptContext ?? ((TypeScriptProject)file.Project).TypeScriptContext;
            _typeScriptContext.OpenFile(file.FilePath, File.ReadAllText(file.FilePath));

            TypeScriptDataAssociation association = null;

            if (dataAssociations.TryGetValue(file, out association))
            {
                throw new InvalidOperationException("Source file already registered with language service.");
            }

            association = new TypeScriptDataAssociation();
            dataAssociations.Add(file, association);
        }
Exemplo n.º 7
0
        public MainWindow()
        {
            InitializeComponent();

            _textEditor                              = this.FindControl <TextEditor>("Editor");
            _textEditor.Background                   = Brushes.Transparent;
            _textEditor.ShowLineNumbers              = true;
            _textEditor.SyntaxHighlighting           = HighlightingManager.Instance.GetDefinition("C#");
            _textEditor.TextArea.TextEntered        += textEditor_TextArea_TextEntered;
            _textEditor.TextArea.TextEntering       += textEditor_TextArea_TextEntering;
            _textEditor.TextArea.IndentationStrategy = new Indentation.CSharp.CSharpIndentationStrategy();

            _outText            = this.FindControl <TextBlock>("outText");
            _executionStatus    = this.FindControl <TextBlock>("executionStatus");
            _console            = this.FindControl <TextBox>("console");
            _console.IsReadOnly = true;
            Interpreter.Printed.Subscribe(PrintToConsole);
            Interpreter.NewRuntimeException.Subscribe(PrintErrorToConsole);


            _openFileBtn        = this.FindControl <Button>("openFileBtn");
            _openFileBtn.Click += _openFileBtn_Click;

            _saveFileBtn        = this.FindControl <Button>("saveFileBtn");
            _saveFileBtn.Click += SaveFileBtnClick;;

            _runBtn        = this.FindControl <Button>("runBtn");
            _runBtn.Click += RunBtnClick;;

            _textEditor.TextArea.TextView.ElementGenerators.Add(_generator);

            this.AddHandler(PointerWheelChangedEvent, (o, i) =>
            {
                if (i.KeyModifiers != KeyModifiers.Control)
                {
                    return;
                }
                if (i.Delta.Y > 0)
                {
                    _textEditor.FontSize++;
                }
                else
                {
                    _textEditor.FontSize = _textEditor.FontSize > 1 ? _textEditor.FontSize - 1 : 1;
                }
            }, RoutingStrategies.Bubble, true);
        }
        public IntellisenseManager(AvaloniaEdit.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file)
        {
            intellisenseJobRunner   = new JobRunner();
            intellisenseQueryRunner = new JobRunner(1);

            Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); });
            Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(new CancellationToken()); });

            this.intellisenseControl = intellisenseControl;
            this.completionAssistant = completionAssistant;
            this.languageService     = languageService;
            this.file   = file;
            this.editor = editor;

            this.editor.LostFocus += Editor_LostFocus;
            _hidden = true;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the word in front of the caret.
        /// </summary>
        public static string GetWordBeforeCaret(this AvaloniaEdit.TextEditor editor)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            int endOffset   = editor.CaretOffset;
            int startOffset = FindPrevWordStart(editor.Document, endOffset);

            if (startOffset < 0)
            {
                return(string.Empty);
            }
            else
            {
                return(editor.Document.GetText(startOffset, endOffset - startOffset));
            }
        }
Exemplo n.º 10
0
        private void OpenBracket(AvaloniaEdit.TextEditor editor, TextDocument document, string text)
        {
            if (text[0].IsOpenBracketChar() && editor.CaretOffset <= document.TextLength && editor.CaretOffset > 0)
            {
                var nextChar = ' ';

                if (editor.CaretOffset != document.TextLength)
                {
                    document.GetCharAt(editor.CaretOffset);
                }

                if (char.IsWhiteSpace(nextChar) || nextChar.IsCloseBracketChar())
                {
                    document.Insert(editor.CaretOffset, text[0].GetCloseBracketChar().ToString());
                }

                editor.CaretOffset--;
            }
        }
Exemplo n.º 11
0
        public IntellisenseManager(AvaloniaEdit.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file)
        {
            intellisenseJobRunner   = new JobRunner();
            intellisenseQueryRunner = new JobRunner(1);

            Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); });
            Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(new CancellationToken()); });

            this.intellisenseControl = intellisenseControl;
            this.completionAssistant = completionAssistant;
            this.languageService     = languageService;
            this.file   = file;
            this.editor = editor;

            this.editor.LostFocus += Editor_LostFocus;
            _hidden = true;

            _shell   = IoC.Get <IShell>();
            _console = IoC.Get <IConsole>();

            var snippetManager = IoC.Get <SnippetManager>();

            _snippets = snippetManager.GetSnippets(languageService, file.Project?.Solution, file.Project);
        }
Exemplo n.º 12
0
        private void CloseBracket(AvaloniaEdit.TextEditor editor, TextDocument document, string text)
        {
            if (text[0].IsCloseBracketChar() && editor.CaretOffset < document.TextLength && editor.CaretOffset > 0)
            {
                var offset = editor.CaretOffset;

                while (offset < document.TextLength)
                {
                    var currentChar = document.GetCharAt(offset);

                    if (currentChar == text[0])
                    {
                        document.Replace(offset, 1, string.Empty);
                        break;
                    }
                    else if (!currentChar.IsWhiteSpace())
                    {
                        break;
                    }

                    offset++;
                }
            }
        }
Exemplo n.º 13
0
 public static void ClearSelection(this AvaloniaEdit.TextEditor editor)
 {
     editor.Select(editor.CaretOffset, 0);
 }
Exemplo n.º 14
0
 public void UnregisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file)
 {
     _typeScriptContext.RemoveFile(file.FilePath);
     dataAssociations.Remove(file);
 }
Exemplo n.º 15
0
 public void Dispose()
 {
     editor.LostFocus -= Editor_LostFocus;
     editor            = null;
 }
        public SelectedLineBackgroundRenderer(AvaloniaEdit.TextEditor textEditor)
        {
            _textEditor = textEditor;

            BorderPen = new Pen(BorderBrush);
        }
Exemplo n.º 17
0
        public STBLEditor()
        {
            AvaloniaXamlLoader.Load(this);

            AvaloniaEdit = this.FindControl <AvaloniaEdit.TextEditor>("PART_AvaloniaEdit");
        }