Пример #1
0
void IAction::update (bool updateLeftView, TUpdateRightView rightViewFlag, CGeorgesEditDoc &doc, const char *_FormName)
{
	// Right and left view
	CGeorgesEditView *rightView = doc.getRightView ();
	nlassert (rightView);
	CLeftView *leftView = doc.getLeftView ();
	nlassert (leftView);

	// Update left view ?
	if (updateLeftView)
		doc.updateDocumentStructure ();

	// Set the current view..
	uint subSelection = leftView->getCurrentSelectionId ();
	if (subSelection != _SelId)
	{
		doc.changeSubSelection (_SelId, NULL);
		return;
	}

	if (leftView->getCurrentSelectionId () == 1)
	{
		rightView->HeaderDialog.getFromDocument (*doc.getHeaderPtr ());
	}
	else if (doc.isType ())
	{
		rightView->TypeDialog.getFromDocument (*(doc.getTypePtr()));
	}
	else if (doc.isDfn ())
	{
		rightView->DfnDialog.getFromDocument (*(doc.getDfnPtr()));
	}
	else if (doc.isForm ())
	{
		if (rightViewFlag == DoNothing)
		{
		}
		else if (rightViewFlag == UpdateLabels)
		{
			rightView->FormDialog.updateLabels ();
		}
		else if (rightViewFlag == UpdateValues)
		{
			rightView->FormDialog.updateValues ();
		}
		else if (rightViewFlag == Redraw)
		{
			rightView->FormDialog.getFromDocument ();
		}
	}
}
Пример #2
0
bool CActionString::doAction (CGeorgesEditDoc &doc, bool redo, bool &modified, bool firstTime)
{
	IAction::doAction (doc, redo, modified, firstTime);

	modified = false;
	bool ok = true;
	uint index = (uint)redo;
	switch (_Type)
	{
	case TypeType:
		{
			CType *type = doc.getTypePtr ();
			type->Type = (CType::TType)(atoi (_Value[index].c_str ()));
			modified = true;
			update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case TypeUI:
		{
			CType *type = doc.getTypePtr ();
			type->UIType = (CType::TUI)(atoi (_Value[index].c_str ()));
			modified = true;
			update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case TypeDefault:
		{
			CType *type = doc.getTypePtr ();
			type->Default = _Value[index];
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case TypeMin:
		{
			CType *type = doc.getTypePtr ();
			type->Min = _Value[index];
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case TypeMax:
		{
			CType *type = doc.getTypePtr ();
			type->Max = _Value[index];
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case TypeIncrement:
		{
			CType *type = doc.getTypePtr ();
			type->Increment = _Value[index];
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case FormTypeValue:
	case FormValue:
		{
			// Empty ?
			if (!_Value[index].empty ())
			{
				// Get / create the node
				const CFormDfn *parentDfn;
				uint indexDfn;
				const CFormDfn *nodeDfn;
				const CType *nodeType;
				CFormElm *node;
				UFormDfn::TEntryType type;
				bool array;
				bool created;
				CForm *form=doc.getFormPtr ();
				CFormElm *elm = doc.getRootNode (_Slot);
				nlverify ( elm->createNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
					&nodeDfn, &nodeType, &node, type, array, created) );
				nlassert (node);

				// Set the atom value
				CFormElmAtom *atom = safe_cast<CFormElmAtom*> (node);
				atom->setValue (_Value[index].c_str ());
				modified = true;

				if (firstTime)
					update (created, UpdateLabels, doc, _FormName.c_str ());
				else
					update (created, UpdateValues, doc, _FormName.c_str ());
			}
			else
			{
				if (FormTypeValue == _Type)
				{
					// Get the node
					const CFormDfn *parentDfn;
					uint indexDfn;
					const CFormDfn *nodeDfn;
					const CType *nodeType;
					CFormElm *node;
					UFormDfn::TEntryType type;
					bool array;
					bool parentVDnfArray;
					CForm *form=doc.getFormPtr ();
					CFormElm *elm = doc.getRootNode (_Slot);
					nlverify ( elm->getNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
						&nodeDfn, &nodeType, &node, type, array, parentVDnfArray, true, NLGEORGES_FIRST_ROUND) );
					nlassert (node);
					CFormElmAtom *atom = safe_cast<CFormElmAtom*> (node);
					atom->setValue ("");
				}
				else
				{
					// Remove the node
					const CFormDfn *parentDfn;
					uint indexDfn;
					const CFormDfn *nodeDfn;
					const CType *nodeType;
					CFormElm *node;
					UFormDfn::TEntryType type;
					bool array;
					CForm *form=doc.getFormPtr ();
					CFormElm *elm = doc.getRootNode (_Slot);
					nlverify ( elm->deleteNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
						&nodeDfn, &nodeType, &node, type, array) );
					nlassert ((FormTypeValue == _Type)||(node == NULL));
				}

				modified = true;

				update (true, UpdateValues, doc, _FormName.c_str ());
			}
		}
		break;
	case HeaderVersion:
		{
			uint v0, v1;
			if (sscanf (_Value[index].c_str (), "Version %d.%d", &v0, &v1)==2)
			{
				CFileHeader *header = doc.getHeaderPtr ();
				header->MajorVersion = v0;
				header->MinorVersion = v1;
				modified = true;
				update (false, Redraw, doc, _FormName.c_str ());
			}
		}
		break;
	case HeaderState:
		{
			CFileHeader *header = doc.getHeaderPtr ();
			header->State = (CFileHeader::TState)atoi (_Value[index].c_str ());
			modified = true;
			update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case HeaderComments:
		{
			doc.getHeaderPtr ()->Comments = _Value[index];
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, _FormName.c_str ());
		}
		break;
	case FormArrayRename:
		{
			int idInParent = atoi (_UserData.c_str ());

			// Get the parent node
			const CFormDfn *parentDfn;
			uint indexDfn;
			const CFormDfn *nodeDfn;
			const CType *nodeType;
			CFormElm *node;
			UFormDfn::TEntryType type;
			bool array;
			bool vdfnArray;
			CForm *form=doc.getFormPtr ();
			CFormElm *elm = doc.getRootNode (_Slot);
			nlverify ( elm->getNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
				&nodeDfn, &nodeType, &node, type, array, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
			if (node)
			{
				CFormElmArray* array = safe_cast<CFormElmArray*> (node->getParent ());
				array->Elements[idInParent].Name = _Value[index];
				modified = true;
				update (true, DoNothing, doc, _FormName.c_str ());
			}
		}
		break;
	case FormArrayInsert:
		{
			int idInParent = atoi (_NewValue.c_str ());

			// Insert ?
			if (redo)
			{
				// Get the parent node
				const CFormDfn *parentDfn;
				uint indexDfn;
				const CFormDfn *nodeDfn;
				const CType *nodeType;
				CFormElm *parentNode;
				UFormDfn::TEntryType type;
				bool array;
				CForm *form=doc.getFormPtr ();
				CFormElm *elm = doc.getRootNode (_Slot);
				nlverify ( elm->arrayInsertNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
					&nodeDfn, &nodeType, &parentNode, type, array, true, idInParent) );
				modified = true;
			}
			else
			{
				// Get the parent node
				const CFormDfn *parentDfn;
				uint indexDfn;
				const CFormDfn *nodeDfn;
				const CType *nodeType;
				CFormElm *parentNode;
				UFormDfn::TEntryType type;
				bool array;
				CForm *form=doc.getFormPtr ();
				CFormElm *elm = doc.getRootNode (_Slot);
				nlverify ( elm->arrayDeleteNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
					&nodeDfn, &nodeType, &parentNode, type, array, true, idInParent) );
				modified = true;
			}

			update (true, Redraw, doc, _FormName.c_str ());
		}
		break;
	default:
		nlstop;
	}

	return ok;
}
Пример #3
0
CActionString::CActionString (IAction::TTypeAction type, const char *newValue, CGeorgesEditDoc &doc, const char *formName, const char *userData, uint selId, uint slot) : IAction (type, selId, slot)
{
	// Set the new value
	_NewValue = newValue;
	_FormName = formName;
	_Log[1] = newValue;
	_UserData = userData;

	// Backup old value
	switch (_Type)
	{
	case TypeType:
		{
			CType *type = doc.getTypePtr ();
			_OldValue = toString ((int)(type->Type));
			setLabel ("Type Type", doc);
			_Log[1] = type->getTypeName ((UType::TType)atoi (newValue));
		}
		break;
	case TypeUI:
		{
			CType *type = doc.getTypePtr ();
			_OldValue = toString ((int)(type->UIType));
			setLabel ("Type UI", doc);
			_Log[1] = type->getUIName ((CType::TUI)atoi (newValue));
		}
		break;
	case TypeDefault:
		{
			CType *type = doc.getTypePtr ();
			_OldValue = type->Default;
			setLabel ("Type Default", doc);
		}
		break;
	case TypeMin:
		{
			CType *type = doc.getTypePtr ();
			_OldValue = type->Min;
			setLabel ("Type Min", doc);
		}
		break;
	case TypeMax:
		{
			CType *type = doc.getTypePtr ();
			_OldValue = type->Max;
			setLabel ("Type Max", doc);
		}
		break;
	case TypeIncrement:
		{
			CType *type = doc.getTypePtr ();
			_OldValue = type->Increment;
			setLabel ("Type Increment", doc);
		}
		break;
	case FormTypeValue:
	case FormValue:
		{
			// Form
			const NLGEORGES::CForm &form = *(doc.getFormPtr ());
			nlverify (doc.getRootNode (_Slot)->getValueByName (_OldValue, formName, UFormElm::NoEval, NULL));
			setLabel (formName, doc);
		}
		break;
	case HeaderVersion:
		{
			CFileHeader *header = doc.getHeaderPtr ();
			char versionText[512];
			smprintf (versionText, 512, "Version %d.%d", header->MajorVersion, header->MinorVersion);
			_OldValue = versionText;
			setLabel ("Header Version", doc);
		}
		break;
	case HeaderState:
		{
			CFileHeader *header = doc.getHeaderPtr ();
			_OldValue = toString ((int)(header->State)).c_str ();
			setLabel ("Header State", doc);
		}
		break;
	case HeaderComments:
		{
			_OldValue = doc.getHeaderPtr ()->Comments;
			setLabel ("Header Comments", doc);
		}
		break;
	case FormArrayRename:
		{
			setLabel ((formName+string (" Renamed")).c_str (), doc);
			int idInParent = atoi (_UserData.c_str ());

			// Get the parent node
			const CFormDfn *parentDfn;
			uint indexDfn;
			const CFormDfn *nodeDfn;
			const CType *nodeType;
			CFormElm *node;
			UFormDfn::TEntryType type;
			bool array;
			bool vdfnArray;
			CForm *form=doc.getFormPtr ();
			CFormElm *elm = doc.getRootNode (slot);
			nlverify ( elm->getNodeByName (_FormName.c_str (), &parentDfn, indexDfn, 
				&nodeDfn, &nodeType, &node, type, array, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
			if (node)
			{
				CFormElmArray* array = safe_cast<CFormElmArray*> (node->getParent ());
				_OldValue = array->Elements[idInParent].Name;
			}
		}
		break;
	case FormArrayInsert:
		{
			// do nothing
			setLabel ("Array Insert", doc);
		}
		break;
	default:
		nlstop;
	}
}