CHANGED: #1471 Apparently the *root* group needed to be serializes separately, otherwise the parser cannot read it back.

--HG--
branch : gsoc2012-gui-editor
hg/feature/sse2
dfighter1985 12 years ago
parent c7b42f0e83
commit 190a048641

@ -44,6 +44,8 @@ namespace NLGUI
std::string getProperty( const std::string &name ) const; std::string getProperty( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value ); void setProperty( const std::string &name, const std::string &value );
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
xmlNodePtr serializeGroup( xmlNodePtr parentNode, const char *type ) const;
xmlNodePtr serializeSubGroups( xmlNodePtr parentNode ) const;
virtual uint32 getMemory (); virtual uint32 getMemory ();

@ -666,6 +666,17 @@ namespace NLGUI
} }
xmlNodePtr CInterfaceGroup::serialize( xmlNodePtr parentNode, const char *type ) const 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 ); xmlNodePtr node = CCtrlBase::serialize( parentNode, type );
if( node == NULL ) if( node == NULL )
@ -700,6 +711,13 @@ namespace NLGUI
xmlNewProp( node, BAD_CAST "lua_class", xmlNewProp( node, BAD_CAST "lua_class",
BAD_CAST CWidgetManager::getInstance()->getParser()->getLuaClassAssociation( (CInterfaceGroup*)this ).c_str() ); 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; std::vector< CInterfaceGroup* >::const_iterator itr;
for( itr = _ChildrenGroups.begin(); itr != _ChildrenGroups.end(); ++itr ) for( itr = _ChildrenGroups.begin(); itr != _ChildrenGroups.end(); ++itr )
{ {

@ -240,6 +240,11 @@ namespace GUIEditor
tr( "There was an error while trying to save the project." ) ); tr( "There was an error while trying to save the project." ) );
return; return;
} }
QMessageBox::information( this,
tr( "Save successful" ),
tr( "Project saved successfully!" ) );
} }
void GUIEditorWindow::close() void GUIEditorWindow::close()

@ -43,13 +43,21 @@ namespace GUIEditor
return false; return false;
} }
if( mg->serialize( root, "root" ) == NULL ) if( mg->serializeGroup( root, "root" ) == NULL )
{ {
xmlFreeNode( root ); xmlFreeNode( root );
out.close(); out.close();
return false; return false;
} }
if( mg->serializeSubGroups( root ) == NULL )
{
xmlFreeNode( root );
out.close();
return false;
}
level = -1;
serializeTree( root ); serializeTree( root );
@ -61,7 +69,13 @@ namespace GUIEditor
bool WidgetSerializer::serializeTree( _xmlNode *node ) 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; xmlAttrPtr prop = node->properties;
while( prop != NULL ) while( prop != NULL )
@ -72,12 +86,12 @@ namespace GUIEditor
std::string value = std::string value =
std::string( reinterpret_cast< const char* >( xmlGetProp( node, BAD_CAST name.c_str() ) ) ); 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; prop = prop->next;
} }
out << ">" << std::endl; out << tabs << ">" << std::endl << std::endl;
xmlNodePtr child = node->children; xmlNodePtr child = node->children;
while( child != NULL ) while( child != NULL )
@ -86,7 +100,9 @@ namespace GUIEditor
child = child->next; child = child->next;
} }
out << "</" << node->name << ">" << std::endl; out << tabs << "</" << node->name << ">" << std::endl << std::endl;
level--;
return true; return true;
} }

@ -29,7 +29,11 @@ namespace GUIEditor
class WidgetSerializer class WidgetSerializer
{ {
public: public:
WidgetSerializer(){} WidgetSerializer()
{
level = 0;
}
~WidgetSerializer(){} ~WidgetSerializer(){}
void setFile( const std::string &name ){ fileName = name; } void setFile( const std::string &name ){ fileName = name; }
@ -40,6 +44,7 @@ namespace GUIEditor
std::string fileName; std::string fileName;
std::ofstream out; std::ofstream out;
long level;
}; };
} }

Loading…
Cancel
Save