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)); }
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)); }
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)); }
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)); }
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); }
int GetProjectIcon(string path) { EnsureSpecialImages(); IProjectFileMapper map = GetService <IProjectFileMapper>(); if (map == null) { return(-1); } ProjectIconReference handle = map.GetPathIconHandle(path); return(ResolveReference(handle)); }
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)); }
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)); }
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); } } }
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; }
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; }
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); }
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); }
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); } }
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)); }
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)); }
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)); }
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)); }