using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
using Vanara.PInvoke;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.PropSys;
using static Vanara.PInvoke.Shell32;
namespace Vanara.Windows.Shell
{
/// Represents a Jump List item.
///
public interface IJumpListItem : INotifyPropertyChanged
{
/// Gets the category to which the item belongs.
/// The category name.
string Category { get; }
/// Creates a shell object based on this item.
/// An instance of either or .
object GetShellObject();
}
/// Provides access to the jump list on the application's task bar icon.
[TypeConverter(typeof(GenericExpandableObjectConverter))]
[Editor("Vanara.Windows.Shell.JumpListItemCollectionEditor, Vanara.Windows.Shell", "System.Drawing.Design.UITypeEditor, System.Drawing")]
[Description("Provides access to the jump list on the application's task bar icon.")]
public class JumpList : ObservableCollection
{
/// Initializes a new instance of the class.
public JumpList() => CollectionChanged += OnCollectionChanged;
/// Gets the number of items in the collection.
/// The count.
[Browsable(false)]
public new int Count => base.Count;
/// Whether to show the special "Frequent" category.
///
/// This category is managed by the Shell and keeps track of items that are frequently accessed by this program. Applications can
/// request that specific items are included here by calling JumpList.AddToRecentCategory. Because of duplication, applications
/// generally should not have both ShowRecentCategory and ShowFrequentCategory set at the same time.
///
[Category("Appearance"), DefaultValue(false)]
[Description("Gets or sets Whether to show the special \"Frequent\" category.")]
public bool ShowFrequentCategory { get; set; }
/// Whether to show the special "Recent" category.
///
/// This category is managed by the Shell and keeps track of items that have been recently accessed by this program. Applications
/// can request that specific items are included here by calling JumpList.AddToRecentCategory Because of duplication, applications
/// generally should not have both ShowRecentCategory and ShowFrequentCategory set at the same time.
///
[Category("Appearance"), DefaultValue(false)]
[Description("Gets or sets Whether to show the special \"Recent\" category.")]
public bool ShowRecentCategory { get; set; }
///
/// Notifies the system that an item has been accessed, for the purposes of tracking those items used most recently and most frequently.
///
/// The document path to add.
public static void AddToRecentDocs(string docPath)
{
if (docPath is null) throw new ArgumentNullException(nameof(docPath));
SHAddToRecentDocs(SHARD.SHARD_PATHW, System.IO.Path.GetFullPath(docPath));
}
///
/// Notifies the system that an item has been accessed, for the purposes of tracking those items used most recently and most frequently.
///
/// The to add.
public static void AddToRecentDocs(IShellItem iShellItem)
{
if (iShellItem is null) throw new ArgumentNullException(nameof(iShellItem));
SHAddToRecentDocs(SHARD.SHARD_SHELLITEM, iShellItem);
}
///
/// Notifies the system that an item has been accessed, for the purposes of tracking those items used most recently and most frequently.
///
/// The to add.
/// iShellLink
public static void AddToRecentDocs(IShellLinkW iShellLink)
{
if (iShellLink is null) throw new ArgumentNullException(nameof(iShellLink));
SHAddToRecentDocs(SHARD.SHARD_LINK, iShellLink);
}
///
/// Notifies the system that an item has been accessed, for the purposes of tracking those items used most recently and most frequently.
///
/// The to add.
/// shellItem
public static void AddToRecentDocs(ShellItem shellItem)
{
if (shellItem is null) throw new ArgumentNullException(nameof(shellItem));
if (shellItem is ShellLink lnk)
AddToRecentDocs(lnk.link);
else
AddToRecentDocs(shellItem.IShellItem);
}
/// Clears the system usage data for recent documents.
public static void ClearRecentDocs() => SHAddToRecentDocs(0, (string)null);
/// Deletes a custom Jump List for a specified application.
/// The AppUserModelID of the process whose taskbar button representation displays the custom Jump List.
public static void DeleteList(string appId = null)
{
using var icdl = ComReleaserFactory.Create(new ICustomDestinationList());
icdl.Item.DeleteList(appId);
}
/// Applies the the current settings for the jumplist to the taskbar button.
/// The application identifier.
public void ApplySettings(string appId = null)
{
using var icdl = ComReleaserFactory.Create(new ICustomDestinationList());
if (!string.IsNullOrEmpty(appId))
icdl.Item.SetAppID(appId);
using var ioaRemoved = ComReleaserFactory.Create(icdl.Item.BeginList(out _));
var removedObjs = ioaRemoved.Item.ToArray