From 1161128eec9004b8284f4a745c342361339c6152 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Fri, 21 Feb 2025 18:50:28 +0100 Subject: [PATCH] Fix more TODOs, reimplement patch validity test when pasting into palettes --- Source/Components/WelcomePanel.h | 1 - Source/Objects/NoteObject.h | 2 +- Source/Objects/ScalarObject.h | 2 +- Source/Sidebar/Palettes.h | 7 +------ Source/Utility/OfflineObjectRenderer.cpp | 12 +++++++++++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Source/Components/WelcomePanel.h b/Source/Components/WelcomePanel.h index 1cdbdf5d8..aedb08c41 100644 --- a/Source/Components/WelcomePanel.h +++ b/Source/Components/WelcomePanel.h @@ -458,7 +458,6 @@ class WelcomePanel final : public Component } tileMenu.addSeparator(); - // TODO: we may want to be clearer about this - that it doesn't delete the file on disk // Put this at he bottom, so it's not accidentally clicked on tileMenu.addItem("Remove from recently opened", onRemove); } diff --git a/Source/Objects/NoteObject.h b/Source/Objects/NoteObject.h index 0dcb3bf83..b20010b6f 100644 --- a/Source/Objects/NoteObject.h +++ b/Source/Objects/NoteObject.h @@ -222,7 +222,7 @@ class NoteObject final : public ObjectBase { needsRepaint = true; noteEditor.setInterceptsMouseClicks(!isLocked, !isLocked); - object->updateIolets(); // TODO: why? + object->updateIolets(); } void resized() override diff --git a/Source/Objects/ScalarObject.h b/Source/Objects/ScalarObject.h index 74c98ed39..7f69e44f3 100644 --- a/Source/Objects/ScalarObject.h +++ b/Source/Objects/ScalarObject.h @@ -33,7 +33,7 @@ class DrawableTemplate : public pd::MessageListener bool mouseWasDown = false; DrawableTemplate(t_scalar* object, t_word* scalarData, t_template* scalarTemplate, t_template* parentTemplate, Canvas* cnv, t_float const x, t_float const y) - : NVGComponent(reinterpret_cast(this)) // TODO: clean this up + : NVGComponent(cnv) , pd(cnv->pd) , canvas(cnv) , baseX(x) diff --git a/Source/Sidebar/Palettes.h b/Source/Sidebar/Palettes.h index f8a0f73c5..de6037304 100644 --- a/Source/Sidebar/Palettes.h +++ b/Source/Sidebar/Palettes.h @@ -86,13 +86,8 @@ class PaletteDraggableList final : public Component pasteButton.onClick = [this] { auto const clipboardText = SystemClipboard::getTextFromClipboard(); - // TODO: reimplement patch validity check if (!OfflineObjectRenderer::checkIfPatchIsValid(clipboardText)) { - /* - juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::AlertIconType::NoIcon, - "Clipboard contents not valid PD objects", - "Pasted text: " + clipboardText.substring(0, 200).quoted()); - */ + Dialogs::showMultiChoiceDialog(&editor->openedDialog, editor, "Clipboard contents not valid PD patch", [](int){}, {"Dismiss"}); return; } ValueTree itemTree("Item"); diff --git a/Source/Utility/OfflineObjectRenderer.cpp b/Source/Utility/OfflineObjectRenderer.cpp index b11b1d56a..8323a7896 100644 --- a/Source/Utility/OfflineObjectRenderer.cpp +++ b/Source/Utility/OfflineObjectRenderer.cpp @@ -356,7 +356,17 @@ ImageWithOffset OfflineObjectRenderer::patchToTempImage(String const& patch, flo bool OfflineObjectRenderer::checkIfPatchIsValid(String const& patch) { - // TODO: fix this! + // Split the patch into lines + auto lines = StringArray::fromLines(patch); + + for (const auto& line : lines) + { + if (line.startsWith("#X") || line.startsWith("#N") || line.startsWith("#A") || !line.containsNonWhitespaceChars()) + continue; + + return false; + } + return true; }