예제 #1
0
        public async Task RemoveItemAsync(JumpListGroup Group, params string[] PathList)
        {
            try
            {
                if (await Initialize().ConfigureAwait(false))
                {
                    bool   ItemModified = false;
                    string GroupString  = ConvertGroupEnumToResourceString(Group);

                    JumpListItem[] GroupItem = InnerList.Items.Where((Item) => Item.GroupName == GroupString).ToArray();

                    foreach (string Path in PathList)
                    {
                        if (GroupItem.FirstOrDefault((Item) => Item.Description == Path) is JumpListItem RemoveItem)
                        {
                            InnerList.Items.Remove(RemoveItem);
                            ItemModified = true;
                        }
                    }

                    if (ItemModified)
                    {
                        await InnerList.SaveAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Groups and sorts into a list of group lists based on a selector.
        /// </summary>
        /// <typeparam name="TSource">Type of the items in the list.</typeparam>
        /// <typeparam name="TSort">Type of value returned by sortSelector.</typeparam>
        /// <typeparam name="TGroup">Type of value returned by groupSelector.</typeparam>
        /// <param name="source">List to be grouped and sorted</param>
        /// <param name="sortSelector">A selector that provides the value that items will be sorted by.</param>
        /// <param name="groupSelector">A selector that provides the value that items will be grouped by.</param>
        /// <param name="isSortDescending">Value indicating to sort groups in reverse. Items in group will still sort ascending.</param>
        /// <returns>A list of JumpListGroups.</returns>
        public static List <JumpListGroup <TSource> > ToGroups <TSource, TSort, TGroup>(
            this IEnumerable <TSource> source, Func <TSource, TSort> sortSelector,
            Func <TSource, TGroup> groupSelector, bool isSortDescending = false)
        {
            var groups = new List <JumpListGroup <TSource> >();

            // Group and sort items based on values returned from the selectors
            var query = from item in source
                        orderby groupSelector(item), sortSelector(item)
            group item by groupSelector(item) into g
            select new { GroupName = g.Key, Items = g };

            // For each group generated from the query, create a JumpListGroup
            // and fill it with its items
            foreach (var g in query)
            {
                JumpListGroup <TSource> group = new JumpListGroup <TSource>();
                group.Key = g.GroupName;
                @group.AddRange(g.Items.Select(item => (object)item));

                if (isSortDescending)
                {
                    groups.Insert(0, group);
                }
                else
                {
                    groups.Add(group);
                }
            }

            return(groups);
        }
예제 #3
0
        public async Task AddItem(JumpListGroup Group, params StorageFolder[] FolderList)
        {
            if (await Initialize().ConfigureAwait(false))
            {
                bool ItemModified = false;

                string GroupString = ConvertGroupEnumToResourceString(Group);

                foreach (StorageFolder Folder in FolderList)
                {
                    if (InnerList.Items.Where((Item) => Item.GroupName == GroupString).All((Item) => Item.Description != Folder.Path))
                    {
                        string RecentGroupString  = ConvertGroupEnumToResourceString(JumpListGroup.Recent);
                        string LibraryGroupString = ConvertGroupEnumToResourceString(JumpListGroup.Library);

                        JumpListItem[] RecentGroupItems = InnerList.Items.Where((Item) => Item.GroupName == RecentGroupString).ToArray();

                        JumpListItem[] LibraryGroupItems = InnerList.Items.Where((Item) => Item.GroupName == LibraryGroupString).ToArray();

                        if (Group == JumpListGroup.Library)
                        {
                            if (LibraryGroupItems.Length >= GroupItemMaxNum && RecentGroupItems.Length + LibraryGroupItems.Length >= 2 * GroupItemMaxNum)
                            {
                                if (RecentGroupItems.Length > 4)
                                {
                                    InnerList.Items.Remove(RecentGroupItems.FirstOrDefault());
                                }
                                else
                                {
                                    InnerList.Items.Remove(LibraryGroupItems.FirstOrDefault());
                                }
                            }
                        }
                        else
                        {
                            if (RecentGroupItems.Length >= GroupItemMaxNum || RecentGroupItems.Length + LibraryGroupItems.Length >= 2 * GroupItemMaxNum)
                            {
                                InnerList.Items.Remove(RecentGroupItems.FirstOrDefault());
                            }
                        }

                        JumpListItem NewItem = JumpListItem.CreateWithArguments(Folder.Path, Folder.DisplayName);

                        NewItem.Logo        = new Uri("ms-appx:///Assets/FolderIcon.png");
                        NewItem.Description = Folder.Path;
                        NewItem.GroupName   = GroupString;

                        InnerList.Items.Add(NewItem);

                        ItemModified = true;
                    }
                }

                if (ItemModified)
                {
                    await InnerList.SaveAsync();
                }
            }
        }
예제 #4
0
        public string ConvertGroupEnumToResourceString(JumpListGroup Group)
        {
            switch (Group)
            {
            case JumpListGroup.Library:
            {
                return("ms-resource:///Resources/JumpList_Group_Library");
            }

            case JumpListGroup.Recent:
            {
                return("ms-resource:///Resources/JumpList_Group_Recent");
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(Group));
            }
            }
        }
예제 #5
0
 public Task RemoveItem(JumpListGroup Group, params StorageFolder[] FolderList)
 {
     return(RemoveItemAsync(Group, FolderList.Select((Item) => Item.Path).ToArray()));
 }