Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| scripting:service [2014/02/09 01:50] – external edit 127.0.0.1 | scripting:service [2018/06/13 00:18] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Service Scripts ====== | ====== Service Scripts ====== | ||
| - | //Service scripts// (or //Script Plugins//) is a rich kind of scripts, that are very close in possibilities to [[plugins: | + | //Service scripts// (or //Script Plugins//) is a rich kind of scripts, that are very close in possibilities to [[plugins: |
| + | |||
| + | 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. | ||
| + | |||
| + | // | ||
| + | // | ||
| + | ===== Examples ===== | ||
| + | |||
| + | ==== Overwrite default syntax of new files ==== | ||
| + | |||
| + | Set syntax dynamically all for new files (normally this is done with Tools-> | ||
| + | <file javascript on-new-document.hejs> | ||
| + | onNewDocument = function() { | ||
| + | this.Syntax = Settings.GetSyntax(" | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | ==== Paste template with a button ==== | ||
| + | The scripts: | ||
| + | * register icon to be used on the toolbar | ||
| + | * creates and registers command to be executed on button click or by shortcut | ||
| + | * adds " | ||
| + | * creates a toolbar and toolbar button and assigns the command to the button. | ||
| + | |||
| + | <file javascript insert-template.hejs> | ||
| + | //${ region Icons } | ||
| + | var nIcon = Application.RegisterImageString( | ||
| + | ' | ||
| + | // | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | //${ endregion } | ||
| + | |||
| + | var vCommand = new Command(" | ||
| + | vCommand.onExecute = function() { | ||
| + | var text = '< | ||
| + | | ||
| + | }; | ||
| + | vCommand.onEnabled = function() { | ||
| + | return ActiveDocument !== null && ActiveDocument.ReadOnly !== true; | ||
| + | }; | ||
| + | |||
| + | Application.RegisterCommand(vCommand); | ||
| + | |||
| + | //////////////////////////////////////////////////////////////////////// | ||
| + | // Initialize Toolbar | ||
| + | Application.onInitToolbars = function() { | ||
| + | var MyToolbar = this.GetToolBar(" | ||
| + | MyToolbar.Name = " | ||
| + | MyToolbar.AddButton(vCommand); | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | ===== Further examples ===== | ||
| + | * [[scripting: | ||