Exemple #1
0
        private static void AddRuleSuggestions(ScopeActionsInfo info, Scope scope)
        {
            List <Suggestion> suggestions = m_SuggestionProvider.GetSuggestions(scope);

            foreach (Suggestion sug in suggestions)
            {
                ApplySuggestionOnSelectionAction action = new ApplySuggestionOnSelectionAction(txt, sug);
                info.RuleSuggestions.Add(action);
            }
        }
Exemple #2
0
            private void GetSuggestionsAsync(object param)
            {
                object[]            args       = param as object[];
                string              searchText = Convert.ToString(args[0]);
                ISuggestionProvider provider   = args[1] as ISuggestionProvider;
                IEnumerable         list       = provider.GetSuggestions(searchText);

                _actb.Dispatcher.BeginInvoke(new Action <IEnumerable, string>(DisplaySuggestions), DispatcherPriority.Background, new object[] {
                    list,
                    searchText
                });
            }
        /// <inheritdoc/>
        public virtual bool PrintSuggestion(UnusedArgumentModel model)
        {
            var suggestions = suggestionProvider.GetSuggestions(model.Key, model.Argument as ICommandLineCommandContainer);

            if (!suggestions.Any())
            {
                return(false);
            }

            Builder.AddSuggestionHeader(model.Key);

            Builder.AddSuggestion(suggestions.First());

            console.WriteLine(Builder.Build());

            return(true);
        }
        /// <summary>
        /// Renders the control at the current location in the layout, akin to EditorGUILayout calls.
        /// </summary>
        /// <param name="text">The value to populate in the TextField portion of the control.</param>
        /// <returns>The new value of the text field based on user input in the text field or in the dropdown suggestion list.</returns>
        public string OnGUI(string text)
        {
            const bool isFirstRenderPass = true;

            EnforceRenderPassOrdering(isFirstRenderPass);

            if (Event.current.type == EventType.KeyDown && _isFocused && _cachedSuggestions.Any())
            {
                if (Event.current.keyCode == KeyCode.Return)
                {
                    SetCurrentSelectedIndexToTextField();
                }
                else
                {
                    OnKeyPressed();
                }
            }

            string controlName = _keyFieldNamePrefix + _controlId;

            if (_setSelectedSuggestionToTextField && _cachedSuggestions.Any())
            {
                // When setting the text on the control, in order to get it to render correctly, we must set focus off of it, render it, then set focus back on it again.
                text = _cachedSuggestions[_selectedIndex].Value;
            }

            // Draw the text field
            // Note: We assign a name to the field so we can later check if it is focused
            string newText;

            using (var horizontalScope = new GUILayout.HorizontalScope())
            {
                GUI.SetNextControlName(controlName);
                newText = EditorGUILayout.TextField(_label, text);
            }

            if (Event.current.type == EventType.Repaint)
            {
                // The name of the focused control is not set properly on Layout.  Wait until Repaint to check.
                _isFocused = (GUI.GetNameOfFocusedControl() == controlName);
            }

            if (_setSelectedSuggestionToTextField)
            {
                GUI.FocusControl(controlName);
                _isFocused = true;
                _setSelectedSuggestionToTextField = false;
            }

            if (newText != _textForCachedSuggestions ||
                _isFocused != _focusedForCachedSuggestions ||
                ThreadSafeCacheInvalid)
            {
                if (Event.current.type == EventType.Layout)
                {
                    _textForCachedSuggestions    = newText;
                    _focusedForCachedSuggestions = _isFocused;
                    ThreadSafeCacheInvalid       = false;

                    var suggestions = _suggestionProvider.GetSuggestions(newText, _isFocused);
                    _cachedSuggestions = (suggestions != null) ? suggestions.ToList() : new List <Suggestion>();
                    _selectedIndex     = 0;
                    _scrolledIndex     = 0;
                }
                else
                {
                    EditorWindow.focusedWindow?.Repaint();
                }
            }

            // Capture the position of the text field for later rendering of the drop-down
            _textFieldPosition = EditorGUILayout.GetControlRect(false, 0);

            // Draw the auto-suggestion overlay.
            DrawAutoSuggestionOverlay(_textFieldPosition, isFirstRenderPass);

            return(newText);
        }