Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| scripting:service [2015/01/20 01:27] – admin | 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 ===== | ===== Examples ===== | ||
| - | Set syntax dynamically for new files (normally this is done with Tools-> | + | ==== Overwrite default syntax of new files ==== |
| + | |||
| + | Set syntax dynamically | ||
| <file javascript on-new-document.hejs> | <file javascript on-new-document.hejs> | ||
| onNewDocument = function() { | onNewDocument = function() { | ||
| Line 11: | Line 17: | ||
| }; | }; | ||
| </ | </ | ||
| + | |||
| + | ==== 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: | ||