Пример #1
0
 /// <summary>
 /// Adds a term item to the the TermItem collection.
 /// </summary>
 /// <param name="termItem">The term item to add.</param>
 public void AddTermItem(TermItem termItem)
 {
     this.termItems.Add(termItem);
     termItem.SelectedChanged += new EventHandler(this.TermItem_SelectedChanged);
     this.RaisePropertyChanged("IsEncodable");
     this.RaisePropertyChanged("IsEncoded");
 }
Пример #2
0
        /// <summary>
        /// Updates the collection of term items.
        /// </summary>
        /// <param name="e">Notify Collection Changed Event Args.</param>
        protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);

            this.termItems.Clear();
            this.itemsByContainer.Clear();
            this.containersByItem.Clear();
            foreach (object item in this.Items)
            {
                TermItem termItem = new TermItem();
                termItem.DataContext = item;
                termItem.SetBinding(TermItem.StartIndexProperty, new System.Windows.Data.Binding(this.StartIndexMemberPath));

                Binding lengthBinding = new Binding(this.LengthMemberPath);
                lengthBinding.Mode = BindingMode.OneTime;
                termItem.SetBinding(TermItem.LengthProperty, lengthBinding);

                termItem.SetBinding(TermItem.IsSelectedProperty, new System.Windows.Data.Binding(this.IsSelectedMemberPath));
                this.termItems.Add(termItem);
                this.itemsByContainer.Add(termItem, item);
                this.containersByItem.Add(item, termItem);
            }

            if (this.TermItemsCollectionChanged != null)
            {
                this.TermItemsCollectionChanged(this, EventArgs.Empty);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets a term data object from a container.
        /// </summary>
        /// <param name="container">The TernItem container.</param>
        /// <returns>A term data object.</returns>
        public object GetItemFromContainer(TermItem container)
        {
            if (this.itemsByContainer.ContainsKey(container))
            {
                return(this.itemsByContainer[container]);
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// Focus highlights a specific term.
        /// </summary>
        /// <param name="term">The term data object.</param>
        /// <param name="highlighted">Whether the term should appear highlighted.</param>
        public void SetTermFocusHighlight(object term, bool highlighted)
        {
            TermItem termItem = this.termItemsControl.GetContainerFromItem(term);

            if (termItem != null && termItem.StartIndex >= 0 && termItem.Length > 0)
            {
                for (int i = termItem.StartIndex; i < termItem.StartIndex + termItem.Length; i++)
                {
                    this.textBoxItems[i].IsFocusHighlighted = highlighted;
                    this.decoratorItemsControl.SetContainerZIndex(this.textBoxItems[i], highlighted ? (i + 2) : 0);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Updates the collection of term items.
        /// </summary>
        /// <param name="e">Notify Collection Changed Event Args.</param>
        protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);

            this.termItems.Clear();
            this.itemsByContainer.Clear();
            this.containersByItem.Clear();
            foreach (object item in this.Items)
            {
                TermItem termItem = new TermItem();
                termItem.DataContext = item;
                termItem.SetBinding(TermItem.StartIndexProperty, new System.Windows.Data.Binding(this.StartIndexMemberPath));

                Binding lengthBinding = new Binding(this.LengthMemberPath);
                lengthBinding.Mode = BindingMode.OneTime;
                termItem.SetBinding(TermItem.LengthProperty, lengthBinding);
                
                termItem.SetBinding(TermItem.IsSelectedProperty, new System.Windows.Data.Binding(this.IsSelectedMemberPath));
                this.termItems.Add(termItem);
                this.itemsByContainer.Add(termItem, item);
                this.containersByItem.Add(item, termItem);
            }

            if (this.TermItemsCollectionChanged != null)
            {
                this.TermItemsCollectionChanged(this, EventArgs.Empty);
            }
        }
Пример #6
0
        /// <summary>
        /// Gets a term data object from a container.
        /// </summary>
        /// <param name="container">The TernItem container.</param>
        /// <returns>A term data object.</returns>
        public object GetItemFromContainer(TermItem container)
        {
            if (this.itemsByContainer.ContainsKey(container))
            {
                return this.itemsByContainer[container];
            }

            return null;
        }
Пример #7
0
        /// <summary>
        /// Handles the Changed event of the IsSelected control.
        /// </summary>
        /// <param name="dependencyObject">The term item.</param>
        /// <param name="args">Dependency Property Changed Event Args.</param>
        private static void IsSelected_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            TermItem termItem = (TermItem)dependencyObject;

            termItem.UpdateSelectedChanged();
        }
Пример #8
0
        /// <summary>
        /// Changes the text for a specific term.
        /// <para>
        /// This method uses the start index (from term item) to move through the decorator textbox
        /// items, and update the text in the item to show the new text. If the new text is longer,
        /// more text box items are inserted. If the new text is shorter, text box items are removed.
        /// </para>
        /// <para>
        /// The text box text is then updated with the change, flagging that the change is a programmatic
        /// change. And finally, each term item that comes after the changed item, has the start index
        /// updated with its new start position.
        /// </para>
        /// </summary>
        /// <param name="termContainer">The term container to update.</param>
        internal void ChangeText(MatchingTermItemContainer termContainer)
        {
            if (termContainer != null)
            {
                TermItem termItem = this.termItemsControl.GetContainerFromItem(termContainer.DataContext);
                if (termItem != null)
                {
                    if (this.textBox != null)
                    {
                        this.programaticTextChangeCount++;
                    }

                    int  count            = 0;
                    bool mouseHighlighted = false;
                    bool focusHighlighted = false;
                    for (int i = termItem.StartIndex; i < Math.Min(termItem.StartIndex + termItem.Length, termItem.StartIndex + termContainer.SelectedItemText.Length); i++)
                    {
                        if (i == termItem.StartIndex)
                        {
                            focusHighlighted = this.textBoxItems[i].IsFocusHighlighted;
                            mouseHighlighted = this.textBoxItems[i].IsMouseHighlighted;
                        }

                        this.textBoxItems[i].Text = termContainer.SelectedItemText[count].ToString(CultureInfo.CurrentCulture);
                        count++;
                    }

                    if (termItem.Length < termContainer.SelectedItemText.Length)
                    {
                        if (termItem.Length > 1)
                        {
                            this.textBoxItems[termItem.StartIndex + termItem.Length - 1].ContainerPosition = ContainerPosition.Middle;
                        }
                        else
                        {
                            this.textBoxItems[termItem.StartIndex].ContainerPosition = ContainerPosition.Start;
                        }

                        for (int i = termItem.StartIndex + termItem.Length; i < termItem.StartIndex + termContainer.SelectedItemText.Length; i++)
                        {
                            DecoratorTextBoxItem textBoxItem = new DecoratorTextBoxItem(termContainer.SelectedItemText[i - termItem.StartIndex].ToString(CultureInfo.CurrentCulture));
                            if (i == termItem.StartIndex + termContainer.SelectedItemText.Length - 1)
                            {
                                textBoxItem.ContainerPosition = ContainerPosition.End;
                            }
                            else
                            {
                                textBoxItem.ContainerPosition = ContainerPosition.Middle;
                            }

                            textBoxItem.IsFocusHighlighted = focusHighlighted;
                            textBoxItem.IsMouseHighlighted = mouseHighlighted;
                            textBoxItem.AddTermItem(termItem);
                            this.textBoxItems.Insert(i, textBoxItem);
                        }
                    }
                    else if (termItem.Length > termContainer.SelectedItemText.Length)
                    {
                        for (int i = termItem.StartIndex + termContainer.SelectedItemText.Length; i < termItem.StartIndex + termItem.Length; i++)
                        {
                            this.textBoxItems.RemoveAt(termItem.StartIndex + termContainer.SelectedItemText.Length);
                        }

                        if (termContainer.SelectedItemText.Length > 1)
                        {
                            this.textBoxItems[termItem.StartIndex + termContainer.SelectedItemText.Length - 1].ContainerPosition = ContainerPosition.End;
                        }
                        else
                        {
                            this.textBoxItems[termItem.StartIndex].ContainerPosition = ContainerPosition.Only;
                        }
                    }

                    if (this.textBox != null)
                    {
                        string newText = this.textBox.Text.Remove(termItem.StartIndex, termItem.Length);
                        newText           = newText.Insert(termItem.StartIndex, termContainer.SelectedItemText);
                        this.textBox.Text = newText;
                    }

                    foreach (TermItem item in this.termItemsControl.TermItems)
                    {
                        if (item.StartIndex > termItem.StartIndex)
                        {
                            item.StartIndex += termContainer.SelectedItemText.Length - termItem.Length;
                        }
                    }

                    termItem.Length = termContainer.SelectedItemText.Length;
                }
            }
        }