Exemplo n.º 1
0
        private IPresenter EnsurePresenter(IPresenter presenter)
        {
            int index = _presenters.IndexOf(presenter);

            if (index == -1)
            {
                _presenters.Add(presenter);
            }
            else
            {
                presenter = _presenters[index];
            }

            var node = presenter as IPresenterNode;

            if (node != null)
            {
                node.Parent = this;
            }

            if (IsInitialized)
            {
                presenter.Initialize();
            }

            return(presenter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// in place sort an <see cref="IObservableCollection{T}"/> utilizing an <see cref="IComparer{T}"/>
        /// </summary>
        /// <remarks>
        /// will undo selection, when collection is bound for example to a ListBox
        /// </remarks>
        public static void Sort <T>(this IObservableCollection <T> collection, IComparer <T> comparer)
        {
            var sorted = collection.OrderBy(x => x, comparer).ToList();

            for (var i = 0; i < sorted.Count; i++)
            {
                collection.Move(collection.IndexOf(sorted[i]), i);
            }
        }
Exemplo n.º 3
0
        public void ReplaceWithRange(T from, T to)
        {
            var iFrom = _allItems.IndexOf(from);
            var iTo   = _allItems.IndexOf(to);

            if (iFrom < 0 || iTo < 0)
            {
                return; //normally unreachable code
            }

            if (iFrom > iTo)
            {
                var tmp = iFrom;
                iFrom = iTo;
                iTo   = tmp;
            }
            _selectedItems.Replace(
                _allItems.Skip(iFrom).Take(iTo - iFrom + 1));
        }
 /// <summary>
 /// Método acionado quando a propriedade de uma dos itens da coleção for alterada.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (_comparerPropertiesContainer != null && _comparerPropertiesContainer.ContainsProperty(e.PropertyName))
     {
         var item        = (T)sender;
         var sourceIndex = _source.IndexOf(item);
         if (sourceIndex >= 0)
         {
             for (var i = 0; i < _indexes.Count; i++)
             {
                 if (_indexes[i] == sourceIndex)
                 {
                     if ((i > 0 && _comparer.Compare(item, _source[_indexes[i - 1]]) < 0) || (i < _indexes.Count && _comparer.Compare(item, _source[_indexes[i + 1]]) > 0))
                     {
                         CalculateIndexes();
                     }
                     break;
                 }
             }
         }
     }
 }