Skip to content

Commit

Permalink
Merge pull request #63 from ffAudio/develop
Browse files Browse the repository at this point in the history
Release 1.3.4
  • Loading branch information
ffAudio authored Aug 1, 2021
2 parents 41e7f2b + 1283f92 commit 9bb30f8
Show file tree
Hide file tree
Showing 31 changed files with 806 additions and 271 deletions.
2 changes: 1 addition & 1 deletion Editor/foleys_GUITreeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void GUITreeEditor::GuiTreeItem::paintItem (juce::Graphics& g, int width, int he

juce::String name = itemNode.getType().toString();

if (itemNode.hasProperty (IDs::id))
if (itemNode.hasProperty (IDs::id) && itemNode.getProperty (IDs::id).toString().isNotEmpty())
name += " (" + itemNode.getProperty (IDs::id).toString() + ")";

if (itemNode.hasProperty (IDs::caption))
Expand Down
10 changes: 7 additions & 3 deletions Editor/foleys_MultiListPropertyComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,25 @@ MultiListPropertyComponent::MultiListPropertyComponent (const juce::Value& value
select.onClick = [&]
{
auto strings = juce::StringArray::fromTokens (text.getText(), separator, "");
juce::Component::SafePointer<juce::Label> textEdit (&text);

juce::PopupMenu popup;
for (const auto& name : choices)
if (! strings.contains (name))
popup.addItem (name, [&]
popup.addItem (name, [&, textEdit]
{
if (textEdit == nullptr)
return;

if (! strings.contains (name))
{
strings.add (name);
strings.removeEmptyStrings (true);
text.setText (strings.joinIntoString (separator), juce::sendNotificationAsync);
textEdit->setText (strings.joinIntoString (separator), juce::sendNotificationAsync);
}
});

popup.showAt (getScreenBounds());
popup.showMenuAsync (juce::PopupMenu::Options());
};
}

Expand Down
72 changes: 46 additions & 26 deletions Editor/foleys_PropertiesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
namespace foleys
{

enum ComboIDs : int
{
TypeEdit=1000,
NodeEdit=2000,
ClassEdit=3000,
PaletteEdit=4000
};

PropertiesEditor::PropertiesEditor (MagicGUIBuilder& builderToEdit)
: builder (builderToEdit),
Expand Down Expand Up @@ -66,24 +73,24 @@ PropertiesEditor::PropertiesEditor (MagicGUIBuilder& builderToEdit)
return;

auto index = nodeSelect.getSelectedId();
if (index >= 4000)
if (index >= ComboIDs::PaletteEdit)
{
auto node = style.getChildWithName (IDs::palettes).getChild (index - 4000);
auto node = style.getChildWithName (IDs::palettes).getChild (index - ComboIDs::PaletteEdit);
setNodeToEdit (node);
}
else if (index >= 3000)
else if (index >= ComboIDs::ClassEdit)
{
auto node = style.getChildWithName (IDs::classes).getChild (index - 3000);
auto node = style.getChildWithName (IDs::classes).getChild (index - ComboIDs::ClassEdit);
setNodeToEdit (node);
}
else if (index >= 2000)
else if (index >= ComboIDs::NodeEdit)
{
auto node = style.getChildWithName (IDs::nodes).getChild (index - 2000);
auto node = style.getChildWithName (IDs::nodes).getChild (index - ComboIDs::NodeEdit);
setNodeToEdit (node);
}
else if (index >= 1000)
else if (index >= ComboIDs::TypeEdit)
{
auto node = style.getChildWithName (IDs::types).getChild (index - 1000);
auto node = style.getChildWithName (IDs::types).getChild (index - ComboIDs::TypeEdit);
setNodeToEdit (node);
}

Expand Down Expand Up @@ -169,21 +176,31 @@ void PropertiesEditor::createNewClass()
{
static juce::String editorID { "styleClass" };

juce::AlertWindow dlg (TRANS ("New style class"), TRANS ("Enter a name:"), juce::AlertWindow::QuestionIcon, this);
dlg.addTextEditor (editorID, "class");
dlg.addButton (TRANS ("Cancel"), 0);
dlg.addButton (TRANS ("Ok"), 1);
if (dlg.runModalLoop() == 0)
return;

if (auto* editor = dlg.getTextEditor (editorID))
classNameInput = std::make_unique<juce::AlertWindow> (TRANS ("New style class"),
TRANS ("Enter a name:"),
juce::AlertWindow::QuestionIcon,
this);
classNameInput->addTextEditor (editorID, "class");
classNameInput->addButton (TRANS ("Cancel"), 0);
classNameInput->addButton (TRANS ("Ok"), 1);
classNameInput->centreAroundComponent (getTopLevelComponent(), 350, 200);
classNameInput->enterModalState (true,
juce::ModalCallbackFunction::create ([this] (int result)
{
auto name = editor->getText().replaceCharacters (".&$@ ", "---__");
auto newNode = builder.getStylesheet().addNewStyleClass (name, &undo);
auto index = newNode.getParent().indexOf (newNode);
updatePopupMenu();
nodeSelect.setSelectedId (3000 + index);
}
if (result > 0)
{
if (auto* editor = classNameInput->getTextEditor (editorID))
{
auto name = editor->getText().replaceCharacters (".&$@ ", "---__");
auto newNode = builder.getStylesheet().addNewStyleClass (name, &undo);
auto index = newNode.getParent().indexOf (newNode);
updatePopupMenu();
nodeSelect.setSelectedId (ComboIDs::ClassEdit + index);
}
}

classNameInput.reset();
}));
}

void PropertiesEditor::deleteClass (const juce::String& name)
Expand Down Expand Up @@ -233,6 +250,9 @@ void PropertiesEditor::addNodeProperties()
array.add (new juce::TextPropertyComponent (styleItem.getPropertyAsValue (IDs::minHeight, &undo), IDs::minHeight.toString(), 8, false));
array.add (new juce::TextPropertyComponent (styleItem.getPropertyAsValue (IDs::maxHeight, &undo), IDs::maxHeight.toString(), 8, false));
array.add (new juce::TextPropertyComponent (styleItem.getPropertyAsValue (IDs::aspect, &undo), IDs::aspect.toString(), 8, false));
array.add (new StyleColourPropertyComponent (builder, IDs::tooltipText, styleItem));
array.add (new StyleColourPropertyComponent (builder, IDs::tooltipBackground, styleItem));
array.add (new StyleColourPropertyComponent (builder, IDs::tooltipOutline, styleItem));
}

auto classNames = builder.getStylesheet().getAllClassesNames();
Expand Down Expand Up @@ -350,7 +370,7 @@ void PropertiesEditor::updatePopupMenu()
if (typesNode.isValid())
{
juce::PopupMenu menu;
int index = 1000;
int index = ComboIDs::TypeEdit;
for (const auto& child : typesNode)
menu.addItem (juce::PopupMenu::Item ("Type: " + child.getType().toString()).setID (index++));

Expand All @@ -360,7 +380,7 @@ void PropertiesEditor::updatePopupMenu()
auto nodesNode = style.getChildWithName (IDs::nodes);
if (nodesNode.isValid())
{
int index = 2000;
int index = ComboIDs::NodeEdit;
juce::PopupMenu menu;
for (const auto& child : nodesNode)
menu.addItem (juce::PopupMenu::Item ("Node: " + child.getType().toString()).setID (index++));
Expand All @@ -371,7 +391,7 @@ void PropertiesEditor::updatePopupMenu()
auto classesNode = style.getChildWithName (IDs::classes);
if (classesNode.isValid())
{
int index = 3000;
int index = ComboIDs::ClassEdit;
juce::PopupMenu menu;
for (const auto& child : classesNode)
menu.addItem (juce::PopupMenu::Item ("Class: " + child.getType().toString()).setID (index++));
Expand Down Expand Up @@ -401,7 +421,7 @@ void PropertiesEditor::updatePopupMenu()
auto palettesNode = style.getChildWithName (IDs::palettes);
if (palettesNode.isValid())
{
int index = 4000;
int index = ComboIDs::PaletteEdit;
juce::PopupMenu menu;
for (const auto& child : palettesNode)
menu.addItem (juce::PopupMenu::Item ("Palette: " + child.getType().toString()).setID (index++));
Expand Down
2 changes: 2 additions & 0 deletions Editor/foleys_PropertiesEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class PropertiesEditor : public juce::Component,
juce::ValueTree style;
juce::ValueTree styleItem;

std::unique_ptr<juce::AlertWindow> classNameInput;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertiesEditor)
};

Expand Down
4 changes: 3 additions & 1 deletion Editor/foleys_StyleColourPropertyComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ StyleColourPropertyComponent::StyleColourPropertyComponent (MagicGUIBuilder& bui
variables.onClick = [&]
{
juce::PopupMenu menu;
juce::PopupMenu::Options options;

juce::Component::SafePointer<juce::Label> l = dynamic_cast<juce::Label*>(editor.get());
for (auto v : builder.getStylesheet().getPaletteEntryNames())
menu.addItem (v, [l, v]() mutable { if (l) l->setText ("$" + v, juce::sendNotification); });

menu.showAt (editor.get());
menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (editor.get()));
};

mouseEvents.onMouseDown = [this](const juce::MouseEvent&)
Expand Down
92 changes: 44 additions & 48 deletions Editor/foleys_ToolBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ ToolBox::ToolBox (juce::Component* parentToUse, MagicGUIBuilder& builderToContro
fileMenu.onClick = [&]
{
juce::PopupMenu file;

file.addItem ("Load XML", [&] { loadDialog(); });
file.addItem ("Save XML", [&] { saveDialog(); });
file.addSeparator();
file.addItem ("Clear", [&] { builder.clearGUI(); });
file.addSeparator();
file.addItem ("Refresh", [&] { builder.updateComponents(); });
file.show();
file.showMenuAsync (juce::PopupMenu::Options());
};

viewMenu.onClick = [&]
Expand All @@ -89,7 +90,7 @@ ToolBox::ToolBox (juce::Component* parentToUse, MagicGUIBuilder& builderToContro
view.addSeparator();
view.addItem ("AlwaysOnTop", true, isAlwaysOnTop(), [&]() { setAlwaysOnTop ( ! isAlwaysOnTop() ); });

view.show ();
view.showMenuAsync (juce::PopupMenu::Options());
};

undoButton.onClick = [&]
Expand Down Expand Up @@ -122,7 +123,7 @@ ToolBox::ToolBox (juce::Component* parentToUse, MagicGUIBuilder& builderToContro
setBounds (100, 100, 300, 700);
addToDesktop (getLookAndFeel().getMenuWindowFlags());

startTimer (100);
startTimer (Timers::WindowDrag, 100);

setVisible (true);

Expand All @@ -135,6 +136,12 @@ ToolBox::~ToolBox()
{
if (parent != nullptr)
parent->removeKeyListener (this);

stopTimer (Timers::WindowDrag);
stopTimer (Timers::AutoSave);

if (autoSaveFile.existsAsFile() && lastLocation.hasIdenticalContentTo (autoSaveFile))
autoSaveFile.deleteFile();
}

void ToolBox::mouseDown (const juce::MouseEvent& e)
Expand All @@ -153,7 +160,7 @@ void ToolBox::loadDialog()
{
auto dialog = std::make_unique<FileBrowserDialog>(NEEDS_TRANS ("Cancel"), NEEDS_TRANS ("Load"),
juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
getLastLocation(), getFileFilter());
lastLocation, getFileFilter());
dialog->setAcceptFunction ([&, dlg=dialog.get()]
{
loadGUI (dlg->getFile());
Expand All @@ -171,10 +178,13 @@ void ToolBox::saveDialog()
{
auto dialog = std::make_unique<FileBrowserDialog>(NEEDS_TRANS ("Cancel"), NEEDS_TRANS ("Save"),
juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::canSelectFiles | juce::FileBrowserComponent::warnAboutOverwriting,
getLastLocation(), getFileFilter());
lastLocation, getFileFilter());
dialog->setAcceptFunction ([&, dlg=dialog.get()]
{
saveGUI (dlg->getFile());
auto xmlFile = dlg->getFile();
saveGUI (xmlFile);
setLastLocation (xmlFile);

builder.closeOverlayDialog();
});
dialog->setCancelFunction ([&]
Expand All @@ -199,13 +209,20 @@ void ToolBox::loadGUI (const juce::File& xmlFile)
setLastLocation (xmlFile);
}

void ToolBox::saveGUI (const juce::File& xmlFile)
bool ToolBox::saveGUI (const juce::File& xmlFile)
{
juce::FileOutputStream stream (xmlFile);
stream.setPosition (0);
stream.truncate();
stream.writeString (builder.getConfigTree().toXmlString());
setLastLocation (xmlFile);
juce::TemporaryFile temp (xmlFile);

if (auto stream = temp.getFile().createOutputStream())
{
auto saved = stream->writeString (builder.getConfigTree().toXmlString());
stream.reset();

if (saved)
return temp.overwriteTargetFileWithTemporary();
}

return false;
}

void ToolBox::setSelectedNode (const juce::ValueTree& node)
Expand Down Expand Up @@ -324,9 +341,12 @@ bool ToolBox::keyPressed (const juce::KeyPress& key)
return false;
}

void ToolBox::timerCallback ()
void ToolBox::timerCallback (int timer)
{
updateToolboxPosition();
if (timer == Timers::WindowDrag)
updateToolboxPosition();
else if (timer == Timers::AutoSave)
saveGUI (autoSaveFile);
}

void ToolBox::setToolboxPosition (PositionOption position)
Expand All @@ -337,9 +357,9 @@ void ToolBox::setToolboxPosition (PositionOption position)
resizeCorner.setVisible (isDetached);

if (isDetached)
stopTimer ();
stopTimer (Timers::WindowDrag);
else
startTimer (100);
startTimer (Timers::WindowDrag, 100);
}

void ToolBox::updateToolboxPosition()
Expand All @@ -357,42 +377,18 @@ void ToolBox::updateToolboxPosition()
setBounds (parentBounds.getRight(), parentBounds.getY(), width, height);
}

juce::File ToolBox::getLastLocation() const
void ToolBox::setLastLocation(juce::File file)
{
juce::File lastLocation;

juce::ApplicationProperties appProperties;
appProperties.setStorageParameters (ToolBox::getApplicationPropertyStorage());
if (auto* p = appProperties.getUserSettings())
lastLocation = juce::File (p->getValue (IDs::lastLocation));

if (lastLocation.exists())
return lastLocation;

auto start = juce::File::getSpecialLocation (juce::File::currentExecutableFile);
while (start.exists() && !start.isRoot() && start.getFileName() != "Builds")
start = start.getParentDirectory();

if (start.getFileName() == "Builds")
{
auto resources = start.getSiblingFile ("Resources");
if (resources.isDirectory())
return resources;
if (file.isDirectory())
file = file.getChildFile ("magic.xml");

auto sources = start.getSiblingFile ("Source");
if (sources.isDirectory())
return sources;
}
lastLocation = file;

return juce::File::getSpecialLocation (juce::File::currentExecutableFile);
}
autoSaveFile.deleteFile();
autoSaveFile = lastLocation.getParentDirectory()
.getNonexistentChildFile (file.getFileNameWithoutExtension() + ".sav", ".xml");

void ToolBox::setLastLocation(juce::File file)
{
juce::ApplicationProperties appProperties;
appProperties.setStorageParameters (ToolBox::getApplicationPropertyStorage());
if (auto* p = appProperties.getUserSettings())
p->setValue (IDs::lastLocation, file.getFullPathName());
startTimer (Timers::AutoSave, 10000);
}

std::unique_ptr<juce::FileFilter> ToolBox::getFileFilter() const
Expand Down
Loading

0 comments on commit 9bb30f8

Please sign in to comment.