scripting:events:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
scripting:events:start [2017/03/16 01:15] – external edit 127.0.0.1scripting:events:start [2018/01/10 20:41] (current) – external edit 127.0.0.1
Line 8: Line 8:
 To subscribe on event, you just assign your handler function to appropriate named plug from engine (plugs are members of [[scripting:api:script-application:start|Application]] object). Something like this: To subscribe on event, you just assign your handler function to appropriate named plug from engine (plugs are members of [[scripting:api:script-application:start|Application]] object). Something like this:
 <file javascript doc_save_handler.js> <file javascript doc_save_handler.js>
-function myDocumentSaveHandler() +function myDocumentSaveHandler() {
-{+
     alert("Some document was Saved!");     alert("Some document was Saved!");
 } }
- 
 Application.onNewDocument = myDocumentSaveHandler; Application.onNewDocument = myDocumentSaveHandler;
 </file> </file>
 The code above will show message box, as far as any document saved. The code above will show message box, as far as any document saved.
  
-Handlers always have **this** object, that represent source of event and can have parameters (can be checked in [[scripting:api:start|API documentation]]), which forward additional information to handler.\\+Handlers always have **this** object, that represents source of event and can have parameters (can be checked in [[scripting:api:start|API documentation]]), which forward additional information to handler.\\
 To receive them you need to define input parameters of your functions in the sequence as it defined by API. If you do not need some trailing parameters, you can skip their definition in handler signature (even if you catch no parameters it will work). And of course, you can always access Application object - it is global.  To receive them you need to define input parameters of your functions in the sequence as it defined by API. If you do not need some trailing parameters, you can skip their definition in handler signature (even if you catch no parameters it will work). And of course, you can always access Application object - it is global. 
 <file javascript on_file_rename.js> <file javascript on_file_rename.js>
-function myRenameHandler = (old_name, new_name, rename)  +Application.onDocumentNameChange function(old_name, new_name, rename) {
-{+
   Output().writeln("onDocumentNameChange : old_name = " + old_name + ",    Output().writeln("onDocumentNameChange : old_name = " + old_name + ", 
   new_name = " + new_name + ", rename = " + rename);   new_name = " + new_name + ", rename = " + rename);
 } }
-Application.onDocumentNameChange = myRenameHandler; 
 </file> </file>
 The above code will be called on file rename and shall output old and new file name together with rename indicator passed as event parameters.  The above code will be called on file rename and shall output old and new file name together with rename indicator passed as event parameters. 
  
-Following code executed when document is modified or saved and uses **this** object, that represent a document here, to get //Title// text. The type of the this pointer for every handler can be checked in documentation, but normally it is clear from handler purpose. +Following code executed when document is modified or saved and uses **this** object, that represent a document here, to get //Title// text. The type of this pointer for every handler can be checked in the documentation, but normally it is clear from handler purpose. 
 <file javascript on_file_modified.js> <file javascript on_file_modified.js>
-function myOnModified (modified)  +Application.onModifiedChanged = function (modified) {
-{+
   Output().writeln("onModifiedChanged : document = " + this.Title + ", modified = " + modified);   Output().writeln("onModifiedChanged : document = " + this.Title + ", modified = " + modified);
 } }
-Application.onModifiedChanged = myOnModified; 
 </file> </file>
  
Line 63: Line 57:
  
 ==== Event Hubs ==== ==== Event Hubs ====
-Sometimes you want to connect more than one event handler to same event plug. Of course, you can do it also in code by creating one hub handler and dispatching event to every single handler, but there is easier way. You can use dedicated functions from HippoEDIT scripting framework:+Sometimes you want to connect more than one event handler to same event plug. Of course, you can do it also in code by creating one hub handler and dispatching the event to every single handler, but there is the easier way. You can use dedicated functions from HippoEDIT scripting framework:
  
   * **boolean attachEvent(string EventName, object eventHandler)** - helper to attach more than one handler to event plug   * **boolean attachEvent(string EventName, object eventHandler)** - helper to attach more than one handler to event plug