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

Method Rename

src/main/java/fieldbox/boxes/plugins/Rename.java:25–90  ·  view source on GitHub ↗
(Box root_unused)

Source from the content-addressed store, hash-verified

23public class Rename extends Box {
24
25 public Rename(Box root_unused) {
26 properties.put(Commands.commands, () -> {
27
28 Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>();
29 m.put(new Pair<>("Rename box", "Sets name of box _Command-double-click_"), new RemoteEditor.ExtendedCommand() {
30
31 public RemoteEditor.SupportsPrompt p;
32
33 @Override
34 public void begin(RemoteEditor.SupportsPrompt prompt, String alternativeChosen/*, Consumer<String> feedback*/) {
35 this.p = prompt;
36 }
37
38 @Override
39 public void run() {
40
41 Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>();
42
43 p.prompt("rename box to...", m, new RemoteEditor.ExtendedCommand() {
44 String altWas = null;
45 Consumer<String> feedback;
46
47 @Override
48 public void begin(RemoteEditor.SupportsPrompt prompt, String alternativeChosen/*, Consumer<String> feedback*/) {
49 altWas = alternativeChosen;
50 this.feedback = feedback;
51 }
52
53 @Override
54 public void run() {
55 Log.log("run", ()->" ALT WAS :" + altWas);
56
57 if (altWas != null) selection().forEach(x -> {
58// UndoStack.u.change(x, Box.name, altWas);
59 x.properties.put(Box.name, altWas);
60 Drawing.dirty(x);
61 if (feedback != null) feedback.accept("Renamed to \"" + altWas + "\"");
62 });
63 }
64 });
65 }
66 });
67
68 if (selection().filter(x -> x.properties.getMap()
69 .keySet()
70 .stream()
71 .filter(y -> y.getName()
72 .startsWith("__filename__") || y.getName()
73 .startsWith("__datafilename__"))
74 .count() > 0)
75 .count() > 0)
76
77 m.put(new Pair<>("Reset filenames", "Removes any explicit or previously saves file associations with this box"), () -> {
78
79
80 selection().forEach(x -> {
81
82 IO.uniqify(x);

Callers

nothing calls this directly

Calls 8

selectionMethod · 0.95
uniqifyMethod · 0.95
countMethod · 0.80
getMapMethod · 0.80
putMethod · 0.45
streamMethod · 0.45
getNameMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected