RangeSelect/MultiSelect: Demo: Delete items from menu.
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 097b219..23e2dda 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -2624,6 +2624,7 @@
// Data
ImGuiStorage Storage; // Selection set
int SelectionSize; // Number of selected items (== number of 1 in the Storage, maintained by this class). // FIXME-MULTISELECT: Imply more difficult to track with intrusive selection schemes?
+ bool QueueDeletion; // Request deleting selected items
// Functions
ExampleSelection() { Clear(); }
@@ -2668,6 +2669,8 @@
template<typename ITEM_TYPE>
int ApplyDeletionPreLoop(ImGuiMultiSelectIO* ms_io, ImVector<ITEM_TYPE>& items)
{
+ QueueDeletion = false;
+
// If current item is not selected.
if (ms_io->NavIdSelected == false) // Here 'NavIdSelected' should be == to 'GetSelected(ms_io->NavIdData)'
{
@@ -2976,7 +2979,7 @@
// FIXME-MULTISELECT: Shortcut(). Hard to demo this? May be helpful to send a helper/optional "delete" signal.
// FIXME-MULTISELECT: may turn into 'ms_io->RequestDelete' -> need HasSelection passed.
// FIXME-MULTISELECT: Test with intermediary modal dialog.
- const bool want_delete = (selection.GetSize() > 0) && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_Delete);
+ const bool want_delete = selection.QueueDeletion || ((selection.GetSize() > 0) && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_Delete));
if (want_delete)
selection.ApplyDeletionPreLoop(ms_io, items);
const int next_focus_item_idx = (int)(intptr_t)ms_io->RequestFocusItem;
@@ -3068,7 +3071,10 @@
// Right-click: context menu
if (ImGui::BeginPopupContextItem())
{
- ImGui::Text("(Testing Selectable inside an embedded popup)");
+ ImGui::BeginDisabled(!use_deletion || selection.GetSize() == 0);
+ sprintf(label, "Delete %d item(s)###DeleteSelected", selection.GetSize());
+ selection.QueueDeletion |= ImGui::Selectable(label);
+ ImGui::EndDisabled();
ImGui::Selectable("Close");
ImGui::EndPopup();
}