Beispiel #1
0
 public TagEventArgs(TagViewModel tag)
 {
     this.tag = tag;
 }
 public void StartEdit(TagViewModel tag)
 {
     SelectedTag          = tag;
     tag.IsTextBoxFocused = true;
 }
        /// <summary>
        /// Создает тег.
        /// </summary>
        private TagViewModel CreateTag(object content = null)
        {
            Contract.Requires(content == null || content is string || content is ConfWithHio || content is IHrItemObject);

            TagViewModel tag;
            var          itemObject = content as IHrItemObject;
            var          chio       = content as ConfWithHio;
            var          str        = content as string;

            if (itemObject != null)
            {
                tag = new TagViewModel(this, itemObject);
            }
            else if (chio != null)
            {
                tag            = new TagViewModel(this, chio.HIO);
                tag.Confidence = chio.Confidence;
            }
            else if (str != null)
            {
                tag = new TagViewModel(this, str);
            }
            else
            {
                tag = new TagViewModel(this);
            }

            tag.Deleted += (s, e) =>
            {
                Contract.Requires(!tag.IsLast);
                tagsWritable.Remove(tag);
                StartEdit(LastTag);
            };
            tag.Converting      += CompleteOnConvert;
            tag.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Query")
                {
                    if (EditingTag == null) // non user change
                    {
                        return;
                    }
                    MakeSuggestions(EditingTag);
                    RefreshPopup();
                    OnPropertyChanged(() => IsEmpty);
                }
                else if (e.PropertyName == "IsTextBoxFocused")
                {
                    if (tag.IsTextBoxFocused)
                    {
                        if (tag.Signalization == null || tag.Signalization == Signalizations.None)
                        {
                            Suggestions.Clear();
                        }
                        else
                        {
                            MakeSuggestions(SelectedTag); // предположения для тегов с сигнализацией
                        }

                        CanCompleteOnLostFocus = true;

                        SelectedTags.Except(tag.ToEnumerable()).ForAll(t => t.IsSelected = false);
                        SelectedTag = tag;
                    }
                    else
                    {
                        // выход из редактирования
                        Suggestions.Clear();

                        // потерялся фокус после перехода не в предположения → завершение введенного текста
                        if (CanCompleteOnLostFocus)
                        {
                            CompleteOnLostFocus(tag);
                        }
                    }

                    RefreshPopup();
                }
                else if (e.PropertyName == "State")
                {
                    if (tag.State == State.Completed)
                    {
                        OnTagCompleted(tag);
                        OnEntitiesChanged();
                    }
                }
            };
            return(tag);
        }
        /// <summary>
        /// Добавляет пустой тег рядом с другим.
        /// </summary>
        public void AddTagNearAndEdit(TagViewModel from, bool left)
        {
            var tag = AddTag(index: Tags.IndexOf(from) + (left ? 0 : 1));

            StartEdit(tag);
        }