protected void remove_WLock(MediaItem item)
        {
            SelectableMediaItem selectableItem = new SelectableMediaItem(item);

            int index = MediaCollectionView.IndexOf(selectableItem);

            removeAt_WLock(index);
        }
 public void ExitWriteLock(bool fireQueuedEvents = true)
 {
     MediaCollectionView.ExitWriteLock(fireQueuedEvents);
     if (fireQueuedEvents)
     {
         FireQueuedEvents();
     }
 }
 public void ExitUpgradeableReadLock(bool fireQueuedEvents = true)
 {
     MediaCollectionView.ExitUpgradeableReadLock(fireQueuedEvents);
     if (fireQueuedEvents)
     {
         FireQueuedEvents();
     }
 }
Exemplo n.º 4
0
        void tagsList_IsFilterChanged(object sender, EventArgs e)
        {
            ToggleButton includedClearToggleButton =
                VisualTreeUtils.findVisualChildByName <ToggleButton>(dataGrid, "includeClearToggleButton");

            ToggleButton excludedClearToggleButton =
                VisualTreeUtils.findVisualChildByName <ToggleButton>(dataGrid, "excludeClearToggleButton");

            TagItem item = (TagItem)sender;

            if (item.IsIncluded || item.IsExcluded)
            {
                mediaCollectionView.TagFilter.Add(item);

                if (item.IsIncluded)
                {
                    includedClearToggleButton.IsEnabled = true;
                    includedClearToggleButton.IsChecked = true;
                }
                else
                {
                    excludedClearToggleButton.IsEnabled = true;
                    excludedClearToggleButton.IsChecked = true;
                }
            }
            else
            {
                mediaCollectionView.TagFilter.Remove(item);

                int nrIncluded = 0, nrExcluded = 0;

                foreach (TagItem tagItem in mediaCollectionView.TagFilter)
                {
                    if (tagItem.IsIncluded)
                    {
                        nrIncluded++;
                    }
                    if (tagItem.IsExcluded)
                    {
                        nrExcluded++;
                    }
                }

                if (nrExcluded == 0)
                {
                    excludedClearToggleButton.IsEnabled = false;
                    excludedClearToggleButton.IsChecked = false;
                }

                if (nrIncluded == 0)
                {
                    includedClearToggleButton.IsEnabled = false;
                    includedClearToggleButton.IsChecked = false;
                }
            }

            MediaCollectionView.refresh();
        }
        public void selectRange(MediaItem end)
        {
            EnterWriteLock();
            try
            {
                bool selectionChanged = false;

                MediaItem start = null;

                int startIndex = getSelectedItem_RLock(out start);
                int endIndex   = MediaCollectionView.IndexOf(new SelectableMediaItem(end));

                if (endIndex == -1)
                {
                    return;
                }
                else if (startIndex == -1)
                {
                    startIndex = 0;
                }

                if (endIndex < startIndex)
                {
                    int temp = startIndex;
                    startIndex = endIndex;
                    endIndex   = temp;
                }

                for (int i = startIndex; i <= endIndex; i++)
                {
                    MediaCollectionView[i].SelectionChanged -= selectableItem_SelectionChanged;

                    if (MediaCollectionView[i].IsSelected == false)
                    {
                        selectionChanged = true;
                    }

                    MediaCollectionView[i].IsSelected = true;

                    MediaCollectionView[i].SelectionChanged += selectableItem_SelectionChanged;
                }

                if (selectionChanged)
                {
                    QueueSelectionChangedEvent();
                }
            }
            finally
            {
                ExitWriteLock();
            }
        }
        protected void reSort(MediaItem item)
        {
            int oldIndex = 0;
            int newIndex = 0;

            EnterWriteLock();
            try
            {
                SelectableMediaItem selectableItem = new SelectableMediaItem(item);

                oldIndex = MediaCollectionView.IndexOf(selectableItem);
                newIndex = oldIndex;

                if (oldIndex != -1)
                {
                    selectableItem = MediaCollectionView[oldIndex];

                    // item is already in the list
                    if (Filter(selectableItem))
                    {
                        // remove and reinsert item
                        MediaCollectionView.RemoveAt(oldIndex);
                        if (oldIndex < sortedItemEnd)
                        {
                            sortedItemEnd -= 1;
                        }

                        newIndex = insertSorted_WLock(selectableItem);

                        if (newIndex != oldIndex)
                        {
                            QueueItemResortedEvent(item, oldIndex, newIndex);
                        }
                    }
                    else
                    {
                        // remove item from list
                        removeAt_WLock(oldIndex);
                    }
                }
                else
                {
                    // add item to list
                    add_WLock(item);
                }
            }
            finally
            {
                ExitWriteLock();
            }
        }
Exemplo n.º 7
0
        private void excludeClearToggleButton_Unchecked(object sender, RoutedEventArgs e)
        {
            MediaCollectionView.TagFilter.RemoveAll((i) => i.IsExcluded == true);
            foreach (TagItem item in tagsList)
            {
                item.IsExcluded = false;
            }

            MediaCollectionView.refresh();

            ToggleButton excludedClearToggleButton =
                VisualTreeUtils.findVisualChildByName <ToggleButton>(dataGrid, "excludeClearToggleButton");

            excludedClearToggleButton.IsEnabled = false;
            excludedClearToggleButton.IsChecked = false;
        }
Exemplo n.º 8
0
 void mapLoadItems()
 {
     MediaCollectionView.EnterReadLock();
     try
     {
         foreach (SelectableMediaItem media in MediaCollectionView)
         {
             if (media.Item.ItemState == MediaItemState.LOADED)
             {
                 mapAddItem(media);
             }
         }
     }
     finally
     {
         MediaCollectionView.ExitReadLock();
     }
 }
        protected void add_WLock(IEnumerable <MediaItem> items)
        {
            // Use a fast(er) path if we are just adding a batch of items to a empty list
            // instead of firing off a whole bunch of itemchanged events
            if (this.MediaCollectionView.Count == 0 && items.Count() > 1)
            {
                List <SelectableMediaItem> addedItems = new List <SelectableMediaItem>();

                foreach (MediaItem item in items)
                {
                    SelectableMediaItem selectableItem = new SelectableMediaItem(item);

                    if (Filter(selectableItem))
                    {
                        selectableItem.SelectionChanged += selectableItem_SelectionChanged;

                        if (selectableItem.Item.Metadata != null)
                        {
                            CollectionsSort.insertIntoSortedCollection(addedItems, selectableItem, sortFunc, 0, sortedItemEnd);
                            sortedItemEnd++;
                        }
                        else
                        {
                            addedItems.Add(selectableItem);
                        }
                    }
                }

                MediaCollectionView.AddRange(addedItems);

                QueueNrItemsInStateChangedEvent(new MediaStateCollectionViewChangedEventArgs(MediaStateChangedAction.Add, addedItems));
                // this is incorrect
                //sortedItemEnd = Media.Count;
            }
            else
            {
                foreach (MediaItem item in items)
                {
                    add_WLock(item);
                }
            }
        }
        protected void add_WLock(MediaItem item)
        {
            SelectableMediaItem selectableItem = new SelectableMediaItem(item);

            if (Filter(selectableItem) && !MediaCollectionView.Contains(selectableItem))
            {
                if (item.Metadata != null)
                {
                    insertSorted_WLock(selectableItem);
                }
                else
                {
                    MediaCollectionView.Add(selectableItem);
                }

                QueueNrItemsInStateChangedEvent(new MediaStateCollectionViewChangedEventArgs(MediaStateChangedAction.Add, selectableItem));
            }

            selectableItem.SelectionChanged += selectableItem_SelectionChanged;
        }
        protected void removeAt_WLock(int index)
        {
            SelectableMediaItem selectableItem = null;

            if (index >= 0)
            {
                selectableItem = MediaCollectionView[index];

                if (selectableItem.IsSelected)
                {
                    QueueSelectionChangedEvent();
                }

                MediaCollectionView.RemoveAt(index);
                if (index < sortedItemEnd)
                {
                    sortedItemEnd -= 1;
                }

                selectableItem.SelectionChanged -= selectableItem_SelectionChanged;

                QueueNrItemsInStateChangedEvent(new MediaStateCollectionViewChangedEventArgs(MediaStateChangedAction.Remove, selectableItem));
            }
        }
        protected void clear_WLock()
        {
            bool selectionChanged = false;

            foreach (SelectableMediaItem selectableItem in MediaCollectionView)
            {
                selectableItem.SelectionChanged -= selectableItem_SelectionChanged;

                if (selectableItem.IsSelected)
                {
                    selectionChanged = true;
                }
            }

            MediaCollectionView.Clear();
            sortedItemEnd = 0;

            if (selectionChanged)
            {
                QueueSelectionChangedEvent();
            }

            QueueNrItemsInStateChangedEvent(new MediaStateCollectionViewChangedEventArgs(MediaStateChangedAction.Clear));
        }
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(MediaCollectionView.GetEnumerator());
 }
 public IEnumerator <SelectableMediaItem> GetEnumerator()
 {
     return(MediaCollectionView.GetEnumerator());
 }
 /// <summary>
 /// Returns index of Media item, query under read lock
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public int IndexOf(SelectableMediaItem item)
 {
     return(MediaCollectionView.IndexOf(item));
 }
 public void EnterUpgradeableReadLock()
 {
     MediaCollectionView.EnterUpgradeableReadLock();
 }
 public void ExitReadLock()
 {
     MediaCollectionView.ExitReadLock();
 }
 public void EnterReadLock()
 {
     MediaCollectionView.EnterReadLock();
 }
 public void EnterWriteLock()
 {
     MediaCollectionView.EnterWriteLock();
 }