diff --git a/tools/GUIEditor/CGUIEditWorkspace.cpp b/tools/GUIEditor/CGUIEditWorkspace.cpp index 3934c027..9934c1d8 100644 --- a/tools/GUIEditor/CGUIEditWorkspace.cpp +++ b/tools/GUIEditor/CGUIEditWorkspace.cpp @@ -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() { diff --git a/tools/GUIEditor/CGUIEditWorkspace.h b/tools/GUIEditor/CGUIEditWorkspace.h index 2c39f271..3c2b491c 100644 --- a/tools/GUIEditor/CGUIEditWorkspace.h +++ b/tools/GUIEditor/CGUIEditWorkspace.h @@ -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();