private void SetupColumns() { // Get the size of the file system entity. // Folders and errors are represented as negative numbers this.olvColumnSize.AspectGetter = delegate(object x) { if (x is DirectoryInfo) { return((long)-1); } try { return(((FileInfo)x).Length); } catch (System.IO.FileNotFoundException) { // Mono 1.2.6 throws this for hidden files return((long)-2); } }; // Show the size of files as GB, MB and KBs. By returning the actual // size in the AspectGetter, and doing the conversion in the // AspectToStringConverter, sorting on this column will work off the // actual sizes, rather than the formatted string. this.olvColumnSize.AspectToStringConverter = delegate(object x) { long sizeInBytes = (long)x; if (sizeInBytes < 0) // folder or error { return(""); } return(Coordinator.FormatFileSize(sizeInBytes)); }; this.olvColumnSize.MakeGroupies(new long[] { 0, 1024 * 1024, 512 * 1024 * 1024 }, new string[] { "Folders", "Small", "Big", "Disk space chewer" }); // Group by month-year, rather than date // This code is duplicated for FileCreated and FileModified, so we really should // create named methods rather than using anonymous delegates. this.olvColumnCreated.GroupKeyGetter = delegate(object x) { DateTime dt = ((FileSystemInfo)x).CreationTime; return(new DateTime(dt.Year, dt.Month, 1)); }; this.olvColumnCreated.GroupKeyToTitleConverter = delegate(object x) { return(((DateTime)x).ToString("MMMM yyyy")); }; // Group by month-year, rather than date this.olvColumnModified.GroupKeyGetter = delegate(object x) { DateTime dt = ((FileSystemInfo)x).LastWriteTime; return(new DateTime(dt.Year, dt.Month, 1)); }; this.olvColumnModified.GroupKeyToTitleConverter = delegate(object x) { return(((DateTime)x).ToString("MMMM yyyy")); }; // Show the system description for this object this.olvColumnFileType.AspectGetter = delegate(object x) { return(ShellUtilities.GetFileType(((FileSystemInfo)x).FullName)); }; // Show the file attributes for this object // A FlagRenderer masks off various values and draws zero or more images based // on the presence of individual bits. this.olvColumnAttributes.AspectGetter = delegate(object x) { return(((FileSystemInfo)x).Attributes); }; FlagRenderer attributesRenderer = new FlagRenderer(); attributesRenderer.ImageList = imageList1; attributesRenderer.Add(FileAttributes.Archive, "archive"); attributesRenderer.Add(FileAttributes.ReadOnly, "readonly"); attributesRenderer.Add(FileAttributes.System, "system"); attributesRenderer.Add(FileAttributes.Hidden, "hidden"); attributesRenderer.Add(FileAttributes.Temporary, "temporary"); this.olvColumnAttributes.Renderer = attributesRenderer; // Tell the filtering subsystem that the attributes column is a collection of flags this.olvColumnAttributes.ClusteringStrategy = new FlagClusteringStrategy(typeof(FileAttributes)); }
private void SetupColumns() { // The column setup here is identical to the File Explorer example tab -- // nothing specific to the TreeListView. // The only difference is that we don't setup anything to do with grouping, // since TreeListViews can't show groups. SysImageListHelper helper = new SysImageListHelper(this.treeListView); this.olvColumnName.ImageGetter = delegate(object x) { return(helper.GetImageIndex(((MyFileSystemInfo)x).FullName)); }; // Get the size of the file system entity. // Folders and errors are represented as negative numbers this.olvColumnSize.AspectGetter = delegate(object x) { MyFileSystemInfo myFileSystemInfo = (MyFileSystemInfo)x; if (myFileSystemInfo.IsDirectory) { return((long)-1); } try { return(myFileSystemInfo.Length); } catch (System.IO.FileNotFoundException) { // Mono 1.2.6 throws this for hidden files return((long)-2); } }; // Show the size of files as GB, MB and KBs. By returning the actual // size in the AspectGetter, and doing the conversion in the // AspectToStringConverter, sorting on this column will work off the // actual sizes, rather than the formatted string. this.olvColumnSize.AspectToStringConverter = delegate(object x) { long sizeInBytes = (long)x; if (sizeInBytes < 0) // folder or error { return(""); } return(Coordinator.FormatFileSize(sizeInBytes)); }; // Show the system description for this object this.olvColumnFileType.AspectGetter = delegate(object x) { return(ShellUtilities.GetFileType(((MyFileSystemInfo)x).FullName)); }; // Show the file attributes for this object // A FlagRenderer masks off various values and draws zero or images based // on the presence of individual bits. this.olvColumnAttributes.AspectGetter = delegate(object x) { return(((MyFileSystemInfo)x).Attributes); }; FlagRenderer attributesRenderer = new FlagRenderer(); attributesRenderer.ImageList = imageListSmall; attributesRenderer.Add(FileAttributes.Archive, "archive"); attributesRenderer.Add(FileAttributes.ReadOnly, "readonly"); attributesRenderer.Add(FileAttributes.System, "system"); attributesRenderer.Add(FileAttributes.Hidden, "hidden"); attributesRenderer.Add(FileAttributes.Temporary, "temporary"); this.olvColumnAttributes.Renderer = attributesRenderer; // Tell the filtering subsystem that the attributes column is a collection of flags this.olvColumnAttributes.ClusteringStrategy = new FlagClusteringStrategy(typeof(FileAttributes)); }