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);
        }
Beispiel #2
0
        private void _update()
        {
            // 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();

            if (_skills == null)
            {
                _skills   = new List <string>();
                _skill_db = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Skills);
                _skill_db.FastItems.ForEach(p => _skills.Add(p.GetStringValue(ServerSkillAttributes.Name.Index)));
            }

            string word = AvalonLoader.GetWholeWord(_textEditor.TextArea.Document, _textEditor);

            List <string> words     = ScriptEditorList.Words.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList();
            List <string> constants = ScriptEditorList.Constants.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList();
            List <string> skills    = _skills.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList();

            if (words.Count == 0 && constants.Count == 0 && skills.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(skills.Select(p => (ICompletionData) new MyCompletionData(p, _textEditor, DataType.Skill)));

            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);
            TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_completionWindow.CompletionList.ListBox, _completionWindow.CompletionList.SelectedItem);
        }