diff --git a/glass/src/libnt/native/cpp/NetworkTables.cpp b/glass/src/libnt/native/cpp/NetworkTables.cpp index 03004b9773..f238fbe42c 100644 --- a/glass/src/libnt/native/cpp/NetworkTables.cpp +++ b/glass/src/libnt/native/cpp/NetworkTables.cpp @@ -1084,54 +1084,58 @@ static void CreateTopicMenuItem(NetworkTablesModel* model, } } +void glass::DisplayNetworkTablesAddMenu(NetworkTablesModel* model, + std::string_view path, + NetworkTablesFlags flags) { + static char nameBuffer[kTextBufferSize]; + + if (ImGui::BeginMenu("Add new...")) { + if (ImGui::IsWindowAppearing()) { + nameBuffer[0] = '\0'; + } + + ImGui::InputTextWithHint("New item name", "example", nameBuffer, + kTextBufferSize); + std::string fullNewPath; + if (path == "/") { + path = ""; + } + fullNewPath = fmt::format("{}/{}", path, nameBuffer); + + ImGui::Text("Adding: %s", fullNewPath.c_str()); + ImGui::Separator(); + auto entry = model->GetEntry(fullNewPath); + bool exists = entry && entry->info.type != NT_Type::NT_UNASSIGNED; + bool enabled = (flags & NetworkTablesFlags_CreateNoncanonicalKeys || + nameBuffer[0] != '\0') && + !exists; + + CreateTopicMenuItem(model, fullNewPath, NT_STRING, "string", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_INTEGER, "int", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_FLOAT, "float", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_DOUBLE, "double", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_BOOLEAN, "boolean", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_STRING_ARRAY, "string[]", + enabled); + CreateTopicMenuItem(model, fullNewPath, NT_INTEGER_ARRAY, "int[]", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_FLOAT_ARRAY, "float[]", enabled); + CreateTopicMenuItem(model, fullNewPath, NT_DOUBLE_ARRAY, "double[]", + enabled); + CreateTopicMenuItem(model, fullNewPath, NT_BOOLEAN_ARRAY, "boolean[]", + enabled); + + ImGui::EndMenu(); + } +} + static void EmitParentContextMenu(NetworkTablesModel* model, const std::string& path, NetworkTablesFlags flags) { - static char nameBuffer[kTextBufferSize]; if (ImGui::BeginPopupContextItem(path.c_str())) { ImGui::Text("%s", path.c_str()); ImGui::Separator(); - if (ImGui::BeginMenu("Add new...")) { - if (ImGui::IsWindowAppearing()) { - nameBuffer[0] = '\0'; - } - - ImGui::InputTextWithHint("New item name", "example", nameBuffer, - kTextBufferSize); - std::string fullNewPath; - if (path == "/") { - fullNewPath = path + nameBuffer; - } else { - fullNewPath = fmt::format("{}/{}", path, nameBuffer); - } - - ImGui::Text("Adding: %s", fullNewPath.c_str()); - ImGui::Separator(); - auto entry = model->GetEntry(fullNewPath); - bool exists = entry && entry->info.type != NT_Type::NT_UNASSIGNED; - bool enabled = (flags & NetworkTablesFlags_CreateNoncanonicalKeys || - nameBuffer[0] != '\0') && - !exists; - - CreateTopicMenuItem(model, fullNewPath, NT_STRING, "string", enabled); - CreateTopicMenuItem(model, fullNewPath, NT_INTEGER, "int", enabled); - CreateTopicMenuItem(model, fullNewPath, NT_FLOAT, "float", enabled); - CreateTopicMenuItem(model, fullNewPath, NT_DOUBLE, "double", enabled); - CreateTopicMenuItem(model, fullNewPath, NT_BOOLEAN, "boolean", enabled); - CreateTopicMenuItem(model, fullNewPath, NT_STRING_ARRAY, "string[]", - enabled); - CreateTopicMenuItem(model, fullNewPath, NT_INTEGER_ARRAY, "int[]", - enabled); - CreateTopicMenuItem(model, fullNewPath, NT_FLOAT_ARRAY, "float[]", - enabled); - CreateTopicMenuItem(model, fullNewPath, NT_DOUBLE_ARRAY, "double[]", - enabled); - CreateTopicMenuItem(model, fullNewPath, NT_BOOLEAN_ARRAY, "boolean[]", - enabled); - - ImGui::EndMenu(); - } + DisplayNetworkTablesAddMenu(model, path, flags); ImGui::EndPopup(); } @@ -1315,7 +1319,6 @@ static void DisplayTable(NetworkTablesModel* model, } ImGui::TableHeadersRow(); - // EmitParentContextMenu(model, "/", flags); if (flags & NetworkTablesFlags_TreeView) { switch (category) { case ShowPersistent: @@ -1546,6 +1549,7 @@ void NetworkTablesView::Display() { void NetworkTablesView::Settings() { m_flags.DisplayMenu(); + DisplayNetworkTablesAddMenu(m_model, {}, m_flags.GetFlags()); } bool NetworkTablesView::HasSettings() { diff --git a/glass/src/libnt/native/include/glass/networktables/NetworkTables.h b/glass/src/libnt/native/include/glass/networktables/NetworkTables.h index a7aa514809..232076782d 100644 --- a/glass/src/libnt/native/include/glass/networktables/NetworkTables.h +++ b/glass/src/libnt/native/include/glass/networktables/NetworkTables.h @@ -194,6 +194,10 @@ void DisplayNetworkTables( NetworkTablesModel* model, NetworkTablesFlags flags = NetworkTablesFlags_Default); +void DisplayNetworkTablesAddMenu( + NetworkTablesModel* model, std::string_view path = {}, + NetworkTablesFlags flags = NetworkTablesFlags_Default); + class NetworkTablesFlagsSettings { public: explicit NetworkTablesFlagsSettings( diff --git a/outlineviewer/src/main/native/cpp/main.cpp b/outlineviewer/src/main/native/cpp/main.cpp index 660a3e1ee0..97ac9fd034 100644 --- a/outlineviewer/src/main/native/cpp/main.cpp +++ b/outlineviewer/src/main/native/cpp/main.cpp @@ -119,6 +119,7 @@ static void DisplayGui() { gui::EmitViewMenu(); if (ImGui::BeginMenu("View")) { gFlagsSettings.DisplayMenu(); + glass::DisplayNetworkTablesAddMenu(gModel.get()); ImGui::EndMenu(); }