diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp b/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp index 13163852f0..3077fa21c0 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp @@ -26,13 +26,8 @@ BEGIN_JUCE_NAMESPACE //============================================================================== -KnownPluginList::KnownPluginList() -{ -} - -KnownPluginList::~KnownPluginList() -{ -} +KnownPluginList::KnownPluginList() {} +KnownPluginList::~KnownPluginList() {} void KnownPluginList::clear() { @@ -101,6 +96,8 @@ namespace { return t1 != t2 || t1 == Time(); } + + enum { menuIdBase = 0x324503f4 }; } bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const @@ -138,7 +135,7 @@ bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier, { const PluginDescription* const d = types.getUnchecked(i); - if (d->fileOrIdentifier == fileOrIdentifier) + if (d->fileOrIdentifier == fileOrIdentifier && d->pluginFormatName == format.getName()) { if (timesAreDifferent (d->lastFileModTime, getPluginFileModTime (fileOrIdentifier))) needsRescanning = true; @@ -201,41 +198,43 @@ void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files, } //============================================================================== -class PluginSorter +struct PluginSorter { -public: - KnownPluginList::SortMethod method; - - PluginSorter() noexcept {} + PluginSorter (KnownPluginList::SortMethod method_) noexcept : method (method_) {} int compareElements (const PluginDescription* const first, const PluginDescription* const second) const { int diff = 0; - if (method == KnownPluginList::sortByCategory) - diff = first->category.compareLexicographically (second->category); - else if (method == KnownPluginList::sortByManufacturer) - diff = first->manufacturerName.compareLexicographically (second->manufacturerName); - else if (method == KnownPluginList::sortByFileSystemLocation) - diff = first->fileOrIdentifier.replaceCharacter ('\\', '/') - .upToLastOccurrenceOf ("/", false, false) - .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/') - .upToLastOccurrenceOf ("/", false, false)); + switch (method) + { + case KnownPluginList::sortByCategory: diff = first->category.compareLexicographically (second->category); break; + case KnownPluginList::sortByManufacturer: diff = first->manufacturerName.compareLexicographically (second->manufacturerName); break; + case KnownPluginList::sortByFileSystemLocation: diff = lastPathPart (first->fileOrIdentifier).compare (lastPathPart (second->fileOrIdentifier)); break; + default: break; + } if (diff == 0) diff = first->name.compareLexicographically (second->name); return diff; } + +private: + static String lastPathPart (const String& path) + { + return path.replaceCharacter ('\\', '/').upToLastOccurrenceOf ("/", false, false); + } + + KnownPluginList::SortMethod method; }; void KnownPluginList::sort (const SortMethod method) { if (method != defaultOrder) { - PluginSorter sorter; - sorter.method = method; + PluginSorter sorter (method); types.sort (sorter, true); sendChangeMessage(); @@ -270,11 +269,54 @@ void KnownPluginList::recreateFromXml (const XmlElement& xml) } //============================================================================== -const int menuIdBase = 0x324503f4; - // This is used to turn a bunch of paths into a nested menu structure. -struct PluginFilesystemTree +class PluginFilesystemTree { +public: + void buildTree (const Array & allPlugins) + { + for (int i = 0; i < allPlugins.size(); ++i) + { + String path (allPlugins.getUnchecked(i) + ->fileOrIdentifier.replaceCharacter ('\\', '/') + .upToLastOccurrenceOf ("/", false, false)); + + if (path.substring (1, 2) == ":") + path = path.substring (2); + + addPlugin (allPlugins.getUnchecked(i), path); + } + + optimise(); + } + + void addToMenu (PopupMenu& m, const OwnedArray & allPlugins) const + { + int i; + for (i = 0; i < subFolders.size(); ++i) + { + const PluginFilesystemTree* const sub = subFolders.getUnchecked(i); + + PopupMenu subMenu; + sub->addToMenu (subMenu, allPlugins); + + #if JUCE_MAC + // avoid the special AU formatting nonsense on Mac.. + m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu); + #else + m.addSubMenu (sub->folder, subMenu); + #endif + } + + for (i = 0; i < plugins.size(); ++i) + { + PluginDescription* const plugin = plugins.getUnchecked(i); + + m.addItem (allPlugins.indexOf (plugin) + menuIdBase, + plugin->name, true, false); + } + } + private: String folder; OwnedArray subFolders; @@ -327,51 +369,6 @@ private: } } } - -public: - void buildTree (const Array & allPlugins) - { - for (int i = 0; i < allPlugins.size(); ++i) - { - String path (allPlugins.getUnchecked(i) - ->fileOrIdentifier.replaceCharacter ('\\', '/') - .upToLastOccurrenceOf ("/", false, false)); - - if (path.substring (1, 2) == ":") - path = path.substring (2); - - addPlugin (allPlugins.getUnchecked(i), path); - } - - optimise(); - } - - void addToMenu (PopupMenu& m, const OwnedArray & allPlugins) const - { - int i; - for (i = 0; i < subFolders.size(); ++i) - { - const PluginFilesystemTree* const sub = subFolders.getUnchecked(i); - - PopupMenu subMenu; - sub->addToMenu (subMenu, allPlugins); - -#if JUCE_MAC - // avoid the special AU formatting nonsense on Mac.. - m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu); -#else - m.addSubMenu (sub->folder, subMenu); -#endif - } - - for (i = 0; i < plugins.size(); ++i) - { - PluginDescription* const plugin = plugins.getUnchecked(i); - - m.addItem (allPlugins.indexOf (plugin) + menuIdBase, - plugin->name, true, false); - } - } }; //============================================================================== @@ -380,8 +377,7 @@ void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) c Array sorted; { - PluginSorter sorter; - sorter.method = sortMethod; + PluginSorter sorter (sortMethod); for (int i = 0; i < types.size(); ++i) sorted.addSorted (sorter, types.getUnchecked(i)); diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h index a1f2f5f18c..dee4b73efa 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h @@ -146,12 +146,10 @@ public: void sort (const SortMethod method); //============================================================================== - /** Creates some XML that can be used to store the state of this list. - */ + /** Creates some XML that can be used to store the state of this list. */ XmlElement* createXml() const; - /** Recreates the state of this list from its stored XML format. - */ + /** Recreates the state of this list from its stored XML format. */ void recreateFromXml (const XmlElement& xml); diff --git a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp index 6d2ecd045d..e9ea822ed2 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp +++ b/modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp @@ -74,10 +74,7 @@ int PluginListComponent::getNumRows() return list.getNumTypes(); } -void PluginListComponent::paintListBoxItem (int row, - Graphics& g, - int width, int height, - bool rowIsSelected) +void PluginListComponent::paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected) { if (rowIsSelected) g.fillAll (findColour (TextEditor::highlightColourId)); @@ -128,21 +125,11 @@ void PluginListComponent::optionsMenuCallback (int result) { switch (result) { - case 1: - list.clear(); - break; + case 1: list.clear(); break; - case 2: - list.sort (KnownPluginList::sortAlphabetically); - break; - - case 3: - list.sort (KnownPluginList::sortByCategory); - break; - - case 4: - list.sort (KnownPluginList::sortByManufacturer); - break; + case 2: list.sort (KnownPluginList::sortAlphabetically); break; + case 3: list.sort (KnownPluginList::sortByCategory); break; + case 4: list.sort (KnownPluginList::sortByManufacturer); break; case 5: { @@ -159,11 +146,8 @@ void PluginListComponent::optionsMenuCallback (int result) { const PluginDescription* const desc = list.getType (listBox.getSelectedRow()); - if (desc != nullptr) - { - if (File (desc->fileOrIdentifier).existsAsFile()) - File (desc->fileOrIdentifier).getParentDirectory().startAsProcess(); - } + if (desc != nullptr && File (desc->fileOrIdentifier).existsAsFile()) + File (desc->fileOrIdentifier).getParentDirectory().startAsProcess(); break; } @@ -277,7 +261,6 @@ void PluginListComponent::scanFor (AudioPluginFormat* format) aw.addButton (TRANS("Cancel"), 0, KeyPress::escapeKey); aw.addProgressBarComponent (progress); - aw.enterModalState(); MessageManager::getInstance()->runDispatchLoopUntil (300); @@ -286,8 +269,7 @@ void PluginListComponent::scanFor (AudioPluginFormat* format) for (;;) { - aw.setMessage (TRANS("Testing:\n\n") - + scanner.getNextPluginFileThatWillBeScanned()); + aw.setMessage (TRANS("Testing:\n\n") + scanner.getNextPluginFileThatWillBeScanned()); MessageManager::getInstance()->runDispatchLoopUntil (100); diff --git a/modules/juce_audio_processors/scanning/juce_PluginListComponent.h b/modules/juce_audio_processors/scanning/juce_PluginListComponent.h index 09e07842e3..97520a4fb9 100644 --- a/modules/juce_audio_processors/scanning/juce_PluginListComponent.h +++ b/modules/juce_audio_processors/scanning/juce_PluginListComponent.h @@ -36,10 +36,11 @@ add, remove and sort them. */ class JUCE_API PluginListComponent : public Component, + public FileDragAndDropTarget, public ListBoxModel, - public ChangeListener, - public ButtonListener, // (can't use Button::Listener due to idiotic VC2005 bug) - public Timer + private ChangeListener, + private ButtonListener, // (can't use Button::Listener due to idiotic VC2005 bug) + private Timer { public: //============================================================================== @@ -61,21 +62,15 @@ public: /** @internal */ void resized(); /** @internal */ - bool isInterestedInFileDrag (const StringArray& files); + bool isInterestedInFileDrag (const StringArray&); /** @internal */ - void filesDropped (const StringArray& files, int, int); + void filesDropped (const StringArray&, int, int); /** @internal */ int getNumRows(); /** @internal */ - void paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected); + void paintListBoxItem (int row, Graphics&, int width, int height, bool rowIsSelected); /** @internal */ void deleteKeyPressed (int lastRowSelected); - /** @internal */ - void buttonClicked (Button* b); - /** @internal */ - void changeListenerCallback (ChangeBroadcaster*); - /** @internal */ - void timerCallback(); private: //============================================================================== @@ -86,11 +81,15 @@ private: PropertiesFile* propertiesToUse; int typeToScan; - void scanFor (AudioPluginFormat* format); + void scanFor (AudioPluginFormat*); static void optionsMenuStaticCallback (int result, PluginListComponent*); void optionsMenuCallback (int result); void updateList(); + void buttonClicked (Button*); + void changeListenerCallback (ChangeBroadcaster*); + void timerCallback(); + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginListComponent); };