public int AddFolderIcon(FolderType type)
        {
            string text = "folder_" + type.ToString();
            int    result;

            if (this._extensionList.ContainsKey(text))
            {
                result = (int)this._extensionList[text];
            }
            else
            {
                int count = ((ImageList)this._imageLists[0]).Images.Count;
                if (this._manageBothSizes)
                {
                    ((ImageList)this._imageLists[0]).Images.Add(IconReader.GetFolderIcon(IconSize.Small, type));
                    ((ImageList)this._imageLists[1]).Images.Add(IconReader.GetFolderIcon(IconSize.Large, type));
                }
                else
                {
                    ((ImageList)this._imageLists[0]).Images.Add(IconReader.GetFolderIcon(this._iconSize, type));
                }
                this.AddExtension(text, count);
                result = count;
            }
            return(result);
        }
        /// <summary>
        /// Adds a folder iconto the imagelist.
        /// </summary>
        /// <param name="type">The type of folder (opened/closed).</param>
        /// <returns>Index in the imagelist pointing to the icon.</returns>
        public int AddFolderIcon(FolderType type)
        {
            string key = "folder_" + type.ToString();

            if (_extensionList.ContainsKey(key))
            {
                return((int)_extensionList[key]);
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;             //store current count -- new item's index

                if (_manageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFolderIcon(IconSize.Small, type));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFolderIcon(IconSize.Large, type));
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFolderIcon(_iconSize, type));  //add to image list
                }

                AddExtension(key, pos); // add to hash table
                return(pos);
            }
        }
        public int AddFileIcon(string filePath)
        {
            string text = Path.GetExtension(filePath).TrimStart(".".ToCharArray());
            int    result;

            if (this._extensionList.ContainsKey(text.ToUpper()))
            {
                result = (int)this._extensionList[text.ToUpper()];
            }
            else
            {
                int count = ((ImageList)this._imageLists[0]).Images.Count;
                if (this._manageBothSizes)
                {
                    ((ImageList)this._imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconSize.Small, false));
                    ((ImageList)this._imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconSize.Large, false));
                }
                else
                {
                    ((ImageList)this._imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, this._iconSize, false));
                }
                this.AddExtension(text.ToUpper(), count);
                result = count;
            }
            return(result);
        }
Пример #4
0
		bool ManageBothSizes = false; //flag, used to determine whether to create two ImageLists.

		/// <summary>
		/// Creates an instance of <c>IconListManager</c> that will add icons to a single <c>ImageList</c> using the
		/// specified <c>IconSize</c>.
		/// </summary>
		/// <param name="imageList"><c>ImageList</c> to add icons to.</param>
		/// <param name="iconSize">Size to use (either 32 or 16 pixels).</param>
		public IconListManager(System.Windows.Forms.ImageList imageList, IconReader.IconSize iconSize )
		{
			// Initialise the members of the class that will hold the image list we're
			// targeting, as well as the icon size (32 or 16)
            _imageLists.Add( imageList );
			_iconSize = iconSize;
		}
Пример #5
0
        public static ImageSource IconFromFile(string fileName)
        {
            var icon = IconReader.GetFileIcon(fileName, IconReader.IconSize.Large, false);
            var bmp  = icon.ToBitmap();

            return(LoadBitmap(bmp));
        }
Пример #6
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        public int AddFileOverlayIcon(string filePath, string overlayTagName, string overlayFilename)
        {
            // Check if the file exists, otherwise, throw exception.
            if (!System.IO.File.Exists(filePath))
            {
                throw new System.IO.FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            string[] splitPath = filePath.Split(new Char[] { '.' });
            string   extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            // Add in the special overlay tag name to the extension name
            extension = "{" + overlayTagName + "}" + extension;

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]);                               //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;                             //store current count -- new item's index

                if (ManageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                }
                else
                {
                    Bitmap myImage = null;

                    // Great, get a copy of that
                    Bitmap lockSource = new Bitmap(overlayFilename);

                    // Great get a copy of that
                    Bitmap source = IconReader.GetFileIcon(filePath, _iconSize, false).ToBitmap();

                    // Ok, if we got a lockSource and a class source icon, lets attempt to overlay them
                    if (source != null && lockSource != null)
                    {
                        myImage = BitmapManipulator.OverlayBitmap(source, lockSource, 100, BitmapManipulator.ImageCornerEnum.BottomRight);
                    }

                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(myImage);                            //add to image list
                }

                AddExtension(extension.ToUpper(), pos);                         // add to hash table
                return(pos);
            }
        }
Пример #7
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        public int AddFileIcon(string filePath)
        {
            // Check if the file exists, otherwise, throw exception.
            if (!System.IO.File.Exists(filePath))
            {
                throw new System.IO.FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            //string[] splitPath = filePath.Split(new Char[] {'.'});
            string extension = Path.GetExtension(filePath);            //(string)splitPath.GetValue( splitPath.GetUpperBound(0) );

            // Also, we want to pull exe's by filename because mose exe's have special icons
            if (string.Compare(extension, ".exe", true) == 0)
            {
                extension = Path.GetFileName(filePath);
            }
            else if (string.Compare(extension, ".ico") == 0)
            {
                extension = Path.GetFileName(filePath);
            }

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]);                               //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;                             //store current count -- new item's index

                if (ManageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false));                         //add to image list
                }

                AddExtension(extension.ToUpper(), pos);                         // add to hash table
                return(pos);
            }
        }
Пример #8
0
        public int AddFileId(string extension, string filePath, bool isFolder = false, FolderType folderType = FolderType.Closed)
        {
            // Split it down so we can get the extension
            // string[] splitPath = filePath.Split(new Char[] { '.' });
            // string extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]);        //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;     //store current count -- new item's index

                if (ManageBothSizes == true)
                {
                    //managing two lists, so add it to small first, then large
                    if (!isFolder)
                    {
                        ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small, false));
                        ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large, false));
                    }
                    else
                    {
                        ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFolderIcon(filePath, IconReader.IconSize.Small, folderType));
                        ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFolderIcon(filePath, IconReader.IconSize.Large, folderType));
                    }
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    if (!isFolder)
                    {
                        ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false)); //add to image list
                    }
                    else
                    {
                        ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFolderIcon(filePath, IconReader.IconSize.Large, folderType));
                    }
                }

                AddExtension(extension.ToUpper(), pos); // add to hash table
                return(pos);
            }
        }
Пример #9
0
        /// <summary>
        /// Called publicly to add a file's icon to the ImageList.
        /// </summary>
        /// <param name="filePath">Full path to the file.</param>
        /// <returns>Integer of the icon's position in the ImageList</returns>
        public int AddFileIcon(string filePath)
        {
#if MONO
            return(2);
#else
            // Check if the file exists, otherwise, throw exception.
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("File does not exist");
            }

            // Split it down so we can get the extension
            string[] splitPath = filePath.Split(new[] { '.' });
            var      extension = (string)splitPath.GetValue(splitPath.GetUpperBound(0));

            //Check that we haven't already got the extension, if we have, then
            //return back its index
            if (_extensionList.ContainsKey(extension.ToUpper()))
            {
                return((int)_extensionList[extension.ToUpper()]); //return existing index
            }
            else
            {
                // It's not already been added, so add it and record its position.

                int pos = ((ImageList)_imageLists[0]).Images.Count;  //store current count -- new item's index

                if (ManageBothSizes)
                {
                    //managing two lists, so add it to small first, then large
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Small,
                                                                                  false));
                    ((ImageList)_imageLists[1]).Images.Add(IconReader.GetFileIcon(filePath, IconReader.IconSize.Large,
                                                                                  false));
                }
                else
                {
                    //only doing one size, so use IconSize as specified in _iconSize.
                    ((ImageList)_imageLists[0]).Images.Add(IconReader.GetFileIcon(filePath, _iconSize, false));
                    //add to image list
                }

                AddExtension(extension.ToUpper(), pos); // add to hash table
                return(pos);
            }
#endif
        }
Пример #10
0
 private void InitializeImageList(ImageList imagelist, IconReader.IconSize iconSize)
 {
     imagelist.Images.Add(IconReader.GetFolderIcon(iconSize, IconReader.FolderType.Closed));
     imagelist.Images.Add(IconReader.GetFolderIcon(iconSize, IconReader.FolderType.Open));
     imagelist.Images.Add(IconReader.GetFileIcon(".", iconSize, false));
     imagelist.Images.Add(YodaClient.Properties.Resources.up);
 }