Skip to content

Commit

Permalink
Core Editor: Add inline button for navigating to a referenced object
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed May 4, 2024
1 parent 1c9431f commit 74e2630
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import com.shade.decima.ui.data.registry.ValueHandlerRegistration;
import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector;
import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type;
import com.shade.decima.ui.editor.core.CoreEditor;
import com.shade.decima.ui.editor.core.menu.FollowReferenceItem;
import com.shade.platform.ui.controls.TextAttributes;
import com.shade.platform.ui.editors.Editor;
import com.shade.platform.ui.editors.EditorManager;
import com.shade.util.NotNull;
import com.shade.util.Nullable;

Expand All @@ -24,15 +28,15 @@ public class ReferenceValueHandler implements ValueHandler {
public Decorator getDecorator(@NotNull RTTIType<?> type) {
return (value, component) -> {
if (value instanceof RTTIReference.External ref) {
component.append(ref.path(), TextAttributes.REGULAR_ATTRIBUTES);
component.append(" : ", TextAttributes.REGULAR_ATTRIBUTES);
component.append(RTTIUtils.uuidToString(ref.uuid()), TextAttributes.REGULAR_ATTRIBUTES);
component.append(ref.path() + " : " + RTTIUtils.uuidToString(ref.uuid()));
component.append(" (" + ref.kind() + ")", TextAttributes.GRAYED_ATTRIBUTES);
component.append(" open", TextAttributes.LINK_ATTRIBUTES, e -> follow(ref));
} else if (value instanceof RTTIReference.Internal ref) {
component.append(RTTIUtils.uuidToString(ref.uuid()), TextAttributes.REGULAR_ATTRIBUTES);
component.append(RTTIUtils.uuidToString(ref.uuid()));
component.append(" (" + ref.kind() + ")", TextAttributes.GRAYED_ATTRIBUTES);
component.append(" open", TextAttributes.LINK_ATTRIBUTES, e -> follow(ref));
} else {
component.append("none", TextAttributes.REGULAR_ATTRIBUTES);
component.append("none");
}
};
}
Expand All @@ -52,4 +56,11 @@ public String getText(@NotNull RTTIType<?> type, @NotNull Object value) {
return null;
}
}

private void follow(@NotNull RTTIReference reference) {
final Editor editor = EditorManager.getInstance().getActiveEditor();
if (editor instanceof CoreEditor e) {
FollowReferenceItem.follow(reference, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

public class CoreTree extends Tree {
public CoreTree(@NotNull CoreNodeFile root) {
setCellRenderer(new CoreTreeCellRenderer());

setCellRenderer(new CoreTreeCellRenderer().withTags(this));
setModel(new CoreTreeModel(this, root));
setSelectionPath(new TreePath(root));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static boolean isValidReference(@Nullable Object value) {
|| value instanceof RTTIReference.External;
}

private static void follow(@NotNull RTTIReference reference, @NotNull CoreEditor currentEditor) {
public static void follow(@NotNull RTTIReference reference, @NotNull CoreEditor currentEditor) {
final RTTIObject uuid;
final CompletableFuture<Editor> future;

Expand Down

0 comments on commit 74e2630

Please sign in to comment.