Skip to content

Commit

Permalink
Restrict input characters for heavy patch name to alphanumerical and …
Browse files Browse the repository at this point in the history
…underscore
  • Loading branch information
timothyschoen committed Nov 8, 2023
1 parent 3018a14 commit 3d950dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 17 additions & 6 deletions Source/Components/PropertiesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ class PropertiesPanel : public Component {
struct EditableComponent : public PropertiesPanelProperty {
std::unique_ptr<Label> label;
Value property;
String allowedCharacters = "";

EditableComponent(String propertyName, Value& value)
: PropertiesPanelProperty(propertyName)
Expand All @@ -745,12 +746,6 @@ class PropertiesPanel : public Component {
draggableNumber->setText(property.toString(), dontSendNotification);
draggableNumber->getTextValue().referTo(property);
draggableNumber->setFont(draggableNumber->getFont().withHeight(14));

/* I think we don't need this?
draggableNumber->onValueChange = [this](float value) {
property = String(value, 8);
}; */

draggableNumber->setEditableOnClick(true);

draggableNumber->onEditorShow = [draggableNumber]() {
Expand All @@ -768,6 +763,17 @@ class PropertiesPanel : public Component {
label->setEditable(true, false);
label->getTextValue().referTo(property);
label->setFont(Font(14));

label->onEditorShow = [this]() {
auto* editor = label->getCurrentTextEditor();
editor->setBorder(BorderSize<int>(2, 1, 4, 1));
editor->setJustification(Justification::centredLeft);

if(allowedCharacters.isNotEmpty())
{
editor->setInputRestrictions(0, allowedCharacters);
}
};
}

addAndMakeVisible(label.get());
Expand All @@ -779,6 +785,11 @@ class PropertiesPanel : public Component {
{
return new EditableComponent<T>(getName(), property);
}

void setInputRestrictions(const String& newAllowedCharacters)
{
allowedCharacters = newAllowedCharacters;
}

void setRangeMin(float minimum)
{
Expand Down
5 changes: 4 additions & 1 deletion Source/Heavy/ExporterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ struct ExporterBase : public Component
patchChooser->comboBox.setSelectedId(-1);
properties.add(patchChooser);

properties.add(new PropertiesPanel::EditableComponent<String>("Project Name (optional)", projectNameValue));
auto* nameProperty = new PropertiesPanel::EditableComponent<String>("Project Name (optional)", projectNameValue);
nameProperty->setInputRestrictions("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
properties.add(nameProperty);

properties.add(new PropertiesPanel::EditableComponent<String>("Project Copyright (optional)", projectCopyrightValue));

for (auto* property : properties) {
Expand Down

0 comments on commit 3d950dc

Please sign in to comment.