mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-11-10 04:37:37 +01:00
Added error dialog to module manager and fixed typo
This commit is contained in:
parent
6c7e952be3
commit
5483268f8f
@ -4,9 +4,12 @@
|
||||
#include <string>
|
||||
#include <gui/gui.h>
|
||||
|
||||
#define GENERIC_DIALOG_BUTTONS_OK "Ok\0"
|
||||
#define GENERIC_DIALOG_BUTTONS_YES_NO "Yes\0No\0"
|
||||
#define GENERIC_DIALOG_BUTTONS_APPLY_CANCEL "Apply\0Cancel\0"
|
||||
#define GENERIC_DIALOG_BUTTONS_OK_CANCEL "Ok\0Cancel\0"
|
||||
|
||||
#define GENERIC_DIALOG_BUTTON_OK 0
|
||||
#define GENERIC_DIALOG_BUTTON_YES 0
|
||||
#define GENERIC_DIALOG_BUTTON_NO 1
|
||||
#define GENERIC_DIALOG_BUTTON_APPLY 0
|
||||
|
@ -10,8 +10,10 @@ namespace module_manager_menu {
|
||||
std::vector<std::string> modTypes;
|
||||
std::string toBeRemoved;
|
||||
std::string modTypesTxt;
|
||||
std::string errorMessage;
|
||||
int modTypeId;
|
||||
bool confirmOpened = false;
|
||||
bool errorOpen = false;
|
||||
|
||||
void init() {
|
||||
modName[0] = 0;
|
||||
@ -66,6 +68,10 @@ namespace module_manager_menu {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
ImGui::GenericDialog("module_mgr_error_", errorOpen, GENERIC_DIALOG_BUTTONS_OK, [](){
|
||||
ImGui::Text(errorMessage.c_str());
|
||||
});
|
||||
|
||||
// Add module row with slightly different settings
|
||||
ImGui::BeginTable("Module Manager Add Table", 3);
|
||||
ImGui::TableSetupColumn("Name");
|
||||
@ -84,9 +90,14 @@ namespace module_manager_menu {
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
if (strlen(modName) == 0) { style::beginDisabled(); }
|
||||
if (ImGui::Button("+##module_mgr_add_btn", ImVec2(16,0))) {
|
||||
core::moduleManager.createInstance(modName, modTypes[modTypeId]);
|
||||
core::moduleManager.postInit(modName);
|
||||
modified = true;
|
||||
if (!core::moduleManager.createInstance(modName, modTypes[modTypeId])) {
|
||||
core::moduleManager.postInit(modName);
|
||||
modified = true;
|
||||
}
|
||||
else {
|
||||
errorMessage = "Could not create new instance of " + modTypes[modTypeId];
|
||||
errorOpen = true;
|
||||
}
|
||||
}
|
||||
if (strlen(modName) == 0) { style::endDisabled(); }
|
||||
ImGui::EndTable();
|
||||
|
@ -79,57 +79,62 @@ ModuleManager::Module_t ModuleManager::loadModule(std::string path) {
|
||||
return mod;
|
||||
}
|
||||
|
||||
void ModuleManager::createInstance(std::string name, std::string module) {
|
||||
int ModuleManager::createInstance(std::string name, std::string module) {
|
||||
if (modules.find(module) == modules.end()) {
|
||||
spdlog::error("Module '{0}' doesn't exist", module);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
if (instances.find(name) != instances.end()) {
|
||||
spdlog::error("A module instance with the name '{0}' already exists", name);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
int maxCount = modules[module].info->maxInstances;
|
||||
if (countModuleInstances(module) >= maxCount && maxCount > 0) {
|
||||
spdlog::error("Maximum number of instances reached for '{0}'", module);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
Instance_t inst;
|
||||
inst.module = modules[module];
|
||||
inst.instance = inst.module.createInstance(name);
|
||||
instances[name] = inst;
|
||||
onInstanceCreated.emit(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModuleManager::deleteInstance(std::string name) {
|
||||
int ModuleManager::deleteInstance(std::string name) {
|
||||
if (instances.find(name) == instances.end()) {
|
||||
spdlog::error("Tried to remove non-existent instance '{0}'", name);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
onInstanceDelete.emit(name);
|
||||
Instance_t inst = instances[name];
|
||||
inst.module.deleteInstance(inst.instance);
|
||||
instances.erase(name);
|
||||
onInstanceDeleted.emit(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModuleManager::deleteInstance(ModuleManager::Instance* instance) {
|
||||
int ModuleManager::deleteInstance(ModuleManager::Instance* instance) {
|
||||
spdlog::error("Delete instance not implemented");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ModuleManager::enableInstance(std::string name) {
|
||||
int ModuleManager::enableInstance(std::string name) {
|
||||
if (instances.find(name) == instances.end()) {
|
||||
spdlog::error("Cannot enable '{0}', instance doesn't exist", name);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
instances[name].instance->enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModuleManager::disableInstance(std::string name) {
|
||||
int ModuleManager::disableInstance(std::string name) {
|
||||
if (instances.find(name) == instances.end()) {
|
||||
spdlog::error("Cannot disable '{0}', instance doesn't exist", name);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
instances[name].instance->disable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ModuleManager::instanceEnabled(std::string name) {
|
||||
|
@ -78,12 +78,12 @@ public:
|
||||
|
||||
ModuleManager::Module_t loadModule(std::string path);
|
||||
|
||||
void createInstance(std::string name, std::string module);
|
||||
void deleteInstance(std::string name);
|
||||
void deleteInstance(ModuleManager::Instance* instance);
|
||||
int createInstance(std::string name, std::string module);
|
||||
int deleteInstance(std::string name);
|
||||
int deleteInstance(ModuleManager::Instance* instance);
|
||||
|
||||
void enableInstance(std::string name);
|
||||
void disableInstance(std::string name);
|
||||
int enableInstance(std::string name);
|
||||
int disableInstance(std::string name);
|
||||
bool instanceEnabled(std::string name);
|
||||
void postInit(std::string name);
|
||||
std::string getInstanceModuleName(std::string name);
|
||||
|
@ -20,7 +20,7 @@ const double DeemphasisModes[] {
|
||||
75e-6
|
||||
};
|
||||
|
||||
const char* DeemhasisModesTxt = "50µS\00075µS\000None\000";
|
||||
const char* DeemhasisModesTxt = "50µs\00075µs\000None\000";
|
||||
|
||||
class RadioModule : public ModuleManager::Instance {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user