Kanzi 3.9.10
ChildContainer Interface Reference

Check validity of child names and create new names. More...

Inheritance diagram for ChildContainer:
[legend]

Public Member Functions

string GenerateUniqueChildName (string defaultName)
 Generates a unique name.
 
string GetInvalidityReasonOfNewName (string newName)
 Returns the reason why the passed name is not valid.
 

Detailed Description

Check validity of child names and create new names.

Member Function Documentation

◆ GenerateUniqueChildName()

string GenerateUniqueChildName ( string defaultName)

Generates a unique name.

In Kanzi the names of property types and sibling nodes must be unique. If in this function you propose a name that another property type or a sibling node already uses, this function uses the name, but adds _n after the name.

Parameters
defaultNameThe proposed name. If another property type or a sibling node already uses the proposed name, this function uses the proposed name as a base for the name it generates.
Returns
The unique name which you can safely use.

Examples

To create a unique name for the new child item:

// This example function shows how you can use the GenerateUniqueChildName to create unique names.
// To see how the GenerateUniqueChildName function generates unique names, run the plugin in Kanzi Studio several times.
private Node2D CreateEmptyNode2D(Node2D parentNode)
{
// The first parameter in the CreateProjectItem function defines the name of the node.
// Use the GenerateUniqueChildName function, because the names of sibling nodes must be unique.
// The second parameter defines the location of the parent node of the Empty Node 2D node you create.
// You pass this parameter to the CreateEmptyNode2D function when you call it.
var emptyNode2D = studio.ActiveProject.CreateProjectItem<EmptyNode2D>(
parentNode.GenerateUniqueChildName("Empty Node 2D"),
parentNode);
return emptyNode2D;
}

◆ GetInvalidityReasonOfNewName()

string GetInvalidityReasonOfNewName ( string newName)

Returns the reason why the passed name is not valid.

This function does not assign the name.

Parameters
newNameThe name the validity of which the function checks.
Returns
The reason why the suggested name is not valid. Null for valid names.
See also
GenerateUniqueChildName

Examples

To check whether a name for a property type is valid:

// Ask the user to provide a name for a property type.
// If the name the user provides is valid, create a property type with that name.
// If the name is not valid, show the reason why the name is not valid.
private void Execute(PluginCommandParameter parameter)
{
// Get the Property Types library in the project.
var propertyTypesLibrary = studio.ActiveProject.PropertyTypeLibrary;
// Ask the user to provide the name for the new property type.
var newName = studio.GetUserInput("Property type name", "Enter a valid name for the new property type");
// Use the GetInvalidityReasonOfNewName function to check whether the name the user entered is valid.
var invalidityReasonOfNewName = propertyTypesLibrary.GetInvalidityReasonOfNewName(newName);
if (invalidityReasonOfNewName == null)
{
// If the name is valid the GetInvalidityReasonOfNewName function returns null.
// Create a new property type with the name the user entered.
studio.ActiveProject.PropertyTypeLibrary.CreateIntProperty(newName, newName, "My Properties", 0, 100, 1);
}
else
{
// If the name is not valid the GetInvalidityReasonOfNewName function returns the reason.
// Show the reason why the name is not valid in a dialog box.
studio.ShowMessageBox(invalidityReasonOfNewName, true);
}
}

To check whether a name for a project item is valid:

// Ask the user to provide a name for a new Page node.
// If the name the user provides is valid, create a Page node with that name.
// If the name is not valid, show the reason why the name is not valid.
private void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node under which to create a Page node with a valid name.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Ask the user to provide the name for the new Page node.
var newName = studio.GetUserInput("Node name", "Enter a name for the Page node.");
// Use the GetInvalidityReasonOfNewName function to check whether the name the user entered is valid.
var invalidityReasonOfNewName = rootPage.GetInvalidityReasonOfNewName(newName);
if (invalidityReasonOfNewName == null)
{
// If the name is valid the GetInvalidityReasonOfNewName function returns null.
// Create a new Page node with the name the user entered.
studio.ActiveProject.CreateProjectItem<Page>(newName, rootPage);
}
else
{
// If the name is not valid the GetInvalidityReasonOfNewName function returns the reason.
// Show the reason why the name is not valid in a dialog box.
studio.ShowMessageBox(invalidityReasonOfNewName, true);
}
}