/** * Handles all of the little problems associated with renaming a folder. */ void MaterialTreeView::RenameMaterial( HTREEITEM item, const char *originalName ) { CTreeCtrl &tree = GetTreeCtrl(); const idMaterial *material = declManager->FindMaterial( originalName ); MaterialDoc *pMaterial; //pMaterial = materialDocManager->GetInProgressDoc(material); //if(!pMaterial) { pMaterial = materialDocManager->CreateMaterialDoc( const_cast<idMaterial *>( material ) ); //} //Remove our old quick lookup value materialToTree.Remove( originalName ); //Generate the new name idStr materialName; HTREEITEM parent = tree.GetParentItem( item ); DWORD parentType = tree.GetItemData( parent ); if( parentType == TYPE_MATERIAL_FOLDER ) { //Need to include the material folder materialName = GetMediaPath( parent, TYPE_MATERIAL_FOLDER ); materialName += "/"; } materialName += tree.GetItemText( item ); //Add it to our quick lookup materialToTree.Set( materialName, item ); //Finally make the change internalChange = true; pMaterial->SetMaterialName( materialName, false ); internalChange = false; }
/** * Makes sure that a rename operation can be performed after a label edit is complete and * performs the folder or material rename. */ void MaterialTreeView::OnTvnEndlabeledit( NMHDR *pNMHDR, LRESULT *pResult ) { LPNMTVDISPINFO pTVDispInfo = reinterpret_cast<LPNMTVDISPINFO>( pNMHDR ); *pResult = 0; if( pTVDispInfo->item.pszText ) { //Convert any edited text to lower case to keep the name canonical idStr newLabel = pTVDispInfo->item.pszText; newLabel.ToLower(); strncpy( pTVDispInfo->item.pszText, newLabel.c_str(), pTVDispInfo->item.cchTextMax ); CTreeCtrl &tree = GetTreeCtrl(); DWORD type = tree.GetItemData( pTVDispInfo->item.hItem ); if( type == TYPE_MATERIAL ) { MaterialDoc *pMaterial = materialDocManager->GetCurrentMaterialDoc(); //Remove our old quick lookup value materialToTree.Remove( pMaterial->name.c_str() ); //Generate the new name idStr material; HTREEITEM parent = tree.GetParentItem( pTVDispInfo->item.hItem ); DWORD parentType = tree.GetItemData( parent ); if( parentType == TYPE_MATERIAL_FOLDER ) { //Need to include the material folder material = GetMediaPath( parent, TYPE_MATERIAL_FOLDER ); material += "/"; } material += pTVDispInfo->item.pszText; if( declManager->FindMaterial( material, false ) ) { //Can't rename because it conflicts with an existing file MessageBox( "Unable to rename material because it conflicts with another material", "Error" ); } else { //Add it to our quick lookup materialToTree.Set( material, pTVDispInfo->item.hItem ); //Finally make the change internalChange = true; pMaterial->SetMaterialName( material ); internalChange = false; renamedFolder = pTVDispInfo->item.hItem; PostMessage( MSG_RENAME_MATERIAL_COMPLETE ); *pResult = 1; } } else if( type == TYPE_MATERIAL_FOLDER ) { //Clean up the quicktree with the current tree before we allow the edit to commit CleanLookupTrees( pTVDispInfo->item.hItem ); //Store some data so the we can make the appropriate changes after the commit renamedFolder = pTVDispInfo->item.hItem; affectedMaterials.Clear(); GetMaterialPaths( renamedFolder, &affectedMaterials ); PostMessage( MSG_RENAME_FOLDER_COMPLETE ); RenameMaterialFolderModifier *mod = new RenameMaterialFolderModifier( materialDocManager, pTVDispInfo->item.pszText, this, pTVDispInfo->item.hItem, tree.GetItemText( pTVDispInfo->item.hItem ) ); materialDocManager->AddMaterialUndoModifier( mod ); *pResult = 1; } } }
/** * Performs a redo operation of a renamed material. */ void RenameMaterialModifier::Redo() { MaterialDoc *material = manager->CreateMaterialDoc(oldName); material->SetMaterialName(materialName, false); }