// Populate tree view void AddPropertyDialog::populateTreeView() { wxIcon folderIcon; folderIcon.CopyFromBitmap(wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + FOLDER_ICON)); // DEF-DEFINED PROPERTIES { // First add a top-level category named after the entity class, and populate // it with custom keyvals defined in the DEF for that class std::string cName = _entity->getEntityClass()->getName(); wxutil::TreeModel::Row defRoot = _treeStore->AddItem(); wxDataViewItemAttr blueBold; blueBold.SetColour(wxColor(0,0,255)); blueBold.SetBold(true); defRoot[_columns.displayName] = wxVariant(wxDataViewIconText(cName, folderIcon)); defRoot[_columns.displayName] = blueBold; defRoot[_columns.propertyName] = ""; defRoot[_columns.description] = _(CUSTOM_PROPERTY_TEXT); defRoot.SendItemAdded(); // Use a CustomPropertyAdder class to visit the entityclass and add all // custom properties from it CustomPropertyAdder adder(_entity, _treeStore, _columns, defRoot.getItem()); _entity->getEntityClass()->forEachClassAttribute(boost::ref(adder)); } // REGISTRY (GAME FILE) DEFINED PROPERTIES // Ask the XML registry for the list of properties game::IGamePtr currentGame = GlobalGameManager().currentGame(); xml::NodeList propNodes = currentGame->getLocalXPath(PROPERTIES_XPATH); // Cache of property categories to GtkTreeIters, to allow properties // to be parented to top-level categories typedef std::map<std::string, wxDataViewItem> CategoryMap; CategoryMap categories; // Add each .game-specified property to the tree view for (xml::NodeList::const_iterator iter = propNodes.begin(); iter != propNodes.end(); ++iter) { // Skip hidden properties if (iter->getAttributeValue("hidden") == "1") { continue; } wxDataViewItem item; // If this property has a category, look up the top-level parent iter // or add it if necessary. std::string category = iter->getAttributeValue("category"); if (!category.empty()) { CategoryMap::iterator mIter = categories.find(category); if (mIter == categories.end()) { // Not found, add to treestore wxutil::TreeModel::Row catRow = _treeStore->AddItem(); catRow[_columns.displayName] = wxVariant(wxDataViewIconText(category, folderIcon));; catRow[_columns.propertyName] = ""; catRow[_columns.description] = ""; // Add to map mIter = categories.insert(CategoryMap::value_type(category, catRow.getItem())).first; catRow.SendItemAdded(); } // Category sorted, add this property below it item = _treeStore->AddItem(mIter->second).getItem(); _treeStore->ItemAdded(mIter->second, item); } else { // No category, add at toplevel item = _treeStore->AddItem().getItem(); _treeStore->ItemAdded(_treeStore->GetRoot(), item); } // Obtain information from the XML node and add it to the treeview std::string name = iter->getAttributeValue("match"); std::string type = iter->getAttributeValue("type"); std::string description = iter->getContent(); wxutil::TreeModel::Row row(item, *_treeStore); wxIcon icon; icon.CopyFromBitmap(PropertyEditorFactory::getBitmapFor(type)); row[_columns.displayName] = wxVariant(wxDataViewIconText(name, icon)); row[_columns.propertyName] = name; row[_columns.description] = description; _treeStore->ItemChanged(item); } }