private ITextView TestAutoFormat(int position, string initialContent = "") { AstRoot ast; ITextView textView = TextViewTest.MakeTextView(initialContent, position, out ast); textView.TextBuffer.Changed += (object sender, TextContentChangedEventArgs e) => { ast.ReflectTextChanges(e.ConvertToRelative(), new TextProvider(textView.TextBuffer.CurrentSnapshot)); if (e.Changes[0].NewText.Length == 1) { char ch = e.Changes[0].NewText[0]; if (AutoFormat.IsPostProcessAutoformatTriggerCharacter(ch)) { position = e.Changes[0].OldPosition + 1; textView.Caret.MoveTo(new SnapshotPoint(e.After, position)); FormatOperations.FormatViewLine(textView, textView.TextBuffer, -1, _exportProvider.GetExportedValue <IEditorShell>()); } } else { ITextSnapshotLine line = e.After.GetLineFromPosition(position); textView.Caret.MoveTo(new SnapshotPoint(e.After, Math.Min(e.After.Length, line.Length + 1))); } }; Typing.Type(textView.TextBuffer, position, "\n"); return(textView); }
private ITextView TestAutoFormat(int position, string textToType, string initialContent = "") { AstRoot ast; ITextView textView = TextViewTest.MakeTextView(initialContent, position, out ast); textView.TextBuffer.Changed += (object sender, TextContentChangedEventArgs e) => { List <TextChangeEventArgs> textChanges = TextUtility.ConvertToRelative(e); ast.ReflectTextChanges(textChanges); if (e.Changes[0].NewText.Length == 1) { char ch = e.Changes[0].NewText[0]; if (AutoFormat.IsAutoformatTriggerCharacter(ch)) { int offset = 0; if (e.Changes[0].NewText[0].IsLineBreak()) { position = e.Changes[0].OldPosition + 1; textView.Caret.MoveTo(new SnapshotPoint(e.After, position)); offset = -1; } FormatOperations.FormatLine(textView, textView.TextBuffer, ast, offset); } } else { ITextSnapshotLine line = e.After.GetLineFromPosition(position); textView.Caret.MoveTo(new SnapshotPoint(e.After, Math.Min(e.After.Length, line.Length + 1))); } }; Typing.Type(textView.TextBuffer, position, textToType); return(textView); }
private ITextView TestAutoFormat(int position, string initialContent = "") { var editorView = TextViewTest.MakeTextView(initialContent, position, out AstRoot ast); var textView = editorView.As <ITextView>(); var af = new AutoFormat(textView, _services); textView.TextBuffer.Changed += (s, e) => { var tc = e.ToTextChange(); ast.ReflectTextChange(tc.Start, tc.OldLength, tc.NewLength, tc.NewTextProvider); if (e.Changes[0].NewText.Length == 1) { var ch = e.Changes[0].NewText[0]; if (af.IsPostProcessAutoformatTriggerCharacter(ch)) { position = e.Changes[0].OldPosition + 1; textView.Caret.MoveTo(new SnapshotPoint(e.After, position)); FormatOperations.FormatViewLine(editorView, editorView.EditorBuffer, -1, _services); } } else { var line = e.After.GetLineFromPosition(position); textView.Caret.MoveTo(new SnapshotPoint(e.After, Math.Min(e.After.Length, line.Length + 1))); } }; Typing.Type(textView.TextBuffer, position, "\n"); return(textView); }
public GridProperties ConvertGridObject(string gridProperty) { JavaScriptSerializer serializer = new JavaScriptSerializer(); IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable)); GridProperties gridProp = new GridProperties(); foreach (KeyValuePair <string, object> ds in div) { var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); if (property != null) { Type type = property.PropertyType; string serialize = serializer.Serialize(ds.Value); object value = serializer.Deserialize(serialize, type); property.SetValue(gridProp, value, null); } } AutoFormat auto = new AutoFormat() { HeaderBorderColor = Color.FromArgb(206, 206, 206), ContentBorderColor = Color.FromArgb(206, 206, 206), GHeaderBorderColor = Color.FromArgb(206, 206, 206), GHeaderBgColor = Color.LightGray, HeaderBgEndColor = Color.FromArgb(236, 236, 236), GContentFontColor = Color.FromArgb(51, 51, 51), AltRowBgColor = Color.FromArgb(255, 255, 255), ContentBgColor = Color.FromArgb(255, 255, 255) }; gridProp.AutoFormat = auto; return(gridProp); }
private void scriptInputBox_TextChanged(object sender, EventArgs e) { if (_textChanging) { return; } if (scriptInputBox.SelectionLength > 0) { return; // don't mess while doing selection operations } lock (_textLock) { try { _textChanging = true; // Try reformatting var caret = scriptInputBox.SelectionStart; var updated = AutoFormat.Reformat(scriptInputBox.Text, ref caret, out var scopeStart, out var scopeLength); // If failed, change nothing if (updated == null) { return; } RefreshSourceDisplay(updated, scopeStart, scopeLength, caret); } finally { _textChanging = false; } } }
public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg) { if (group == VSConstants.VSStd2K) { char typedChar = GetTypedChar(group, id, inputArg); if (AutoFormat.IsPreProcessAutoformatTriggerCharacter(typedChar)) { AutoFormat.HandleAutoformat(TextView, typedChar); } } return(base.Invoke(group, id, inputArg, ref outputArg)); }
public override void PostProcessInvoke(CommandResult result, Guid group, int id, object inputArg, ref object outputArg) { if (group == VSConstants.VSStd2K) { char typedChar = GetTypedChar(group, id, inputArg); if (AutoFormat.IsPostProcessAutoformatTriggerCharacter(typedChar)) { AutoFormat.HandleAutoformat(TextView, typedChar); } base.PostProcessInvoke(result, group, id, inputArg, ref outputArg); } }
public Task <TextEdit[]> AutoformatAsync(IEditorBufferSnapshot snapshot, Position position, string typedChar) { var editorBuffer = snapshot.EditorBuffer; var editorView = new EditorView(editorBuffer, position.ToStreamPosition(snapshot)); var formatter = new AutoFormat(_services, editorView, editorBuffer, new IncrementalTextChangeHandler()); // AST build happens asynchronously, give it a chance to finish since // up -to-date AST improves outcome of the on-type formatting. var document = editorBuffer.GetEditorDocument <IREditorDocument>(); if (!document.EditorTree.IsReady) { SpinWait.SpinUntil(() => document.EditorTree.IsReady, 50); } return(DoFormatActionAsync(snapshot, () => formatter.HandleTyping(typedChar[0], position.ToStreamPosition(snapshot)))); }
public override void AfterConstruction() { base.AfterConstruction(); SOHOKHAU = Convert.ToInt32(AutoFormat.LayMaTuDong <HOKHAU>(Session, "SOHOKHAU", "{0:d8}")); NGAYDK = DateTime.Today; }
public RTypingCommandHandler(ITextView textView, IServiceContainer services) : base(textView) { _services = services; _autoFormat = new AutoFormat(textView, services); }
public override void AfterConstruction() { base.AfterConstruction(); MAKHAISINH = AutoFormat.LayMaTuDong <NHANKHAU>(Session, "MAKHAISINH", "{0:d8}"); SOHOKHAU = Bientoancuc.sohokhau; }