Esempio n. 1
0
        public IOItem AddItem(FileSystemInfo pathInfo, IOItemType type)
        {
            string[] segments = pathInfo.FullName.Split(Path.DirectorySeparatorChar);

            ObservableCollection <IOItem> currentItemList = Root;
            IOItem lastItem = null;

            //enumerate through all items in the list
            for (int i = 0; i < segments.Length - 1; i++)
            {
                foreach (IOItem item in currentItemList)
                {
                    string name = item.DisplayName.Trim('\\');
                    if (item.DisplayName.Trim('\\') == segments[i])
                    {
                        //item found, set currentItemList one path higher
                        currentItemList = item.Children;
                        lastItem        = item;
                    }
                }
            }
            //reload the children (refresh TreeView UI)
            lastItem.SetChildren();
            //return the new IOItem
            return(lastItem.Children.Single(i => i.DisplayName == segments[segments.Length - 1]));
        }
Esempio n. 2
0
        internal IOItem(string path, IOItemType type, IOItem parent, List <Wildcard> fileWildcard, List <Wildcard> dirWildcard, FileSystemTemplate template)
        {
            switch (type)
            {
            case IOItemType.Folder:
                ItemInfo = new DirectoryInfo(path);
                break;

            case IOItemType.File:
                ItemInfo = new FileInfo(path);
                break;
            }

            Icon i = GetIcon(path, type);

            this.Icon         = Imaging.CreateBitmapSourceFromHIcon(i.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(i.Width, i.Height));
            this.Type         = type;
            this.Parent       = parent;
            this.fileWildcard = fileWildcard;
            this.dirWildcard  = dirWildcard;
            _template         = template;
        }
Esempio n. 3
0
        private static Icon GetIcon(string path, IOItemType type, IconSize size, IconState state)
        {
            var flags     = (uint)(NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_USEFILEATTRIBUTES);
            var attribute = (uint)(object.Equals(type, IOItemType.Folder) ? NativeMethods.FILE_ATTRIBUTE_DIRECTORY : NativeMethods.FILE_ATTRIBUTE_FILE);

            if (object.Equals(type, IOItemType.Folder) && object.Equals(state, IconState.Open))
            {
                flags += NativeMethods.SHGFI_OPENICON;
            }
            if (object.Equals(size, IconSize.Small))
            {
                flags += NativeMethods.SHGFI_SMALLICON;
            }
            else
            {
                flags += NativeMethods.SHGFI_LARGEICON;
            }
            var shfi = new SHFileInfo();
            var res  = NativeMethods.SHGetFileInfo(path, attribute, out shfi, (uint)Marshal.SizeOf(shfi), flags);

            if (object.Equals(res, IntPtr.Zero))
            {
                throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            try
            {
                System.Drawing.Icon.FromHandle(shfi.hIcon);
                return((Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone());
            }
            catch
            {
                throw;
            }
            finally
            {
                NativeMethods.DestroyIcon(shfi.hIcon);
            }
        }
Esempio n. 4
0
 public static Icon GetIcon(string path, IOItemType type)
 {
     return(GetIcon(path, type, IconSize.Large, IconState.Undefined));
 }