Skip to content

Commit

Permalink
Select first shape if none were previously selected
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Jun 21, 2019
1 parent 1865ce2 commit 9c333d7
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/program/OutfitStudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2221,40 +2221,46 @@ void OutfitStudioFrame::RefreshGUIFromProj() {
outfitRoot = outfitShapes->AppendItem(shapesRoot, wxString::FromUTF8(project->OutfitName()));
}

wxTreeItemId subItem;
wxTreeItemId prevSelItem;
wxTreeItemId item;
wxTreeItemId firstItem;
wxTreeItemId prevFirstSelItem;
for (auto &shape : shapes) {
auto itemData = new ShapeItemData(shape);
subItem = outfitShapes->AppendItem(outfitRoot, wxString::FromUTF8(shape->GetName()));
outfitShapes->SetItemState(subItem, 0);
outfitShapes->SetItemData(subItem, itemData);
item = outfitShapes->AppendItem(outfitRoot, wxString::FromUTF8(shape->GetName()));
outfitShapes->SetItemState(item, 0);
outfitShapes->SetItemData(item, itemData);

if (project->IsBaseShape(shape)) {
outfitShapes->SetItemBold(subItem);
outfitShapes->SetItemTextColour(subItem, wxColour(0, 255, 0));
outfitShapes->SetItemBold(item);
outfitShapes->SetItemTextColour(item, wxColour(0, 255, 0));
}

auto it = std::find_if(prevStates.begin(), prevStates.end(), [&shape](const ShapeItemState& state) {
return state.shape == shape;
});

if (it != prevStates.end()) {
outfitShapes->SetItemState(subItem, it->state);
outfitShapes->SetItemState(item, it->state);

if (it->selected) {
outfitShapes->SelectItem(subItem);
outfitShapes->SelectItem(item);
selectedItems.push_back(itemData);

if (!prevSelItem.IsOk())
prevSelItem = subItem;
if (!prevFirstSelItem.IsOk())
prevFirstSelItem = item;
}
}

if (!firstItem.IsOk())
firstItem = item;
}

UnlockShapeSelect();

if (prevSelItem.IsOk())
activeItem = (ShapeItemData*)outfitShapes->GetItemData(prevSelItem);
if (prevFirstSelItem.IsOk())
activeItem = (ShapeItemData*)outfitShapes->GetItemData(prevFirstSelItem);
else if (firstItem.IsOk())
outfitShapes->SelectItem(firstItem);
else
activeItem = nullptr;

Expand Down

0 comments on commit 9c333d7

Please sign in to comment.