CHANGED: #1471 Keys are now parsed from the config files, and then serialized on save.

--HG--
branch : gsoc2012-gui-editor
This commit is contained in:
dfighter1985 2012-08-18 20:28:56 +02:00
parent c532f23ac1
commit a0559ee680
4 changed files with 84 additions and 0 deletions

View file

@ -151,6 +151,7 @@ namespace NLGUI
bool setupTree (xmlNodePtr cur, CWidgetManager::SMasterGroup *parentGroup);
bool setupTreeNode (xmlNodePtr cur, CGroupContainer *parentGroup);
void savePointerSettings( xmlNodePtr node );
void saveKeySettings( xmlNodePtr node );
void addModule( std::string name, IParserModule *module );
IParserModule* getModuleFor( std::string name ) const;
@ -350,6 +351,7 @@ namespace NLGUI
bool editorMode;
std::map< std::string, VariableData > variableCache;
std::map< std::string, std::string > pointerSettings;
std::map< std::string, std::map< std::string, std::string > > keySettings;
public:
void initLUA();
@ -379,6 +381,7 @@ namespace NLGUI
bool serializeVariables( xmlNodePtr parentNode ) const;
bool serializeProcs( xmlNodePtr parentNode ) const;
bool serializePointerSettings( xmlNodePtr parentNode ) const;
bool serializeKeySettings( xmlNodePtr parentNode ) const;
};
}

View file

@ -85,6 +85,7 @@ namespace NLGUI
virtual bool serializeVariables( xmlNodePtr parentNode ) const = 0;
virtual bool serializeProcs( xmlNodePtr parentNode ) const = 0;
virtual bool serializePointerSettings( xmlNodePtr parentNode ) const = 0;
virtual bool serializeKeySettings( xmlNodePtr parentNode ) const = 0;
};
}

View file

@ -478,6 +478,11 @@ namespace NLGUI
// todo hulud interface syntax error
nlwarning ("could not read all styles");
}
if( !strcmp((char*)curNode->name,"key" ) )
{
if( editorMode )
saveKeySettings( curNode );
}
// If define and style oks, try to parse "1st pass" objets (define, options....).
else if ( !strcmp((char*)curNode->name,"template") )
{
@ -1576,6 +1581,43 @@ namespace NLGUI
}
}
void CInterfaceParser::saveKeySettings( xmlNodePtr node )
{
if( node == NULL )
return;
xmlAttrPtr prop = node->properties;
std::string name( reinterpret_cast< char* >( xmlGetProp( node, BAD_CAST "name" ) ) );
if( name.empty() )
return;
std::string key;
std::string value;
std::map< std::string, std::string > propMap;
while( prop != NULL )
{
key = std::string( reinterpret_cast< const char* >( prop->name ) );
value = std::string( reinterpret_cast< char* >( prop->children->content ) );
if( key == "name" )
{
prop = prop->next;
continue;
}
propMap[ key ] = value;
prop = prop->next;
}
if( propMap.empty() )
return;
keySettings[ name ] = propMap;
}
void CInterfaceParser::addModule( std::string name, IParserModule *module )
{
std::map< std::string, IParserModule* >::iterator itr =
@ -3071,5 +3113,36 @@ namespace NLGUI
return true;
}
bool CInterfaceParser::serializeKeySettings( xmlNodePtr parentNode ) const
{
if( parentNode == NULL )
return false;
std::map< std::string, std::map< std::string, std::string > >::const_iterator itr;
for( itr = keySettings.begin(); itr != keySettings.end(); ++itr )
{
xmlNodePtr node = xmlNewNode( NULL, BAD_CAST "key" );
if( node == NULL )
return false;
xmlAddChild( parentNode, node );
xmlSetProp( node, BAD_CAST "name", BAD_CAST itr->first.c_str() );
const std::map< std::string, std::string > &settings = itr->second;
std::map< std::string, std::string >::const_iterator itr2;
for( itr2 = settings.begin(); itr2 != settings.end(); ++itr2 )
{
const std::string &key = itr2->first;
const std::string &value = itr2->second;
xmlSetProp( node, BAD_CAST key.c_str(), BAD_CAST value.c_str() );
}
}
return true;
}
}

View file

@ -50,6 +50,13 @@ namespace GUIEditor
return false;
}
if( !CWidgetManager::getInstance()->getParser()->serializeKeySettings( root ) )
{
xmlFreeNode( root );
out.close();
return false;
}
if( !CWidgetManager::getInstance()->getParser()->serializePointerSettings( root ) )
{