private void _update() { if (!SdeAppConfiguration.IronPythonAutocomplete) { if (_completionWindow != null) { _completionWindow.Close(); } return; } // Open code completion after the user has pressed dot: if (_completionWindow == null || !_completionWindow.IsVisible) { if (_li.Parent != null) { ((CompletionWindow)_li.Parent).Content = null; } _completionWindow = new CompletionWindow(_textEditor.TextArea, _li); _completionWindow.Changed += new EventHandler(_completionWindow_Changed); _completionWindow.Closed += delegate { if (_completionWindow != null) { _completionWindow.Content = null; } _completionWindow = null; }; } RangeObservableCollectionX <ICompletionData> data = (RangeObservableCollectionX <ICompletionData>)_li.CompletionData; data.Clear(); string word = AvalonLoader.GetWholeWordAdv(_textEditor.TextArea.Document, _textEditor); List <string> words = PythonEditorList.Tables.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> constants = PythonEditorList.Constants.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); List <string> flags = FlagsManager.GetFlagNames().Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList(); if (words.Count == 0 && constants.Count == 0 && flags.Count == 0) { _completionWindow.Close(); return; } IEnumerable <ICompletionData> results = words.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Function)). Concat(constants.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Constant))). Concat(flags.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Constant))); data.AddRange(results); _completionWindow.CompletionList.ListBox.ItemsSource = data; _completionWindow.Show(); _completionWindow.CompletionList.SelectedItem = _completionWindow.CompletionList.CompletionData.FirstOrDefault(p => String.Compare(p.Text, word, StringComparison.OrdinalIgnoreCase) >= 0); _completionWindow.CompletionList.ListBox.ScrollToCenterOfView(_completionWindow.CompletionList.SelectedItem); }
private void _textArea_TextEntering(object sender, TextCompositionEventArgs e) { try { if (e.Text.Length > 0 && _completionWindow != null) { if (!char.IsLetterOrDigit(e.Text[0]) && e.Text[0] != '_' && e.Text[0] != ' ') { string word = AvalonLoader.GetWholeWordAdv(_textEditor.TextArea.Document, _textEditor); var strategy = new RegexSearchStrategy(new Regex(word), true); if ((e.Text[0] != '\t' || e.Text[0] != '\n') && strategy.FindAll(_textEditor.Document, 0, _textEditor.Document.TextLength).Count() > 1) { _completionWindow.Close(); return; } string line = _getText(_textEditor.TextArea.Caret.Line); if (line.IndexOf('#') > -1) { _completionWindow.Close(); return; } _completionWindow.CompletionList.RequestInsertion(e); } else if (e.Text[0] == ' ') { _completionWindow.Close(); } } if (e.Text.Length > 0 && _completionWindow == null) { if (e.Text[0] == '\n') { int currentLine = _textEditor.TextArea.Caret.Line; DocumentLine docLine = _getLine(currentLine); string line = _getText(currentLine); int currentIndent = LineHelper.GetIndent(line); if (line.EndsWith(":") && _textEditor.CaretOffset >= docLine.EndOffset) { currentIndent++; } if (_textEditor.LineCount == currentLine) { _textEditor.Document.Insert(_textEditor.Document.TextLength, "\n" + LineHelper.GenerateIndent(currentIndent)); _textEditor.CaretOffset = _textEditor.Text.Length; } else { var position = _textEditor.CaretOffset; _textEditor.Document.Insert(_textEditor.CaretOffset, "\n" + LineHelper.GenerateIndent(currentIndent)); _textEditor.CaretOffset = position + ("\n" + LineHelper.GenerateIndent(currentIndent)).Length; } _textEditor.TextArea.Caret.BringCaretToView(); e.Handled = true; } } } catch { } }