From 6f2ed283ed7a8e33e9c6a42db52cf97c2aa8a810 Mon Sep 17 00:00:00 2001 From: Rolando Islas Date: Fri, 27 May 2016 14:48:06 -0700 Subject: [PATCH] Added plugin reordering --- Source/IconMenu.cpp | 61 +++++++++++++++++++++++++++++++++++++++------ Source/IconMenu.hpp | 2 +- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Source/IconMenu.cpp b/Source/IconMenu.cpp index cb0049f..1041b2d 100644 --- a/Source/IconMenu.cpp +++ b/Source/IconMenu.cpp @@ -59,7 +59,7 @@ class IconMenu::PluginListWindow : public DocumentWindow IconMenu& owner; }; -IconMenu::IconMenu() : INDEX_EDIT(1000000), INDEX_BYPASS(2000000), INDEX_DELETE(3000000) +IconMenu::IconMenu() : INDEX_EDIT(1000000), INDEX_BYPASS(2000000), INDEX_DELETE(3000000), INDEX_MOVE_UP(4000000), INDEX_MOVE_DOWN(5000000) { // Initiialization formatManager.addDefaultFormats(); @@ -224,6 +224,7 @@ void IconMenu::timerCallback() menu.addItem(1, "Preferences"); menu.addItem(2, "Edit Plugins"); menu.addSeparator(); + menu.addSectionHeader("Active Plugins"); // Active plugins int time = 0; for (int i = 0; i < activePluginList.getNumTypes(); i++) @@ -234,17 +235,24 @@ void IconMenu::timerCallback() String key = getKey("bypass", timeSorted[i]); bool bypass = getAppProperties().getUserSettings()->getBoolValue(key); options.addItem(INDEX_BYPASS + i, "Bypass", true, bypass); + options.addSeparator(); + options.addItem(INDEX_MOVE_UP + i, "Move Up", i > 0); + options.addItem(INDEX_MOVE_DOWN + i, "Move Down", i < timeSorted.size() - 1); + options.addSeparator(); options.addItem(INDEX_DELETE + i, "Delete"); PluginDescription plugin = getNextPluginOlderThanTime(time); menu.addSubMenu(plugin.name, options); } menu.addSeparator(); + menu.addSectionHeader("Avaliable Plugins"); // All plugins knownPluginList.addToMenu(menu, pluginSortMethod); } else { menu.addItem(1, "Quit"); + menu.addSeparator(); + menu.addItem(2, "Delete Plugin States"); } #if JUCE_MAC || JUCE_LINUX menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this), ModalCallbackFunction::forComponent(menuInvocationCallback, this)); @@ -276,10 +284,18 @@ void IconMenu::mouseDown(const MouseEvent& e) void IconMenu::menuInvocationCallback(int id, IconMenu* im) { // Right click - if ((!im->menuIconLeftClicked) && id == 1) + if ((!im->menuIconLeftClicked)) { - im->savePluginStates(); - return JUCEApplication::getInstance()->quit(); + if (id == 1) + { + im->savePluginStates(); + return JUCEApplication::getInstance()->quit(); + } + if (id == 2) + { + im->deletePluginStates(); + return im->loadActivePlugins(); + } } #if JUCE_MAC // Click elsewhere @@ -330,8 +346,6 @@ void IconMenu::menuInvocationCallback(int id, IconMenu* im) // Add plugin else if (im->knownPluginList.getIndexChosenByMenu(id) > -1) { - im->deletePluginStates(); - PluginDescription plugin = *im->knownPluginList.getType(im->knownPluginList.getIndexChosenByMenu(id)); String key = getKey("order", plugin); int t = time(0); @@ -345,8 +359,6 @@ void IconMenu::menuInvocationCallback(int id, IconMenu* im) // Bypass plugin else if (id >= im->INDEX_BYPASS && id < im->INDEX_BYPASS + 1000000) { - im->deletePluginStates(); - int index = id - im->INDEX_BYPASS; std::vector timeSorted = im->getTimeSortedList(); String key = getKey("bypass", timeSorted[index]); @@ -366,6 +378,39 @@ void IconMenu::menuInvocationCallback(int id, IconMenu* im) if (PluginWindow* const w = PluginWindow::getWindowFor(f, PluginWindow::Normal)) w->toFront(true); } + // Move plugin up the list + else if (id >= im->INDEX_MOVE_UP && id < im->INDEX_MOVE_UP + 1000000) + { + im->savePluginStates(); + std::vector timeSorted = im->getTimeSortedList(); + PluginDescription toMove = timeSorted[id - im->INDEX_MOVE_UP]; + for (int i = 0; i < timeSorted.size(); i++) + { + bool move = getKey("move", toMove).equalsIgnoreCase(getKey("move", timeSorted[i])); + getAppProperties().getUserSettings()->setValue(getKey("order", timeSorted[i]), move ? i : i+1); + if (move) + getAppProperties().getUserSettings()->setValue(getKey("order", timeSorted[i-1]), i+1); + } + im->loadActivePlugins(); + } + // Move plugin down the list + else if (id >= im->INDEX_MOVE_DOWN && id < im->INDEX_MOVE_DOWN + 1000000) + { + im->savePluginStates(); + std::vector timeSorted = im->getTimeSortedList(); + PluginDescription toMove = timeSorted[id - im->INDEX_MOVE_DOWN]; + for (int i = 0; i < timeSorted.size(); i++) + { + bool move = getKey("move", toMove).equalsIgnoreCase(getKey("move", timeSorted[i])); + getAppProperties().getUserSettings()->setValue(getKey("order", timeSorted[i]), move ? i+2 : i+1); + if (move) + { + getAppProperties().getUserSettings()->setValue(getKey("order", timeSorted[i + 1]), i + 1); + i++; + } + } + im->loadActivePlugins(); + } // Update menu im->startTimer(50); } diff --git a/Source/IconMenu.hpp b/Source/IconMenu.hpp index c256e64..98ea96c 100644 --- a/Source/IconMenu.hpp +++ b/Source/IconMenu.hpp @@ -21,7 +21,7 @@ class IconMenu : public SystemTrayIconComponent, private Timer, public ChangeLis void changeListenerCallback(ChangeBroadcaster* changed); static String getKey(String type, PluginDescription plugin); - const int INDEX_EDIT, INDEX_BYPASS, INDEX_DELETE; + const int INDEX_EDIT, INDEX_BYPASS, INDEX_DELETE, INDEX_MOVE_UP, INDEX_MOVE_DOWN; private: #if JUCE_MAC std::string exec(const char* cmd);