Skip to content

Commit 9417f63

Browse files
committed
[toolkit] Fix resource duplication when opening another dir
1 parent e35fd80 commit 9417f63

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/apps/toolkit/viewmodel/resource/explorer.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,11 @@ void ResourceExplorerViewModel::loadResources() {
371371
_routines = std::make_unique<Routines>(_gameId, nullptr, nullptr);
372372
_routines->init();
373373

374-
std::list<ResourcesItem *> resItems;
375374
_idToResItem.clear();
375+
_allResItems.clear();
376+
_expandedItemId.reset();
377+
378+
std::list<ResourcesItem *> resItems;
376379
for (auto &file : std::filesystem::directory_iterator(_resourcesPath)) {
377380
auto filename = boost::to_lower_copy(file.path().filename().string());
378381
auto extension = boost::to_lower_copy(file.path().extension().string());
@@ -403,10 +406,13 @@ void ResourceExplorerViewModel::loadResources() {
403406
_idToResItem.insert({item->id, item.get()});
404407
_allResItems.push_back(std::move(item));
405408
}
409+
406410
_resItems = std::move(resItems);
407411

408412
_resourceModule->setGameID(_gameId);
409413
_resourceModule->setGamePath(_resourcesPath);
414+
415+
_goToParentEnabled = false;
410416
}
411417

412418
void ResourceExplorerViewModel::loadTools() {
@@ -907,25 +913,25 @@ void ResourceExplorerViewModel::onResourcesListBoxDoubleClick(const ResourcesIte
907913
}
908914
expandingItem.loaded = true;
909915
}
910-
_expandedItem = expandingItem.id;
916+
_expandedItemId = expandingItem.id;
911917
_resItems = std::move(resItems);
912918
_goToParentEnabled = true;
913919
}
914920

915921
void ResourceExplorerViewModel::onGoToParentButton() {
916-
if (!_expandedItem) {
922+
if (!_expandedItemId) {
917923
return;
918924
}
919-
auto &parent = _idToResItem.at(*_expandedItem);
925+
auto &expandedItem = _idToResItem.at(*_expandedItemId);
920926
std::list<ResourcesItem *> resItems;
921927
for (auto &item : _allResItems) {
922-
if (item->parentId == parent->parentId) {
928+
if (item->parentId == expandedItem->parentId) {
923929
resItems.push_back(item.get());
924930
}
925931
}
926932
_resItems = std::move(resItems);
927-
_expandedItem = parent->parentId;
928-
_goToParentEnabled = _expandedItem.has_value();
933+
_expandedItemId = expandedItem->parentId;
934+
_goToParentEnabled = _expandedItemId.has_value();
929935
}
930936

931937
} // namespace reone

src/apps/toolkit/viewmodel/resource/explorer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ResourceExplorerViewModel : public ResourceViewModel {
230230

231231
std::map<ResourcesItemId, ResourcesItem *> _idToResItem;
232232
std::list<std::shared_ptr<ResourcesItem>> _allResItems;
233-
std::optional<ResourcesItemId> _expandedItem;
233+
std::optional<ResourcesItemId> _expandedItemId;
234234

235235
std::vector<std::shared_ptr<Tool>> _tools;
236236

0 commit comments

Comments
 (0)