@@ -73,6 +73,8 @@ struct Model { | |||||
/** Returns the module or plugin manual URL, whichever exists. */ | /** Returns the module or plugin manual URL, whichever exists. */ | ||||
std::string getManualUrl(); | std::string getManualUrl(); | ||||
void appendContextMenu(ui::Menu* menu); | void appendContextMenu(ui::Menu* menu); | ||||
bool isFavorite(); | |||||
void setFavorite(bool favorite); | |||||
}; | }; | ||||
@@ -239,8 +239,9 @@ struct ModelBox : widget::OpaqueWidget { | |||||
mw->dragEnabled() = false; | mw->dragEnabled() = false; | ||||
} | } | ||||
// Toggle favorite | |||||
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | ||||
setFavorite(!isFavorite()); | |||||
model->setFavorite(!model->isFavorite()); | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
@@ -305,27 +306,6 @@ struct ModelBox : widget::OpaqueWidget { | |||||
menu->addChild(createMenuLabel(model->name)); | menu->addChild(createMenuLabel(model->name)); | ||||
menu->addChild(createMenuLabel(model->plugin->brand)); | menu->addChild(createMenuLabel(model->plugin->brand)); | ||||
model->appendContextMenu(menu); | model->appendContextMenu(menu); | ||||
menu->addChild(new ui::MenuSeparator); | |||||
menu->addChild(createBoolMenuItem("Favorite", | |||||
[=]() { | |||||
return isFavorite(); | |||||
}, | |||||
[=](bool favorite) { | |||||
setFavorite(favorite); | |||||
} | |||||
)); | |||||
} | |||||
bool isFavorite() { | |||||
const settings::ModuleInfo* mi = settings::getModuleInfo(model->plugin->slug, model->slug); | |||||
return mi && mi->favorite; | |||||
} | |||||
void setFavorite(bool favorite) { | |||||
settings::ModuleInfo& mi = settings::moduleInfos[model->plugin->slug][model->slug]; | |||||
mi.favorite = favorite; | |||||
} | } | ||||
}; | }; | ||||
@@ -4,6 +4,7 @@ | |||||
#include <plugin.hpp> | #include <plugin.hpp> | ||||
#include <asset.hpp> | #include <asset.hpp> | ||||
#include <system.hpp> | #include <system.hpp> | ||||
#include <settings.hpp> | |||||
#include <string.hpp> | #include <string.hpp> | ||||
#include <tag.hpp> | #include <tag.hpp> | ||||
#include <ui/Menu.hpp> | #include <ui/Menu.hpp> | ||||
@@ -178,6 +179,28 @@ void Model::appendContextMenu(ui::Menu* menu) { | |||||
system::openDirectory(plugin->path); | system::openDirectory(plugin->path); | ||||
})); | })); | ||||
} | } | ||||
// Favorite | |||||
menu->addChild(createBoolMenuItem("Favorite", | |||||
[=]() { | |||||
return isFavorite(); | |||||
}, | |||||
[=](bool favorite) { | |||||
setFavorite(favorite); | |||||
} | |||||
)); | |||||
} | |||||
bool Model::isFavorite() { | |||||
const settings::ModuleInfo* mi = settings::getModuleInfo(plugin->slug, slug); | |||||
return mi && mi->favorite; | |||||
} | |||||
void Model::setFavorite(bool favorite) { | |||||
settings::ModuleInfo& mi = settings::moduleInfos[plugin->slug][slug]; | |||||
mi.favorite = favorite; | |||||
} | } | ||||