Introduction to Classes

Classes allow you to group other settings, such as aliases, variables, triggers, etc, into a single group or folder. In addition to organizing your settings, classes can be enabled and disabled and also allow you to perform some advanced scripting.

Creating a Class

To create a new class, or to switch the current class to an existing class, use the #CLASS command:

#CLASS Class1

will create a new class called Class1, or will switch to that class for all following commands.

Many of the commands for creating settings, such as the #ALIAS command for creating an alias, already contain an argument for specifying the class name. In the case of an alias, the third argument is the name of the class:

#ALIAS aliasname {commands} "classname"

If the classname doesn't exist, then it is created. If the classname is not specified, the current class is used. Most all settings have an argument like this for specifying the class.

In the Package Editor, classes are displayed as folders, and you can drag settings into these folders to change the class they are in. To display all settings no matter what class folder they are in, uncheck the "Group by Class" option in the View menu.

Classes can be nested, like subfolders. To refer to a nested path, seperate the class names with the / character. So, if Class1 contained a subclass named Class2, you would refer to it as "Class1/Class2". So, for example:

#ALIAS aliasname {commands} "Class1/Class2"

would create a new alias within the Class2 subclass of Class1. To refer to a subclass of the current class you are already in, use the syntax "/Subclass". So, if your current class was already Class1, you could create an alias in the subclass Class2 using the syntax:

#ALIAS aliasname {commands} "/Class2"

For variables, you can also specify the class path in the name of the variable itself. For example, to create a variable in Class1, you could use the syntax:

#VAR class1/varname value

This is a more general purpose syntax for refering to a setting in a specific class, and can also be used for executing specific aliases or expanding specific variables.

For example, imagine the following situation:

#CLASS Class1
#ALIAS Test {in class1}
#CLASS Class2
#ALIAS Test {in class2}
Now, if you just type "Test" on the command line, which "Test" alias will get executed? You don't really know. The rule is that if your current class is set to something other than the root class (class 0), then TeSSH will check the current class, and then the parent classes for a matching alias. So, in the above example, we are still currently in Class2, so typing "Test" will execute the "in class2" alias. If you are set to the root class (class 0), then TeSSH will search all enabled classes, starting with the last class created.

To force execution of a specific alias, you can specify the full path. For example:


will always execute the "in class1" alias, no matter what the current class is.

When specifying the path to a setting, such as an alias, '..' can be used to refer to the Parent class, and '.' can be used to refer to the Current class. A path starting the '/' starts with the root class.

So, if you just type: "Test", you don't really know which alias will get executed, although it will usually be the one that you want. If you always want it to execute the "Test" alias in the current class, you would type "./Test". If you always wanted to execute the "Test" alias in the root or None class, you would type "/Test". To execute the alias in the Parent class, you would type "../Test"

Variables are different

There is an exception when dealing with Variables. Normally, if you try to create a new setting with the SAME NAME as a setting in the parent class, a new setting will be created in the current class. For example, if you have nested classes:

#CLASS Class1
#ALIAS Test {in class1}
#CLASS /Class2
#ALIAS Test {in class2 which is within class1}
this will create two aliases, one in the parent Class1 and one in the subclass Class2 within Class1. To execute the second alias, you would use the syntax "Class1/Class2/Test"

Variables are handled a bit differently. If you use #VAR to create a variable with the SAME NAME as a variable in a parent class, then the variable in the parent class will be changed instead of creating a new variable. So, in the example:
#CLASS Class1
#VAR Data 1
#CLASS /Class2
#VAR Data 2
this will actually change the value of the Data variable in Class1 to 2 instead of 1. Only one variable would still exist. This is done because when doing object-oriented programming, you normally do not create new data fields with the same name as in a parent class.

If you want to force TeSSH to create a new variable in the subclass, use the './' at the beginning of the variable name to force it to the current class. So:

#VAR ./Data 2

will force TeSSH to create a new variable in the current class with a value of 2 rather than changing the Data variable in the parent class. You can also use the #NEWVAR command, instead of #VAR, to create a new variable within the current class.

Enabling and Disabling Classes

There are two ways to enable or disable a class: using the #CLASS command, or the #T+ and #T- class. The #T+ and #T- commands are used to enable and disable a class, respectively. This is older, backwards compatible syntax from when classes could only contain Triggers, so #T- was the method to disable a "trigger class". Classes can contain more than triggers now, but the syntax remains.

The #CLASS command is a more versatile way to enable and disable classes:

#CLASS classname value

will enable the classname if value is true (non-zero), or disable classname if value is false (zero). You can retrieve the current condition of a class using the %trigger(classname) function. This will return one if the classname is enabled, or zero if classname is disabled. (Again, the name of this function is left over from TeSSH when classes only contained triggers).

When you disable a parent class, all subclasses of that parent are also considered to be disabled.

Disabling a class prevents execution of any aliases, triggers, or macros within the class. Buttons in the disabled class disappear from the button bar, and menu items in the disabled class disappear from the right-click menu. Variables in a disabled class cannot be accessed unless you specify the full path to the variable specifically.

Add comment

Login or register to post comments