示例#1
0
文件: action.cpp 项目: mixxit/solinia
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
文件: action.cpp 项目: mixxit/solinia
bool CActionStringVectorVector::doAction (CGeorgesEditDoc &doc, bool redo, bool &modified, bool firstTime)
{
	IAction::doAction (doc, redo, modified, firstTime);

	modified = false;
	bool ok = true;
	uint index = (uint)redo;

	// Backup old value
	switch (_Type)
	{
	case DfnStructure:
		{
			// Dfn
			NLGEORGES::CFormDfn &dfn = *(doc.getDfnPtr ());

			// Add the entries
			dfn.setNumEntry (_Value[index].size ());
			uint elm;
			for (elm=0; elm<_Value[index].size (); elm++)
			{
				// Ref on the entry
				CFormDfn::CEntry &entry = dfn.getEntry (elm);

				// Get the name
				entry.setName (_Value[index][elm][0].c_str ());

				// Get the filename
				string &filename = _Value[index][elm][2];

				// Get the type
				string &type= _Value[index][elm][1];
				if ((type == "Type") || (type == "Type array"))
				{
					// Set the type
					entry.setType (doc.FormLoader, filename.c_str ());

					// Set the default value
					string &def = _Value[index][elm][3];
					entry.setDefault (def.c_str ());

					// Set the default extension
					string &ext = _Value[index][elm][4];
					entry.setFilenameExt (ext.c_str ());
				}
				else if ((type == "Dfn") || (type == "Dfn array"))
				{
					// Set the type
					entry.setDfn (doc.FormLoader, filename.c_str ());
				}
				else if (type == "Virtual Dfn")
				{
					// Set the type
					entry.setDfnPointer ();
				}
				entry.setArrayFlag ((type == "Type array") || (type == "Dfn array"));
			}
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, "");
		}
		break;
	case TypePredef:
		{
			// Type
			CType &type = *(doc.getTypePtr ());

			// Add the predef
			type.Definitions.resize (_Value[index].size ());
			uint predef;
			for (predef=0; predef<type.Definitions.size(); predef++)
			{
				// Add the label and value
				type.Definitions[predef].Label = _Value[index][predef][0];
				type.Definitions[predef].Value = _Value[index][predef][1];
			}
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, "");
		}
		break;
	default:
		nlstop;
	}

	return ok;
}
示例#3
0
文件: action.cpp 项目: mixxit/solinia
bool CActionStringVector::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 DfnParents:
		{
			// Get document pointer
			CFormDfn *dfn = doc.getDfnPtr ();
			nlassert (dfn);

			// Add the parents
			dfn->setNumParent (_Value[index].size ());

			uint parent;
			for (parent=0; parent<_Value[index].size (); parent++)
			{
				try
				{
					// Set the parent
					dfn->setParent (parent, doc.FormLoader, _Value[index][parent].c_str ());

					modified = true;
				}
				catch (Exception &e)
				{
					ok = false;
					char message[512];
					smprintf (message, 512, "Error while loading Dfn file (%s): %s", _Value[index][parent].c_str (), e.what());
					theApp.outputError (message);

					// Next parent
					parent--;
				}
			}
			modified = true;
			if (!firstTime)
				update (false, Redraw, doc, "");
		}
		break;
	case FormParents:
		{
			// Get the form
			NLGEORGES::CForm &form = *(doc.getFormPtr ());

			// Remove parent
			form.clearParents ();

			// Get the result value
			uint count = _Value[index].size ();
			uint value;
			for (value = 0; value<count; value++)
			{
				// Load the parent
				if (!_Value[index].empty ())
				{
					// Try to load the form
					NLMISC::CSmartPtr<CForm> parentForm = (CForm*)doc.FormLoader.loadForm (_Value[index][value].c_str ());
					if (parentForm)
					{
						if ((&form) != parentForm)
						{
							// Check it is the same dfn
							if (parentForm->Elements.FormDfn == form.Elements.FormDfn)
							{
								// This is the parent form selector
								if (form.insertParent (value, _Value[index][value].c_str(), parentForm))
								{
								}
								else
								{
									ok = false;
									char msg[512];
									smprintf (msg, 512, "Internal error while assign the form (%s) as parent.", _Value[index][value].c_str());
									theApp.outputError (msg);
								}
							}
							else
							{
								ok = false;
								char msg[512];
								smprintf (msg, 512, "The parent form (%s) doesn't use the same DFN than the current form.", _Value[index][value].c_str());
								theApp.outputError (msg);
							}
						}
						else
						{
							ok = false;
							char msg[512];
							smprintf (msg, 512, "Can't assign a form it self as parent.");
							theApp.outputError (msg);
						}
					}
					else
					{
						ok = false;
						char msg[512];
						smprintf (msg, 512, "Can't read the form %s.", _Value[index][value].c_str());
						theApp.outputError (msg);
					}
				}
			}
			modified = true;
			update (true, Redraw, doc, _FormName.c_str ());
		}
		break;
	/*case FormArrayReplace:
	case FormArrayAppend:
		{
			// Get the node
			const CFormDfn *parentDfn;
			uint indexDfn;
			const CFormDfn *nodeDfn;
			const CType *nodeType;
			CFormElm *node;
			UFormDfn::TEntryType type;
			bool array;
			bool parentVDfnArray;
			CForm *form=doc.getFormPtr ();
			CFormElm *elm = doc.getRootNode (slot);
			nlverify ( elm->getNodeByName (_FormName.c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true) );

			// Is a type entry ?
			if ((type == UFormDfn::EntryType) && array)
			{
				// Create the array
				bool created;
				nlverify ( elm->createNodeByName (_FormName.c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, created) );
				nlassert (node);

				// Get the atom
				CFormElmArray *arrayPtr = safe_cast<CFormElmArray*>(node);

				// Replace ?
				if (_Type == FormArrayReplace)
				{
					arrayPtr->clean ();
				}

				// For each element
				uint arraySize = arrayPtr->Elements.size();
				for (uint i=0; i<_Value[index].size (); i++)
				{
					// Name
					char name[512];
					smprintf (name, 512, "[%d]", i+arraySize);

					// Create the atom node
					nlverify ( arrayPtr->createNodeByName (name, &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, created) );
					nlassert (node);

					// Get the atom
					CFormElmAtom *atom = safe_cast<CFormElmAtom*>(node);

					// Set the value
					atom->setValue (_Value[index][i].c_str());
				}

				modified = true;
				update (true, Redraw, doc, _FormName.c_str ());
			}
		}
		break;*/
	}

	return ok;
}
示例#4
0
文件: action.cpp 项目: mixxit/solinia
CActionStringVectorVector::CActionStringVectorVector (IAction::TTypeAction type, const std::vector<std::vector<std::string> > &stringVector, 
													  CGeorgesEditDoc &doc, uint selId, uint slot) : IAction (type, selId, slot)
{
	// Set the new value
	_NewValue = stringVector;

	// Backup old value
	switch (_Type)
	{
	case DfnStructure:
		{
			// Dfn
			const NLGEORGES::CFormDfn &dfn = *(doc.getDfnPtr ());

			// Add the struct element
			_OldValue.resize (dfn.getNumEntry ());
			uint elm;
			for (elm=0; elm<_OldValue.size (); elm++)
			{
				// Resize the entry
				_OldValue[elm].resize (5);

				// Add the label and value
				_OldValue[elm][0] = dfn.getEntry (elm).getName ();
				switch (elm, dfn.getEntry (elm).getType ())
				{
				case UFormDfn::EntryType:
					_OldValue[elm][1] = dfn.getEntry (elm).getArrayFlag () ? "Type array" : "Type";
					_OldValue[elm][4] = dfn.getEntry (elm).getFilenameExt ();
					break;
				case UFormDfn::EntryDfn:
					_OldValue[elm][1] = dfn.getEntry (elm).getArrayFlag () ? "Dfn array" : "Dfn";
					break;
				case UFormDfn::EntryVirtualDfn:
					_OldValue[elm][1] = "Virtual Dfn";
					break;
				}
				_OldValue[elm][2] = dfn.getEntry (elm).getFilename ();
				_OldValue[elm][3] = dfn.getEntry (elm).getDefault ();
			}
			setLabel ("Dfn Structure", doc);
		}
		break;
	case TypePredef:
		{
			// Type
			const NLGEORGES::CType &type = *(doc.getTypePtr ());

			uint predef;
			_OldValue.resize (type.Definitions.size());
			for (predef=0; predef<_OldValue.size(); predef++)
			{
				// Add the label and value
				_OldValue[predef].resize (2);
				_OldValue[predef][0] = type.Definitions[predef].Label;
				_OldValue[predef][1] = type.Definitions[predef].Value;
			}
			setLabel ("Type Predef", doc);
		}
		break;
	}
}
示例#5
0
文件: action.cpp 项目: mixxit/solinia
CActionStringVector::CActionStringVector (IAction::TTypeAction type, const std::vector<std::string> &stringVector, CGeorgesEditDoc &doc, const char *formName, uint selId, uint slot) : IAction (type, selId, slot)
{
	// Set the new value
	_FormName = formName;
	_NewValue = stringVector;

	// Backup old value
	switch (_Type)
	{
	case DfnParents:
		{
			// Dfn
			const NLGEORGES::CFormDfn &dfn = *(doc.getDfnPtr ());

			// Add the parents
			_OldValue.resize (dfn.getNumParent ());
			uint parent;
			for (parent=0; parent<dfn.getNumParent (); parent++)
			{
				// Add the label and value
				_OldValue[parent] = dfn.getParentFilename (parent);
			}
			setLabel ("Dfn Parents", doc);
		}
		break;
	case FormParents:
		{
			// Get the form
			const NLGEORGES::CForm &form = *(doc.getFormPtr ());

			// Resize old string array
			_OldValue.resize (form.getParentCount ());

			// For each parent
			uint parent;
			for (parent=0; parent<form.getParentCount (); parent++)
			{
				// Get the parent filename
				_OldValue[parent] = form.getParentFilename (parent);
			}
			setLabel ("Form Parents", doc);
		}
		break;
/*	case FormArrayReplace:
	case FormArrayAppend:
		{
			// Get the form
			const NLGEORGES::CForm &form = *(doc.getFormPtr ());

			// Get the node
			const CFormDfn *parentDfn;
			uint indexDfn;
			const CFormDfn *nodeDfn;
			const CType *nodeType;
			CFormElm *node;
			UFormDfn::TEntryType type;
			bool array;
			bool parentVDfnArray;
			CFormElm *elm = doc.getRootNode (slot);
			nlverify ( elm->getNodeByName (formName, &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true) );

			// Get the atom
			_OldValue.clear ();
			if (node)
			{
				// Get the atom
				CFormElmArray *arrayPtr = safe_cast<CFormElmArray*>(node);

				uint size;
				nlverify (arrayPtr->getArraySize (size));
				_OldValue.resize (size);
				uint elm;
				for (elm=0; elm<_OldValue.size (); elm++)
				{
					if (arrayPtr->Elements[elm])
					{
						CFormElmAtom *atom = safe_cast<CFormElmAtom*>(arrayPtr->Elements[elm]);
						atom->getValue (_OldValue[elm], false);
					}
				}
			}
			if (_Type == FormArrayReplace)
				setLabel ("Form Array Replace", doc);
			else 
				setLabel ("Form Array Append", doc);
		}
		break;*/
	default:
		nlstop;
	}
}