Example #1
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        {
            var shellItem = shellObject as IShellItem2;
            var shellLink = shellObject as IShellLinkW;

            if (shellItem != null)
            {
                JumpPath path = new JumpPath
                {
                    Path = shellItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
                };
                return(path);
            }

            if (shellLink != null)
            {
                var pathBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);
                var argsBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetArguments(argsBuilder, argsBuilder.Capacity);
                var descBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetDescription(descBuilder, descBuilder.Capacity);
                var iconBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                int iconIndex;
                shellLink.GetIconLocation(iconBuilder, iconBuilder.Capacity, out iconIndex);
                var dirBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetWorkingDirectory(dirBuilder, dirBuilder.Capacity);

                JumpTask task = new JumpTask
                {
                    // Set ApplicationPath and IconResources, even if they're from the current application.
                    // This means that equivalent JumpTasks won't necessarily compare property-for-property.
                    ApplicationPath   = pathBuilder.ToString(),
                    Arguments         = argsBuilder.ToString(),
                    Description       = descBuilder.ToString(),
                    IconResourceIndex = iconIndex,
                    IconResourcePath  = iconBuilder.ToString(),
                    WorkingDirectory  = dirBuilder.ToString(),
                };

                using (PROPVARIANT pv = new PROPVARIANT())
                {
                    var  propStore = (IPropertyStore)shellLink;
                    PKEY pkeyTitle = PKEY.Title;

                    propStore.GetValue(ref pkeyTitle, pv);

                    // PKEY_Title should be an LPWSTR if it's not empty.
                    task.Title = pv.GetValue() ?? "";
                }

                return(task);
            }

            // Unsupported type?
            Debug.Assert(false);
            return(null);
        }
 private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath)
 {
     try
     {
         return(ShellUtil.GetShellItemForPath(Path.GetFullPath(jumpPath.Path)));
     }
     catch (Exception)
     {
     }
     return(null);
 }
        private static object GetShellObjectForJumpItem(JumpItem jumpItem)
        {
            JumpPath jumpPath = jumpItem as JumpPath;
            JumpTask jumpTask = jumpItem as JumpTask;

            if (jumpPath != null)
            {
                return(JumpList.CreateItemFromJumpPath(jumpPath));
            }
            if (jumpTask != null)
            {
                return(JumpList.CreateLinkFromJumpTask(jumpTask, true));
            }
            return(null);
        }
Example #4
0
        private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath)
        {
            Debug.Assert(jumpPath != null);

            try
            {
                // This will return null if the path doesn't exist.
                return(ShellUtil.GetShellItemForPath(Path.GetFullPath(jumpPath.Path)));
            }
            catch (Exception)
            {
                // Don't propagate exceptions here.  If we couldn't create the item, it's just invalid.
            }

            return(null);
        }
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
     Contract.Requires(jumpPath != null);
     Contract.Requires(jumpPath.Path != null);
 }
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
   Contract.Requires(jumpPath != null);
   Contract.Requires(jumpPath.Path != null);
 }
Example #7
0
 public static void AddToRecentCategory(JumpPath jumpPath)
 { 
     Verify.IsNotNull(jumpPath, "jumpPath"); 
     AddToRecentCategory(jumpPath.Path);
 } 
Example #8
0
        private static JumpItem GetJumpItemForShellObject(object shellObject)
        { 
            var shellItem = shellObject as IShellItem2;
            var shellLink = shellObject as IShellLinkW; 
 
            if (shellItem != null)
            { 
                JumpPath path = new JumpPath
                {
                    Path = shellItem.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING),
                }; 
                return path;
            } 
 
            if (shellLink != null)
            { 
                var pathBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetPath(pathBuilder, pathBuilder.Capacity, null, SLGP.RAWPATH);
                var argsBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetArguments(argsBuilder, argsBuilder.Capacity); 
                var descBuilder = new StringBuilder(Win32Constant.INFOTIPSIZE);
                shellLink.GetDescription(descBuilder, descBuilder.Capacity); 
                var iconBuilder = new StringBuilder(Win32Constant.MAX_PATH); 
                int iconIndex;
                shellLink.GetIconLocation(iconBuilder, iconBuilder.Capacity, out iconIndex); 
                var dirBuilder = new StringBuilder(Win32Constant.MAX_PATH);
                shellLink.GetWorkingDirectory(dirBuilder, dirBuilder.Capacity);

                JumpTask task = new JumpTask 
                {
                    // Set ApplicationPath and IconResources, even if they're from the current application. 
                    // This means that equivalent JumpTasks won't necessarily compare property-for-property. 
                    ApplicationPath = pathBuilder.ToString(),
                    Arguments = argsBuilder.ToString(), 
                    Description = descBuilder.ToString(),
                    IconResourceIndex = iconIndex,
                    IconResourcePath = iconBuilder.ToString(),
                    WorkingDirectory = dirBuilder.ToString(), 
                };
 
                using (PROPVARIANT pv = new PROPVARIANT()) 
                {
                    var propStore = (IPropertyStore)shellLink; 
                    PKEY pkeyTitle = PKEY.Title;

                    propStore.GetValue(ref pkeyTitle, pv);
 
                    // PKEY_Title should be an LPWSTR if it's not empty.
                    task.Title = pv.GetValue() ?? ""; 
                } 

                return task; 
            }

            // Unsupported type?
            Debug.Assert(false); 
            return null;
        } 
Example #9
0
        private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath) 
        {
            Debug.Assert(jumpPath != null);

            try 
            {
                // This will return null if the path doesn't exist. 
                return ShellUtil.GetShellItemForPath(Path.GetFullPath(jumpPath.Path)); 
            }
            catch (Exception) 
            {
                // Don't propagate exceptions here.  If we couldn't create the item, it's just invalid.
            }
 
            return null;
        } 
Example #10
0
 /// <summary>
 /// Add the item to the application's JumpList's recent items.
 /// </summary>
 /// <remarks>
 /// This makes the item eligible for inclusion in the special Recent and Frequent categories.
 /// </remarks>
 public static void AddToRecentCategory(JumpPath jumpPath)
 {
     Verify.IsNotNull(jumpPath, "jumpPath");
     AddToRecentCategory(jumpPath.Path);
 }