FoxDock is the plugin system for the Visual FoxPro 9 IDE. A plugin is a folder with a .prg, and FoxDock loads it when VFP opens: it puts the plugin’s bars in the menu, tells it what happens in the IDE and hands the AI agent the tools the plugin wants to offer.

In this tutorial we write one from scratch. At the end you will have a plugin with a bar in the FoxDock menu, a shortcut, an IDE event, an option you can change without touching the code and two tools for the agent. There are seven steps, and each one says what you type, what you should see and what to do if you do not see it. You do not need to know about classes: each thing is explained when it shows up.

Before you start

  • FoxDock is installed. When you open Visual FoxPro, the FoxDock menu shows up in the menu bar, in the language you chose; the names here are the English ones.
  • Your plugins live in %LOCALAPPDATA%\FoxDock\plugins\. To open the folder, type %LOCALAPPDATA%\FoxDock\plugins in the address bar of Windows Explorer.
  • FoxDock writes down everything it does in a log. It opens with FoxDock > Log > Open log. When something does not come out, look there first.

How to try each change without closing VFP

While a .prg of your plugin is open in the editor, FoxDock unloads the plugin, because VFP does not save a file whose classes are in use. When you close the editor, it loads it again. So every step is the same: you type, save with Ctrl+S and close the editor. The log tells you with two lines, plugins: hello unloaded (being edited) and then plugin loaded: hello.

Once your plugin has tools for the agent (step 5), VFP may ask Remove classes from memory? while you type or save. Click Remove and carry on. Do not press Enter: the button Enter picks is Ignore, and with Ignore VFP throws away what you were typing.

Before you close VFP, save and close the editor of your plugin. If you close VFP with the editor open and changes in it, VFP asks whether to save, as always; if it asks Remove classes from memory? instead, answer Remove and close VFP again.

FoxDock > Plugins > New plugin… and New tool… write all of this for you: the folder, the .prg with its bar and its shortcut, and the class of each tool. Here it is written by hand so that you know what is inside.

Step 1. The folder and the class

Create a folder hello inside your plugins folder, and in it a file HelloPlugin.prg. Both are done with these two lines in the Command window of VFP (MODIFY COMMAND creates the file if it does not exist):

MD (GETENV("LOCALAPPDATA") + "\FoxDock\plugins\hello")
MODIFY COMMAND (GETENV("LOCALAPPDATA") + "\FoxDock\plugins\hello\HelloPlugin.prg")

The editor opens, empty. Type this:

HelloPlugin.prg
DEFINE CLASS HelloPlugin AS PluginBase
	cTitle = "Hello plugin"

	PROCEDURE BuildMenu
		LPARAMETERS toMenu
		toMenu.AddBar("Say \<hello", "SayHello", "Say hello in a notice at the top right of VFP")
	ENDPROC

	PROCEDURE SayHello
		This.oHost.Notify("Hello from my first plugin")
	ENDPROC
ENDDEFINE

Save it, close the editor and choose FoxDock > Plugins > Reload plugins: FoxDock looks for plugins again and finds yours. Closing VFP and opening it again does the same.

What you should see. The FoxDock menu has a new bar, Say hello. When you click it, a notice at the top right of the VFP window says Hello from my first plugin. The log has a line plugin loaded: hello, and the ready: line counts one plugin more than before.

What you wrote. DEFINE CLASS HelloPlugin AS PluginBase defines a class, which is a mould for making an object. Yours starts from PluginBase, which already knows how to talk to FoxDock, so you only write your own part. FoxDock makes an object from it when VFP starts and calls its methods: BuildMenu to put its bars in the menu, and SayHello when you click the bar.

The names follow a rule. The folder is the plugin’s id (hello), the file is called <Id>Plugin.prg and the class <Id>Plugin. The \<h in Say \<hello underlines the letter that opens the bar from the keyboard.

If it does not come out.

  • There is no Say hello: open the log. The line plugin 'hello' failed to load says why. Usually a name does not match (folder hello, file HelloPlugin.prg, class HelloPlugin) or something is mistyped.
  • There is no hello line in the log at all: the folder is not in %LOCALAPPDATA%\FoxDock\plugins\.

Step 2. A shortcut

The shortcut is one more argument to AddBar, the key. Replace the AddBar line with this one:

Program1
		toMenu.AddBar("Say \<hello", "SayHello", "Say hello in a notice at the top right of VFP", "ALT+Y")

Save and close the editor.

What you should see. Say hello has Alt+Y written beside it. Press Alt+Y in the Command window and the greeting comes up.

If the key already belongs to someone. FoxDock does not take a key that VFP uses (ALT+H, for example, opens the Help menu), that another plugin uses or that an ON KEY LABEL of yours uses. It leaves the bar without a shortcut, and the log says which key, which bar and whose it is:

menu: shortcut ALT+H for hello.SayHello skipped: it is a shortcut of VFP itself

You can change the shortcut without touching the plugin. Your FoxDock settings are in config.json, which opens with this line:

MODIFY FILE (GETENV("LOCALAPPDATA") + "\FoxDock\config.json")

Usually it holds something like this. Add the "keys" line before the last brace, with a comma at the end of the line above:

{
  "previousStartup": "",
  "timerInterval": 500,
  "plugins": {},
  "options": {},
  "keys": { "hello.SayHello": "ALT+J" }
}

The name is <id>.<method>, and "" removes the shortcut. Save, close config.json and choose FoxDock > Plugins > Reload plugins: Say hello now has Alt+J. The shortcut in config.json wins over the one the plugin sets, so you can change the shortcut of any plugin, including the ones that are not yours.

Before going on, remove the "keys" line again, and the comma you added above it, and reload the plugins. Say hello goes back to Alt+Y.

Step 3. An IDE event

FoxDock tells your plugin what happens in the IDE. You write only the methods you care about, and FoxDock calls them. OnEditorActivate arrives every time an editor comes to the front. Write it below SayHello, before ENDDEFINE:

Program1
	PROCEDURE OnEditorActivate
		LPARAMETERS toInfo
		*-- The Command window is an editor too, and it has no file.
		IF !EMPTY(toInfo.file)
			This.oHost.Notify("Now editing " + JUSTFNAME(toInfo.file))
		ENDIF
	ENDPROC

Save and close the editor.

What you should see. First take VFP to a folder where it can write, with CD (SYS(2023)) in the Command window. That is your temporary folder, and you need it because VFP may start in C:\Windows\System32. Then open two programs, MODIFY COMMAND a.prg and MODIFY COMMAND b.prg, and move from one to the other with the mouse. The notice says Now editing a.prg and then Now editing b.prg.

What you wrote. toInfo is what FoxDock knows about that editor, and toInfo.file is its file. The Command window is an editor too and has no file; that is why the IF !EMPTY(toInfo.file). There are more events (a window opens, a project is built, VFP closes), and the manual lists them all.

If it does not come out. The ready: line in the log ends with what FoxDock knows about its FLL. Without the FLL, FoxDock does not see the editors and this event never arrives; the menu and the shortcut work the same.

Step 4. An option

Now whoever uses the plugin chooses the greeting, in config.json, and each greeting is counted and written to the log. Add the line nHellos = 0 below cTitle, and replace SayHello with this one:

Program1
	PROCEDURE SayHello
		LOCAL lcGreeting
		This.nHellos = This.nHellos + 1
		lcGreeting = This.oHost.Options.Get(This.cId, "greeting", "Hello from my first plugin")
		This.oHost.Log(This.cId + ": " + lcGreeting + " (" + TRANSFORM(This.nHellos) + ")")
		This.oHost.Notify(lcGreeting)
	ENDPROC

Open config.json again, with the same line as in step 2, and put the option inside the "options" entry that is already there:

{
  "previousStartup": "",
  "timerInterval": 500,
  "plugins": {},
  "options": {
    "hello": { "greeting": "Hola, foxero" }
  }
}

Do not add a second "options": FoxDock reads only the last one, and whatever was in the first is lost. If yours already had something inside ("themes", for example), put a comma after it and add the "hello" line below.

Save the plugin and close its editor, save and close config.json, and reload the plugins so that FoxDock reads config.json again.

What you should see. Say hello says Hola, foxero, and the log says hello: Hola, foxero (1). The second time, (2). Without the option, it says Hello from my first plugin.

What you wrote. nHellos = 0 is a property: a variable that belongs to the plugin and lives while VFP is open. This.oHost is FoxDock. Options.Get reads an option and takes three things: the id of your plugin, the name of the option inside "options": { "hello": ... }, and what it returns when the option is not in config.json. Log writes to the log, and Notify writes to the log and also shows the notice at the top right.

If it does not come out. If the greeting is still the usual one, look at config.json. A comma or some quotes may be missing, the option has to go inside "options" and then inside "hello", and hello has to be the name of your folder. If there are two "options", the log says so:

config.json: key "options" appears 2 times; the last one wins, the others are ignored

Step 5. Two tools for the agent

This step needs FoxAgent installed and an AI client connected to it, such as Claude Desktop. Your plugin gives the agent two tools: one that only reads (how many greetings there have been) and one that acts (it says hello in the IDE).

First, inside the plugin class and before its ENDDEFINE, the method that hands the tools to FoxDock:

Program1
	*-- FoxDock asks for the tools when it connects to FoxAgent, and keeps this
	*-- file loaded while they exist.
	PROCEDURE GetAgentTools
		LPARAMETERS toTools
		toTools.Add(CREATEOBJECT("HelloCountTool"))
		toTools.Add(CREATEOBJECT("HelloSayTool"))
		RETURN toTools.Count
	ENDPROC

Then, below the plugin’s ENDDEFINE, at the end of the file, the two tools. Each one is a class of its own:

Program1
*-- It only reads: any agent role.
DEFINE CLASS HelloCountTool AS IdeTool
	ToolName = "ide_hello_count"
	ToolDescription = "How many times the Hello plugin has said hello since the IDE started."

	FUNCTION Run(toContext)
		LOCAL loPlugin, loResult
		loPlugin = _screen.oFoxDock.PluginById("hello")
		loResult = THIS.NewObject("hellos")
		loResult.hellos = loPlugin.nHellos
		RETURN THIS.Ok(loResult)
	ENDFUNC
ENDDEFINE

*-- It acts on the IDE: agent role 10 (operator) or higher.
DEFINE CLASS HelloSayTool AS IdeTool
	ToolName = "ide_hello_say"
	ToolDescription = "Says hello in a notice at the top right of the VFP window, as the bar Say hello does."
	lActsOnIde = .T.

	FUNCTION Run(toContext)
		LOCAL loPlugin, loResult
		loPlugin = _screen.oFoxDock.PluginById("hello")
		loPlugin.SayHello()
		loResult = THIS.NewObject("hellos")
		loResult.hellos = loPlugin.nHellos
		RETURN THIS.Ok(loResult)
	ENDFUNC
ENDDEFINE

Save and close the editor. If you are not sure where each piece goes, the whole file is at the end of the article.

What you should see. The first line of FoxDock > FoxAgent says how many tools the agent has, and now there are two more than before. The log says so too, in the line foxagent: the plugins changed; N tool(s) registered that comes out when you close the editor. The line foxagent: connected as ... is from when VFP opened and keeps the count of that moment.

Then talk to the agent. It goes like this, with the answers of the tools as the agent receives them:

You: How many times has my Hello plugin said hello?

The agent calls ide_hello_count, which answers {"hellos":0}, and tells you it has not said hello yet.

You: Say hello in VFP.

The agent calls ide_hello_say, which answers {"hellos":1}. Your greeting shows up at the top right of VFP, and the log says hello: Hola, foxero (1).

What you wrote.

  • Each tool is a class that starts from IdeTool, which comes with FoxDock. ToolName is the name the agent sees, ToolDescription tells it what the tool is for, and Run is what it does. FoxDock calls Run every time the agent uses the tool.
  • The answer is built as in FoxServer. THIS.NewObject("hellos") creates an object with the fields in the list, separated by commas; you give each field its value and THIS.Ok(loResult) turns it into the text the agent receives, {"hellos":1}. A name with [] is a list that takes .Add: THIS.NewObject("files[]") and then loResult.files.Add("a.prg").
  • GetAgentTools hands the tools to FoxDock when it connects to FoxAgent: it adds them to toTools, which is a collection, and returns how many there are.
  • If your tool changes something in the IDE, give it lActsOnIde = .T.. FoxDock lets it run only with role 10 or higher, and tells the agent so in the tool’s description before it calls it. You do not need to write any check, because FoxDock looks at the role before calling Run. A tool that only reads does not have it.
  • If your tool receives something from the agent, it declares it in DefineParameters() with one THIS.AddParam(name, type, what it is for, required) per parameter. The type is string, number or boolean, and Run reads each one with THIS.PText, THIS.PNum or THIS.PBool. New tool… writes all of that for you from its screen.

The agent role. In FoxDock > FoxAgent > Agent role you choose what the agent may do. With role 0, the tool that reads keeps answering, and ide_hello_say refuses with this message:

ide_hello_say acts on the IDE, and FoxDock lets the agent act only with agent role 10 (operator) or higher

With role 10 or higher, it says hello. Only you change the role, from that menu.

If it does not come out.

  • While you type or save, VFP asks Remove classes from memory?: FoxAgent holds on to the objects of your tools for a while. FoxDock has already unloaded your plugin, so click Remove and carry on. Ctrl+S saves as always and nothing breaks.
  • You close the editor and your change is not there yet: with FoxAgent connected, FoxDock may have to wait until FoxAgent lets go of your tools. The notice says so, and FoxDock loads your changes by itself within a few seconds.
  • The menu says FoxAgent: not installed: install FoxAgent and open VFP again. Without FoxAgent your plugin works the same, without tools.
  • The tool count did not go up: the log says plugin 'hello' GetAgentTools failed with the reason.
  • The agent does not see your tools: ask it for the list of tools of your IDE. If the other ide_* tools are there and yours are not, open VFP again, because FoxDock hands them to FoxAgent when it connects.

Step 6. When something fails

Let’s add a bar that fails, to see what FoxDock does with an error in your plugin. In BuildMenu, below the bar you already have:

Program1
		toMenu.AddBar("\<Fail on purpose", "FailOnPurpose", "Raise an error to see how FoxDock handles it")

And the method, below SayHello:

Program1
	PROCEDURE FailOnPurpose
		ERROR "Hello plugin: this failure is on purpose"
	ENDPROC

Save and close the editor. With two bars, your plugin gets its own submenu: FoxDock > Hello plugin.

What you should see. Click Fail on purpose. No dialog opens and VFP carries on. The log says:

ERROR bar hello.FailOnPurpose failed: 1098 Hello plugin: this failure is on purpose

and Say hello still works.

What it means. FoxDock calls everything in your plugin inside a TRY. An error of yours goes to the log with its number and its message, and it does not stop the IDE or the other plugins. The three lines to look for in the log are plugin 'hello' failed to load (the plugin did not load), BuildMenu failed (the menu) and bar hello.<method> failed (a bar).

Step 7. The finished plugin

It still needs a fixed place in the menu and a version. Add two properties below cTitle:

Program1
	nOrder = 1000
	cVersion = "1.0.0"

Save and close the editor. The log says plugin loaded: hello 1.0.0.

nOrder is the plugin’s place in the FoxDock menu, from lowest to highest. The plugins that come with FoxDock go from 910 to 970, so with 1000 yours comes after them; a plugin without nOrder has 100 and comes first. cVersion is the version the log shows when it loads, and cTitle the name in the menu. The id (cId) is the name of the folder, unless you write another one.

This is the whole file:

HelloPlugin.prg, finished
*==================================================================
* HelloPlugin.prg: my first FoxDock plugin, with two bars, a shortcut, a hook,
* an option, and two tools for the agent.
*==================================================================

DEFINE CLASS HelloPlugin AS PluginBase
	cTitle = "Hello plugin"
	nOrder = 1000
	cVersion = "1.0.0"
	nHellos = 0

	PROCEDURE BuildMenu
		LPARAMETERS toMenu
		toMenu.AddBar("Say \<hello", "SayHello", "Say hello in a notice at the top right of VFP", "ALT+Y")
		toMenu.AddBar("\<Fail on purpose", "FailOnPurpose", "Raise an error to see how FoxDock handles it")
	ENDPROC

	PROCEDURE SayHello
		LOCAL lcGreeting
		This.nHellos = This.nHellos + 1
		lcGreeting = This.oHost.Options.Get(This.cId, "greeting", "Hello from my first plugin")
		This.oHost.Log(This.cId + ": " + lcGreeting + " (" + TRANSFORM(This.nHellos) + ")")
		This.oHost.Notify(lcGreeting)
	ENDPROC

	PROCEDURE FailOnPurpose
		ERROR "Hello plugin: this failure is on purpose"
	ENDPROC

	PROCEDURE OnEditorActivate
		LPARAMETERS toInfo
		*-- The Command window is an editor too, and it has no file.
		IF !EMPTY(toInfo.file)
			This.oHost.Notify("Now editing " + JUSTFNAME(toInfo.file))
		ENDIF
	ENDPROC

	*-- FoxDock asks for the tools when it connects to FoxAgent, and keeps this
	*-- file loaded while they exist.
	PROCEDURE GetAgentTools
		LPARAMETERS toTools
		toTools.Add(CREATEOBJECT("HelloCountTool"))
		toTools.Add(CREATEOBJECT("HelloSayTool"))
		RETURN toTools.Count
	ENDPROC
ENDDEFINE

*-- It only reads: any agent role.
DEFINE CLASS HelloCountTool AS IdeTool
	ToolName = "ide_hello_count"
	ToolDescription = "How many times the Hello plugin has said hello since the IDE started."

	FUNCTION Run(toContext)
		LOCAL loPlugin, loResult
		loPlugin = _screen.oFoxDock.PluginById("hello")
		loResult = THIS.NewObject("hellos")
		loResult.hellos = loPlugin.nHellos
		RETURN THIS.Ok(loResult)
	ENDFUNC
ENDDEFINE

*-- It acts on the IDE: agent role 10 (operator) or higher.
DEFINE CLASS HelloSayTool AS IdeTool
	ToolName = "ide_hello_say"
	ToolDescription = "Says hello in a notice at the top right of the VFP window, as the bar Say hello does."
	lActsOnIde = .T.

	FUNCTION Run(toContext)
		LOCAL loPlugin, loResult
		loPlugin = _screen.oFoxDock.PluginById("hello")
		loPlugin.SayHello()
		loResult = THIS.NewObject("hellos")
		loResult.hellos = loPlugin.nHellos
		RETURN THIS.Ok(loResult)
	ENDFUNC
ENDDEFINE

Where it lives and how to share it

Your plugin is in %LOCALAPPDATA%\FoxDock\plugins\hello\, and installing a new version of FoxDock leaves it alone.

A plugin is a folder. To give it to another VFP developer, copy hello into their plugins folder; the next time they open VFP, it is there. If you want anyone to install it from the plugin center with the address of a repository, the next step is How to publish your FoxDock plugin.

The FoxDock manual covers everything a plugin can declare, what This.oHost has, the editor keys, all the events and the tools for the agent in more detail. It opens from FoxDock > Help, in your browser and in the language of the menu.

If something does not work for you, write to me at soporte@irwinrodriguez.dev.