protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { editor = this.Find <TextEditor.TextEditor>("editor"); editor.CaretChangedByPointerClick += Editor_CaretChangedByPointerClick; editor.EditorScrolled += Editor_EditorScrolled; }
/// <summary> /// Open file as JSharp document /// </summary> public void OpenDocument(string filename) { if (Properties.Settings.Default.RecentFiles == null) { Properties.Settings.Default.RecentFiles = new StringCollection(); } if (!Properties.Settings.Default.RecentFiles.Contains(filename)) { Properties.Settings.Default.RecentFiles.Add(filename); Properties.Settings.Default.Save(); } if (OpenedFiles.Contains(filename)) { return; } TextEditor.TextEditor ex; string name = Path.GetFileName(filename); if (GetSelectedTextEditor()?.IsUnoccupied() == true) { ex = GetSelectedTextEditor(); SelectedDocumentPane.Title = name; } else { ex = new TextEditor.TextEditor(); AddDocumentPage(name, ex); } ex.OpenDocument(filename); }
public Editor() { InitializeComponent(); disposables = new CompositeDisposable(); editor = this.Find <TextEditor.TextEditor>("editor"); disposables.Add(DataContextProperty.Changed.Subscribe(o => { if (o.NewValue is EditorViewModel) // for some reason intellisense view model gets passed here! bug in avalonia? { if (o.OldValue is EditorViewModel && (o.OldValue as EditorViewModel).Model.Editor == editor) { (o.OldValue as EditorViewModel).Model.Editor = null; } if (editorViewModel != DataContext) { editorViewModel = DataContext as EditorViewModel; if (editorViewModel != null && editor != null) { editorViewModel.Model.Editor = editor; editor.Focus(); } } } })); }
/// <summary> /// Add document page to JSharp (Empty Text-Editor without any open editor or a specified TextEditor /// </summary> private void AddDocumentPage(string fileName, TextEditor.TextEditor e) { LayoutDocument newDocument = new LayoutDocument { Title = fileName ?? "Untitled Document", Content = e ?? new TextEditor.TextEditor() }; ((TextEditor.TextEditor)newDocument.Content).HorizontalAlignment = HorizontalAlignment.Stretch; ((TextEditor.TextEditor)newDocument.Content).VerticalAlignment = VerticalAlignment.Stretch; ((TextEditor.TextEditor)newDocument.Content).DocumentChanged += delegate { newDocument.Title = ((TextEditor.TextEditor)newDocument.Content).OpenedDocumentShortName; }; ((TextEditor.TextEditor)newDocument.Content).Text = $"public class {newDocument.Title.Substring(0, newDocument.Title.Length - 5)}" + "\n{\n\n}"; ((TextEditor.TextEditor)newDocument.Content)._paneParent = newDocument; newDocument.IsSelectedChanged += delegate { if (newDocument.IsSelected) { var data = ((TextEditor.TextEditor)newDocument.Content).OpenedDocumentShortName; Title = data != null ? $"JSharp ({data})" : "JSharp"; } }; DocumentPane.Children.Add(newDocument); SelectDocumentTab(DocumentPane.IndexOfChild(newDocument)); }
public CSharpIntellisenseManager(ILanguageService languageService, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ISourceFile file, TextEditor.TextEditor editor) { this.languageService = languageService; this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.file = file; this.editor = editor; }
private void CloseBracket(TextEditor.TextEditor editor, TextDocument document, string text) { if (text[0].IsCloseBracketChar() && editor.CaretIndex < document.TextLength && editor.CaretIndex > 0) { if (document.GetCharAt(editor.CaretIndex) == text[0]) { document.Replace(editor.CaretIndex - 1, 1, string.Empty); } } }
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { editor.EditorScrolled -= Editor_EditorScrolled; editor.CaretChangedByPointerClick -= Editor_CaretChangedByPointerClick; editor = null; editorViewModel = null; disposables.Dispose(); }
protected override void OnAttached() { editor = AssociatedObject as TextEditor.TextEditor; if (editor != null) { editor.DataContextChanged += Editor_DataContextChanged; } base.OnAttached(); }
public void UnregisterSourceFile(TextEditor.TextEditor editor, ISourceFile file) { var association = GetAssociatedData(file); editor.RemoveHandler(InputElement.KeyUpEvent, association.KeyUpHandler); editor.TextInput -= association.TextInputHandler; association.TranslationUnit?.Dispose(); dataAssociations.Remove(file); }
protected override void OnDetaching() { editorVm = null; if (editor != null) { editor.DataContextChanged -= Editor_DataContextChanged; editor = null; } base.OnDetaching(); }
public IntellisenseManager(TextEditor.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file) { intellisenseJobRunner = new JobRunner(); Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; }
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { editor = this.Find<TextEditor.TextEditor>("editor"); editor.CaretChangedByPointerClick += Editor_CaretChangedByPointerClick; editor.EditorScrolled += Editor_EditorScrolled; editorViewModel = DataContext as EditorViewModel; if (editorViewModel != null && editor != null) { editorViewModel.Model.Editor = editor; editor.Focus(); } }
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { editor = this.Find <TextEditor.TextEditor>("editor"); editor.CaretChangedByPointerClick += Editor_CaretChangedByPointerClick; editor.EditorScrolled += Editor_EditorScrolled; editorViewModel = DataContext as EditorViewModel; if (editorViewModel != null && editor != null) { editorViewModel.Model.Editor = editor; editor.Focus(); } }
private void OpenBracket(TextEditor.TextEditor editor, TextDocument document, string text) { if (text[0].IsOpenBracketChar() && editor.CaretIndex <= document.TextLength && editor.CaretIndex > 0) { var nextChar = ' '; if (editor.CaretIndex != document.TextLength) { document.GetCharAt(editor.CaretIndex); } if (char.IsWhiteSpace(nextChar) || nextChar.IsCloseBracketChar()) { document.Insert(editor.CaretIndex, text[0].GetCloseBracketChar().ToString()); } } }
public void RegisterSourceFile(IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, TextEditor.TextEditor editor, ISourceFile file, TextDocument textDocument) { _tsContext = _tsContext ?? ((TypeScriptProject)file.Project).TypeScriptContext; _tsContext.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(textDocument); dataAssociations.Add(file, association); }
public void RegisterSourceFile(IIntellisenseControl intellisense, ICompletionAssistant completionAssistant, TextEditor.TextEditor editor, ISourceFile file, TextDocument doc) { CPlusPlusDataAssociation association = null; if (dataAssociations.TryGetValue(file, out association)) { throw new Exception("Source file already registered with language service."); } association = new CPlusPlusDataAssociation(doc); dataAssociations.Add(file, association); association.IntellisenseManager = new CPlusPlusIntellisenseManager(this, intellisense, completionAssistant, file, editor); association.TunneledKeyUpHandler = async(sender, e) => { await intellisenseJobRunner.InvokeAsync(() => { association.IntellisenseManager.OnKeyUp(e).Wait(); }); }; association.TunneledKeyDownHandler = async(sender, e) => { association.IntellisenseManager.OnKeyDown(e); await intellisenseJobRunner.InvokeAsync(() => { association.IntellisenseManager.CompleteOnKeyDown(e).Wait(); }); }; association.KeyUpHandler = (sender, e) => { if (editor.TextDocument == doc) { switch (e.Key) { case Key.Return: { if (editor.CaretIndex >= 0 && editor.CaretIndex < editor.TextDocument.TextLength) { if (editor.TextDocument.GetCharAt(editor.CaretIndex) == '}') { editor.TextDocument.Insert(editor.CaretIndex, Environment.NewLine); editor.CaretIndex--; var currentLine = editor.TextDocument.GetLineByOffset(editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine.NextLine, editor.CaretIndex); editor.CaretIndex = IndentationStrategy.IndentLine(editor.TextDocument, currentLine.NextLine, editor.CaretIndex); } var newCaret = IndentationStrategy.IndentLine(editor.TextDocument, editor.TextDocument.GetLineByOffset(editor.CaretIndex), editor.CaretIndex); editor.CaretIndex = newCaret; } } break; } } }; association.TextInputHandler = (sender, e) => { if (editor.TextDocument == doc) { OpenBracket(editor, editor.TextDocument, e.Text); CloseBracket(editor, editor.TextDocument, e.Text); switch (e.Text) { case "}": case ";": editor.CaretIndex = Format(editor.TextDocument, 0, (uint)editor.TextDocument.TextLength, editor.CaretIndex); break; case "{": var lineCount = editor.TextDocument.LineCount; var offset = Format(editor.TextDocument, 0, (uint)editor.TextDocument.TextLength, editor.CaretIndex); // suggests clang format didnt do anything, so we can assume not moving to new line. if (lineCount != editor.TextDocument.LineCount) { if (offset <= editor.TextDocument.TextLength) { var newLine = editor.TextDocument.GetLineByOffset(offset); editor.CaretIndex = newLine.PreviousLine.EndOffset; } } else { editor.CaretIndex = offset; } break; } } }; editor.AddHandler(InputElement.KeyDownEvent, association.TunneledKeyDownHandler, RoutingStrategies.Tunnel); editor.AddHandler(InputElement.KeyUpEvent, association.TunneledKeyUpHandler, RoutingStrategies.Tunnel); editor.AddHandler(InputElement.KeyUpEvent, association.KeyUpHandler, RoutingStrategies.Tunnel); editor.TextInput += association.TextInputHandler; }
public void Dispose() { editor.LostFocus -= Editor_LostFocus; editor = null; }
public void UnregisterSourceFile(TextEditor.TextEditor editor, ISourceFile file) { _tsContext.RemoveFile(file.FilePath); dataAssociations.Remove(file); }