Skip to content

Commit

Permalink
Added plugin reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandoislas committed May 27, 2016
1 parent 2a407bc commit 6f2ed28
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
61 changes: 53 additions & 8 deletions Source/IconMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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++)
Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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<PluginDescription> timeSorted = im->getTimeSortedList();
String key = getKey("bypass", timeSorted[index]);
Expand All @@ -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<PluginDescription> 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<PluginDescription> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/IconMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6f2ed28

Please sign in to comment.