diff --git a/Source/Components/WelcomePanel.h b/Source/Components/WelcomePanel.h index 325ced620..1cdbdf5d8 100644 --- a/Source/Components/WelcomePanel.h +++ b/Source/Components/WelcomePanel.h @@ -891,9 +891,9 @@ class WelcomePanel final : public Component tile->onClick = [this, patchFile]() mutable { if (patchFile.existsAsFile()) { - editor->pd->autosave->checkForMoreRecentAutosave(patchFile, editor, [this, patchFile] { + editor->pd->autosave->checkForMoreRecentAutosave(patchFile, editor, [this](File patchFile, File patchPath) { editor->getTabComponent().openPatch(URL(patchFile)); - SettingsFile::getInstance()->addToRecentlyOpened(patchFile); + SettingsFile::getInstance()->addToRecentlyOpened(patchPath); }); } else { editor->pd->logError("Patch not found"); diff --git a/Source/Connection.cpp b/Source/Connection.cpp index 944bb0c9d..c33b8aedf 100644 --- a/Source/Connection.cpp +++ b/Source/Connection.cpp @@ -262,7 +262,6 @@ void Connection::render(NVGcontext* nvg) nvgStroke(nvg); }; - // TODO: refactor this outside of the render function if (cnv->shouldShowConnectionDirection()) { if (isSegmented()) { for (int i = 1; i < currentPlan.size(); i++) { @@ -1302,12 +1301,6 @@ bool Connection::straightLineIntersectsObject(Line const toCheck, SmallAr if (intersectsV || intersectsH) { return true; } - - /* - if(bounds.toFloat().intersects(toCheck.toFloat())) { - return true; - } TODO: benchmark these two options */ - // TODO: possible mark areas that have already been visited? } return false; } diff --git a/Source/Dialogs/MainMenu.h b/Source/Dialogs/MainMenu.h index de376937b..b2033a9b2 100644 --- a/Source/Dialogs/MainMenu.h +++ b/Source/Dialogs/MainMenu.h @@ -31,9 +31,9 @@ class MainMenu : public PopupMenu { auto path = File(recentlyOpenedTree.getChild(i).getProperty("Path").toString()); recentlyOpened->addItem(path.getFileName(), [path, editor]() mutable { if (path.existsAsFile()) { - editor->pd->autosave->checkForMoreRecentAutosave(path, editor, [editor, path] { - editor->getTabComponent().openPatch(URL(path)); - SettingsFile::getInstance()->addToRecentlyOpened(path); + editor->pd->autosave->checkForMoreRecentAutosave(path, editor, [editor](File patchFile, File patchPath) { + editor->getTabComponent().openPatch(URL(patchFile)); + SettingsFile::getInstance()->addToRecentlyOpened(patchPath); }); } else { editor->pd->logError("Patch not found"); diff --git a/Source/Dialogs/ThemeSettingsPanel.h b/Source/Dialogs/ThemeSettingsPanel.h index 6c7688190..35b8db163 100644 --- a/Source/Dialogs/ThemeSettingsPanel.h +++ b/Source/Dialogs/ThemeSettingsPanel.h @@ -623,13 +623,6 @@ class ThemeSettingsPanel final : public SettingsDialogPanel } } } - - /* TODO: Fix this, maybe with a LookAndFeelChanged on the property component? - for (int i = 0; i < 2; i++) { - themeSelectors[i].setColour(ComboBox::backgroundColourId, Colours::transparentBlack); - themeSelectors[i].setColour(ComboBox::outlineColourId, Colours::transparentBlack); - themeSelectors[i].setColour(ComboBox::textColourId, findColour(PlugDataColour::panelTextColourId)); - }*/ } void resized() override diff --git a/Source/Objects/ArrayObject.h b/Source/Objects/ArrayObject.h index 9a7694361..d8dca31b1 100644 --- a/Source/Objects/ArrayObject.h +++ b/Source/Objects/ArrayObject.h @@ -783,7 +783,6 @@ struct ArrayPropertiesPanel final : public PropertiesPanelProperty void valueChanged(Value& v) override { // when array parameters are changed we need to resync the canavs to PD - // TODO: do we need to protect this in a callasync also? syncCanvas(); repaint(); } diff --git a/Source/Objects/TextObject.h b/Source/Objects/TextObject.h index dd76a6634..2e7a2bd8c 100644 --- a/Source/Objects/TextObject.h +++ b/Source/Objects/TextObject.h @@ -417,8 +417,7 @@ class TextBase : public ObjectBase return; } - // TODO: this system is fragile - // If anything grabs keyboard focus when clicking an object, this will close the editor! + // Be careful, if anything grabs keyboard focus when clicking an object, this will close the editor! hideEditor(); }; diff --git a/Source/Objects/ToggleObject.h b/Source/Objects/ToggleObject.h index 5af862052..65b6277a2 100644 --- a/Source/Objects/ToggleObject.h +++ b/Source/Objects/ToggleObject.h @@ -76,7 +76,7 @@ class ToggleObject final : public ObjectBase { auto const bgColour = ::getValue(iemHelper.secondaryColour); auto const backgroundColour = convertColour(bgColour); - auto const toggledColour = convertColour(::getValue(iemHelper.primaryColour)); // TODO: don't access audio thread variables in render loop + auto const toggledColour = convertColour(::getValue(iemHelper.primaryColour)); auto const untoggledColour = convertColour(::getValue(iemHelper.primaryColour).interpolatedWith(::getValue(iemHelper.secondaryColour), 0.8f)); auto const selectedOutlineColour = convertColour(cnv->editor->getLookAndFeel().findColour(PlugDataColour::objectSelectedOutlineColourId)); auto const outlineColour = convertColour(cnv->editor->getLookAndFeel().findColour(PlugDataColour::objectOutlineColourId)); diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 3bd57fa7f..f72501341 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -806,9 +806,9 @@ void PluginEditor::filesDropped(StringArray const& files, int const x, int const auto file = File(path); if (file.exists() && file.hasFileExtension("pd")) { openedPdFiles = true; - pd->autosave->checkForMoreRecentAutosave(file, this, [this, file] { - tabComponent.openPatch(URL(file)); - SettingsFile::getInstance()->addToRecentlyOpened(file); + pd->autosave->checkForMoreRecentAutosave(file, this, [this](File patchFile, File patchPath) { + tabComponent.openPatch(URL(patchFile)); + SettingsFile::getInstance()->addToRecentlyOpened(patchPath); }); } } diff --git a/Source/Sidebar/CommandInput.h b/Source/Sidebar/CommandInput.h index 02d2e8eed..b0ac7f17b 100644 --- a/Source/Sidebar/CommandInput.h +++ b/Source/Sidebar/CommandInput.h @@ -810,7 +810,6 @@ class CommandInput final return true; } // Use default commandID mappings for other keys - // TODO: make sure we have dealt with all editor chars / commands before getting to here! if (auto const* keyMappings = editor->commandManager.getKeyMappings()) { if (auto const commandID = keyMappings->findCommandForKeyPress(key)) { editor->commandManager.invokeDirectly(commandID, false); diff --git a/Source/Sidebar/Palettes.h b/Source/Sidebar/Palettes.h index fe9ce3506..f8a0f73c5 100644 --- a/Source/Sidebar/Palettes.h +++ b/Source/Sidebar/Palettes.h @@ -86,9 +86,9 @@ class PaletteDraggableList final : public Component pasteButton.onClick = [this] { auto const clipboardText = SystemClipboard::getTextFromClipboard(); + // TODO: reimplement patch validity check if (!OfflineObjectRenderer::checkIfPatchIsValid(clipboardText)) { /* - // TODO: should we put an alert here? Needs to be themed however juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::AlertIconType::NoIcon, "Clipboard contents not valid PD objects", "Pasted text: " + clipboardText.substring(0, 200).quoted()); diff --git a/Source/TabComponent.cpp b/Source/TabComponent.cpp index cc25cc2a9..124dfb3c2 100644 --- a/Source/TabComponent.cpp +++ b/Source/TabComponent.cpp @@ -65,6 +65,15 @@ Canvas* TabComponent::openPatch(const URL& path) } auto const patch = pd->loadPatch(path); + + // If we're opening a temp file, assume it's dirty upon opening + // This is so that you can recover an autosave without directly overewriting it, but still be prompted to save if you close the autosaved patch + if(path.getLocalFile().getParentDirectory() == File::getSpecialLocation(File::tempDirectory)) + { + if(auto p = patch->getPointer()) { + canvas_dirty(p.get(), 1.0f); + } + } return openPatch(patch, true); } @@ -133,9 +142,9 @@ void TabComponent::openPatch() Dialogs::showOpenDialog([this](URL resultURL) { auto result = resultURL.getLocalFile(); if (result.exists() && result.getFileExtension().equalsIgnoreCase(".pd")) { - editor->pd->autosave->checkForMoreRecentAutosave(result, editor, [this, result, resultURL] { - openPatch(resultURL); - SettingsFile::getInstance()->addToRecentlyOpened(result); + editor->pd->autosave->checkForMoreRecentAutosave(result, editor, [this, result, resultURL](File patchFile, File patchPath) { + openPatch(URL(patchFile)); + SettingsFile::getInstance()->addToRecentlyOpened(patchPath); }); } }, diff --git a/Source/Utility/Autosave.h b/Source/Utility/Autosave.h index 3864fa428..8e8693ab2 100644 --- a/Source/Utility/Autosave.h +++ b/Source/Utility/Autosave.h @@ -38,7 +38,7 @@ class Autosave final : public Timer } // Call this whenever we load a file - static void checkForMoreRecentAutosave(File& patchPath, PluginEditor* editor, std::function callback) + static void checkForMoreRecentAutosave(File& patchPath, PluginEditor* editor, std::function callback) { auto lastAutoSavedPatch = autoSaveTree.getChildWithProperty("Path", patchPath.getFullPathName()); auto const autoSavedTime = static_cast(lastAutoSavedPatch.getProperty("LastModified")); @@ -47,20 +47,25 @@ class Autosave final : public Timer auto const timeDescription = RelativeTime((autoSavedTime - fileChangedTime) / 1000.0f).getApproximateDescription(); Dialogs::showMultiChoiceDialog( - &editor->openedDialog, editor, "Restore autosave?\n (last autosave is " + timeDescription + " newer)", [lastAutoSavedPatch, patchPath, callback](int const dontUseAutosaved) { + &editor->openedDialog, editor, "Restore autosave?\n (last autosave is " + timeDescription + " newer)", [lastAutoSavedPatch, &patchPath, callback, editor](int const dontUseAutosaved) { if (!dontUseAutosaved) { MemoryOutputStream ostream; Base64::convertFromBase64(ostream, lastAutoSavedPatch.getProperty("Patch").toString()); auto const autosavedPatch = String::fromUTF8(static_cast(ostream.getData()), ostream.getDataSize()); - patchPath.replaceWithText(autosavedPatch); - // TODO: instead of replacing, it would be better to load it as a string, (but also with the correct patch path) + + glob_forcefilename(editor->pd->generateSymbol(patchPath.getFileName().toRawUTF8()), editor->pd->generateSymbol(patchPath.getParentDirectory().getFullPathName().replaceCharacter('\\', '/').toRawUTF8())); + auto patchFile = File::createTempFile(".pd"); + patchFile.replaceWithText(autosavedPatch); + callback(patchFile, patchPath); + } + else { + callback(patchPath, patchPath); } - callback(); }, { "Yes", "No" }); } else { - callback(); + callback(patchPath, patchPath); } } diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index d9292abcc..dc0437a3a 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -15,7 +15,7 @@ void runTests(PluginEditor* editor) HelpFileErrorTest helpfileErrorTest(editor); UnitTestRunner runner; - runner.runTests({&helpfileFuzzer, &objectFuzzer, &helpfileErrorTest}, 23); + //runner.runTests({&helpfileFuzzer, &objectFuzzer, &helpfileErrorTest}, 23); }); testRunnerThread.detach(); }