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

Method saveAsNewFile

src/main/java/fieldbox/DefaultMenus.java:331–388  ·  view source on GitHub ↗
(Box root, String absoluteFilename)

Source from the content-addressed store, hash-verified

329 String workspaceWas = FieldBox.fieldBox.io.getDefaultDirectory(); // no sure we reset that...
330
331 FieldBox.fieldBox.io.setDefaultDirectory(tmpWorkspace);
332
333
334 IO.uniqify(root);
335
336 String path = IO.WORKSPACE + "/" + filename + "/";
337
338 special.put(root, ">>root<<");
339
340 List<Runnable> undo = new LinkedList<>();
341
342 IO.Document doc = FieldBox.fieldBox.io.compileDocument("", root, x -> {
343 undo.add(IO.uniqify(x));
344 return true;
345 }, special);
346
347 Map<String, String> remap = new LinkedHashMap<String, String>();
348
349 doc.externalList.forEach(x -> {
350 String nid = Box.newID();
351 remap.put(x.id, nid);
352 x.id = nid;
353 });
354
355 doc.externalList.forEach(x -> {
356 x.children = x.children.stream().map(y -> remap.getOrDefault(y, y)).filter(y -> y != null).collect(Collectors.toList());
357 x.parents = x.parents.stream().map(y -> remap.getOrDefault(y, y)).filter(y -> y != null).collect(Collectors.toList());
358 });
359
360
361 boolean error = false;
362 try {
363 FieldBox.fieldBox.io.writeOutDocument(IO.WORKSPACE + "/" + filename, doc);
364 } catch (IOException e) {
365 e.printStackTrace();
366 Drawing.notify("Error saving " + e.getMessage(), root, 200);
367 error = true;
368 }
369
370 for (Runnable r : undo)
371 r.run();
372
373
374 this.filename = filename;
375
376 return true;
377 }
378
379 private boolean isNothingSelected() {
380
381 return !find(Mouse.isSelected, both()).filter(x -> x.booleanValue())
382 .findFirst()
383 .isPresent();
384 }
385
386}

Callers 1

DefaultMenusMethod · 0.95

Calls 15

uniqifyMethod · 0.95
newIDMethod · 0.95
notifyMethod · 0.95
getDefaultDirectoryMethod · 0.80
setDefaultDirectoryMethod · 0.80
compileDocumentMethod · 0.80
collectMethod · 0.80
writeOutDocumentMethod · 0.80
getNameMethod · 0.45
putMethod · 0.45
addMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected