private ArrayList _imageLists = new ArrayList(); //will hold ImageList objects

        #endregion Fields

        #region Constructors

        /// <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(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;
        }
Ejemplo n.º 2
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 (!File.Exists(filePath))
            {
                throw new 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));

            //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
            }

            // 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);
        }
Ejemplo n.º 3
0
        private void LoadDirectory(string path)
        {
            currentDirectory = path;
            FillDirectories(currentDirectory);

            List <FtpItem> list = FTPAdapter.GetDirList(currentDirectory).
                                  OrderBy(x => x.ItemType != FtpItemType.Directory).ThenBy(x => x.Name).ToList();

            list.Insert(0, new FtpItem("..", DateTime.Now, 0, null, null, FtpItemType.Unknown, null));

            lvFTPList.Items.Clear();
            lvFTPList.SmallImageList = new ImageList {
                ColorDepth = ColorDepth.Depth32Bit
            };

            foreach (FtpItem file in list)
            {
                if (file.ItemType == FtpItemType.Directory && (file.Name == "." || file.Name == ".."))
                {
                    continue;
                }

                ListViewItem lvi = new ListViewItem(file.Name);

                lvi.Tag = file;

                if (file.ItemType != FtpItemType.Unknown)
                {
                    if (file.ItemType == FtpItemType.File)
                    {
                        lvi.SubItems.Add(file.Size.ToString("N0"));
                    }
                    else
                    {
                        lvi.SubItems.Add(string.Empty);
                    }

                    lvi.SubItems.Add(IconReader.GetDisplayName(file.Name, file.ItemType == FtpItemType.Directory));
                    lvi.SubItems.Add(file.Modified.ToLocalTime().ToString());
                    lvi.SubItems.Add(file.Attributes);
                }

                string ext;
                if (file.ItemType == FtpItemType.Directory || file.ItemType == FtpItemType.Unknown)
                {
                    ext = "Directory";
                }
                else if (Path.HasExtension(file.Name))
                {
                    ext = Path.GetExtension(file.Name);
                }
                else
                {
                    ext = "File";
                }

                if (!lvFTPList.SmallImageList.Images.Keys.Contains(ext))
                {
                    Icon icon;
                    if (ext == "Directory")
                    {
                        icon = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed);
                    }
                    else
                    {
                        icon = IconReader.GetFileIcon(ext, IconReader.IconSize.Small, false);
                    }

                    if (icon != null)
                    {
                        lvFTPList.SmallImageList.Images.Add(ext, icon.ToBitmap());
                    }
                }

                if (lvFTPList.SmallImageList.Images.Keys.Contains(ext))
                {
                    lvi.ImageKey = ext;
                }

                lvFTPList.Items.Add(lvi);
            }

            CheckFiles(false);
        }