示例#1
0
        public void TestProjectIconReference_SameImageListIndex_Equal()
        {
            var one   = new ProjectIconReference(new IntPtr(3), 4);
            var other = new ProjectIconReference(new IntPtr(3), 4);

            Assert.That(one, Is.EqualTo(other));
        }
示例#2
0
        public void TestProjectIconReference_ImageListIndexVSHandle_NotEqual()
        {
            var one   = new ProjectIconReference(new IntPtr(3), 3);
            var other = new ProjectIconReference(new IntPtr(3));

            Assert.That(one, Is.Not.EqualTo(other));
        }
示例#3
0
        public void TestProjectIconReference_SameHandle_Equal()
        {
            var one   = new ProjectIconReference(new IntPtr(3));
            var other = new ProjectIconReference(new IntPtr(3));

            Assert.That(one, Is.EqualTo(other));
        }
示例#4
0
        public void TestProjectIconReference_DifferentHandle_NotEqual()
        {
            var one   = new ProjectIconReference(new IntPtr(4));
            var other = new ProjectIconReference(new IntPtr(3));

            Assert.That(one, Is.Not.EqualTo(other));
        }
示例#5
0
        private int ResolveReference(ProjectIconReference handle)
        {
            if (handle == null)
            {
                return(-1);
            }

            int value;

            if (_iconMap.TryGetValue(handle, out value))
            {
                return(value);
            }

            using (handle)
            {
                IntPtr iconHandle = handle.GetHandle();

                if (iconHandle == IntPtr.Zero)
                {
                    return(-1);
                }

                Icon icon;
                try
                {
                    icon = Icon.FromHandle(iconHandle);
                }
                catch (ArgumentException)
                {   // Win32 handle that was passed to Icon is not valid or is the wrong type.
                    return(-1);
                }

                try
                {
                    _imageList.Images.Add(icon);
                }
                catch (InvalidOperationException)
                {
                    // Unmanaged add icon operation failed (Reported on mailinglist)
                    return(-1);
                }
            }

            int n = _imageList.Images.Count - 1;

            _iconMap.Add(handle, n);
            return(n);
        }
示例#6
0
        int GetProjectIcon(string path)
        {
            EnsureSpecialImages();

            IProjectFileMapper map = GetService <IProjectFileMapper>();

            if (map == null)
            {
                return(-1);
            }

            ProjectIconReference handle = map.GetPathIconHandle(path);

            return(ResolveReference(handle));
        }
示例#7
0
        int GetOsIcon(string path)
        {
            NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO();
            IntPtr sysImageList = NativeMethods.SHGetFileInfoW(path, 0, ref fileinfo,
                                                               (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE |
                                                               NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON);

            if (sysImageList == IntPtr.Zero)
            {
                return(-1);
            }

            ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon);

            return(ResolveReference(handle));
        }
示例#8
0
        int GetSpecialIcon(string name, FileAttributes attr)
        {
            EnsureSpecialImages();

            NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO();
            IntPtr sysImageList = NativeMethods.SHGetFileInfoW(name, (uint)(int)attr, ref fileinfo,
                                                               (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE |
                                                               NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_USEFILEATTRIBUTES);

            if (sysImageList == IntPtr.Zero)
            {
                return(-1);
            }

            ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon);

            return(ResolveReference(handle));
        }
示例#9
0
        public int GetSpecialFolderIcon(WindowsSpecialFolder folder)
        {
            EnsureSpecialImages();

            int index;

            if (_folderMap.TryGetValue(folder, out index))
            {
                return(index);
            }

            IntPtr pidl = IntPtr.Zero;

            try
            {
                if (VSErr.S_OK != NativeMethods.SHGetFolderLocation(IntPtr.Zero, folder, IntPtr.Zero, 0, out pidl))
                {
                    return(-1);
                }


                NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO();
                IntPtr sysImageList = NativeMethods.SHGetFileInfoW(pidl, (uint)(int)FileAttributes.Directory, ref fileinfo,
                                                                   (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE |
                                                                   NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_PIDL);

                if (sysImageList == IntPtr.Zero)
                {
                    return(-1);
                }

                ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon);

                return(_folderMap[folder] = ResolveReference(handle));
            }
            finally
            {
                if (pidl != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pidl);
                }
            }
        }
示例#10
0
        public bool TryGetIcon(out ProjectIconReference icon)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            uint id = ProjectItemId;

            icon = null;

            if (id == 0 || id == VSItemId.Nil)
            {
                return(false);
            }

            try
            {
                IntPtr imageList = _project.ProjectImageList;
                object value;

                if (imageList != IntPtr.Zero)
                {
                    if (VSErr.Succeeded(
                            Project.ProjectHierarchy.GetProperty(id, (int)__VSHPROPID.VSHPROPID_IconIndex, out value)))
                    {
                        icon = new ProjectIconReference(imageList, SafeToInt(value));
                        return(true);
                    }
                }

                // Only do this if we know there is no imagelist behind the icons
                // (This will create a cached icon handle if called on a managed project, which we only need once)
                if (imageList == IntPtr.Zero && VSErr.Succeeded(
                        Project.ProjectHierarchy.GetProperty(id, (int)__VSHPROPID.VSHPROPID_IconHandle, out value)))
                {
                    icon = new ProjectIconReference((IntPtr)SafeToInt(value)); // Marshalled by VS as 32 bit integer
                    return(true);
                }
            }
            catch
            { /* Eat all project exceptions */ }

            return(false);
        }
        internal bool TryGetIcon(out ProjectIconReference icon)
        {
            uint id = ProjectItemId;
            icon = null;

            if (id == 0 || id == VSConstants.VSITEMID_NIL)
                return false;

            try
            {

                IntPtr imageList = _project.ProjectImageList;
                object value;

                if (imageList != IntPtr.Zero)
                {
                    if (ErrorHandler.Succeeded(
                        Project.ProjectHierarchy.GetProperty(id, (int)__VSHPROPID.VSHPROPID_IconIndex, out value)))
                    {
                        icon = new ProjectIconReference(imageList, SafeToInt(value));
                        return true;
                    }
                }

                // Only do this if we know there is no imagelist behind the icons
                // (This will create a cached icon handle if called on a managed project, which we only need once)
                if (imageList == IntPtr.Zero && ErrorHandler.Succeeded(
                    Project.ProjectHierarchy.GetProperty(id, (int)__VSHPROPID.VSHPROPID_IconHandle, out value)))
                {
                    icon = new ProjectIconReference((IntPtr)SafeToInt(value)); // Marshalled by VS as 32 bit integer
                    return true;
                }
            }
            catch
            { /* Eat all project exceptions */ }

            return false;
        }
示例#12
0
        private int ResolveReference(ProjectIconReference handle)
        {
            if (handle == null)
                return -1;

            int value;
            if (_iconMap.TryGetValue(handle, out value))
                return value;

            using (handle)
            {
                IntPtr iconHandle = handle.GetHandle();

                if (iconHandle == IntPtr.Zero)
                    return -1;

                Icon icon;
                try
                {
                    icon = Icon.FromHandle(iconHandle);
                }
                catch (ArgumentException)
                {   // Win32 handle that was passed to Icon is not valid or is the wrong type.
                    return -1;
                }

                try
                {
                    _imageList.Images.Add(icon);
                }
                catch (InvalidOperationException)
                {
                    // Unmanaged add icon operation failed (Reported on mailinglist)
                    return -1;
                }
            }

            int n = _imageList.Images.Count - 1;
            _iconMap.Add(handle, n);
            return n;
        }
示例#13
0
        int GetSpecialIcon(string name, FileAttributes attr)
        {
            EnsureSpecialImages();

            NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO();
            IntPtr sysImageList = NativeMethods.SHGetFileInfoW(name, (uint)(int)attr, ref fileinfo,
                (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE |
                NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_USEFILEATTRIBUTES);

            if (sysImageList == IntPtr.Zero)
                return -1;

            ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon);

            return ResolveReference(handle);
        }
示例#14
0
        int GetOsIcon(string path)
        {
            NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO();
            IntPtr sysImageList = NativeMethods.SHGetFileInfoW(path, 0, ref fileinfo,
                (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE |
                NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON);

            if (sysImageList == IntPtr.Zero)
                return -1;

            ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon);

            return ResolveReference(handle);
        }
示例#15
0
        public int GetSpecialFolderIcon(WindowsSpecialFolder folder)
        {
            EnsureSpecialImages();

            int index;

            if (_folderMap.TryGetValue(folder, out index))
                return index;

            IntPtr pidl = IntPtr.Zero;
            try
            {
                if (VSConstants.S_OK != NativeMethods.SHGetFolderLocation(IntPtr.Zero, folder, IntPtr.Zero, 0, out pidl))
                    return -1;

                NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO();
                IntPtr sysImageList = NativeMethods.SHGetFileInfoW(pidl, (uint)(int)FileAttributes.Directory, ref fileinfo,
                                                            (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE |
                                                            NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_PIDL);

                if (sysImageList == IntPtr.Zero)
                    return -1;

                ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon);

                return _folderMap[folder] = ResolveReference(handle);
            }
            finally
            {
                if (pidl != IntPtr.Zero)
                    Marshal.FreeCoTaskMem(pidl);
            }
        }
示例#16
0
        public void TestProjectIconReference_SameImageListIndex_Equal()
        {
            var one = new ProjectIconReference(new IntPtr(3), 4);
            var other = new ProjectIconReference(new IntPtr(3), 4);

            Assert.That(one, Is.EqualTo(other));
        }
示例#17
0
        public void TestProjectIconReference_SameHandle_Equal()
        {
            var one = new ProjectIconReference(new IntPtr(3));
            var other = new ProjectIconReference(new IntPtr(3));

            Assert.That(one, Is.EqualTo(other));
        }
示例#18
0
        public void TestProjectIconReference_ImageListIndexVSHandle_NotEqual()
        {
            var one = new ProjectIconReference(new IntPtr(3), 3);
            var other = new ProjectIconReference(new IntPtr(3));

            Assert.That(one, Is.Not.EqualTo(other));
        }
示例#19
0
        public void TestProjectIconReference_DifferentIndex_NotEqual()
        {
            var one = new ProjectIconReference(new IntPtr(3),4);
            var other = new ProjectIconReference(new IntPtr(3), 5);

            Assert.That(one, Is.Not.EqualTo(other));
        }