Add shared source-preserving DirectBinding inspector
This commit is contained in:
@@ -42,6 +42,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
var hit = kit.editor().getSelection().getHitItem();
|
||||
if (hit == null) return;
|
||||
String id = hit.getFxId();
|
||||
if (bindingEditor != null) bindingEditor.selectControl(id);
|
||||
if (id == null || !projection.components().containsKey(id)) return;
|
||||
componentInspector.getChildren().add(new Label(projection.components().get(id) + " · " + id));
|
||||
componentInspector
|
||||
@@ -113,6 +114,8 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
private DesignerWorkflow interactiveWorkflow;
|
||||
private DesignerWorkflow bindingWorkflow;
|
||||
private BindingBrowser bindingBrowser;
|
||||
private DirectBindingEditor bindingEditor;
|
||||
private Tab directBindingTab;
|
||||
private long bindingRequest;
|
||||
private boolean interactiveRequested, interactiveRestart;
|
||||
private long interactiveRequest;
|
||||
@@ -172,7 +175,21 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
launch.maven(),
|
||||
launch.tools(),
|
||||
this::log);
|
||||
bindingBrowser = new BindingBrowser(this::discoverBindings);
|
||||
bindingEditor =
|
||||
new DirectBindingEditor(
|
||||
this::editBinding,
|
||||
id -> {
|
||||
if (kit.editor().getFxomDocument() == null) return;
|
||||
var target = new FXOMFxIdIndex(kit.editor().getFxomDocument()).lookup(id);
|
||||
if (target != null) kit.editor().getSelection().select(target);
|
||||
});
|
||||
bindingBrowser =
|
||||
new BindingBrowser(
|
||||
this::discoverBindings,
|
||||
values -> {
|
||||
bindingEditor.newBinding(values);
|
||||
directBindingTab.getTabPane().getSelectionModel().select(directBindingTab);
|
||||
});
|
||||
interactiveWorkflow.onInteractiveClosed(
|
||||
() ->
|
||||
fx(
|
||||
@@ -308,7 +325,11 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
var properties = new ScrollPane(componentInspector);
|
||||
properties.setFitToWidth(true);
|
||||
properties.setPrefViewportHeight(100);
|
||||
var bindings = new TitledPane("Bindings — discovery", bindingBrowser);
|
||||
var discoveryTab = new Tab("Discover targets", bindingBrowser);
|
||||
discoveryTab.setClosable(false);
|
||||
directBindingTab = new Tab("Direct bindings", bindingEditor);
|
||||
directBindingTab.setClosable(false);
|
||||
var bindings = new TitledPane("Bindings", new TabPane(directBindingTab, discoveryTab));
|
||||
bindings.setExpanded(false);
|
||||
center.setBottom(new VBox(properties, bindings));
|
||||
output.setEditable(false);
|
||||
@@ -448,6 +469,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
draft = value;
|
||||
bindingEditor.load(value.text(), value.writable());
|
||||
submittedSource = null;
|
||||
commitSource();
|
||||
return;
|
||||
@@ -469,6 +491,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
var hit = kit.editor().getSelection().getHitItem();
|
||||
String selectedId = hit == null ? null : hit.getFxId();
|
||||
draft = value;
|
||||
bindingEditor.load(value.text(), value.writable());
|
||||
if (!source.getText().equals(value.text())) {
|
||||
int anchor = source.getAnchor(), caret = source.getCaretPosition();
|
||||
var edits =
|
||||
@@ -620,6 +643,45 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
bindingBrowser.invalidate(message);
|
||||
}
|
||||
|
||||
private void editBinding(DirectBindingEditor.Intent intent) {
|
||||
withDraft(
|
||||
() -> {
|
||||
try {
|
||||
if (!draft.writable()) throw new IllegalStateException("Document is read-only");
|
||||
if (!draft.text().equals(intent.source()))
|
||||
throw new IllegalStateException("Document changed; select the binding again");
|
||||
var bindings = new DirectBindingDocument(draft.text());
|
||||
var edits =
|
||||
intent.remove()
|
||||
? bindings.remove(java.util.Objects.requireNonNull(intent.index()))
|
||||
: bindings.write(intent.index(), intent.values(), intent.replace());
|
||||
submit(
|
||||
edits,
|
||||
intent.remove()
|
||||
? "Remove DirectBinding"
|
||||
: intent.index() == null ? "Create DirectBinding" : "Edit DirectBinding");
|
||||
} catch (Exception error) {
|
||||
bindingEditor.error(error.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean bindingPreviewAllowed() {
|
||||
try {
|
||||
var errors = new DirectBindingDocument(draft.text()).errors();
|
||||
if (errors.isEmpty()) return true;
|
||||
status.setText("Preview blocked: " + String.join("; ", errors));
|
||||
if (projection != null)
|
||||
for (String id : projection.components().keySet()) {
|
||||
var region = proxy(id);
|
||||
if (region != null) region.show(images.get(id), "Binding errors; preview outdated");
|
||||
}
|
||||
} catch (Exception error) {
|
||||
report(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void discoverBindings(String path, String direction) {
|
||||
withDraft(
|
||||
() -> {
|
||||
@@ -740,6 +802,7 @@ public final class DesignerPane extends BorderPane implements AutoCloseable {
|
||||
public void render() {
|
||||
withDraft(
|
||||
() -> {
|
||||
if (!bindingPreviewAllowed()) return;
|
||||
var selected = examples.getValue();
|
||||
if (selected == null || projection == null) return;
|
||||
long ticket = renderSequence.incrementAndGet();
|
||||
|
||||
Reference in New Issue
Block a user