Added new dialog helpers and added Are You Sure dialogs in a few places

This commit is contained in:
AlexandreRouma 2021-12-13 03:01:06 +01:00
parent b4924a8fae
commit 964fd467f8
2 changed files with 34 additions and 16 deletions

View File

@ -3,13 +3,15 @@
#include <core.h> #include <core.h>
#include <string.h> #include <string.h>
#include <gui/style.h> #include <gui/style.h>
#include <gui/dialogs/dialog_box.h>
namespace module_manager_menu { namespace module_manager_menu {
char modName[1024]; char modName[1024];
std::vector<std::string> modTypes; std::vector<std::string> modTypes;
std::vector<std::string> toBeRemoved; std::string toBeRemoved;
std::string modTypesTxt; std::string modTypesTxt;
int modTypeId; int modTypeId;
bool confirmOpened = false;
void init() { void init() {
modName[0] = 0; modName[0] = 0;
@ -35,8 +37,6 @@ namespace module_manager_menu {
float height = ImGui::CalcTextSize("-").y; float height = ImGui::CalcTextSize("-").y;
toBeRemoved.clear();
for (auto& [name, inst] : core::moduleManager.instances) { for (auto& [name, inst] : core::moduleManager.instances) {
ImGui::TableNextRow(); ImGui::TableNextRow();
@ -50,19 +50,21 @@ namespace module_manager_menu {
ImVec2 origPos = ImGui::GetCursorPos(); ImVec2 origPos = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(origPos.x - 3, origPos.y)); ImGui::SetCursorPos(ImVec2(origPos.x - 3, origPos.y));
if (ImGui::Button(("##module_mgr_"+name).c_str(), ImVec2(height,height))) { if (ImGui::Button(("##module_mgr_"+name).c_str(), ImVec2(height,height))) {
toBeRemoved.push_back(name); toBeRemoved = name;
modified = true; confirmOpened = true;
} }
ImGui::SetCursorPos(ImVec2(origPos.x + 2, origPos.y - 5)); ImGui::SetCursorPos(ImVec2(origPos.x + 2, origPos.y - 5));
ImGui::Text("_"); ImGui::Text("_");
} }
ImGui::EndTable(); ImGui::EndTable();
for (auto& rem : toBeRemoved) {
core::moduleManager.deleteInstance(rem);
}
} }
if (ImGui::GenericDialog("module_mgr_confirm_", confirmOpened, GENERIC_DIALOG_BUTTONS_YES_NO, [](){
ImGui::Text("Deleting \"%s\". Are you sure?", toBeRemoved.c_str());
}) == GENERIC_DIALOG_BUTTON_YES) {
core::moduleManager.deleteInstance(toBeRemoved);
modified = true;
}
// Add module row with slightly different settings // Add module row with slightly different settings
ImGui::BeginTable("Module Manager Add Table", 3); ImGui::BeginTable("Module Manager Add Table", 3);

View File

@ -12,6 +12,7 @@
#include <gui/tuner.h> #include <gui/tuner.h>
#include <gui/file_dialogs.h> #include <gui/file_dialogs.h>
#include <utils/freq_formatting.h> #include <utils/freq_formatting.h>
#include <gui/dialogs/dialog_box.h>
SDRPP_MOD_INFO { SDRPP_MOD_INFO {
/* Name: */ "frequency_manager", /* Name: */ "frequency_manager",
@ -391,7 +392,14 @@ private:
ImGui::SameLine(); ImGui::SameLine();
if (_this->selectedListName == "") { style::beginDisabled(); } if (_this->selectedListName == "") { style::beginDisabled(); }
if (ImGui::Button(("-##_freq_mgr_del_lst_" + _this->name).c_str(), ImVec2(lineHeight, 0))) { if (ImGui::Button(("-##_freq_mgr_del_lst_" + _this->name).c_str(), ImVec2(lineHeight, 0))) {
if (_this->selectedListName == "") { style::endDisabled(); } _this->deleteListOpen = true;
}
if (_this->selectedListName == "") { style::endDisabled(); }
// List delete confirmation
if (ImGui::GenericDialog(("freq_manager_del_list_confirm"+_this->name).c_str(), _this->deleteListOpen, GENERIC_DIALOG_BUTTONS_YES_NO, [_this](){
ImGui::Text("Deleting list named \"%s\". Are you sure?", _this->selectedListName.c_str());
}) == GENERIC_DIALOG_BUTTON_YES) {
config.acquire(); config.acquire();
config.conf["lists"].erase(_this->selectedListName); config.conf["lists"].erase(_this->selectedListName);
_this->refreshWaterfallBookmarks(false); _this->refreshWaterfallBookmarks(false);
@ -405,9 +413,6 @@ private:
_this->selectedListName = ""; _this->selectedListName = "";
} }
} }
else {
if (_this->selectedListName == "") { style::endDisabled(); }
}
if (_this->selectedListName == "") { style::beginDisabled(); } if (_this->selectedListName == "") { style::beginDisabled(); }
//Draw buttons on top of the list //Draw buttons on top of the list
@ -454,8 +459,7 @@ private:
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
if (selectedNames.size() == 0 && _this->selectedListName != "") { style::beginDisabled(); } if (selectedNames.size() == 0 && _this->selectedListName != "") { style::beginDisabled(); }
if (ImGui::Button(("Remove##_freq_mgr_rem_" + _this->name).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) { if (ImGui::Button(("Remove##_freq_mgr_rem_" + _this->name).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) {
for (auto& _name : selectedNames) { _this->bookmarks.erase(_name); } _this->deleteBookmarksOpen = true;
_this->saveByName(_this->selectedListName);
} }
if (selectedNames.size() == 0 && _this->selectedListName != "") { style::endDisabled(); } if (selectedNames.size() == 0 && _this->selectedListName != "") { style::endDisabled(); }
ImGui::TableSetColumnIndex(2); ImGui::TableSetColumnIndex(2);
@ -470,6 +474,15 @@ private:
ImGui::EndTable(); ImGui::EndTable();
// Bookmark delete confirm dialog
// List delete confirmation
if (ImGui::GenericDialog(("freq_manager_del_list_confirm"+_this->name).c_str(), _this->deleteBookmarksOpen, GENERIC_DIALOG_BUTTONS_YES_NO, [_this](){
ImGui::Text("Deleting selected bookmaks. Are you sure?");
}) == GENERIC_DIALOG_BUTTON_YES) {
for (auto& _name : selectedNames) { _this->bookmarks.erase(_name); }
_this->saveByName(_this->selectedListName);
}
// Bookmark list // Bookmark list
if (ImGui::BeginTable(("freq_manager_bkm_table"+_this->name).c_str(), 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, 200))) { if (ImGui::BeginTable(("freq_manager_bkm_table"+_this->name).c_str(), 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(0, 200))) {
ImGui::TableSetupColumn("Name"); ImGui::TableSetupColumn("Name");
@ -786,6 +799,9 @@ private:
bool renameListOpen = false; bool renameListOpen = false;
bool selectListsOpen = false; bool selectListsOpen = false;
bool deleteListOpen = false;
bool deleteBookmarksOpen = false;
EventHandler<ImGui::WaterFall::FFTRedrawArgs> fftRedrawHandler; EventHandler<ImGui::WaterFall::FFTRedrawArgs> fftRedrawHandler;
EventHandler<ImGui::WaterFall::InputHandlerArgs> inputHandler; EventHandler<ImGui::WaterFall::InputHandlerArgs> inputHandler;