GUIEditor clears now existing elements before loading new ones.

Thanks @Artem Shoobovych for the patch (#323)
I changed it a bit, but basically same idea.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6210 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2021-05-02 12:59:55 +00:00
parent 9417b22b86
commit 22a7280e95
2 changed files with 32 additions and 13 deletions

View File

@ -598,9 +598,14 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
}
// load a gui file
case EGET_FILE_SELECTED:
{
dialog = (IGUIFileOpenDialog*)e.GUIEvent.Caller;
Environment->loadGUI(core::stringc(dialog->getFileName()).c_str());
core::stringc guiFilename(core::stringc(dialog->getFileName()).c_str());
clearParentElements();
Environment->loadGUI(guiFilename, Parent);
EditorWindow->updateTree();
break;
}
case EGET_MENU_ITEM_SELECTED:
{
@ -614,18 +619,7 @@ bool CGUIEditWorkspace::OnEvent(const SEvent &e)
//! file commands
case EGUIEDMC_FILE_NEW:
// clear all elements belonging to our parent
setSelectedElement(0);
MouseOverElement = 0;
el = Parent;
grab();
// remove all children
while(Children.end() != el->getChildren().begin())
el->removeChild(*(el->getChildren().begin()));
// attach to parent again
el->addChild(this);
drop();
clearParentElements();
break;
case EGUIEDMC_FILE_LOAD:
Environment->addFileOpenDialog(L"Please select a GUI file to open", false, this);
@ -843,10 +837,32 @@ void CGUIEditWorkspace::removeChild(IGUIElement* child)
{
IGUIElement::removeChild(child);
// TODO: Can anyone find out why the workspace removes itself when it has no more children
// and document it here?
if (Children.empty())
remove();
}
void CGUIEditWorkspace::clearParentElements()
{
setSelectedElement(0);
MouseOverElement = 0;
IGUIElement * el = Parent;
grab();
if ( el->isMyChild(Environment->getFocus()) )
Environment->setFocus(0);
// remove all children except first one (EditorWindow)
while (!el->getChildren().empty())
{
el->removeChild(*(el->getChildren().begin()));
}
el->addChild(this);
drop();
}
void CGUIEditWorkspace::updateAbsolutePosition()
{

View File

@ -46,6 +46,9 @@ namespace gui
//! Removes a child.
virtual void removeChild(IGUIElement* child);
//! Remove all gui elements from parent except this one
virtual void clearParentElements();
//! draws the element and its children
virtual void draw();