Пример #1
0
void CDFFDJump::OnReplace()
{
	// See if we have a subelement to replace (otherwise we just insert)
	CXmlTree::CElt curr_elt(pelt_->GetFirstChild());
	if (!curr_elt.IsEmpty())
	{
		ASSERT(valid_element_);
		CString sub_name = get_name(curr_elt);

		CString mess;
		if (curr_elt.GetFirstChild().IsEmpty())
		{
			mess.Format("This will replace the contents of %s.  "
						"The existing contents will be deleted.\n\n"
						"Are you sure you want to do this?", sub_name);
		}
		else
		{
			mess.Format("This will replace the contents of %s "
						"and all elements below it.  "
						"The existing contents will be deleted.\n\n"
						"Are you sure you want to do this?", sub_name);
		}
		if (TaskMessageBox("Replacing Element", mess, MB_YESNO) != IDYES)
			return;

		pelt_->DeleteChild(curr_elt);         // Remove the replaced node from the tree
	}

	// Work out where to put the dialog
	pos_ = update_posn(this);
	if (first_) orig_ = pos_;
	CPoint pt = get_posn(this, orig_);
	int dlg_ret;
	CXmlTree::CElt ee;

	switch (ctl_replace_.m_nMenuResult)
	{
	case ID_DFFD_INSERT_STRUCT:
		ee = pelt_->InsertNewChild("struct");

		{
			CDFFDStruct dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt,orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_USE_STRUCT:
		ee = pelt_->InsertNewChild("use_struct", NULL);

		{
			CDFFDUseStruct dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt,orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_FOR:
		ee = pelt_->InsertNewChild("for");

		{
			CDFFDFor dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_IF:
		ee = pelt_->InsertNewChild("if");
		ee.SetAttr("test", "true");

		{
			CDFFDIf dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_SWITCH:
		ee = pelt_->InsertNewChild("switch");

		{
			CDFFDSwitch dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_DATA:
		ee = pelt_->InsertNewChild("data");
		ee.SetAttr("type", "none");

		{
			CDFFDData dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	default:
		ASSERT(0);
	}

	if (dlg_ret == IDCANCEL)
	{
		// Restore elts again (remove new element, add back old elt)
		pelt_->DeleteChild(ee);
		if (!curr_elt.IsEmpty())
		{
			ASSERT(valid_element_);
			pelt_->InsertChild(curr_elt, NULL);
		}
		return;
	}

	modified_ = true;
	valid_element_ = true;

	UpdateData(TRUE);
	elt_name_ = get_name(ee);
	UpdateData(FALSE);
}