From 58c02823c511ce4adef8df6f5fafc67e2b8239fd Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 12 Mar 2018 15:16:26 +0000 Subject: [PATCH] Projucer: Moved some methods into MiscUtilities --- .../Source/Application/jucer_AutoUpdater.cpp | 6 +-- .../Source/Application/jucer_CommandLine.cpp | 13 ++---- .../UI/Sidebar/jucer_ModuleTreeItems.h | 6 +-- .../Projucer/Source/Project/jucer_Module.cpp | 43 ++--------------- extras/Projucer/Source/Project/jucer_Module.h | 5 +- .../ProjectSaving/jucer_ProjectExporter.cpp | 4 +- .../Utility/Helpers/jucer_MiscUtilities.cpp | 46 +++++++++++++++++++ .../Utility/Helpers/jucer_MiscUtilities.h | 7 +++ .../Wizards/jucer_NewProjectWizardComponent.h | 4 +- 9 files changed, 72 insertions(+), 62 deletions(-) diff --git a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp index 2309c93ff7..5945125190 100644 --- a/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp +++ b/extras/Projucer/Source/Application/jucer_AutoUpdater.cpp @@ -744,7 +744,7 @@ void LatestVersionChecker::askUserForLocationToDownload (URL& newVersionToDownlo { File targetFolder (EnabledModuleList::findGlobalModulesFolder()); - if (isJuceModulesFolder (targetFolder)) + if (isJUCEModulesFolder (targetFolder)) targetFolder = targetFolder.getParentDirectory(); FileChooser chooser (TRANS("Please select the location into which you'd like to install the new version"), @@ -754,7 +754,7 @@ void LatestVersionChecker::askUserForLocationToDownload (URL& newVersionToDownlo { targetFolder = chooser.getResult(); - if (isJuceModulesFolder (targetFolder)) + if (isJUCEModulesFolder (targetFolder)) targetFolder = targetFolder.getParentDirectory(); if (targetFolder.getChildFile ("JUCE").isDirectory()) @@ -772,7 +772,7 @@ void LatestVersionChecker::askUserForLocationToDownload (URL& newVersionToDownlo return; } - if (isJuceFolder (targetFolder)) + if (isJUCEFolder (targetFolder)) { if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, TRANS("Overwrite existing JUCE folder?"), diff --git a/extras/Projucer/Source/Application/jucer_CommandLine.cpp b/extras/Projucer/Source/Application/jucer_CommandLine.cpp index 4d0f5201f8..4ec4116a33 100644 --- a/extras/Projucer/Source/Application/jucer_CommandLine.cpp +++ b/extras/Projucer/Source/Application/jucer_CommandLine.cpp @@ -99,14 +99,6 @@ namespace return files; } - static String joinLinesIntoSourceFile (StringArray& lines) - { - while (lines.size() > 10 && lines [lines.size() - 1].isEmpty()) - lines.remove (lines.size() - 1); - - return lines.joinIntoString (getLineEnding()) + getLineEnding(); - } - static void replaceFile (const File& file, const String& newText, const String& message) { std::cout << message << file.getFullPathName() << std::endl; @@ -371,7 +363,7 @@ namespace for (int i = 0; i < lines.size(); ++i) { - String& line = lines.getReference(i); + String& line = lines.getReference (i); if (options.removeTabs && line.containsChar ('\t')) { @@ -380,6 +372,7 @@ namespace for (;;) { const int tabPos = line.indexOfChar ('\t'); + if (tabPos < 0) break; @@ -761,7 +754,7 @@ namespace { hideDockIcon(); - const String appName (JUCEApplication::getInstance()->getApplicationName()); + auto appName = JUCEApplication::getInstance()->getApplicationName(); std::cout << appName << std::endl << std::endl diff --git a/extras/Projucer/Source/Project/UI/Sidebar/jucer_ModuleTreeItems.h b/extras/Projucer/Source/Project/UI/Sidebar/jucer_ModuleTreeItems.h index b99a28925b..9a03739976 100644 --- a/extras/Projucer/Source/Project/UI/Sidebar/jucer_ModuleTreeItems.h +++ b/extras/Projucer/Source/Project/UI/Sidebar/jucer_ModuleTreeItems.h @@ -111,7 +111,7 @@ public: void refreshModuleInfoIfCurrentlyShowing (bool juceModulePathChanged) { - auto isJuceModule = EnabledModuleList::isJuceModule (moduleID); + auto isJuceModule = isJUCEModule (moduleID); auto shouldRefresh = (juceModulePathChanged && isJuceModule) || (! juceModulePathChanged && ! isJuceModule); if (! shouldRefresh) @@ -170,8 +170,8 @@ private: if (exporter->isCLion()) continue; - auto key = modules.isJuceModule (moduleID) ? Ids::defaultJuceModulePath - : Ids::defaultUserModulePath; + auto key = isJUCEModule (moduleID) ? Ids::defaultJuceModulePath + : Ids::defaultUserModulePath; Value src (modulePathValueSources.add (new DependencyPathValueSource (exporter->getPathForModuleValue (moduleID), key, exporter->getTargetOSForExporter()))); diff --git a/extras/Projucer/Source/Project/jucer_Module.cpp b/extras/Projucer/Source/Project/jucer_Module.cpp index 70d72bc8e0..986fde54ef 100644 --- a/extras/Projucer/Source/Project/jucer_Module.cpp +++ b/extras/Projucer/Source/Project/jucer_Module.cpp @@ -30,11 +30,6 @@ #include "../ProjectSaving/jucer_ProjectExport_Xcode.h" //============================================================================== -static String trimCommentCharsFromStartOfLine (const String& line) -{ - return line.trimStart().trimCharactersAtStart ("*/").trimStart(); -} - static var parseModuleDesc (const StringArray& lines) { DynamicObject* o = new DynamicObject(); @@ -735,7 +730,7 @@ File EnabledModuleList::getModuleFolder (const String& moduleID) { if (shouldUseGlobalPath (moduleID)) { - if (isJuceModule (moduleID)) + if (isJUCEModule (moduleID)) return getModuleFolderFromPathIfItExists (getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString(), moduleID, project); return findUserModuleFolder (getAppSettings().getStoredPath (Ids::defaultUserModulePath).toString(), moduleID); @@ -940,36 +935,6 @@ File EnabledModuleList::findDefaultModulesFolder (Project& project) return File::getCurrentWorkingDirectory(); } -bool EnabledModuleList::isJuceModule (const String& moduleID) -{ - static StringArray juceModuleIds = - { - "juce_analytics", - "juce_audio_basics", - "juce_audio_devices", - "juce_audio_formats", - "juce_audio_plugin_client", - "juce_audio_processors", - "juce_audio_utils", - "juce_blocks_basics", - "juce_box2d", - "juce_core", - "juce_cryptography", - "juce_data_structures", - "juce_dsp", - "juce_events", - "juce_graphics", - "juce_gui_basics", - "juce_gui_extra", - "juce_opengl", - "juce_osc", - "juce_product_unlocking", - "juce_video" - }; - - return juceModuleIds.contains (moduleID); -} - void EnabledModuleList::addModuleFromUserSelectedFile() { static auto lastLocation = findDefaultModulesFolder (project); @@ -1030,12 +995,12 @@ void EnabledModuleList::addModuleOfferingToCopy (const File& f, bool isFromUserS : areMostModulesUsingGlobalPath()); } -bool isJuceFolder (const File& f) +bool isJUCEFolder (const File& f) { - return isJuceModulesFolder (f.getChildFile ("modules")); + return isJUCEModulesFolder (f.getChildFile ("modules")); } -bool isJuceModulesFolder (const File& f) +bool isJUCEModulesFolder (const File& f) { return f.isDirectory() && f.getChildFile ("juce_core").isDirectory(); } diff --git a/extras/Projucer/Source/Project/jucer_Module.h b/extras/Projucer/Source/Project/jucer_Module.h index afbd2a89c9..2c0bbd957b 100644 --- a/extras/Projucer/Source/Project/jucer_Module.h +++ b/extras/Projucer/Source/Project/jucer_Module.h @@ -31,8 +31,8 @@ class ProjectExporter; class ProjectSaver; //============================================================================== -bool isJuceModulesFolder (const File&); -bool isJuceFolder (const File&); +bool isJUCEModulesFolder (const File&); +bool isJUCEFolder (const File&); //============================================================================== struct ModuleDescription @@ -140,7 +140,6 @@ public: static File findGlobalModulesFolder(); static File findDefaultModulesFolder (Project&); - static bool isJuceModule (const String& moduleID); bool isModuleEnabled (const String& moduleID) const; diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp index 9176b9cecb..fdd7cb503e 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp @@ -516,8 +516,8 @@ String ProjectExporter::getPathForModuleString (const String& moduleID) const if (exporterPath.isEmpty() || project.getModules().shouldUseGlobalPath (moduleID)) { - auto id = EnabledModuleList::isJuceModule (moduleID) ? Ids::defaultJuceModulePath - : Ids::defaultUserModulePath; + auto id = isJUCEModule (moduleID) ? Ids::defaultJuceModulePath + : Ids::defaultUserModulePath; if (TargetOS::getThisOS() != getTargetOSForExporter()) return getAppSettings().getFallbackPathForOS (id, getTargetOSForExporter()).toString(); diff --git a/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp b/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp index 1ca5766773..7584f9ee6b 100644 --- a/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp +++ b/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp @@ -27,6 +27,21 @@ #include "../../Application/jucer_Headers.h" //============================================================================== +const char* getLineEnding() { return "\r\n"; } + +String joinLinesIntoSourceFile (StringArray& lines) +{ + while (lines.size() > 10 && lines [lines.size() - 1].isEmpty()) + lines.remove (lines.size() - 1); + + return lines.joinIntoString (getLineEnding()) + getLineEnding(); +} + +String trimCommentCharsFromStartOfLine (const String& line) +{ + return line.trimStart().trimCharactersAtStart ("*/").trimStart(); +} + String createAlphaNumericUID() { String uid; @@ -275,3 +290,34 @@ bool fileNeedsCppSyntaxHighlighting (const File& file) return CharPointer_UTF8::isValidString (fileStart, sizeof (fileStart)) && String (fileStart).trimStart().startsWith ("// -*- C++ -*-"); } + +//============================================================================== +bool isJUCEModule (const String& moduleID) noexcept +{ + static StringArray juceModuleIds = + { + "juce_analytics", + "juce_audio_basics", + "juce_audio_devices", + "juce_audio_formats", + "juce_audio_plugin_client", + "juce_audio_processors", + "juce_audio_utils", + "juce_blocks_basics", + "juce_box2d", + "juce_core", + "juce_cryptography", + "juce_data_structures", + "juce_dsp", + "juce_events", + "juce_graphics", + "juce_gui_basics", + "juce_gui_extra", + "juce_opengl", + "juce_osc", + "juce_product_unlocking", + "juce_video" + }; + + return juceModuleIds.contains (moduleID); +} diff --git a/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.h b/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.h index 947c52c92b..c7d8be4f3f 100644 --- a/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.h +++ b/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.h @@ -28,6 +28,11 @@ //============================================================================== +const char* getLineEnding(); +String joinLinesIntoSourceFile (StringArray& lines); + +String trimCommentCharsFromStartOfLine (const String& line); + String hexString8Digits (int value); String createAlphaNumericUID(); @@ -53,6 +58,8 @@ void addPlistDictionaryKeyInt (XmlElement* xml, const String& key, int value); bool fileNeedsCppSyntaxHighlighting (const File& file); +bool isJUCEModule (const String& moduleID) noexcept; + //============================================================================== int indexOfLineStartingWith (const StringArray& lines, const String& text, int startIndex); diff --git a/extras/Projucer/Source/Wizards/jucer_NewProjectWizardComponent.h b/extras/Projucer/Source/Wizards/jucer_NewProjectWizardComponent.h index 98ef3295a7..07b4003237 100644 --- a/extras/Projucer/Source/Wizards/jucer_NewProjectWizardComponent.h +++ b/extras/Projucer/Source/Wizards/jucer_NewProjectWizardComponent.h @@ -91,7 +91,7 @@ public: if (! fc.browseForDirectory()) return false; - if (isJuceModulesFolder (fc.getResult())) + if (isJUCEModulesFolder (fc.getResult())) { result = fc.getResult(); return true; @@ -406,7 +406,7 @@ public: wizard->modulesFolder = modulesPathBox.isUsingGlobalPaths ? File (getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString()) : modulesPathBox.modulesFolder; - if (! isJuceModulesFolder (wizard->modulesFolder)) + if (! isJUCEModulesFolder (wizard->modulesFolder)) { if (modulesPathBox.isUsingGlobalPaths) AlertWindow::showMessageBox (AlertWindow::AlertIconType::WarningIcon, "Invalid Global Path",