Skip to content

Commit fac8c4e

Browse files
committed
More list related changes
1 parent 8336982 commit fac8c4e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Editor/EditorManager.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ namespace RTEGUI {
136136
rootCollectionBox->SetDrawBackground(false);
137137
m_RootControl = rootCollectionBox;
138138
m_CollectionBoxList->AddItem(m_RootControl->GetName());
139+
m_CollectionBoxList->SetSelectedIndex(0);
139140
}
140141

141142
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -229,14 +230,12 @@ namespace RTEGUI {
229230
s_SelectionInfo.SetControl(control);
230231
}
231232
UpdateCollectionBoxChildrenList(dynamic_cast<GUICollectionBox *>(control));
232-
m_ControlsInCollectionBoxList->SetSelectedIndex(-1);
233233
}
234234
} else {
235235
// Deselection if clicked on no list item
236236
ClearCurrentSelection();
237237
// When nothing is selected populate the children list with the root control's children to show any "loose" controls
238238
UpdateCollectionBoxChildrenList(dynamic_cast<GUICollectionBox *>(m_RootControl));
239-
m_ControlsInCollectionBoxList->SetSelectedIndex(-1);
240239
}
241240
RemoveFocus();
242241
}
@@ -290,6 +289,9 @@ namespace RTEGUI {
290289
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
291290

292291
void EditorManager::UpdateCollectionBoxList() const {
292+
// Store the last collection box that was selected before the update so it can be selected if it still exists, if no selection then select root
293+
std::string lastSelection = (m_CollectionBoxList->GetSelectedIndex() != -1) ? m_CollectionBoxList->GetSelected()->m_Name : "";
294+
293295
m_CollectionBoxList->ClearList();
294296
m_CollectionBoxList->AddItem(m_RootControl->GetName());
295297

@@ -305,6 +307,14 @@ namespace RTEGUI {
305307
for (GUIControl *control : *m_WorkspaceManager->GetControlList()) {
306308
if ((collectionBox = dynamic_cast<GUICollectionBox *>(control)) && collectionBox->GetParent() == m_RootControl) { recursiveAddItem(collectionBox, "\t"); }
307309
}
310+
311+
for (const GUIListBox::Item *listEntry : *m_CollectionBoxList->GetItemList()) {
312+
if (listEntry->m_Name == lastSelection) {
313+
m_CollectionBoxList->SetSelectedIndex(listEntry->m_ID);
314+
break;
315+
}
316+
m_CollectionBoxList->SetSelectedIndex(0);
317+
}
308318
}
309319

310320
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -385,7 +395,7 @@ namespace RTEGUI {
385395
void EditorManager::ClearCurrentSelection() const {
386396
s_SelectionInfo.ClearSelection();
387397
m_PropertyPage->ClearValues();
388-
m_CollectionBoxList->SetSelectedIndex(-1);
398+
m_CollectionBoxList->SetSelectedIndex(0);
389399
m_ControlsInCollectionBoxList->ClearList();
390400

391401
// Clear focused control of the manager itself so it doesn't persist between selection changes (e.g property page line remains selected after clearing or changing selection)

0 commit comments

Comments
 (0)