From b6ead6ace69d6dc84636dcfc3af74156a9d1dea6 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Fri, 21 Feb 2025 17:51:42 +0100 Subject: [PATCH] Fix more TODOs, implement opening helpfiles from object browser --- Source/Dialogs/ObjectBrowserDialog.h | 15 ++++++++++----- Source/Object.cpp | 2 +- Source/ObjectGrid.cpp | 2 +- Source/Pd/Library.cpp | 25 +++++++++++++++++++++++++ Source/Pd/Library.h | 1 + 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Source/Dialogs/ObjectBrowserDialog.h b/Source/Dialogs/ObjectBrowserDialog.h index 5611d9441..2a2d85629 100644 --- a/Source/Dialogs/ObjectBrowserDialog.h +++ b/Source/Dialogs/ObjectBrowserDialog.h @@ -347,12 +347,16 @@ class ObjectViewer final : public Component { reference.showObject(objectName); }; - openHelp.onClick = [] { - // TODO: implement this! + openHelp.onClick = [this, editor, dismissMenu] { + auto const file = pd::Library::findHelpfile(objectName); + if (auto const* helpCanvas = editor->getTabComponent().openPatch(URL(file))) { + if (auto patch = helpCanvas->patch.getPointer()) { + patch->gl_edit = 0; + } + } + dismissMenu(false); }; - openHelp.setVisible(false); - SmallArray buttons = { &openHelp, &openReference }; for (auto* button : buttons) { @@ -493,7 +497,8 @@ class ObjectViewer final : public Component { auto const objectInfo = library.getObjectInfo(name); bool const valid = name.isNotEmpty() && objectInfo.isValid(); - // openHelp.setVisible(valid); + openHelp.setEnabled(pd::Library::findHelpfile(name).existsAsFile()); + openHelp.setVisible(valid); openReference.setVisible(valid); objectDragArea.setVisible(valid); diff --git a/Source/Object.cpp b/Source/Object.cpp index faa80ba84..92183031f 100644 --- a/Source/Object.cpp +++ b/Source/Object.cpp @@ -1504,7 +1504,7 @@ void Object::openHelpPatch() const cnv->pd->setThis(); if (auto* ptr = getPointer()) { - auto const file = cnv->pd->objectLibrary->findHelpfile(ptr, cnv->patch.getCurrentFile()); + auto const file = pd::Library::findHelpfile(ptr, cnv->patch.getCurrentFile()); if (!file.existsAsFile()) { cnv->pd->logMessage("Couldn't find help file"); diff --git a/Source/ObjectGrid.cpp b/Source/ObjectGrid.cpp index 3f44f9e93..924a933f6 100644 --- a/Source/ObjectGrid.cpp +++ b/Source/ObjectGrid.cpp @@ -434,7 +434,7 @@ void ObjectGrid::timerCallback() cnv->editor->nvgSurface.invalidateArea(lineArea); } - bool done = true; // TODO: use multi-timer? + bool done = true; for (int i = 0; i < 2; i++) { lineAlpha[i] = jmap(lineAlphaMultiplier[i], lineTargetAlpha[i], lineAlpha[i]); if (std::abs(lineAlpha[i] - lineTargetAlpha[i]) < 1e-5) { diff --git a/Source/Pd/Library.cpp b/Source/Pd/Library.cpp index 11ed2150d..e1ee166d7 100644 --- a/Source/Pd/Library.cpp +++ b/Source/Pd/Library.cpp @@ -379,6 +379,31 @@ String Library::getObjectOrigin(t_gobj* obj) return {}; } +File Library::findHelpfile(String const& helpName) +{ + String firstName = helpName + "-help.pd"; + String secondName = "help-" + helpName + ".pd"; + + for (auto& path : helpPaths) { + if (!path.exists()) + continue; + + for (auto const& file : OSUtils::iterateDirectory(path, false, true)) { + auto pathName = file.getFullPathName().replace("\\", "/").trimCharactersAtEnd("/"); + // Hack to make it find else/cyclone/Gem helpfiles... + pathName = pathName.replace("/9.else", "/else"); + pathName = pathName.replace("/10.cyclone", "/cyclone"); + pathName = pathName.replace("/14.gem", "/Gem"); + + if (pathName.endsWith("/" + firstName) || pathName.endsWith("/" + secondName)) { + return file; + } + } + } + + return {}; +} + File Library::findHelpfile(t_gobj* obj, File const& parentPatchFile) { String helpName; diff --git a/Source/Pd/Library.h b/Source/Pd/Library.h index e27aa8a37..f37f46286 100644 --- a/Source/Pd/Library.h +++ b/Source/Pd/Library.h @@ -41,6 +41,7 @@ class Library final : public FileSystemWatcher::Listener void filesystemChanged() override; + static File findHelpfile(String const& name); static File findHelpfile(t_gobj* obj, File const& parentPatchFile); ValueTree getObjectInfo(String const& name);