Exemple #1
0
 /// <summary>
 /// update the "selected" scope when the user click in scintilla
 /// </summary>
 public void UpdateCurrentScope()
 {
     if (!IsVisible)
     {
         return;
     }
     UpdateCurrentScope(Npp.CurrentFile.IsProgress ? ParserHandler.GetScopeOfLine(Sci.Line.CurrentLine) : null);
 }
Exemple #2
0
        /// <summary>
        /// this methods sorts the items to put the best match on top and then filter it with modelFilter
        /// </summary>
        private void ApplyFilter()
        {
            Keyword.Width = _normalWidth - (Config.Instance.AutoCompleteHideScrollBar ? 0 : 17);

            // save position in the list
            var curPos = new Point(fastOLV.SelectedIndex, fastOLV.TopItemIndex);

            // apply filter to each item in the list then set the list
            try {
                _initialObjectsList.ForEach(data => data.FilterApply(_filterByText));
            } catch (Exception e) {
                if (!(e is NullReferenceException))
                {
                    ErrorHandler.LogError(e);
                }
            }
            if (String.IsNullOrEmpty(_filterByText))
            {
                fastOLV.SetObjects(_initialObjectsList);
            }
            else
            {
                fastOLV.SetObjects(_initialObjectsList.OrderBy(data => data.FilterDispertionLevel).ToList());
            }

            // apply the filter, need to match the filter + need to be an active type (Selector button activated)
            // + need to be in the right scope for variables
            _currentLineNumber = Npp.Line.CurrentLine;
            _currrentScope     = ParserHandler.GetScopeOfLine(_currentLineNumber);
            if (!Config.Instance.AutoCompleteOnlyShowDefinedVar)
            {
                _currentLineNumber = -1;
            }
            _useTypeFiltering   = true;
            _useTextFiltering   = true;
            fastOLV.ModelFilter = new ModelFilter(FilterPredicate);

            // update total items
            TotalItems   = ((ArrayList)fastOLV.FilteredObjects).Count;
            nbitems.Text = TotalItems + StrItems;

            if (TotalItems <= Config.Instance.AutoCompleteShowListOfXSuggestions)
            {
                Keyword.Width = _normalWidth;
            }

            // reposition the cursor in the list
            if (TotalItems > 0)
            {
                fastOLV.SelectedIndex = Math.Max(0, Math.Min(curPos.X, TotalItems - 1));
                fastOLV.TopItemIndex  = Math.Max(0, Math.Min(curPos.Y, TotalItems - 1));
            }
        }
Exemple #3
0
 /// <summary>
 /// Applies the same sorting / filtering as the autocompletion form to a given list
 /// of items
 /// </summary>
 public static List <CompletionItem> ExternalFilterItems(List <CompletionItem> objectsList, int line, bool dontCheckLine = false)
 {
     objectsList.Sort(new CompletionDataSortingClass());
     if (_displayedTypes == null)
     {
         _displayedTypes = new Dictionary <CompletionType, SelectorButton <CompletionType> >();
     }
     _useTypeFiltering  = false;
     _useTextFiltering  = false;
     _currrentScope     = ParserHandler.GetScopeOfLine(line);
     _currentLineNumber = (!Config.Instance.AutoCompleteOnlyShowDefinedVar || dontCheckLine) ? -1 : line;
     return(objectsList.Where(FilterPredicate).ToList());
 }
Exemple #4
0
        /// <summary>
        /// Returns true if the conditions have changed
        /// </summary>
        public bool UpdateConditions(int currentLineNumber, bool checkLine = true)
        {
            if (currentLineNumber != _currentLineNumber)
            {
                _currentLineNumber = currentLineNumber;
                _currentScope      = ParserHandler.GetScopeOfLine <ParsedScopeBlock>(currentLineNumber);
                if (!checkLine || !Config.Instance.AutoCompleteOnlyShowDefinedVar)
                {
                    _currentLineNumber = -1;
                }
                return(true);
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Event on format cell
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private static void FastOlvOnFormatCell(object sender, FormatCellEventArgs args)
        {
            CodeExplorerItem obj = (CodeExplorerItem)args.Model;
            var curScope         = ParserHandler.GetScopeOfLine(Npp.Line.CurrentLine);

            // currently selected block
            if (curScope != null && !obj.IsNotBlock && obj.DisplayText.Equals(curScope.Name))
            {
                RowBorderDecoration rbd = new RowBorderDecoration {
                    FillBrush      = new SolidBrush(Color.FromArgb(50, ThemeManager.Current.MenuFocusedBack)),
                    BorderPen      = new Pen(Color.FromArgb(128, ThemeManager.Current.MenuFocusedBack.IsColorDark() ? ControlPaint.Light(ThemeManager.Current.MenuFocusedBack, 0.10f) : ControlPaint.Dark(ThemeManager.Current.MenuFocusedBack, 0.10f)), 1),
                    BoundsPadding  = new Size(-2, 0),
                    CornerRounding = 6.0f
                };
                args.SubItem.Decoration = rbd;
            }

            // display the flags
            int offset = -5;

            obj.DoForEachFlag((name, flag) => {
                Image tryImg = (Image)ImageResources.ResourceManager.GetObject(name);
                if (tryImg != null)
                {
                    ImageDecoration decoration = new ImageDecoration(tryImg, 100, ContentAlignment.MiddleRight)
                    {
                        Offset = new Size(offset, 0)
                    };
                    if (args.SubItem.Decoration == null)
                    {
                        args.SubItem.Decoration = decoration;
                    }
                    else
                    {
                        args.SubItem.Decorations.Add(decoration);
                    }
                    offset -= 20;
                }
            });

            // display the sub string
            if (offset < -5)
            {
                offset -= 5;
            }
            if (!string.IsNullOrEmpty(obj.SubString))
            {
                TextDecoration decoration = new TextDecoration(obj.SubString, 100)
                {
                    Alignment      = ContentAlignment.MiddleRight,
                    Offset         = new Size(offset, 0),
                    Font           = FontManager.GetFont(FontStyle.Bold, 10),
                    TextColor      = ThemeManager.Current.SubTextFore,
                    CornerRounding = 1f,
                    Rotation       = 0,
                    BorderWidth    = 1,
                    BorderColor    = ThemeManager.Current.SubTextFore
                };
                args.SubItem.Decorations.Add(decoration);
            }
        }