A component for handling environment values. More...
Import Statement: | import ArcGIS.AppFramework 1.0 |
Signals
- valueChanged(string name, var value)
Methods
- bool isEmpty(string name)
- bool isSet(string name)
- var remove(string name)
- var setValue(string name, var value)
- var value(string variable)
- var value(string variable, var defaultValue)
Detailed Description
The Environment component provides means to set, access, or remove environment values that exist within the system environment. This is useful for assigning variables that are needed to manage other components of your app.
This code sample demonstrates usage of the Environment component. A 'scripts' folder is appended to your PATH environment variable, which has already been set in your system. The value method is used to read the current value, while the setValue method is used to set a new value.
ListView { id: listView anchors.fill: parent delegate: ItemDelegate { text: modelData } function getPathSeparator() { var windowsPathSeparator = ";"; var unixPathSeparator = ":"; if (Qt.platform.os === "windows") { return windowsPathSeparator; } else { return unixPathSeparator; } } function getPathArray() { return AppFramework.environment.value("PATH").split(getPathSeparator()); } function appendPath(newPath) { var pathArray = getPathArray(); if (pathArray.indexOf(newPath) !== -1) { console.log("2b"); return; } pathArray.push(newPath); AppFramework.environment.setValue("PATH", pathArray.join(getPathSeparator())); } function getScriptsPath() { var scriptsPath = AppFramework.userHomeFolder.filePath("scripts"); if (Qt.platform.os === "windows") { var windowsDirSeparator = "\\"; scriptsPath = scriptsPath.replace(/\//g, windowsDirSeparator); } return scriptsPath; } Component.onCompleted: { var scriptsPath = getScriptsPath(); appendPath(scriptsPath); listView.model = getPathArray(); } }
Signal Documentation
Signal emitted when an environment variable has been changed.
Note: The corresponding handler is onValueChanged
.
Method Documentation
Returns true if the environmental variable named is empty.
The name parameter
The name of the variable to check.
Returns true if the named environment variable has been set. Otherwise, returns false.
The name parameter
The name of the environment variable to check.
Returns, and then deletes, the named variable from the environment.
The name parameter
The name of the environment variable to delete.
Sets the named environment variable to the given value.
The name parameter
The name of the variable to set.
The value parameter
The contents of the value to set.
See also value().
Returns the value the named environment variable is set to.
The variable parameter
The name of the environment variable to return.
Returns the value the named environment variable is set to. If a variable is not declared, returns the default value.
The variable parameter
The name of the environment variable to return.
The defaultValue parameter
The default value to return if the environment variable is not declared.
See also setValue().