void CDialogPDAEditor::OnBtnClickedEmailEdit()
{
	int index = pdaList.GetCurSel();
	if ( index < 0 ) {
		return;
	}
	const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );

	if ( pda ) {
		index = emailList.GetCurSel();
		if ( index < 0 ) {
			return;
		}

		CDialogPDAEditEmail editDlg;
		editDlg.SetEmail( pda->GetEmailByIndex( index ) );
		if ( editDlg.DoModal() == IDOK ) {
			idDeclEmail *email = const_cast<idDeclEmail *>( pda->GetEmailByIndex( index ) );
			email->SetText( editDlg.GetDeclText() );
			email->ReplaceSourceFileText();
			email->Invalidate();

			// Get it again to reparse
			email = const_cast<idDeclEmail *>( pda->GetEmailByIndex( index ) );

			emailList.DeleteString( index );
			emailList.InsertString( index, email->GetSubject() );
		}
	}
}
void CDialogPDAEditor::OnBtnClickedEmailAdd()
{
    int index = pdaList.GetCurSel();
    if ( index < 0 )
    {
        return;
    }
    const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );

    if ( pda )
    {
        CString name;

        // Search for an unused name
        int newIndex = pda->GetNumEmails();
        do
        {
            name.Format("%s_email_%d", pda->GetName(), newIndex++);
        }
        while ( declManager->FindType(DECL_EMAIL, name, false) != NULL );

        CDialogPDAEditEmail addDlg;
        addDlg.SetName(name);
        if ( addDlg.DoModal() == IDOK )
        {
            idDeclEmail *email = static_cast<idDeclEmail *>(declManager->CreateNewDecl(DECL_EMAIL, name, pda->GetFileName()));
            email->SetText( addDlg.GetDeclText() );
            email->ReplaceSourceFileText();
            email->Invalidate();

            pda->AddEmail( name );

            // Get it again to reparse
            const idDeclEmail *emailConst = static_cast<const idDeclEmail *>( declManager->FindType( DECL_EMAIL, name) );
            emailList.AddString( emailConst->GetSubject() );

            // Save the pda to include this email in the list
            // This has a side-effect of saving any other changes, but I don't really care right now
            OnBtnClickedSave();
        }
    }
}