Beispiel #1
0
        /// <summary>
        /// Fills the ListView, or rather CurrentItems
        /// </summary>
        public void PopulateView()
        {
            CurrentItems.Clear();
            if (!Directory.Exists(FV.CurrentFolder))
            {
                return;
            }

            try
            {
                DirectoryInfo cur   = new DirectoryInfo(FV.CurrentFolder);
                ImageSource   dummy = new BitmapImage();
                if (FV.ShowFolders)
                {
                    foreach (DirectoryInfo dir in cur.GetDirectories())
                    {
                        if (!FV.ShowHidden && dir.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            continue;
                        }
                        FSItemVM info = new FSItemVM()
                        {
                            FullPath    = dir.FullName,
                            DisplayName = dir.Name,
                            type        = FSItemType.Folder
                        };
                        if (!FV.ShowIcons)
                        {
                            info.DisplayIcon = dummy;  // to prevent the icon from being loaded from file later
                        }
                        CurrentItems.Add(info);
                    }
                }

                string FilterString = "*";
                if (FV.FilterIndex >= 0 && FV.FilterIndex < FilterCount)
                {
                    FilterString = FilterList[FV.FilterIndex].ToString();
                }
                foreach (var CurFilterString in FilterString.Split(';'))
                {
                    foreach (FileInfo f in cur.EnumerateFiles(CurFilterString))
                    {
                        if (!FV.ShowHidden && f.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            continue;
                        }

                        FSItemVM info = new FSItemVM()
                        {
                            FullPath    = f.FullName,
                            DisplayName = f.Name, //System.IO.Path.GetFileName(s),
                            type        = FSItemType.File
                        };
                        if (!FV.ShowIcons)
                        {
                            info.DisplayIcon = dummy; // to prevent the icon from being loaded from file later
                        }
                        CurrentItems.Add(info);
                    }
                }
            }
            catch (Exception) { }

            // reset column width manually (otherwise it is not updated)
            FV.TheGVColumn.Width = FV.TheGVColumn.ActualWidth;
            FV.TheGVColumn.Width = Double.NaN;

            if (RecentFolders.Count == 0 || String.Compare(FV.CurrentFolder, RecentFolders.Last()) != 0)
            {
                if (Directory.Exists(FV.CurrentFolder))
                {
                    RecentFolders.Push(FV.CurrentFolder);
                    if (ClearFuture)
                    {
                        FutureFolders.Clear();
                    }
                }
            }
        }
Beispiel #2
0
        void PopulateView()
        {
            //CurrentItems.Clear();
            string bak          = CurrentFolder;
            var    CurrentItems = Items;

            Items.Clear();
            CurrentFolder = bak;

            // add special folders
            CurrentItems.Add(new FSItemVM()
            {
                FullPath    = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                DisplayName = "Desktop",     //System.IO.Path.GetFileName(s),
                type        = FSItemType.Folder,
                //DisplayIcon =
                //IconExtractor.GetFolderIcon(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)).ToImageSource()
                //new BitmapImage(new Uri(@"/FileListView;component/Images/Desktop.png", UriKind.Relative)) //((ShellObject)o).Thumbnail.SmallBitmapSource//Etier.IconHelper.IconReader.GetFolderIcon(s, Etier.IconHelper.IconReader.IconSize.Small, Etier.IconHelper.IconReader.FolderType.Closed).ToImageSource()
            }
                             );
            CurrentItems.Add(new FSItemVM()
            {
                FullPath    = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                DisplayName = "My Documents",     //System.IO.Path.GetFileName(s),
                type        = FSItemType.Folder,
                //DisplayIcon = IconExtractor.GetFolderIcon(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), true).ToImageSource()
                //new BitmapImage(new Uri(@"/FileListView;component/Images/MyDocuments.png", UriKind.Relative)) //((ShellObject)o).Thumbnail.SmallBitmapSource//Etier.IconHelper.IconReader.GetFolderIcon(s, Etier.IconHelper.IconReader.IconSize.Small, Etier.IconHelper.IconReader.FolderType.Closed).ToImageSource()
            }
                             );
            // The commented out code can be used with Microsofts Shell API Codepack
            //ShellObject o = (ShellObject)KnownFolders.Desktop;

            /* foreach (IKnownFolder o in new IKnownFolder[] { KnownFolders.Desktop, KnownFolders.Documents })
             * {
             *   //string s = o. //Environment.GetFolderPath(spf);
             *   FSItemVM info = new FSItemVM()
             *   {
             *       FullPath = o.Path,
             *       DisplayName = o.LocalizedName, //System.IO.Path.GetFileName(s),
             *       type = FSItemType.Folder,
             *       DisplayIcon = ((ShellObject)o).Thumbnail.SmallBitmapSource//Etier.IconHelper.IconReader.GetFolderIcon(s, Etier.IconHelper.IconReader.IconSize.Small, Etier.IconHelper.IconReader.FolderType.Closed).ToImageSource()
             *   };
             *   CurrentItems.Add(info);
             *   //((ShellObject)o).Thumbnail.SmallBitmap.Save(o.LocalizedName + ".png");
             * }*/

            /*foreach (ShellObject o in KnownFolders.Desktop)
             * {
             *  FSItemVM info = new FSItemVM()
             *  {
             *      FullPath = o.ParsingName,
             *      DisplayName = o.Name, //System.IO.Path.GetFileName(s),
             *      type = FSItemType.Folder,
             *      DisplayIcon = ((ShellObject)o).Thumbnail.BitmapSource//Etier.IconHelper.IconReader.GetFolderIcon(s, Etier.IconHelper.IconReader.IconSize.Small, Etier.IconHelper.IconReader.FolderType.Closed).ToImageSource()
             *  };
             *  CurrentItems.Add(info);
             * }*/

            CurrentItems.Add(null);     // add a separator
            // add drives
            string pathroot;

            try { pathroot = System.IO.Path.GetPathRoot(CurrentFolder); }
            catch (Exception) { pathroot = ""; }

            foreach (string s in Directory.GetLogicalDrives())
            {
                FSItemVM info = new FSItemVM()
                {
                    FullPath    = s,
                    DisplayName = s,
                    type        = FSItemType.Folder,
                    DisplayIcon = IconExtractor.GetFolderIcon(s).ToImageSource()
                };
                CurrentItems.Add(info);

                // add items under current folder
                if (String.Compare(pathroot, s, true) == 0)
                {
                    string[] dirs = CurrentFolder.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 1; i < dirs.Length; i++)
                    {
                        string curdir = String.Join("" + System.IO.Path.DirectorySeparatorChar, dirs, 0, i + 1);
                        info = new FSItemVM()
                        {
                            FullPath    = curdir,
                            DisplayName = dirs[i],
                            type        = FSItemType.Folder,
                            DisplayIcon = IconExtractor.GetFolderIcon(curdir, true).ToImageSource(),
                            Indentation = i * 10
                        };
                        CurrentItems.Add(info);
                    }
                    SelectedItem = CurrentItems[CurrentItems.Count - 1];
                }
            }

            CurrentItems.Add(null);

            // add recent locations
            if (RecentLocations != null)
            {
                List <string> fullpaths = new List <string>();    // remember paths to avoid adding duplicates
                foreach (object o in RecentLocations)
                {
                    string s = o.ToString();
                    s = System.IO.Path.GetDirectoryName(s);
                    if (!fullpaths.Contains(s))
                    {
                        fullpaths.Add(s);
                        FSItemVM it = new FSItemVM()
                        {
                            FullPath    = s,
                            ShowToolTip = true,
                            DisplayName = System.IO.Path.GetFileName(s),
                            type        = FSItemType.Folder,
                            DisplayIcon = IconExtractor.GetFolderIcon(s).ToImageSource()
                        };
                        if (it.DisplayName.Trim() == "")
                        {
                            it.DisplayName = it.FullPath;
                        }
                        CurrentItems.Add(it);
                    }
                }
            }
        }