From 190a048641f3c0875fba64c21bb797d835794131 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 10 Aug 2012 17:10:01 +0200 Subject: [PATCH] CHANGED: #1471 Apparently the *root* group needed to be serializes separately, otherwise the parser cannot read it back. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/interface_group.h | 2 ++ code/nel/src/gui/interface_group.cpp | 18 +++++++++++++ .../plugins/gui_editor/gui_editor_window.cpp | 5 ++++ .../plugins/gui_editor/widget_serializer.cpp | 26 +++++++++++++++---- .../plugins/gui_editor/widget_serializer.h | 7 ++++- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 05b8b3bdc..12e83dda8 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -44,6 +44,8 @@ namespace NLGUI std::string getProperty( const std::string &name ) const; void setProperty( const std::string &name, const std::string &value ); xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + xmlNodePtr serializeGroup( xmlNodePtr parentNode, const char *type ) const; + xmlNodePtr serializeSubGroups( xmlNodePtr parentNode ) const; virtual uint32 getMemory (); diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index d672b01e3..7f0f3c1e3 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -666,6 +666,17 @@ namespace NLGUI } xmlNodePtr CInterfaceGroup::serialize( xmlNodePtr parentNode, const char *type ) const + { + xmlNodePtr node = serializeGroup( parentNode, type ); + if( node == NULL ) + return NULL; + + serializeSubGroups( node ); + + return node; + } + + xmlNodePtr CInterfaceGroup::serializeGroup( xmlNodePtr parentNode, const char *type ) const { xmlNodePtr node = CCtrlBase::serialize( parentNode, type ); if( node == NULL ) @@ -700,6 +711,13 @@ namespace NLGUI xmlNewProp( node, BAD_CAST "lua_class", BAD_CAST CWidgetManager::getInstance()->getParser()->getLuaClassAssociation( (CInterfaceGroup*)this ).c_str() ); + return node; + } + + xmlNodePtr CInterfaceGroup::serializeSubGroups( xmlNodePtr parentNode ) const + { + xmlNodePtr node = parentNode; + std::vector< CInterfaceGroup* >::const_iterator itr; for( itr = _ChildrenGroups.begin(); itr != _ChildrenGroups.end(); ++itr ) { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index d615f078c..c991e458a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -240,6 +240,11 @@ namespace GUIEditor tr( "There was an error while trying to save the project." ) ); return; } + + QMessageBox::information( this, + tr( "Save successful" ), + tr( "Project saved successfully!" ) ); + } void GUIEditorWindow::close() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp index bf6a9f83e..14f311b63 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp @@ -43,13 +43,21 @@ namespace GUIEditor return false; } - if( mg->serialize( root, "root" ) == NULL ) + if( mg->serializeGroup( root, "root" ) == NULL ) { xmlFreeNode( root ); out.close(); return false; } + if( mg->serializeSubGroups( root ) == NULL ) + { + xmlFreeNode( root ); + out.close(); + return false; + } + + level = -1; serializeTree( root ); @@ -61,7 +69,13 @@ namespace GUIEditor bool WidgetSerializer::serializeTree( _xmlNode *node ) { - out << "<" << node->name; + level++; + + std::string tabs; + for( int i = 0; i < level; i++ ) + tabs.push_back( '\t' ); + + out << tabs << "<" << node->name; xmlAttrPtr prop = node->properties; while( prop != NULL ) @@ -72,12 +86,12 @@ namespace GUIEditor std::string value = std::string( reinterpret_cast< const char* >( xmlGetProp( node, BAD_CAST name.c_str() ) ) ); - out << " " << name << "=\"" << value << "\"" << std::endl; + out << " " << name << "=\"" << value << "\"" << std::endl << tabs; prop = prop->next; } - out << ">" << std::endl; + out << tabs << ">" << std::endl << std::endl; xmlNodePtr child = node->children; while( child != NULL ) @@ -86,7 +100,9 @@ namespace GUIEditor child = child->next; } - out << "name << ">" << std::endl; + out << tabs << "name << ">" << std::endl << std::endl; + + level--; return true; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.h index 16f88cdd4..a67adf6fb 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.h @@ -29,7 +29,11 @@ namespace GUIEditor class WidgetSerializer { public: - WidgetSerializer(){} + WidgetSerializer() + { + level = 0; + } + ~WidgetSerializer(){} void setFile( const std::string &name ){ fileName = name; } @@ -40,6 +44,7 @@ namespace GUIEditor std::string fileName; std::ofstream out; + long level; }; }