Skip to content

Commit

Permalink
Rename Serial Accessory History
Browse files Browse the repository at this point in the history
Co-authored-by: Jelle Bakker <jellebakker@jb-audio.com>
  • Loading branch information
xioTechnologies and JelleBakker authored Nov 23, 2023
1 parent f7483eb commit ac54378
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
33 changes: 15 additions & 18 deletions x-IMU3-GUI/Source/Windows/SerialAccessoryTerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SerialAccessoryTerminalWindow::SerialAccessoryTerminalWindow(const juce::ValueTr
addAndMakeVisible(sendValue);
sendValue.setEditableText(true);

loadSendHistory();
loadHistory();

addAndMakeVisible(sendButton);
sendButton.onClick = [this]
Expand All @@ -21,24 +21,24 @@ SerialAccessoryTerminalWindow::SerialAccessoryTerminalWindow(const juce::ValueTr

serialAccessoryTerminal.add(uint64_t(-1), removeEscapeCharacters(sendValue.getText()));

for (const auto serial : serialHistory)
for (const auto data : history)
{
if (serial.getProperty("serial") == sendValue.getText())
if (data["data"] == sendValue.getText())
{
serialHistory.removeChild(serial, nullptr);
history.removeChild(data, nullptr);
break;
}
}

while (serialHistory.getNumChildren() >= 12)
while (history.getNumChildren() >= 12)
{
serialHistory.removeChild(serialHistory.getChild(serialHistory.getNumChildren() - 1), nullptr);
history.removeChild(history.getChild(history.getNumChildren() - 1), nullptr);
}

serialHistory.addChild({ "Serial", {{ "serial", sendValue.getText() }}}, 0, nullptr);
file.replaceWithText(serialHistory.toXmlString());
history.addChild({ "Data", {{ "data", sendValue.getText() }}}, 0, nullptr);
file.replaceWithText(history.toXmlString());

loadSendHistory();
loadHistory();
};

callbackID = devicePanel.getConnection()->addSerialAccessoryCallback(callback = [&, self = SafePointer<juce::Component>(this)](auto message)
Expand Down Expand Up @@ -145,22 +145,19 @@ juce::String SerialAccessoryTerminalWindow::removeEscapeCharacters(const juce::S
return output;
}

void SerialAccessoryTerminalWindow::loadSendHistory()
void SerialAccessoryTerminalWindow::loadHistory()
{
serialHistory = juce::ValueTree::fromXml(file.loadFileAsString());
if (serialHistory.isValid() == false)
history = juce::ValueTree::fromXml(file.loadFileAsString());
if (history.isValid() == false)
{
serialHistory = juce::ValueTree("SerialHistory");
history = juce::ValueTree("SerialAccessoryHistory");
}

sendValue.clear(juce::dontSendNotification);

juce::StringArray items;
for (const auto serial : serialHistory)
for (const auto data : history)
{
items.add(serial["serial"]);
sendValue.addItem(data["data"], sendValue.getNumItems() + 1);
}
sendValue.addItemList(items, 1);

sendValue.setText(sendValue.getNumItems() > 0 ? sendValue.getItemText(0) : "Hello World!", juce::dontSendNotification);
}
Expand Down
6 changes: 3 additions & 3 deletions x-IMU3-GUI/Source/Windows/SerialAccessoryTerminalWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class SerialAccessoryTerminalWindow : public Window
CustomComboBox sendValue;
IconButton sendButton { BinaryData::send_svg, "Send" };

juce::ValueTree serialHistory;
const juce::File file = ApplicationSettings::getDirectory().getChildFile("Serial History.xml");
juce::ValueTree history;
const juce::File file = ApplicationSettings::getDirectory().getChildFile("Serial Accessory History.xml");

std::function<void(ximu3::XIMU3_SerialAccessoryMessage)> callback;
uint64_t callbackID;

static juce::String removeEscapeCharacters(const juce::String& input);

void loadSendHistory();
void loadHistory();

juce::PopupMenu getMenu();

Expand Down

0 comments on commit ac54378

Please sign in to comment.