<commit_before>// ****************************************************************************
// <copyright file="ApplicationBarItemCollectionBase.cs" company="<NAME>">
// Copyright  <NAME> 2011
// </copyright>
// ****************************************************************************
// <author><NAME></author>
// <email><EMAIL></email>
// <date>17-11-2011</date>
// <project>Cimbalino.Phone.Toolkit</project>
// <web>http://www.pedrolamas.com</web>
// <license>
// See license.txt in this solution or http://www.pedrolamas.com/license_MIT.txt
// </license>
// ****************************************************************************

using System.ComponentModel;
using System.Windows;
using Microsoft.Phone.Shell;

namespace Cimbalino.Phone.Toolkit.Behaviors
{
    /// <summary>
    /// Represents a collection of <see cref="ApplicationBarItemBase{T}" />.
    /// </summary>
    /// <typeparam name="T">The type of items in the collection.</typeparam>
    public abstract class ApplicationBarItemCollectionBase<T> : DependencyObjectCollection<ApplicationBarItemBase<T>>
        where T : IApplicationBarMenuItem
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
            Justification = "Necessary")]
        private readonly System.Collections.IList _itemsList;
        private readonly int _maxVisibleItems;

        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationBarItemCollectionBase{T}" /> class.
        /// </summary>
        /// <param name="itemsList">The items list.</param>
        /// <param name="maxVisibleItems">The maximum visible items.</param>
        public ApplicationBarItemCollectionBase(System.Collections.IList itemsList, int maxVisibleItems)
        {
            _itemsList = itemsList;
            _maxVisibleItems = maxVisibleItems;

            CollectionChanged += OnCollectionChanged;
        }

        internal void UpdateApplicationBar()
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            _itemsList.Clear();

            var itemCount = 0;

            foreach (var item in this)
            {
                var internalItem = item.Item;

                if (item.IsVisible)
                {
                    _itemsList.Add(internalItem);

                    if (itemCount++ == _maxVisibleItems)
                    {
                        break;
                    }
                }
            }
        }

        private void OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)<commit_msg>Fixed a small issue with the handling of the ApplicationBar Icon Buttons and Menu Items limit<commit_after>// ****************************************************************************
// <copyright file="ApplicationBarItemCollectionBase.cs" company="<NAME>">
// Copyright  <NAME> 2011
// </copyright>
// ****************************************************************************
// <author><NAME></author>
// <email><EMAIL></email>
// <date>17-11-2011</date>
// <project>Cimbalino.Phone.Toolkit</project>
// <web>http://www.pedrolamas.com</web>
// <license>
// See license.txt in this solution or http://www.pedrolamas.com/license_MIT.txt
// </license>
// ****************************************************************************

using System.ComponentModel;
using System.Windows;
using Microsoft.Phone.Shell;

namespace Cimbalino.Phone.Toolkit.Behaviors
{
    /// <summary>
    /// Represents a collection of <see cref="ApplicationBarItemBase{T}" />.
    /// </summary>
    /// <typeparam name="T">The type of items in the collection.</typeparam>
    public abstract class ApplicationBarItemCollectionBase<T> : DependencyObjectCollection<ApplicationBarItemBase<T>>
        where T : IApplicationBarMenuItem
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
            Justification = "Necessary")]
        private readonly System.Collections.IList _itemsList;
        private readonly int _maxVisibleItems;

        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationBarItemCollectionBase{T}" /> class.
        /// </summary>
        /// <param name="itemsList">The items list.</param>
        /// <param name="maxVisibleItems">The maximum visible items.</param>
        public ApplicationBarItemCollectionBase(System.Collections.IList itemsList, int maxVisibleItems)
        {
            _itemsList = itemsList;
            _maxVisibleItems = maxVisibleItems;

            CollectionChanged += OnCollectionChanged;
        }

        internal void UpdateApplicationBar()
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            _itemsList.Clear();

            var itemCount = 0;

            foreach (var item in this)
            {
                var internalItem = item.Item;

                if (item.IsVisible)
                {
                    _itemsList.Add(internalItem);

                    if (++itemCount == _maxVisibleItems)
                    {
                        break;
                    }
                }
            }
        }

        private void OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{'fraction_non_alphanumeric': 0.1862923806051768, 'fraction_numerical': 0.006197593875318994, 'mean_word_length': 2.472784810126582, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '984250', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1282, 'n_words': 270}