(Box currentSelection, Dict.Prop<String> editingProperty)
| 1122 | return currentSelection; |
| 1123 | } |
| 1124 | |
| 1125 | public void changeSelection(Box currentSelection, Dict.Prop<String> editingProperty) { |
| 1126 | |
| 1127 | try { |
| 1128 | Log.log("remote.trace", () -> " publishing selection changed :" + currentSelection + " " + editingProperty); |
| 1129 | |
| 1130 | if (currentSelection == null || editingProperty == null) { |
| 1131 | server.send(socketName, "_messageBus.publish('selection.changed', {box:null, property:null, text:''})"); |
| 1132 | } else { |
| 1133 | |
| 1134 | String text = currentSelection.properties.get(editingProperty); |
| 1135 | if (text == null) text = ""; |
| 1136 | |
| 1137 | final String finalText = text; |
| 1138 | Log.log("remote.trace", () -> " current text is :" + finalText); |
| 1139 | |
| 1140 | |
| 1141 | //todo: pass back two cookies for this box --- one persistant (saved to disk), one just for current things |
| 1142 | |
| 1143 | JSONObject buildMessage = new JSONObject(); |
| 1144 | buildMessage.put("box", currentSelection.properties.get(IO.id)); |
| 1145 | buildMessage.put("text", currentSelection.properties.getOr(editingProperty, () -> "")); |
| 1146 | buildMessage.put("property", editingProperty.getName()); |
| 1147 | buildMessage.put("name", currentSelection.properties.get(Box.name)); |
| 1148 | |
| 1149 | |
| 1150 | String cooked = currentSelection.properties.get(new Dict.Prop<String>("_" + editingProperty.getName() + "_cookie")); |
| 1151 | IO.persist(new Dict.Prop<String>("_" + editingProperty.getName() + "_cookie")); |
| 1152 | |
| 1153 | Log.log("remote.cookie", () -> "cookie ns now :" + cooked); |
| 1154 | buildMessage.put("cookie", new JSONObject(cooked == null ? "{}" : cooked)); |
| 1155 | |
| 1156 | |
| 1157 | Execution ex = getExecution(currentSelection, editingProperty); |
| 1158 | if (ex != null) { |
| 1159 | Execution.ExecutionSupport support = ex.support(currentSelection, editingProperty); |
| 1160 | if (support != null) { |
| 1161 | String cmln = support.getCodeMirrorLanguageName(); |
| 1162 | Log.log("remote.general", () -> "langage :" + cmln); |
| 1163 | buildMessage.put("languageName", cmln); |
| 1164 | support.setFilenameForStacktraces("" + currentSelection + "/" + currentSelection.properties.getOrConstruct(IO.id)); |
| 1165 | } else { |
| 1166 | } |
| 1167 | } else { |
| 1168 | // this can happen when we're editing something that isn't 'code' |
| 1169 | String cmln = FieldBox.fieldBox.io.getLanguageForProperty(editingProperty); |
| 1170 | String finalCmln = cmln; |
| 1171 | Log.log("remote.general", () -> "langage :" + finalCmln); |
| 1172 | if (cmln == null || cmln.trim().equals("")) cmln = "javascript"; |
| 1173 | buildMessage.put("languageName", cmln); |
| 1174 | |
| 1175 | } |
| 1176 | Log.log("remote.trace", () -> " message will be sent " + buildMessage.toString()); |
| 1177 | |
| 1178 | Log.log("remote.trace", () -> "\n " + currentSelection.properties.get(new Dict.Prop<JSONObject>("_" + editingProperty.getName() + "_cookie")) + "\n"); |
| 1179 | |
| 1180 | server.send(socketName, "_messageBus.publish('selection.changed', " + buildMessage.toString() + ")"); |
| 1181 |
no test coverage detected