//-----------------------------------------------------------------------------
// Purpose: Invokes the replace texture dialog.
//-----------------------------------------------------------------------------
void CTextureBrowser::OnReplace(void)
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if(!pDoc)
		return;

	CReplaceTexDlg dlg(pDoc->GetSelection()->GetCount());

	dlg.m_strFind = m_cTextureWindow.szCurTexture;

	if(dlg.DoModal() != IDOK)
		return;
	
	// mark undo position
	GetHistory()->MarkUndoPosition(pDoc->GetSelection()->GetList(), "Replace Textures");

	if(dlg.m_bMarkOnly)
	{
		pDoc->SelectObject(NULL, scClear);	// clear selection first
	}

	dlg.DoReplaceTextures();

	//EndDialog(IDOK);

	if (m_bUsed)
	{
		SetUsed(TRUE);
	}
}
//-----------------------------------------------------------------------------
// Purpose: Invokes the texture replace dialog.
//-----------------------------------------------------------------------------
void CFaceEditMaterialPage::OnReplace( void )
{
	// Set the material tool current.
	SetMaterialPageTool( MATERIALPAGETOOL_MATERIAL );

	//
	// get active map doc
	//
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if( !pDoc )
		return;

	// ready the replace dialog
	CReplaceTexDlg dlg( pDoc->GetSelection()->GetCount() );

	// get the texture to replace -- the default texture?!
	dlg.m_strFind = GetDefaultTextureName();

	//
	// open replace dialog -- modal
	//
	if( dlg.DoModal() != IDOK )
		return;
	
	// mark undo position
	GetHistory()->MarkUndoPosition( pDoc->GetSelection()->GetList(), "Replace Textures" );

	if( dlg.m_bMarkOnly )
	{
		pDoc->SelectObject( NULL, scClear );	// clear selection first
	}

	dlg.DoReplaceTextures();
}