diff --git a/file/system_dir.cc b/file/system_dir.cc index 56c3aba..56f3d74 100644 --- a/file/system_dir.cc +++ b/file/system_dir.cc @@ -90,6 +90,8 @@ class Dir final : public nf7::FileBase, std::unordered_set opened_; gui::Window win_; + std::vector>> trash_; + static bool TestFlags(nf7::File& f, nf7::DirItem::Flags flags) noexcept try { @@ -153,7 +155,7 @@ void Dir::UpdateTree() noexcept { if (ImGui::MenuItem("remove")) { env().ExecMain( std::make_shared(*this, "removing item"), - [this, name]() { dir_.Remove(name); }); + [this, name]() { trash_.emplace_back(name, dir_.Remove(name)); }); } if (ImGui::BeginMenu("rename")) { ItemRenamer(name); @@ -222,6 +224,28 @@ void Dir::UpdateMenu() noexcept { ItemAdder(); ImGui::EndMenu(); } + if (ImGui::BeginMenu("restore item", trash_.size() > 0)) { + for (auto itr = trash_.rbegin(); itr < trash_.rend();) { + const auto idx = std::distance(trash_.rbegin(), itr); + const auto& type = itr->second->type(); + const auto id = itr->first + " (" + type.name() + ") ##" + std::to_string(idx); + + const auto uniq = !dir_.Find(itr->first); + if (ImGui::MenuItem(id.c_str(), nullptr, false, uniq)) { + auto ctx = std::make_shared(*this, "restoring an item"); + auto p = std::make_shared>>(std::move(*itr)); // this sucks + env().ExecMain(ctx, [this, p]() mutable { + dir_.Add(p->first, std::move(p->second)); + }); + + trash_.erase(std::next(itr).base()); + itr = trash_.rbegin()+idx; + } else { + ++itr; + } + } + ImGui::EndMenu(); + } ImGui::Separator(); win_.MenuItem(); }