MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / FileBrowser

Class FileBrowser

src/main/java/fieldbox/boxes/plugins/FileBrowser.java:38–815  ·  view source on GitHub ↗

Load files from inside Field/ For speed, rather than parsing the EDN for our Box files, we simply regex them into the correct spot

Source from the content-addressed store, hash-verified

36 * For speed, rather than parsing the EDN for our Box files, we simply regex them into the correct spot
37 */
38public class FileBrowser extends Box implements IO.Loaded {
39
40 static public final Dict.Prop<Boolean> isLinked = new Dict.Prop<Boolean>("isLinked").doc(
41 "property is set to true if this box is used in other sheets, and you are editing all of them at the same time")
42 .type()
43 .toCanon();
44
45 static public final Dict.Prop<BiFunction<String, Vec2, Set<Box>>> copyFromFileCalled = new Dict.Prop<>("copyFromFileCalled").toCanon()
46 .type()
47 .doc("`_.copyFromFileCalled('banana', new Vec2(0,0))` will copy into this document any file (.field2 file or box or template) called 'banana', centering all the boxes loaded on the point `Vec2(0,0)`");
48 static public final Dict.Prop<BiFunction<String, Vec2, Set<Box>>> insertFromFileCalled = new Dict.Prop<>("insertFromFileCalled").toCanon()
49 .type()
50 .doc("`_.copyFromFileCalled('banana', new Vec2(0,0))` will insert a live reference into this document any file (.field2 file or box or template) called 'banana', centering all the boxes loaded on the point `Vec2(0,0)`");
51
52 static AtomicInteger sheetsInFlight = new AtomicInteger();
53 private final Box root;
54 LinkedHashMap<String, FieldFile> files = new LinkedHashMap<>();
55 LinkedHashMap<String, FieldBox> boxes = new LinkedHashMap<>();
56
57 long allFrameHashSalt = 0;
58
59 public FileBrowser(Box root) {
60
61 this.root = root;
62
63 properties.put(copyFromFileCalled, this::copyFromFileCalled);
64 properties.put(insertFromFileCalled, this::insertFromFileCalled);
65
66 properties.put(Commands.commands, () -> {
67
68 Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>();
69 m.put(new Pair<>("New", "Copies templates, individual boxes, or whole files from the workspace into this document"), new RemoteEditor.ExtendedCommand() {
70
71 public RemoteEditor.SupportsPrompt p;
72
73 @Override
74 public void begin(RemoteEditor.SupportsPrompt prompt, String alternativeChosen/*, Consumer<String> feedback*/) {
75 this.p = prompt;
76 }
77
78 @Override
79 public void run() {
80
81 Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>();
82
83 files.values()
84 .stream()
85 .filter(f -> f.name != null)
86 .forEach(f -> {
87 String cm = f.getComment(FileBrowser.this);
88 m.put(new Pair<>(quote(f.name) + " <i>&mdash; document</i>",
89 (cm == null ? "" : (cm + "<br>")) + ("contains " + f.boxes.size() + " box" + (f.boxes.size() == 1 ? "" : "es")) + " <br>"), () -> {
90
91 // doit
92
93 Open.doOpen(root, f.name)
94 .forEach(IO::uniqify);
95

Callers

nothing calls this directly

Calls 3

toCanonMethod · 0.80
typeMethod · 0.80
docMethod · 0.80

Tested by

no test coverage detected