/// <summary> /// Adds the item to the list of recently used items. /// </summary> /// <param name="item">The item.</param> /// <exception cref="ArgumentNullException">The <paramref name="item"/> is <c>null</c>.</exception> public void AddItem(RecentlyUsedItem item) { Argument.IsNotNull(() => item); Log.Debug("Adding new item '{0}' to the list of recently used items", item.Name); if (IsAvailableInCollection(_items.PinnedItems, item.Name)) { Log.Info("Item '{0}' is pinned, no need to add it to list of recently used items", item.Name); return; } AddSorted(_items.Items, item); Updated.SafeInvoke(this); Save(); }
private void AddSorted(List<RecentlyUsedItem> collection, RecentlyUsedItem item) { for (var i = 0; i < collection.Count; i++) { if (string.Equals(collection[i].Name, item.Name, StringComparison.OrdinalIgnoreCase)) { Log.Debug("Found item '{0}' in the list of items, removing it and adding it to top", item.Name); collection.RemoveAt(i); break; } } var added = false; for (var i = 0; i < collection.Count; i++) { var collectionItem = collection[i]; if (collectionItem.DateTime < item.DateTime) { added = true; collection.Insert(i, item); break; } } if (!added) { collection.Add(item); } if (collection.Count > MaximumItemCount) { Log.Debug("Number of items is larger than allowed maximum of '{0}'", MaximumItemCount); for (int i = MaximumItemCount; i < collection.Count; i++) { collection.RemoveAt(i); } } }
/// <summary> /// Removes the item from the list of recently used items. /// </summary> /// <param name="item">The item.</param> /// <exception cref="ArgumentNullException">The <paramref name="item"/> is <c>null</c>.</exception> public void RemoveItem(RecentlyUsedItem item) { Argument.IsNotNull(() => item); Log.Debug("Removing item '{0}' to the list of recently used items", item.Name); RemoveItemFromCollection(_items.PinnedItems, item.Name); RemoveItemFromCollection(_items.Items, item.Name); Updated.SafeInvoke(this); Save(); }