Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,32 @@ StylePropertyComponent::StylePropertyComponent (MagicGUIBuilder& builderToUse, j
remove.setConnectedEdges (juce::TextButton::ConnectedOnLeft | juce::TextButton::ConnectedOnRight);
remove.onClick = [&]
{
node.removeProperty (property, &builder.getUndoManager());
// Three states:
// 1) Property has a non-empty value -> set to empty string
// 2) Property is explicitly empty string -> remove property entirely
// 3) Property not set (only default) -> do nothing

if (node.hasProperty (property))
{
if (node.getProperty (property).toString().isEmpty())
{
// State 2 -> State 3: remove property entirely
// Break the label's Value binding BEFORE removing to prevent sync-back
if (auto* label = dynamic_cast<juce::Label*>(editor.get()))
{
juce::Value disconnected;
label->getTextValue().referTo (disconnected);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird that there is no other way to reset the value source.
Did you try this?

label->getTextValue().referTo({});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try that! I'm not familiar with most of this ecosystem so that's probably just my mistake.

}
node.removeProperty (property, &builder.getUndoManager());
}
else
{
// State 1 -> State 2: set to empty string
node.setProperty (property, "", &builder.getUndoManager());
}
}
// State 3: property not set, do nothing (button should be disabled)

refresh();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ void StyleTextPropertyComponent::refresh()
if (node == inheritedFrom)
{
label->getTextValue().referTo (node.getPropertyAsValue (property, &builder.getUndoManager()));
label->setColour (juce::Label::textColourId, EditorColours::text);
}
else
{
label->getTextValue().referTo (label->getTextValue());
label->setText (value.toString(), juce::dontSendNotification);
label->setColour (juce::Label::textColourId, EditorColours::disabledText);
}
}

Expand Down