JavaScript ConsoleJavaScript Console&Alt;&Ctrl;
j opens the JavaScript console.
(only available if libkjsembed is present at compile- and
runtime)The JavaScript console is an interface to the embedded
JS-Interpreter which can be used for amusement or
testing.JavaScript interfaceJavaScript interfaceWarning: The JS-Support is
quite stable, and you can not lose any data by using it. However,
your scripts may not work with future versions of
&krusader;, as the JS-Support is changing.Please
upload your favorite JavaScript
Extensions so that they become available for the
&krusader; community. Thanks!JavaScript applications usually have 2 files
foo.jsand
foo.ui. They will be installed in
~/.trinity/share/apps/krusader/js/, a
user action with a "%_Script" action will start the
Javascripting. Currently we have 2 JS demos
root-mount-extension.tar.bz2 and
js-demo-calc.tar.bz2 that will be more
explanatory.When a script is executed, the script doesn't know its
origin (or maybe there is a way to do so that we do not know of)
and all relative paths are relative to the current working-dir.
But this dir is (normally) not the one where the script is
located but the current dir of the active Panel of Krusader.
This needs to stay like this. However, for referencing
additional files like .ui (Userinterface, exported by
&Qt;'s Designer) one needs the path of the script.
The alternative where absolute paths are used is more than
unhandy. For this reason the Variable "scriptDir" was
introduced. If a Script wants to load a &GUI; from a
.ui-file this can be done this way:
var ui = Factory.loadui( scriptDir + 'filename.ui'
); I recommend using Dialog as a base when designing
&GUI;s to be used with JS. Execute the dialog with:
ui.exec(); The elements of the
&GUI; may be accessed in the following way:
ui.child('widgetName')Currently only the objects 'Krusader' and
'PanelManager' are exposed C++ objects without a logic
behind them. They can be inspected using the JS-Console and the
functions 'properties()', 'children()' and 'slots()'. The
children can be accessed with the function
'child("nameOfChild")' with returns an object itself. Currently, the Variable scriptDir is more useful. Following the root-mount
extension it is already possible to create advanced
&GUI;s for command line toolsYou can play around with 'Krusader.setCaption("Hey Ho,
Let's go!");', 'Krusader.children();',
'Krusader.child("help").slots();',
'alert(Krusader.properties())' or
'Krusader.child("help").show();'.... In addition, a new
placeholder for the &useractions-lnk;, %_Script()%,
will execute an external file.NOTE: The object 'Krusader' will change. We have not made
decisions about the JS-interface yet (at the time of the
1.70.0-release). Any ideas are welcome. Plase use our
&kruforum-url; for feedback.The JavaScript-support is based on
&kjsembed-url;. Some examples which show the power
of this library can be found
here. Support for all of KDE's ground-laying technologies
such as DCOP or KParts is provided. You can even load whole
GUIs from .ui-files, created with &Qt;'s Designer.
An example extension making use of this can be found
here.