Ejemplo n.º 1
0
void
CMVarNode::SetValid
	(
	const JBoolean valid
	)
{
	if (valid != itsValidFlag)
		{
		itsValidFlag = valid;

		JTree* tree;
		if (GetTree(&tree))
			{
			tree->BroadcastChange(this);
			}
		}

	// pointer values update their own contents

	if (!valid || !itsIsPointerFlag)
		{
		const JSize count = GetChildCount();
		for (JIndex i=1; i<=count; i++)
			{
			(GetVarChild(i))->SetValid(valid);
			}
		}
}
void
JNamedTreeNode::SetName
	(
	const JCharacter* name
	)
{
	if (name != itsName)
		{
		itsName = name;

		NameChanged();

		JTree* tree;
		if (GetTree(&tree))
			{
			tree->BroadcastChange(this);
			}
		}
}
Ejemplo n.º 3
0
void
CMVarNode::SetValue
	(
	const JString& value
	)
{
	itsNewValueFlag = JI2B(!itsValue.IsEmpty() && value != itsValue);
	itsValue        = value;	// set *after* checking value

	itsValue.TrimWhitespace();
	if (itsOrigValue != NULL)
		{
		itsOrigValue->Clear();
		}
	ConvertToBase();

	JTree* tree;
	if (!itsCanConvertBaseFlag && GetTree(&tree))
		{
		tree->BroadcastChange(this);
		}
}
Ejemplo n.º 4
0
void
CMVarNode::ConvertToBase()
{
	itsCanConvertBaseFlag = kJFalse;
	if (itsOrigValue != NULL && !itsOrigValue->IsEmpty())
		{
		JTree* tree;
		if (itsValue != *itsOrigValue && GetTree(&tree))
			{
			tree->BroadcastChange(this);
			}
		itsValue = *itsOrigValue;
		}

	if (itsBase == 0 || itsIsPointerFlag)
		{
		return;		// avoid constructing matchList
		}

	JArray<JIndexRange> matchList;
	if (valuePattern.Match(itsValue, &matchList))
		{
		JString vStr = itsValue.GetSubstring(matchList.GetElement(2));

		JUInt v;
		itsCanConvertBaseFlag = JI2B(
			vStr.ConvertToUInt(&v, vStr.GetFirstCharacter() == '0' ? 8 : 10) &&
			(itsBase != 1 || (0 <= v && v <= 255)));
		if (itsCanConvertBaseFlag)
			{
			// save value for when base reset to "default"

			itsOrigValue = new JString(itsValue);
			assert( itsOrigValue != NULL );

			// replace only the value, preserving whatever else is there

			if (itsBase == 1)
				{
				assert( 0 <= v && v <= 255 );

				vStr  = JString(v, JString::kBase16, kJTrue);
				vStr += " '";

				JBoolean found = kJFalse;
				for (JIndex i=0; i<kSpecialCharCount; i++)
					{
					if (JCharacter(v) == kSpecialCharInfo[i].c)
						{
						vStr += kSpecialCharInfo[i].s;
						found = kJTrue;
						}
					}
				if (!found)
					{
					vStr.AppendCharacter(v);
					}

				vStr.AppendCharacter('\'');
				}
			else
				{
				vStr = JString(v, (JString::Base) itsBase, kJTrue);
				if (itsBase == 8)
					{
					vStr.PrependCharacter('0');
					}
				}

			JIndexRange r;
			itsValue.ReplaceSubstring(matchList.GetElement(2), vStr, &r);

			JTree* tree;
			if (GetTree(&tree))
				{
				tree->BroadcastChange(this);
				}
			}
		}
}