Skip to content

Commit

Permalink
Loading of custom docs from txt files (#155)
Browse files Browse the repository at this point in the history
* Load custom documentation from dir

* whitespace

* removed commented code

* Fix "extra qualification" error in AWConsolidatedEditor.h
  • Loading branch information
BrokenGravityMusic authored Sep 16, 2024
1 parent 096ec6c commit b23583d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src-juce/AWConsolidatedEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,17 @@ void AWConsolidatedAudioProcessorEditor::resizeDocArea()
docString = docString.fromFirstOccurrenceOf("\n", false, false).trim();
}

// Load custom manual
juce::String customDocumentationContent;
if (loadCustomDocumentation(AirwinRegistry::registry[processor.curentProcessorIndex].name, customDocumentationContent))
{
if (!customDocumentationContent.isEmpty())
{
docString = customDocumentationContent + "\n\n# --------------------\n\n" + docString;
}
}


auto r = docAreaRect;
auto tFont = lnf->lookupFont(documentationLabel);
juce::GlyphArrangement gaTitle;
Expand Down Expand Up @@ -2330,7 +2341,7 @@ void AWConsolidatedAudioProcessorEditor::unstreamFavorites()
}
}

juce::File AWConsolidatedAudioProcessorEditor::getFavoritesFile(bool makeDir) const
juce::File AWConsolidatedAudioProcessorEditor::getSettingsDirectory(bool makeDir) const
{
juce::File res;

Expand All @@ -2347,11 +2358,52 @@ juce::File AWConsolidatedAudioProcessorEditor::getFavoritesFile(bool makeDir) co
res.createDirectory();
}

return res;
}

juce::File AWConsolidatedAudioProcessorEditor::getFavoritesFile(bool makeDir) const
{
juce::File res = getSettingsDirectory(makeDir);

res = res.getChildFile("consolidatedFavorites.xml");

return res;
}

bool AWConsolidatedAudioProcessorEditor::loadCustomDocumentation(const juce::String& fileName, juce::String& outContent) const
{
static juce::String lastFileName;
static juce::String cachedContent;

if (fileName == lastFileName)
{
// Return the cached content
outContent = cachedContent;
return true;
}

juce::File customDocumentationDir = getSettingsDirectory(false).getChildFile("customDocs");
juce::File documentationFile = customDocumentationDir.getChildFile(fileName + ".txt");

if (!documentationFile.existsAsFile())
{
return false; // The file doesn't exist
}

juce::FileInputStream fileStream(documentationFile);

if (!fileStream.openedOk())
{
return false; // The file can't be opened
}

cachedContent = fileStream.readEntireStreamAsString();
lastFileName = fileName;
outContent = cachedContent;

return true;
}

void AWConsolidatedAudioProcessorEditor::setCurrentCollection(const std::string &s)
{
processor.properties->setValue("collection", juce::String(s));
Expand Down
2 changes: 2 additions & 0 deletions src-juce/AWConsolidatedEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ class AWConsolidatedAudioProcessorEditor : public juce::AudioProcessorEditor,
void removeCurrentAsFavorite();
void streamFavorites();
void unstreamFavorites();
juce::File getSettingsDirectory(bool makeDir) const;
juce::File getFavoritesFile(bool makeDir) const;
bool loadCustomDocumentation(const juce::String& fileName, juce::String& outContent) const;
std::set<std::string> favoritesList{};

private:
Expand Down

0 comments on commit b23583d

Please sign in to comment.