scripting:service

Action unknown: addtobook

Service Scripts

Service scripts (or Script Plugins) is a rich kind of scripts, that are very close in possibilities to binary plugins and allows you to create extensions for HippoEDIT that seamlessly integrating into its UI giving the same feeling as native built-in functionality.

Such scripts are living resident in a HippoEDIT process and react on events (as menu command selection, shortcut call, or document load). Another feature of service scripts is automatic loading on every HippoEDIT start. So, you install it, and then it runs always until you uninstall it.

Installation here means simple running/execution of script using Tools→Execute… HippoEDIT automatically detects that script has been registered to one of events and keep plugin loaded (and reloads on start).
Un-install means unload it with Tools→Options→Plugins→your plugin name → uncheck.

Set syntax dynamically all for new files (normally this is done with Tools→Options→Syntax Settings→Syntax→Miscellaneous→File Pattern)

on-new-document.hejs
onNewDocument = function() {
  this.Syntax = Settings.GetSyntax("xml");
};

The scripts:

  • register icon to be used on the toolbar
  • creates and registers command to be executed on button click or by shortcut
  • adds “enabled” callback to block execution if a document is read-only
  • creates a toolbar and toolbar button and assigns the command to the button.
insert-template.hejs
//${ region Icons }
var nIcon = Application.RegisterImageString(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAbFBMVEUAAAAAAACSkpIAAACNjY2Ghob/\
 //+NjY35+fv8/P37+/33+PlLS0qhoaCLi4pfX1+fn5+dnZ2EhYRNTU1ISEfv7/GPj4/x8vWcnJxQUE/m\
 5umjo6NkY2NRUVFDQ0L19ffo6ezn6OtnZmZUVFSk4DKEAAAABnRSTlMAM+8n4cDnOMTRAAAAlUlEQVQY\
 02WPiwqDMAxFs7mlj7S1L6tO3fP//3GhFSbsEBI4XBIC5yJ+lDNAQaklaSWJJxYAgTHHp0nxFfMdRRWj\
 G2edRjPcmjA60fZ5EwtVRdpmNWOS5jG0RMasjXHk9h31ChfJQTaxrou1nvrF+iYYpRWDqone+olbwD40\
 ccTVRA34EML0n2Bx5SedEzsXgO50pIMvSrkKZWDj8XwAAAAASUVORK5CYII=');
//${ endregion }
 
var vCommand = new Command("MyTools.Paste", "Paste Template", "Paste my template", nIcon);
vCommand.onExecute = function() {
	var text = '<base href="file:///' + ActiveDocument.Path + '">';
 	ActiveDocument.InsertText(ActiveView.Position, text);
};
vCommand.onEnabled = function() {
	return ActiveDocument !== null && ActiveDocument.ReadOnly !== true;
};
 
Application.RegisterCommand(vCommand);
 
////////////////////////////////////////////////////////////////////////
// Initialize Toolbar
Application.onInitToolbars = function() {
	var MyToolbar = this.GetToolBar("MyTools", true);
	MyToolbar.Name = "MyTools";
	MyToolbar.AddButton(vCommand);
};