evaluator:applicable_contexts:functions:evaluation_clauses

The @eval and @evalalways command modifiers let you run evaluation expressions inline in your functions.

The main purpose of this is to set variables that can then be used later on in the function by other modifiers like @if, @icon, @label etc.

  • Variables set via @eval can only be seen by other modifiers. They're executed when Opus performs dynamic updates of the toolbar (e.g. to update the label or icon), but not when the function is actually run.
  • Variables set by @evalalways can also been seen by the main function itself, when it is run. That means they can also be accessed via evaluation insertion code or by generated command lines.

For example, you might want a button that behaves differently in a normal filesystem folder to other locations. You can use an @eval clause to calculate the folder type once, and then refer to that in later lines.

@eval:=type = pathtype(source); fIsFileSystem = (type == "shell" || type == "filesys")
@enableif:=fIsFileSystem
@label:=fIsFileSystem ? ("Open " + filepart(displayname(source)) + " in Explorer") : ("Disabled (" + type + ")")
explorer.exe "{sourcepath}"

A number of variables are available to the evaluator in this context. Note that some are only applicable to toolbars in the standalone image viewer, and some only apply to Lister toolbars.

Variable Type Description

dest

path

The current destination path.

dest_shell

bool

True if the destination is a shell (virtual) folder hosted by Explorer, otherwise false.

expanded

uint

Returns the number of expanded directories.

fullscreen

bool

Viewer only. True if the viewer is fullscreen, otherwise false.

key_repeat

bool

True if the function was launched from a repeated key press (i.e. the key was held down).

seldirs

uint

Returns the number of selected directories.

selfiles

uint

Returns the number of selected files.

selimage

bool

Viewer only. True if an area of the image has been selected, false otherwise.

selitems

uint

Returns the total number of selected items.

source

path

The current source path.

source_shell

bool

True if the source is a shell (virtual) folder hosted by Explorer, otherwise false.

totaldirs

uint

Returns the total number of directories.

totalfiles

uint

Returns the total number of files.

totalitems

uint

Returns the total number of items.

viewmode

str

Returns the current view mode in the file display. Values are largeicons, smallicons, list, details, power, thumbnails and tiles.

As well as the above variables, you can also use evaluator functions like IsChecked and IsEnabled to query other information about the state of the Lister.

The return value from the evaluation expression will be used to determine the result of the condition. Return true if the lines following the modifier should be executed, or false to skip to the next @if / @ifset modifier.