Exemple #1
0
 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 {
     base.OnPropertyChanged(e);
     if (e.Property == DataContextProperty)
     {
         if (e.OldValue is MRACltItemInfo)
         {
             MRACltItemInfo oldinfo = (MRACltItemInfo)(e.OldValue);
             oldinfo.PropertyChanged -= OnInfoPropertyChanged;
         }
         if (e.NewValue is MRACltItemInfo)
         {
             MRACltItemInfo newinfo = (MRACltItemInfo)(e.NewValue);
             newinfo.PropertyChanged += OnInfoPropertyChanged;
         }
         Initialize();
         InvalidateVisual();
     }
 }
Exemple #2
0
        public void SetInputText(string inputtext)
        {
            List <MRACltItemInfo>    _items = new List <MRACltItemInfo>();
            List <MRACltBoldSegment> bolds  = new List <MRACltBoldSegment>();
            double maxsimi   = 0.0;
            int    maxsimiid = -1;

            foreach (ITextKeyCore keyword in keywords)
            {
                bolds.Clear();
                double _simi = 0.0;
                if (!Match(inputtext, keyword.Keyword, bolds, ref _simi))
                {
                    continue;
                }
                if (maxsimiid < 0 || _simi > maxsimi)
                {
                    maxsimi = _simi; maxsimiid = items.Count();
                }
                MRACltItemInfo item = new MRACltItemInfo(core, this, MRACltItemTypes.Keyword, items.Count(), keyword.Keyword);
                item.Bolds.AddRange(bolds);
                _items.Add(item);
            }
            foreach (IMRACltItem cltitem in cltsrcs)
            {
                bolds.Clear();
                double _simi = 0.0;
                if (!Match(inputtext, cltitem.Text, bolds, ref _simi))
                {
                    continue;
                }
                if (maxsimiid < 0 || _simi > maxsimi)
                {
                    maxsimi = _simi; maxsimiid = items.Count();
                }
                MRACltItemTypes itemtype = MRACltItemTypes.Variable;
                if (cltitem is IMRACltType)
                {
                    itemtype = MRACltItemTypes.Class;
                }
                if (cltitem is IMRACltVar)
                {
                    itemtype = MRACltItemTypes.Variable;
                }
                if (cltitem is IMRACltFunc)
                {
                    itemtype = MRACltItemTypes.Function;
                }
                MRACltItemInfo item = new MRACltItemInfo(core, this, itemtype, items.Count(), cltitem.Text);
                item.Bolds.AddRange(bolds);
                _items.Add(item);
            }
            if (_items.Count() > 0)
            {
                _items.Sort((i1, i2) => i1.Text.CompareTo(i2.Text));
                items              = _items;
                ItemsSource        = items;
                this.selectedindex = maxsimiid;
                if (selectedindex >= 0 && selectedindex < items.Count())
                {
                    items[selectedindex].IsSelected = true;
                    ScrollIntoMiddle(selectedindex);
                }
            }
        }