-
Notifications
You must be signed in to change notification settings - Fork 0
/
Recent.cs
87 lines (81 loc) · 2.81 KB
/
Recent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.IO;
using TextReader.ScrollingView;
namespace TextReader.TreeBrowse.FileSystem {
class RecentItemsHolder : ItemsHolder {
private Dictionary<FileSystemInfo, FileRow> createdRows = new Dictionary<FileSystemInfo, FileRow>();
private DrawParams drawParams;
private FileInfo[] recent;
public RecentItemsHolder(FileInfo[] recent, DrawParams drawParams) {
this.drawParams = drawParams;
this.recent = recent;
}
public IScrollable<Row> CreateRows() {
var files = new ArrayScrollable<FileInfo>(recent);
return new MappingScrollable<Row, FileInfo>(files, getRow);
}
private Row getRow(FileSystemInfo f) {
if (!createdRows.ContainsKey(f)) {
createdRows.Add(f, new FileRow(f, drawParams));
}
return createdRows[f];
}
public void Dispose() {
if (createdRows != null) {
foreach (FileRow row in createdRows.Values) {
row.Dispose();
}
createdRows = null;
}
}
}
public class RecentRootItem : TreeItem {
private DrawParams drawParams;
private DirectoryInfo startDir;
private FileInfo[] recent;
public RecentRootItem(FileInfo[] recent, DirectoryInfo startDir, DrawParams drawParams) {
this.drawParams = drawParams;
this.startDir = startDir;
this.recent = recent;
}
public String Name { get { return "(Recent)"; } }
public ItemsHolder CreateItems() {
return new RecentItemsHolder(recent, drawParams);
}
public TreeItem Parent { get { return new DirectoryTreeItem(startDir, drawParams); } }
public bool IsChildOf(TreeItem other) {
if (other is DirectoryTreeItem) {
return startDir.Equals((other as DirectoryTreeItem).Dir);
}
return false;
}
public bool IsLeaf { get { return false; } }
public TreeItem ChildFromRow(Row row) {
if (row is FileRow) {
FileRow fileRow = row as FileRow;
return new RecentItem(fileRow.Info as FileInfo);
} else {
throw new ArgumentException("Not a FileRow");
}
}
}
public class RecentItem : TreeItem {
public readonly FileInfo File;
public RecentItem(FileInfo file) {
this.File = file;
}
public String Name { get { return File.Name; } }
public ItemsHolder CreateItems() {
throw new ArgumentException("Leaf node");
}
public TreeItem Parent { get { return null; } }
public bool IsChildOf(TreeItem other) {
return other is RecentRootItem;
}
public bool IsLeaf { get { return true; } }
public TreeItem ChildFromRow(Row row) {
throw new ArgumentException("Leaf node");
}
}
}