Skip to content

Commit

Permalink
Fix more TODOs, implement opening helpfiles from object browser
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 21, 2025
1 parent efe53fb commit b6ead6a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
15 changes: 10 additions & 5 deletions Source/Dialogs/ObjectBrowserDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextButton*> buttons = { &openHelp, &openReference };

for (auto* button : buttons) {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Source/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Source/ObjectGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(lineAlphaMultiplier[i], lineTargetAlpha[i], lineAlpha[i]);
if (std::abs(lineAlpha[i] - lineTargetAlpha[i]) < 1e-5) {
Expand Down
25 changes: 25 additions & 0 deletions Source/Pd/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/Pd/Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b6ead6a

Please sign in to comment.