public override void TextInput(TextCompositionEventArgs args) { try { VimKeyEventArgs vim_args = new VimKeyEventArgs(new VimKeyInput(args.Text)); if (!String.IsNullOrEmpty(args.Text) && 1 == args.Text.Length) { // Only want to intercept text coming from the keyboard. Let other // components edit without having to come through us var keyboard = args.Device as KeyboardDevice; if (keyboard != null) { if (_host.CanProcess(vim_args.KeyInput)) { _host.KeyDown(vim_args); } } } if (vim_args.Handled) { args.Handled = true; } else { base.TextInput(args); } } catch (Exception ex) { #if DEBUG System.Windows.MessageBox.Show(ex.Message + "\n" + ex.StackTrace); #endif } }
//文本输入时 protected override void OnPreviewTextInput(TextCompositionEventArgs e) { base.OnPreviewTextInput(e); char ch = char.Parse(e.Text); if (ch == '.') { if ((CaretIndex == Text.Length) && (rightBox != null)) { rightBox.Focus(); rightBox.SelectAll(); e.Handled = true; return; } } if (ch < '0' || ch > '9') { e.Handled = true; return; } if ((Text.Length >= 3) && SelectionLength == 0) { e.Handled = true; return; } }
private void OnTextEntered(object sender, TextCompositionEventArgs e) { if (CaretOffset <= 0) return; var isTrigger = _scriptManager.IsCompletionTriggerCharacter(CaretOffset - 1); if (!isTrigger) return; _completionWindow = new CompletionWindow(TextArea); var data = _completionWindow.CompletionList.CompletionData; var completion = _scriptManager.GetCompletion(CaretOffset, Text[CaretOffset - 1]).ToList(); if (!completion.Any()) { _completionWindow = null; return; } foreach (var completionData in completion) { data.Add(new CompletionData(completionData)); } _completionWindow.Show(); _completionWindow.Closed += (o, args) => _completionWindow = null; }
private void TextInput(object sender, TextCompositionEventArgs e) { string message = //"At: " + e.Timestamp.ToString() + "Event: " + e.RoutedEvent + " " + " Text: " + e.Text; lstMessages.Items.Add(message); }
public override void CheckValidCharacter(object sender, TextCompositionEventArgs e) { if (!Regex.IsMatch(e.Text, @"^\d$")) { e.Handled = true; } }
private void GridPreviewTextInput(object sender, TextCompositionEventArgs e) { if(e.Source is TextBox && !((TextBox)e.Source).Name.Equals("Note") && !((TextBox)e.Source).Name.Equals("Barcode")) e.Handled = !IsTextValid(e.Text); }
void VisualElement_TextInput(object sender, TextCompositionEventArgs e) { var array = keyProcessors; foreach (var keyProcessor in array) { if (keyProcessor.IsInterestedInHandledEvents || !e.Handled) keyProcessor.TextInput(e); } }
private void OnTextEntered(object sender, TextCompositionEventArgs e) { var ch = e.Text[0]; // Set last key stroke _codeViewModel.LastKeyStroke = DateTime.Now; // Notify our language context that the document is dirty and needs a reparsing _languageContext.IsDirty = true; // Update any parse errors to account for the new text inserted var caretOffset = _textArea.Caret.Offset; var lineText = _textArea.Document.GetText(_textArea.Document.GetLineByOffset(caretOffset)); Task.Run(() => { _bookmarkManager.RecalculateOffsets(_textArea, BookmarkType.ParseError, caretOffset, e.Text.Length); _bookmarkManager.RecalculateOffsets(_textArea, BookmarkType.AnalyzerInfo, caretOffset, e.Text.Length); _bookmarkManager.RecalculateOffsets(_textArea, BookmarkType.AnalyzerWarning, caretOffset, e.Text.Length); }); //if ((IsCodeCompletionTrigger(ch) || char.IsLetter(ch)) && _completionWindow == null) if (_completionWindow == null && (IsCodeCompletionTrigger(ch) || string.IsNullOrEmpty(lineText.Trim())))// || IsCompletionPosition(caretOffset)) { TriggerCompletion(); } }
private void PasswordBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { if (!char.IsNumber(e.Text.ToCharArray()[0])) { e.Handled = true; } }
private void PreviewTextInput(object sender, TextCompositionEventArgs e) { if ((sender as TextBox).Text.Length >= 2) e.Handled = true; else e.Handled = !IsTextAllowed(e.Text); }
private void GameOneView_TextInput(object sender, TextCompositionEventArgs e) { var gameOneView = sender as GameOneView; if(gameOneView == null) return; var gameOneViewModel = gameOneView.DataContext as GameOneViewModel; if (gameOneViewModel != null) gameOneViewModel.KeyPressReceivedCommand.Execute(e.Text); }
private void textBox3_TextInputStart(object sender, TextCompositionEventArgs e) { if (textBox1.Text == "Port") { textBox1.Text = ""; } }
private void passwordBox1_TextInputStart(object sender, TextCompositionEventArgs e) { if (passwordBox1.Password == "******") { passwordBox1.Password = ""; } }
private void textBox1_TextInput(object sender, TextCompositionEventArgs e) { if (textBox1.Text == "Server") { textBox1.Text = ""; } }
private void textbox_PreviewTextInput(object sender, TextCompositionEventArgs e) { FileViewModel vm = DataContext as FileViewModel; if (vm == null) return; vm.Modified = true; }
private void textEditor_TextEntered(object sender, TextCompositionEventArgs e) { if (e.Text == "<" || e.Text == " ") { CompletionData[] completions1; if (completions.TryGetValue("!" + e.Text + "!" + GetActiveElement(1), out completions1)) { completionWindow = new CompletionWindow(textEditor.TextArea); var completions2 = completionWindow.CompletionList.CompletionData; foreach (var completion in completions1) completions2.Add(completion); completionWindow.Show(); completionWindow.Closed += delegate { completionWindow = null; }; } } if (e.Text == ">") { var tag = GetOpenTag(1); if (tag != string.Empty) textEditor.Document.Insert(textEditor.CaretOffset, tag.Insert(1, "/") + ">"); } }
private void OnTextEntered(object sender, TextCompositionEventArgs e) { if (this.extension == ".pwn" || this.extension == ".inc") { this.ShowCompletion(e.Text, false); } }
private void NumberBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { if (new Regex("[^0-9.-]+").IsMatch(e.Text)) { e.Handled = true; } }
// Sample event handler: private void OnWindowKeyDown(object sender, TextCompositionEventArgs /*System.Windows.Input.KeyEventArgs*/ e) { string s = e.Text; char c = (s.ToCharArray())[0]; e.Handled = true; if ((c >= '0' && c <= '9') || c == '.' || c == '\b') // '\b' is backspace { ProcessKey(c); return; } switch (c) { case '+': ProcessOperation("BPlus"); break; case '-': ProcessOperation("BMinus"); break; case '*': ProcessOperation("BMultiply"); break; case '/': ProcessOperation("BDevide"); break; case '%': ProcessOperation("BPercent"); break; case '=': ProcessOperation("BEqual"); break; } }
private void NumberTextBoxPreviewInput(object sender, TextCompositionEventArgs textCompositionEventArgs) { if (!char.IsDigit(textCompositionEventArgs.Text.ToCharArray().First())) { textCompositionEventArgs.Handled = true; } }
private void VideoTerminal_Main_PreviewTextInput(object sender, TextCompositionEventArgs e) { string x = e.Text; Console.WriteLine(e.Text); VideoTerminal_Main.HandleClientData(e.Text); e.Handled = true; }
private void value_PreviewTextInput(object sender, TextCompositionEventArgs e) { var tb = (TextBox)sender; var text = tb.Text.Insert(tb.CaretIndex, e.Text); e.Handled = !_numMatch.IsMatch(text); }
private void edSQL_TextArea_TextEntered(object sender, TextCompositionEventArgs e) { if (e.Text == ".") { edSQL_TextArea_Sense(sender, e); } }
private void castomer_PreviewTextInput(object sender, TextCompositionEventArgs e) { // if (!System.Text.RegularExpressions.Regex.Match(castomer.ToString(),@"[a-z]").Success) // { // e.Handled = false; // } }
private void text_box_only_digits_PreviewTextInput(object sender, TextCompositionEventArgs e) { if (!char.IsDigit(e.Text, e.Text.Length - 1)) { e.Handled = true; } }
private void txthour_TextInput(object sender, TextCompositionEventArgs e) { //switch (Strings.Asc(e.KeyChar)) //{ // case 8: // case 48: // case 49: // case 50: // case 51: // case 52: // case 53: // case 54: // case 55: // case 56: // case 57: // break; // // Zahlen und Backspace zulassen // default: // // alle anderen Eingaben unterdrücken // e.Handled = true; // break; //} }
public void txtblk0ByteAddressClmn1_PreviewTextInput(object sender, TextCompositionEventArgs e) { try { int hexNumber; if (null != objReader) { btnWrite.IsEnabled = true; e.Handled = !int.TryParse(e.Text, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out hexNumber); TextBox txt = (TextBox)sender; string temp = txt.Text; if (CacheUserMem.Count > 0) { if (CacheUserMem[txt.Name.ToString()].ToString() != txt.Text) { txt.Foreground = Brushes.Red; string num = txt.Name.Split(new string[] { "txtNumber"}, StringSplitOptions.None)[1].ToString(); editedDataCellLocation.Add(Convert.ToUInt32(num) - 1); btnWriteAscii.IsEnabled = true; } else { txt.Foreground = Brushes.Black; } } } } catch (Exception) { } }
private void _textArea_TextEntering(object sender, TextCompositionEventArgs e) { if (e.Text.Length > 0 && _completionWindow != null) { if (!char.IsLetterOrDigit(e.Text[0]) && e.Text[0] != '_') { _completionWindow.CompletionList.RequestInsertion(e); } } }
protected override void OnTextInput(TextCompositionEventArgs e) { this.LastInputEvent = InputEvents.OnTextInput; this.OnTextInserted(this, new TextInsertedEventArgs(e.Text, true, true)); this.ClearText(); }
private static void textBox_OnPreviewTextInput(object sender, TextCompositionEventArgs e) { // 入力値が空白の場合は処理しない if (string.IsNullOrEmpty(e.TextComposition.Text)) return; if (RegexCheck.IsMatched(e.TextComposition.Text, GetInputCharcter((DependencyObject)sender))) { // 入力条件則に一致する場合は処理続行 e.Handled = false; } else { // Textプロパティを取得 PropertyInfo property = sender.GetType().GetProperty("Text"); // Textプロパティの値を取得 string value = (string)property.GetValue(sender); // Textプロパティの値を置換 value = value.Replace(e.TextComposition.Text, string.Empty); // Textプロパティの値を更新 property.SetValue(sender, value); // ComboBoxのText対応 TextBox comboText = (TextBox)e.OriginalSource; if (comboText != sender) { comboText.Text = value; } e.Handled = true; } }
private void TextArea_TextEntered(object sender, System.Windows.Input.TextCompositionEventArgs e) { if (e.Text == ".") { try { string startString = RoslynExpressionEditorService.Instance.UsingNamespaces + "namespace SomeNamespace { public class NotAProgram { private void SomeMethod() { " + variableDeclarations + "var blah = "; //string endString = " } } }"; var tree = CSharpSyntaxTree.ParseText(startString + this.Text.Substring(0, this.CaretOffset)); var compilation = CSharpCompilation.Create( "MyCompilation", syntaxTrees: new[] { tree }, references: RoslynExpressionEditorService.Instance.BaseAssemblies); var semanticModel = compilation.GetSemanticModel(tree); // Ask for symbols at the caret position. var position = this.CaretOffset + startString.Length - 1; var token = tree.GetRoot().FindToken(position); var identifier = token.Parent; IList <ISymbol> symbols = null; if (identifier is QualifiedNameSyntax) { var semanticInfo = semanticModel.GetTypeInfo((identifier as QualifiedNameSyntax).Left); var type = semanticInfo.Type; symbols = semanticModel.LookupSymbols(position, container: type, includeReducedExtensionMethods: true); } else if (identifier is MemberAccessExpressionSyntax) { var semanticInfo = semanticModel.GetTypeInfo((identifier as MemberAccessExpressionSyntax).Expression); var type = semanticInfo.Type; symbols = semanticModel.LookupSymbols(position, container: type, includeReducedExtensionMethods: true); } else if (identifier is IdentifierNameSyntax) { var semanticInfo = semanticModel.GetTypeInfo(identifier as IdentifierNameSyntax); var type = semanticInfo.Type; symbols = semanticModel.LookupSymbols(position, container: type, includeReducedExtensionMethods: true); } if (symbols != null && symbols.Count > 0) { completionWindow = new CompletionWindow(this.TextArea); IList <ICompletionData> data = completionWindow.CompletionList.CompletionData; //var distinctSymbols = (from s in symbols select s.Name).Distinct(); var distinctSymbols = from s in symbols group s by s.Name into g select new { Name = g.Key, Symbols = g }; foreach (var group in distinctSymbols.OrderBy(s => s.Name)) { data.Add(new QueryCompletionData(group.Name, group.Symbols.ToArray())); } completionWindow.Show(); completionWindow.Closed += delegate { completionWindow = null; }; } } catch { } } }
private void targetTextbox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { Char newChar = e.Text.ToString()[0]; e.Handled = !(Char.IsNumber(newChar) || (newChar == '.') || (newChar == '-')); }
private void gg_vertexCount_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = CustomHelper.IsIntegerInput(e.Text) && Convert.ToInt32(e.Text) <= datasourceSize; }
void OnPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = !IsValid(e.Text, false); }
//处理用户输入 private void NumericTextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { HandleInput(e.Text); e.Handled = true; }
public void ProcessTextEntering(object sender, System.Windows.Input.TextCompositionEventArgs e, ref CompletionWindow completionWindow) { }
private void mheight_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = !IsNumeric(e.Text); }
public static void OnUnsignedIntPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = Utils.OnUnsignedIntTextInput(e); }
private void BlockWrongInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = !IsTextAllowed(e.Text); }
//在TextInput的参数e中包含经过处理的,控件即将接收到的文本 private void Txt_input_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { string msg = $"Event:{e.RoutedEvent} Text:{e.Text}"; list_msg.Items.Insert(0, msg); }
//テキストボックスの長文入力時に、上から下まですべての内容をスクロールで見れるようにするため。 private void TextBox_Note_TextInputStart(object sender, System.Windows.Input.TextCompositionEventArgs e) { this.ScrollViewer_Note.UpdateLayout(); this.ScrollViewer_Note.ScrollToVerticalOffset(this.TextBox_Note.ActualHeight); }
static void host_PreviewTextInputOnlyEnglish(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = !IsAllEnglishCharacters(e.Text); }
/// <summary> /// Blocks entering any other values than numbers into every "No" TextBox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DoneNo_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); }
private void AlphabetOnly(System.Object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = IsAlphabet(e.Text); }
private void txtQuantity_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { CheckIsNumeric(e); }
private void FloatingPointOnly(System.Object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = IsFloatingPointvalue(e.Text); }
public void ProcessTextEntered(object sender, System.Windows.Input.TextCompositionEventArgs e, ref ICSharpCode.AvalonEdit.CodeCompletion.CompletionWindow completionWindow) { if (HasThrownException) { return; // exit here if intellisense has previous thrown and exception } try { if (completionWindow != null) { // close the completion window if it has no items if (!completionWindow.CompletionList.ListBox.HasItems) { completionWindow.Close(); return; } // close the completion window if the current text is a 100% match for the current item var txt = ((TextArea)sender).Document.GetText(new TextSegment() { StartOffset = completionWindow.StartOffset, EndOffset = completionWindow.EndOffset }); var selectedItem = completionWindow.CompletionList.SelectedItem; if (string.Compare(selectedItem.Text, txt, true) == 0 || string.Compare(selectedItem.Content.ToString(), txt, true) == 0) { completionWindow.Close(); } return; } if (char.IsLetterOrDigit(e.Text[0]) || "\'[".Contains(e.Text[0])) { // exit if the completion window is already showing if (completionWindow != null) { return; } // exit if we are inside a string or comment _daxState = ParseLine(); var lineState = _daxState.LineState; if (lineState == LineState.String || _editor.IsInComment()) { return; } // don't show intellisense if we are in the measure name of a DEFINE block if (DaxLineParser.IsLineMeasureDefinition(GetCurrentLine())) { return; } // TODO add insights window for Function parameters //InsightWindow insightWindow = new InsightWindow(sender as ICSharpCode.AvalonEdit.Editing.TextArea); completionWindow = new CompletionWindow(sender as ICSharpCode.AvalonEdit.Editing.TextArea); completionWindow.CloseAutomatically = false; completionWindow.CompletionList.BorderThickness = new System.Windows.Thickness(1); if (char.IsLetterOrDigit(e.Text[0])) { // if the window was opened by a letter or digit include it in the match segment //completionWindow.StartOffset -= 1; completionWindow.StartOffset = _daxState.StartOffset; System.Diagnostics.Debug.WriteLine("Setting Completion Offset: {0}", _daxState.StartOffset); } IList <ICompletionData> data = completionWindow.CompletionList.CompletionData; switch (e.Text) { case "[": string tableName = GetPreceedingTableName(); if (string.IsNullOrWhiteSpace(tableName)) { PopulateCompletionData(data, IntellisenseMetadataTypes.Measures); } else { PopulateCompletionData(data, IntellisenseMetadataTypes.Columns, _daxState); } break; case "'": PopulateCompletionData(data, IntellisenseMetadataTypes.Tables); break; default: switch (_daxState.LineState) { case LineState.Column: PopulateCompletionData(data, IntellisenseMetadataTypes.Columns, _daxState); break; case LineState.Table: PopulateCompletionData(data, IntellisenseMetadataTypes.Tables, _daxState); break; case LineState.Measure: PopulateCompletionData(data, IntellisenseMetadataTypes.Measures); break; case LineState.Dmv: PopulateCompletionData(data, IntellisenseMetadataTypes.DMV); break; default: PopulateCompletionData(data, IntellisenseMetadataTypes.ALL); break; } break; } if (data.Count > 0) { //var line = GetCurrentLine(); //System.Diagnostics.Debug.Assert(line.Length >= _daxState.EndOffset); var txt = _editor.DocumentGetText(new TextSegment() { StartOffset = _daxState.StartOffset, EndOffset = _daxState.EndOffset }); //var txt = line.Substring(_daxState.StartOffset,_daxState.EndOffset - _daxState.StartOffset); completionWindow.CompletionList.SelectItem(txt); // only show the completion window if we have valid items to display if (completionWindow.CompletionList.ListBox.HasItems) { Log.Verbose("InsightWindow == null : {IsNull}", _editor.InsightWindow == null); if (_editor.InsightWindow != null && _editor.InsightWindow.IsVisible) { Log.Verbose("hiding insight window"); _editor.InsightWindow.Visibility = Visibility.Collapsed; //_editor.InsightWindow = null; } Log.Verbose("CW null: {CompletionWindowNull} CW.Vis: {CompletionWindowVisible} IW null: {insightWindowNull} IW.Vis: {InsightWindowVisible}", completionWindow == null, completionWindow.Visibility.ToString(), _editor.InsightWindow == null, completionWindow.Visibility.ToString()); completionWindow.Show(); completionWindow.Closing += completionWindow_Closing; completionWindow.PreviewKeyUp += completionWindow_PreviewKeyUp; completionWindow.Closed += delegate { _editor.DisposeCompletionWindow(); }; } else { Log.Debug("{class} {method} {message}", "DaxIntellisenseProvider", "ProcessTextEntered", "Closing CompletionWindow as it has no matching items"); completionWindow.Close(); _editor.DisposeCompletionWindow(); completionWindow = null; } } else { _editor.DisposeCompletionWindow(); completionWindow = null; } } if (e.Text[0] == '(') { var funcName = DaxLineParser.GetPreceedingWord(GetCurrentLine().TrimEnd('(').Trim()).ToLower(); Log.Verbose("Func: {Function}", funcName); ShowInsight(funcName); } } catch (Exception ex) { HasThrownException = true; Log.Error("{class} {method} {exception} {stacktrace}", "DaxIntellisenseProvider", "ProcessTextEntered", ex.Message, ex.StackTrace); Document.OutputError(string.Format("Intellisense Disabled for this window - {0}", ex.Message)); } }
/// <summary>Hit when the text control gets a character.</summary> /// <param name="sender">txtMinutes</param> /// <param name="e">TextCompositionEventArgs</param> private void TextBox_PreviewTextInput_IsNumber(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = !e.Text.All(Char.IsNumber); base.OnPreviewTextInput(e); }
//文字入力後 private void TextArea_TextEntered(object sender, System.Windows.Input.TextCompositionEventArgs e) { Console.WriteLine("TextArea_TextEntered: " + e.ToString()); CompletionHelper completionHelpler = new CompletionHelper(); // Ctrl+スペース で入力補完Windowを表示する // 自クラスが保持する属性・操作の一覧("this."付き)と、集約・参照・依存の接続先クラス名が対象 if (e.Text == " " && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))) { //入力補完Windowを生成 completionWindow = new CompletionWindow(jpBehaviorEdit.TextArea); // 補完リストに表示するアイテムをコレクションに追加する IList <ICompletionData> cmplList = completionHelpler.searchCompletionDataFromMyOwn(this.element); foreach (ICompletionData cmp in cmplList) { completionWindow.CompletionList.CompletionData.Add(cmp); } // Windowを表示 completionWindow.Show(); completionWindow.Closed += delegate { completionWindow = null; }; } // "$"入力で別Windowを表示する(全クラスから属性・メソッドを一覧検索する) if (e.Text == "$") { // モーダル表示する attrMethSearch = new AttrMethSearch(); attrMethSearch.Owner = GetWindow(this); attrMethSearch.ShowDialog(); //attrMethSearch.Show(); } // ピリオドを入力 -> キャレットの前のキーワードをクラス名とし、配下の属性・要素の一覧を表示する if (e.Text == ".") { string className = getClassNameFromText(jpBehaviorEdit.Text, jpBehaviorEdit.TextArea.Caret.Offset - 1); Console.WriteLine("探しに行くクラス名 = " + className); // 補完リストに表示するアイテムをコレクションに追加する IList <ICompletionData> cmplList = completionHelpler.searchCompletionDataFromClassName(className); if (cmplList != null && cmplList.Count > 0) { //入力補完Windowを生成 completionWindow = new CompletionWindow(jpBehaviorEdit.TextArea); foreach (ICompletionData cmp in cmplList) { completionWindow.CompletionList.CompletionData.Add(cmp); } // Windowを表示 completionWindow.Show(); completionWindow.Closed += delegate { completionWindow = null; }; } else { // 補完リストにうまくつながらないと判断した場合、 // クラス名が初期表示された形で属性・操作検索画面をモーダル表示する attrMethSearch = new AttrMethSearch(className); attrMethSearch.Owner = GetWindow(this); attrMethSearch.ShowDialog(); } } }
/// <summary> /// Valida que el control solo acepte números y letras. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TxtValidarNumerosLetrasSinAcentosPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = Extensor.ValidarNumerosLetrasSinAcentos(e.Text); }
private void TextArea_TextEntered(object sender, System.Windows.Input.TextCompositionEventArgs e) { try { var completionDataList = new List <QueryCompletionData>(); if (e.Text == ".") { //字符串不需要代码提示 var txt = textEditor.Text.Trim(); if ((txt.StartsWith("\"") || txt.StartsWith("“") || txt.StartsWith("”")) && (txt.EndsWith("\"") || txt.EndsWith("“") || txt.EndsWith("”"))) { return; } try { var importsNamespace = "";//导入命名空间以实现省略命名空间的功能 foreach (var ns in ImportedNamespaces) { importsNamespace += string.Format("Imports {0}", ns); importsNamespace += Environment.NewLine; } var startString = importsNamespace + @" Module Module1 Sub Main() Dim _tmp_ ="; var endString = @" End Sub End Module "; string codeString = startString + textEditor.Text.Substring(0, textEditor.CaretOffset) + endString; var tree = VisualBasicSyntaxTree.ParseText(codeString); var root = tree.GetRoot(); //TODO WJF 动态加载组件后,此处运行是否还正常? Assembly[] references = AppDomain.CurrentDomain.GetAssemblies(); var CustomIntellisense = VisualBasicCompilation.Create("CustomIntellisense"); foreach (var assembly in references) { try { //只加载系统自带的DLL,避免代码提示偶发的异常报错 var name = assembly.GetName().Name; if (name.StartsWith("System.") || name == "mscorlib") { CustomIntellisense = CustomIntellisense.AddReferences(MetadataReference.CreateFromFile(assembly.Location)); } } catch (Exception err) { } } CustomIntellisense = CustomIntellisense.AddSyntaxTrees(tree); var model = CustomIntellisense.GetSemanticModel(tree); var exprSyntaxNode = root.FindToken(codeString.LastIndexOf('.') - 1).Parent; var exprFullNameString = exprSyntaxNode.Parent.ToString().Trim(); if (exprFullNameString.EndsWith(".")) { exprFullNameString = exprFullNameString.Substring(0, exprFullNameString.Length - 1); } List <ExpressionNode> rootNodes = ExpressionNode.SubsetAutoCompletionList(m_namespaceNodeRoot, exprFullNameString); foreach (var item in rootNodes) { foreach (var child_item in item.Nodes) { if (child_item.ItemType == "namespace") { completionDataList.Add(new QueryCompletionData(child_item.Name, child_item.Description, SymbolKind.Namespace)); } else if (child_item.ItemType == "class") { completionDataList.Add(new QueryCompletionData(child_item.Name, child_item.Description, SymbolKind.NamedType)); } else { //TODO WJF后期根据需要添加 } } } var literalInfo = model.GetTypeInfo(exprSyntaxNode); var stringTypeSymbol = (INamedTypeSymbol)literalInfo.Type; IList <ISymbol> symbols = new List <ISymbol>() { }; foreach (var s in (from method in stringTypeSymbol.GetMembers() where method.DeclaredAccessibility == Accessibility.Public select method).Distinct()) { symbols.Add(s); } if (symbols != null && symbols.Count > 0) { var distinctSymbols = from s in symbols group s by s.Name into g select new { Name = g.Key, Symbols = g }; foreach (var g in distinctSymbols.OrderBy(s => s.Name.ToLower())) { completionDataList.Add(new QueryCompletionData(g.Name, g.Symbols.ToArray())); } } } catch { } } else { if (completionWindow == null) { //列出本地变量列表 bool bShow = false; if (textEditor.SelectionStart == textEditor.Text.Length) { if (textEditor.Text.Length == 1) { bShow = true; } if (textEditor.Text.Length >= 2) { var prevChar = textEditor.Text[textEditor.Text.Length - 2]; bShow = !char.IsLetterOrDigit(prevChar); } } if (bShow) { var queryVarList = from s in variableDeclarations where s.StartsWith(e.Text, System.StringComparison.CurrentCultureIgnoreCase) select s; foreach (var name in queryVarList.OrderBy(s => s.ToLower())) { completionDataList.Add(new QueryCompletionData(name, string.Format("本地变量 {0}", name), SymbolKind.Local)); } } } } if (completionDataList.Count > 0) { completionWindow = new CompletionWindow(textEditor.TextArea); IList <ICompletionData> data = completionWindow.CompletionList.CompletionData; data.Clear(); foreach (var item in completionDataList) { data.Add(item); } if (e.Text != ".") { //此处需要特殊处理下 completionWindow.StartOffset -= e.Text.Length; completionWindow.CompletionList.SelectItem(e.Text); } completionWindow.Show(); completionWindow.Closed += CompletionWindowClosed; } } catch (Exception) { } }
/// <summary> /// We check whether we are ok /// </summary> /// <param name="e"></param> protected override void OnPreviewTextInput(System.Windows.Input.TextCompositionEventArgs e) { switch (_maskType) { case MaskType.Mask: { System.ComponentModel.MaskedTextResultHint hint; int TestPosition; if (e.Text.Length == 1) { this._NewTextIsOk = _mprovider.VerifyChar(e.Text[0], this.CaretIndex, out hint); } else { this._NewTextIsOk = _mprovider.VerifyString(e.Text, out TestPosition, out hint); } } break; case MaskType.DoubleNumber: { double num = 0; if ((Text == string.Empty) || (Text == "-") || (e.Text == ".")) { this._NewTextIsOk = true; } else { this._NewTextIsOk = double.TryParse(Text + "0", System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out num); } } break; case MaskType.IntegerNumber: { int num = 0; if ((Text == string.Empty) || ((bus == EnumerationSystem.Dec) && (Text == "-"))) { this._NewTextIsOk = true; } else { switch (bus) { case EnumerationSystem.Dec: this._NewTextIsOk = int.TryParse(Text + "0", System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out num); break; case EnumerationSystem.Bin: { this._NewTextIsOk = true; foreach (char ch in Text + "0") { if (!((ch == '0') || (ch == '1'))) { this._NewTextIsOk = false; break; } } } break; case EnumerationSystem.Oct: { this._NewTextIsOk = true; foreach (char ch in Text + "0") { if (!((ch == '0') || (ch == '1') || (ch == '2') || (ch == '3') || (ch == '4') || (ch == '5') || (ch == '6') || (ch == '7'))) { this._NewTextIsOk = false; break; } } } break; case EnumerationSystem.Hex: this._NewTextIsOk = int.TryParse(Text + "0", System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out num); break; } } } break; default: break; } base.OnPreviewTextInput(e); }
private void SearchField_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { // TODO: Add event handler implementation here. }
/// <summary> /// When text is received by the TextBox we check whether to accept it or not /// </summary> /// <param name="e"></param> protected override void OnTextInput(System.Windows.Input.TextCompositionEventArgs e) { string PreviousText = this.Text; if (NewTextIsOk) { base.OnTextInput(e); switch (_maskType) { case MaskType.Mask: { if (_mprovider.VerifyString(this.Text) == false) { this.Text = PreviousText; } while (!_mprovider.IsEditPosition(this.CaretIndex) && _mprovider.Length > this.CaretIndex) { this.CaretIndex++; } } break; case MaskType.DoubleNumber: { double num = 0; if (double.TryParse(Text + "0", System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out num) == false) { this.Text = PreviousText; } } break; case MaskType.IntegerNumber: { int num = 0; bool res = true; switch (bus) { case EnumerationSystem.Dec: res = int.TryParse(Text, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out num); break; case EnumerationSystem.Bin: { foreach (char ch in Text) { if (!((ch == '0') || (ch == '1'))) { res = false; break; } } } break; case EnumerationSystem.Oct: { this._NewTextIsOk = true; foreach (char ch in Text) { if (!((ch == '0') || (ch == '1') || (ch == '2') || (ch == '3') || (ch == '4') || (ch == '5') || (ch == '6') || (ch == '7'))) { res = false; break; } } } break; case EnumerationSystem.Hex: res = int.TryParse(Text, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out num); break; } if (res == false) { this.Text = PreviousText; } } break; } } else { e.Handled = true; } }
private new void PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = !IsTextAllowed(e.Text); }
private void DigitOnlyWatermarkTextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { var textBox = sender as TextBox; e.Handled = Regex.IsMatch(e.Text, "[^0-9]+"); }
private void NumericOnly(System.Object sender, System.Windows.Input.TextCompositionEventArgs e) { e.Handled = IsTextNumeric(e.Text); }
private void Window_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { }
protected override void OnPreviewTextInput(System.Windows.Input.TextCompositionEventArgs e) { bool isValid = IsSymbolValid(Mask, e.Text, ValueType); bool textInserted = false; bool toNDS = false; if (isValid) { //Current content string txtOld = Text.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty); //New content string txtNew = String.Empty; bool handled = false; int caret = CaretIndex; int rcaret = 0; if (e.Text == NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) { //If we entered a decimal separator. int ind = Text.IndexOf(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) + 1; rcaret = Text.Length - ind; //The text doesn't change. txtNew = txtOld; handled = true; } if ((!handled) && (e.Text == NumberFormatInfo.CurrentInfo.NegativeSign)) { //We entered a negative symbol. if (Text.Contains(NumberFormatInfo.CurrentInfo.NegativeSign)) { //A negative symbol is already in the text. //As overriding the text initializes the cursor, the present position is remembered. rcaret = Text.Length - caret; txtNew = txtOld.Replace(NumberFormatInfo.CurrentInfo.NegativeSign, string.Empty); } else { //There is no negative symbol in the text. //As overriding the text initializes the cursor, the present position is remembered. rcaret = Text.Length - caret; txtNew = NumberFormatInfo.CurrentInfo.NegativeSign + txtOld; } handled = true; } if (!handled) { textInserted = true; if (0 < SelectionLength) { //We delete the highlighted text and insert what we have just written. int ind = SelectionStart; rcaret = Text.Length - ind - SelectionLength; string txtWS = Text.Substring(0, ind); string txtWOS = txtWS.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty); string txtSWS = Text.Substring(ind, SelectionLength); string txtSWOS = txtSWS.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty); string txtNWS = e.Text; string txtNWOS = txtNWS.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty); txtNew = txtOld.Substring(0, ind - (txtWS.Length - txtWOS.Length)) + txtNWOS + (txtSWOS.Contains(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) ? NumberFormatInfo.CurrentInfo.NumberDecimalSeparator : String.Empty) + txtOld.Substring(ind - (txtWS.Length - txtWOS.Length) + SelectionLength - (txtSWS.Length - txtSWOS.Length)); if (txtSWOS.Contains(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)) { //If the decimal separator was also highlighted, then the cursor is put in front of the decimal separator. toNDS = true; } } else { //We insert the character to the right of the cursor. int ind = CaretIndex; rcaret = Text.Length - ind; if ((0 < rcaret) && (NumberFormatInfo.CurrentInfo.NumberGroupSeparator == Text.Substring(ind, 1))) { rcaret -= 1; } string txtWS = Text.Substring(0, ind); string txtWOS = txtWS.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty); string txtNWS = e.Text; string txtNWOS = txtNWS.Replace(NumberFormatInfo.CurrentInfo.NumberGroupSeparator, String.Empty); txtNew = txtOld.Substring(0, ind - (txtWS.Length - txtWOS.Length)) + txtNWOS + txtOld.Substring(ind - (txtWS.Length - txtWOS.Length)); } } try { double val = Double.Parse(txtNew); double newVal = ValidateLimits(MinValue, MaxValue, val, ValueType); if (val != newVal) { txtNew = newVal.ToString(); } else if (val == 0) { if (!txtNew.Contains(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)) { txtNew = "0"; } } } catch { txtNew = "0"; } Text = txtNew; if ((true == Text.Contains(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)) && (caret > Text.IndexOf(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator))) { //If the cursor is at the decimal value, then it moves to the right of the decimal separator, if possible. if (caret < Text.Length) { if (textInserted) { caret += 1; rcaret = Text.Length - caret; } } else { //We are at the very end; it's not possible to enter more characters. if (textInserted) { Text = txtOld; } } } caret = Text.Length - rcaret; if (caret < 0) { caret = 0; } if (toNDS) { CaretIndex = Text.IndexOf(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator); } else { CaretIndex = caret; } } e.Handled = true; }
private void Window_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) { barCode += e.Text; }