Command Model

Basic Concepts

About the Command Model

WebEdit.NET offers a command interface much like a console application, in addition to the graphical user interface. Commands can be file paths, URLs, menu actions, macro calls (which invoke methods implemented in an AddIn), code snippets (evaluated by the built-in code interpreter), and various other specialized things.

Where to invoke

Commands can be invoked directly from the following locations:

The Console tool window remembers a history of recently executed commands, as well as history substitution (any input starting with an exclamation mark is exanded to the most recent command whose begin matches), so it is the most convenient place to execute commands from.

Links in a document may be used for a variety of interesting purposes besides linking to other files, such as compilation commands ("shell", "build", and "addin" protocols), shortcuts to certain .NET types in the built-in assembly browser ("type" protocol), or common tasks the code interpreter can perform ("code" protocol).

Commands can also be linked in the Favorites (just open the Favorites Window, click the "Add To Favorites ..." button, and type in the command), or the project (open the Project Window, click "Add Command To Project ...", and type the command).

You may also add commands to the toolbars, and choose a keyboard shortcut and a custom icon. For this, use the toolbar customization dialog after you have executed the command once, or use drag-and-drop from the Favorites, Project, or History windows, a type in the Assembly Browser window, a token in the Tokens window, or selected text.

You may also indirectly invoke commands from code in an AddIn (call the RunCommand method of the WebEditApp module).

Syntax

The syntax for URLs largely applies to commands. Each command consists of the protocol and the target separated by a colon, and optionally a query string (sometimes called parameter list) separated by a question mark.

Built-in protocols are "action", "addin", "build", "code", "doc", "config", "edit", "find", "file", "ftp", "http", "https", "history", "macro", "resource", "shell", "start", "tokens", and "type".

In general, targets are not case-sensitive (subject to exceptions). Some protocols may perform text expansion on the target or query string. For example, the "action" protocol has a mechanism for suggesting actions that closely match the target string.

If the "Use Token Expansion" setting in the "Command Model" setting group is active, both the target and the query string may contain parameter expressions (further detailed in Token Expansion) that are substited by the built-in code interpreter (or failing that, the parameter dialog). This allows using variables or accessing WebEdit properties, in order to generalize command usage. An example would be substitution of the current document's file path in a "shell:" command. However, note that "code:" commands invoke the code interpreter directly, so in this case, using parameters only makes sense for user-provided values.

Working with paths

All relative paths as well as absolute file system paths do not use a protocol (however, the "file" protocol is supported as well). If a path refers to a shell link or an internet shortcut, it will be resolved automatically.

Relative paths are resolved according to the location of the current document, and failing that, the folders shown in the File Manager and FTP Servers tool windows. Commands invoked from within a document (i.g., hyperlinks) are always resolved by the document's location, however. For commands entered in the Console window, you may also specifically choose which of these base paths should be used for path relative path resolution.

Extensibility

With an AddIn, you can override the default implementation for any protocol, register a new protocol, or change the priority of command managers (objects that handle commands of one or more protocols).

Examples

Some commands are shown in several forms (sometimes the abbreviated form) - each line is one command, and the following lines are variations or alternate forms. If you are viewing this document in WebEdit, you can just select the command and press Ctrl+L to execute a sample command (most commands will work from the edit pane, except where noted otherwise:

File/Folder/URL Navigation

To show the folder that contains the current document:

.

To show a local folder in the file manager:

C:\WINNT

To show a local folder in the file manager if no document is open (using a path that's relative to the current folder; these examples will only work from the address bar or the console):

WINNT
..\Inetpub

To open file "C:\AutoExec.bat":

C:\AutoExec.bat

To open a config file:

$Vars.ConfigFolderPath%\WebEditSettings.xml

To open file "AddIns.txt" as a relative path (local, HTTP, or FTP):

AddIns.txt

To browse to a web site:

http://peisker.de/

To show the FTP directory the contains the current FTP document:

./

To show a directory on an FTP site in the FTP tool window:

ftp://ftp.mysite.com/

To open a document from an FTP server:

ftp://ftp.mysite.com/docs/readme.txt

Action Protocol

To exit the application:

action:Exit
action:ex

To show the file manager:

action:FileManagerWindow
action:file

To maximize the work area:

action:MaximizeWorkArea
action:max

AddIn Protocol

To start and stop the "DataDocs" AddIn (assuming it is in the list of AddIns):

addin:start?DataDocs
addin:stop?DataDocs

To install an AddIn (copies the DLL specified to WebEdit's "bin" subdirectory, and adds it to the list of available AddIns):

addin:install?C:\MyAddIns\SnafuAddIn.dll
addin:install?$Vars.ProjectFolderPath%\SnafuAddIn.dll

To uninstall an AddIn:

addin:uninstall?SnafuAddIn

To build a Script AddIn from the current document (the second example means don't show the language dialog, just go ahead and use the C# compiler on the code with no further wrappings):

addin:build
addin:build?C#,0

Build Protocol

To build the current document, group of documents, or projects, respectively:

build:doc
build:group
build:project

Note: optionally, the build mode may be passed as a parameter; otherwise, the user is prompted for the build mode. Build commands must be configured in the language configuration file (WebEditLanguages.xml) for the current language:

build:doc?Application 1.5

Code Protocol

See the Code Interpreter topic for examples.

Config Protocol

To save configuration:

config:saveconfig
config:saveautoconfig
config:saveuserconfig

To show the configuration files in the File Manager:

config:showfiles

To show the settings dialog:

config:show
action:ShowSettings

Document Protocol

To open a new document:

doc:new

To mark document as unchanged:

doc:throw

To open a new document based on a local file (template):

doc:opentemplate?C:\SharpCollectionTemplate.cs

To insert the contents of a local file or template:

doc:inserttemplate?C:\SharpIndexerTemplate.cs
doc:inserttemplate?resource:Gregor.WebEdit?Gregor.WebEdit.ReadMe.txt

Edit/Find Protocols

To go to a line in the current document (show dialog):

edit:go

To go to a specific line in the current document:

edit:go?5

To find the first occurrance a given string in a document:

edit:find?FTP
find:FTP

To find the next or previous occurance:

edit:findnext
edit:findprev

To list all occurances of a given string in a document:

edit:findall?Hello

History Protocol

To move back and forward in the history:

history:back
history:forward

Macro Protocol

Macro are provided by AddIns, and may invoked with the "macro:" protocol.

To run a macro in an AddIn:

macro:Indigo.CIndigoConnector.TestMacro

To run a macro in a Script AddIn with an automagically created wrapper module:

macro:N.M.Foo

Resource Protocol

To open an embedded resource file:

resource:Gregor.WebEdit?Gregor.WebEdit.ReadMe.txt

Tokens Protocol

To insert a token into the current selection:

tokens:insert?<a href="%Url%" title="$Tooltip%">$Text%</a>

To add a token to the token list currently selected in the Tokens tool window:

tokens:add?Hello\nWorld!

Type Protocol

The type protocol helps with browsing .NET data types in WebEdit's built-in assembly browser:

type:Gregor.Core.Reflect
type:System.String

Shell Protocol

To compile a C# file:

shell:csc.exe /r:System.dll C:\Hello.cs

To compile the current document with the C# compiler (you may have to quote the path):

shell:csc.exe "$WebEditApp.DocumentManager.ActiveDocument.FullPath%"
shell:csc.exe "$Vars.DocPath%"

To run an executable in the shell (assuming its location is in the PATH environment variable):

shell:Hello.exe

To shell a console exe you've just build from the active document:

shell:$Vars.DocExeName%

To use a specific comiler version, enter these two commands:

code:Compiler = "C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\csc.exe"
shell:$Compiler% $Vars.DocPath%

Start Protocol

To shell an URL:

start:http://localhost/

To open the current folder in Windows Explorer:

start:.

To start a Windows program you've just built from the current document:

start:"$Vars.DocExePath%"

See Also: Code Interpreter | Command Model Protocols