Skip to content

Commit

Permalink
Core Editor: Show/hide object indices and array element types
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Mar 2, 2024
1 parent c382af6 commit 05a185a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ private CoreEditor(@NotNull ProjectEditorInput input, @NotNull RTTICoreFile file
breadcrumbBarPane.setVisible(settings.showBreadcrumbs);
revalidate();
}
// In case any of presentation attributes were changed
tree.getUI().invalidateSizes();
});

final CoreEditorSettings settings = CoreEditorSettings.getInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.shade.decima.ui.editor.core;

import com.shade.decima.model.rtti.path.RTTIPathElement;
import com.shade.decima.ui.data.ValueHandler;
import com.shade.decima.ui.editor.core.settings.CoreEditorSettings;
import com.shade.decima.ui.navigator.NavigatorTreeCellRenderer;
import com.shade.platform.ui.controls.CommonTextAttributes;
import com.shade.platform.ui.controls.TextAttributes;
Expand All @@ -14,7 +16,9 @@
public class CoreTreeCellRenderer extends NavigatorTreeCellRenderer {
@Override
protected void customizeCellRenderer(@NotNull JTree tree, @NotNull TreeNode value, boolean selected, boolean expanded, boolean focused, boolean leaf, int row) {
if (value instanceof CoreNodeEntry entry) {
final CoreEditorSettings settings = CoreEditorSettings.getInstance();

if (settings.showEntryIndices && value instanceof CoreNodeEntry entry) {
// TODO: Add a preference for toggling this on/off
append("[%d] ".formatted(entry.getIndex()), TextAttributes.GRAYED_ATTRIBUTES);
}
Expand All @@ -23,8 +27,13 @@ protected void customizeCellRenderer(@NotNull JTree tree, @NotNull TreeNode valu
final ValueHandler.Decorator decorator = node.getHandler().getDecorator(node.getType());

append(node.getLabel(), CommonTextAttributes.IDENTIFIER_ATTRIBUTES);
append(" = ", TextAttributes.REGULAR_ATTRIBUTES);
append("{%s}".formatted(node.getType().getFullTypeName()), TextAttributes.GRAYED_ATTRIBUTES);

if (decorator != null && !settings.showArrayElementTypes && node.getPath().last() instanceof RTTIPathElement.Index) {
append(" =", TextAttributes.REGULAR_ATTRIBUTES);
} else {
append(" = ", TextAttributes.REGULAR_ATTRIBUTES);
append("{%s}".formatted(node.getType().getFullTypeName()), TextAttributes.GRAYED_ATTRIBUTES);
}

if (decorator != null) {
if (decorator.needsGap()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class CoreEditorSettings implements PersistableComponent<CoreEditorSettin
public boolean selectFirstEntry = true;
public boolean groupEntries = false;
public boolean sortEntries = false;
public boolean showEntryIndices = true;
public boolean showArrayElementTypes = false;

@NotNull
public static CoreEditorSettings getInstance() {
Expand All @@ -38,5 +40,7 @@ public void loadState(@NotNull CoreEditorSettings state) {
selectFirstEntry = state.selectFirstEntry;
groupEntries = state.groupEntries;
sortEntries = state.sortEntries;
showEntryIndices = state.showEntryIndices;
showArrayElementTypes = state.showArrayElementTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class CoreEditorSettingsPage implements SettingsPage {
private JCheckBox selectFirstEntryCheckbox;
private JCheckBox groupEntriesCheckbox;
private JCheckBox sortEntriesCheckbox;
private JCheckBox showEntryIndicesCheckbox;
private JCheckBox showArrayElementTypesCheckbox;

@NotNull
@Override
Expand All @@ -46,6 +48,8 @@ public JComponent createComponent(@NotNull PropertyChangeListener listener) {
panel.add(selectFirstEntryCheckbox = new JCheckBox("Select first entry"));
panel.add(groupEntriesCheckbox = new JCheckBox("Group entries by default"));
panel.add(sortEntriesCheckbox = new JCheckBox("Sort entries by default"));
panel.add(showEntryIndicesCheckbox = new JCheckBox("Show entry indices"));
panel.add(showArrayElementTypesCheckbox = new JCheckBox("Show array element types"));

root.add(panel);
}
Expand All @@ -57,6 +61,8 @@ public JComponent createComponent(@NotNull PropertyChangeListener listener) {
selectFirstEntryCheckbox.addItemListener(adapter);
groupEntriesCheckbox.addItemListener(adapter);
sortEntriesCheckbox.addItemListener(adapter);
showEntryIndicesCheckbox.addItemListener(adapter);
showArrayElementTypesCheckbox.addItemListener(adapter);

return root;
}
Expand All @@ -69,6 +75,8 @@ public void apply() {
settings.selectFirstEntry = selectFirstEntryCheckbox.isSelected();
settings.groupEntries = groupEntriesCheckbox.isSelected();
settings.sortEntries = sortEntriesCheckbox.isSelected();
settings.showEntryIndices = showEntryIndicesCheckbox.isSelected();
settings.showArrayElementTypes = showArrayElementTypesCheckbox.isSelected();

MessageBus.getInstance().publisher(CoreEditorSettings.SETTINGS).settingsChanged();
}
Expand All @@ -81,6 +89,8 @@ public void reset() {
selectFirstEntryCheckbox.setSelected(settings.selectFirstEntry);
groupEntriesCheckbox.setSelected(settings.groupEntries);
sortEntriesCheckbox.setSelected(settings.sortEntries);
showEntryIndicesCheckbox.setSelected(settings.showEntryIndices);
showArrayElementTypesCheckbox.setSelected(settings.showArrayElementTypes);
}

@Override
Expand All @@ -90,7 +100,9 @@ public boolean isModified() {
|| settings.showValuePanel != showValuePanelCheckbox.isSelected()
|| settings.selectFirstEntry != selectFirstEntryCheckbox.isSelected()
|| settings.groupEntries != groupEntriesCheckbox.isSelected()
|| settings.sortEntries != sortEntriesCheckbox.isSelected();
|| settings.sortEntries != sortEntriesCheckbox.isSelected()
|| settings.showEntryIndices != showEntryIndicesCheckbox.isSelected()
|| settings.showArrayElementTypes != showArrayElementTypesCheckbox.isSelected();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ protected void completeEditing(boolean messageStop, boolean messageCancel, boole
}
}
}

public void invalidateSizes() {
treeState.invalidateSizes();
updateSize();
}
}

0 comments on commit 05a185a

Please sign in to comment.