Author
Topic: FARR plugin: Bakko (Read 10864 times)

The main point of this plugin is to provide a customizable means for transforming the main FARR window's text field content. At the moment, "customizable" means that the user can write a bit of JavaScript to operate on the text field content. It's also possible that people could share these bits of JavaScript

Usage Examples

1. Bring up FARR and type some text into the text field.

2. A statusbar icon should appear at (or near) the bottom right of the FARR main window, Click (currently, left-click) on this icon to bring up some possible transformations.

3. Some or all of the following may appear -- try one by clicking on the corresponding context menu item.

4. There is rudimentary support for access to a history of text strings which were successfully operated on (but not the results). The strings in the history may be accessed via the History submenu of the statusbar menu. NOTE: The history does not currently survive plugin reloads nor FARR restarts.

Creating a Transformation

Each transformation is implemented as a JavaScript file living in the directory %PLUGINDIR%\transformations\. Before reading further, I suggest opening up one of the samples in a text editor -- the following description may be easier to follow. Choosing the shortest sample may be a good idea

The JavaScript file gets eval()-ed (nasty word, eh?) and the plugin expects the eval() result to be an object.

(In case it wasn't obvious, what evaluation of that does (as I understand it), is to call a function which returns an object.)

In between, define the following (some optional):

name string no spaces

caption(stxt) function returns a string for the menu item's caption. currently, the returned string gets truncated and " ..." is appended if it is too long (see source of plugin for details). stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.

hint(stxt) optional function returns a string for the hint of the menu item. stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.

icon(stxt) optional function returns a string of the path to an icon for the menu item. stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.

launch(stxt) function returns a string used by FARR to execute the transformation code -- typically returns values looking like: farr://pcommand bakko xform <name> <stxt> stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.

display(stxt) (optional) function returns a boolean, true if the transformation should show up in the context menu, false if not. stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.

code(argtxt) function returns a string or null. a string value represents a successful transformation and FARR's main window text field should be replaced with it. a null value means failure. argtxt is currently the same as stxt (as mentioned above).

The transformation has access to variables and functions within the plugin's (function () {} ()) scope (I think). What this means is that displayname, aliasstr, pu, and the like may all be used within transformations.

If something isn't clear (or you think there are mistakes) here, I suggest asking on the forums and/or "Use the source, Luke"

Tips

Having a hotkey defined to bring up FARR with clipboard content pasted in FARR's main window can be handy.

FWIW, what I tend to use the plugin for are the following transformations:

wikimedia http URL -> https URL

evaluator

prime factorization

The evaluator just hands things to Javascript to evaluate -- so although the examples documented in the OP are for mathematical calculations, one can actually do a fair bit more. What I tend to use this for is small bits of testing. For example, recently mouser added %APPDRIVE% support for FARR and I wanted to see if it worked. What I ended up doing to test this was to type the following into FARR's main window text edit field:

Quote

FARR.getStrValue("resolve:%APPDRIVE%");

and then choose the "Evaluate" context menu item. This saved me a tiny amount of time and effort changing code in a plugin and reloading it.

I did something similar to test mouser's implementation of %PLUGINDIR% too