// this is an example of service script var nIconTable = Application.RegisterImageString( 'R0lGODlhEAAQAMQAAABIAMPN1gBaxQAbis3w/7vFz///AA6iDm14gwCZ/ygzP////0pTXi+6He3y \ 9yKs/67h/wBDsM3V3nuIlFDVPgBdAODl57/J0xeuEWJqdYyVmgBmzPf5/BytHtbz/////yH5BAEH \ AB8ALAAAAAAQABAAAAWD4CaMQkKW57ZBBOElXvvGBKQ++JPkOr9Fg6BwOIxoFsiFJalkaiZMSZQ5 \ mUgC2Cs2oOVOEAuOOBDmMJEIsJhzWS8q8MoiHSjYL5fl22CQLzILDoIFDm9wBh1xgEkFSBV8iA19 \ DAqVlnsHBxibFR+en54AABUUDRWioKkfj6aqqqKoHyEAOw==' ); // add optional script information, nice when you want to see something meaningful // in plugin description in options dialog Application.AddScriptInfo("63B059B7-6F70-47FA-A5CA-F29099EF2B63", "Script Plugin", "1.0.0.0", "Example script plug-in", "HippoEDIT", "supportbox@hippoedit.com", "http://www.hippoedit.com"); function onTestCommand() { alert(this.Name + " called!" + "\r\nStored Value: " + readStorage("val1", 25)); } var vTestCMD = new Command("Script.TestCommand", "Test", "I will show alert box", nIconTable, onTestCommand); Application.RegisterCommand(vTestCMD); function onTestCommand2() { alert(this.Name + " called!" + "\r\nStored Value: " + readStorage("val1", 25)); } var vTestCMD2 = new Command("Script.TestCommand2", "Test2", "I will show alert box 2", -1, onTestCommand); Application.RegisterCommand(vTestCMD2); // it is not necessary to create a function for handler, you can also create an in-line code // which will be automatically converted to a function Application.RegisterCommand(new Command("Script.InlineCmd", "Test In-line CMD", "I will show alert box", -1, "alert(this.Name + \"!\\r\\n I am In-line command!\");")); var bval1 = true; function readStorage(key, def_val) { var vStorage = GetStorage(eStorageTypeWorkspace, "", eAccessTypeRead); if ( vStorage != undefined ) { var val1 = vStorage.read(key); if (val1 != undefined) return val1; } return def_val; } function onOptionsInit() { this.Layout = '@ \ \ \ \ \ \ '; // read "setting" from persistent storage this.Parameters.write("val1", readStorage("val1", 25)); } function onOptionsApply() { var val1 = this.Parameters.read("val1"); Output().writeln("val1 : " + val1); Output().writeln("Variable bval1: " + bval1); // store new "setting" value in persistent storage GetStorage(eStorageTypeWorkspace, "", eAccessTypeWrite).write("val1", val1); } function onOptionsContextHelp(varID) { Output().writeln("varID : " + varID); return "I am test description for field: " + varID; } // here we register script settings options page, passing call back functions // which will be called when option page is created // Init is required, Apply is needed if you do not use global options variables, ContextHelp handler is optional Application.RegisterOptionsPage("Service Script", onOptionsInit, onOptionsApply, onOptionsContextHelp); //////////////////////////////////////////////////////////////////////// // Test Frame Events Application.onDocumentListUpdate = "Output().writeln(\"onDocumentListUpdate\")"; Application.onDocumentListUpdate = "Output().writeln(\"onDocumentListUpdate\")"; //////////////////////////////////////////////////////////////////////// // attach/detach event tests // this is extended technique if you want to have more than one handler attached to same event from same script // and normally is not needed, while you can also copy previous handler and call it inside of your handler // as an alternative function onDocumentListUpdate2() { Output().writeln("onDocumentListUpdate2"); } function onDocumentListUpdate3() { Output().writeln("onDocumentListUpdate3"); if (Application.detachEvent("onDocumentListUpdate", onDocumentListUpdate3)) Output().writeln("onDocumentListUpdate3 detached"); } if (Application.attachEvent("onDocumentListUpdate", onDocumentListUpdate2)) Output().writeln("onDocumentListUpdate2 attached"); if (Application.attachEvent("onDocumentListUpdate", onDocumentListUpdate3)) Output().writeln("onDocumentListUpdate3 attached"); Application.onDocumentStateUpdate = function () { Output().writeln("onDocumentStateUpdate : name = " + this.Title); } Application.onDocumentNameChange = function (old_name, new_name, rename) { Output().writeln("onDocumentNameChanged : old_name = " + old_name + ", new_name = " + new_name + ", rename = " + rename); } Application.onWorkspaceOpen = function (bSaveState) { Output().writeln("onWorkspaceOpened : save_state = " + bSaveState); } Application.onWorkspaceClose = function (bSaveState) { Output().writeln("onWorkspaceClose : save_state = " + bSaveState); } // Application.onIdle = "Output().writeln(\"onIdle\")"; Application.onCanCloseWorkspace = function () { Output().writeln("onCanCloseWorkspace"); return true; } Application.onCanCloseApplication = function () { Output().writeln("onCanCloseApplication"); return true; } Application.onModifiedChange = function (modified) { Output().writeln("onModifiedChanged : document = " + this.Title + ", modified = " + modified); } Application.onDocumentClose = "Output().writeln(\"onFileClose : document = \" + this.Title)"; Application.onDocumentOpen = "Output().writeln(\"onFileOpen : document = \" + this.Title)"; Application.onDocumentSave = "Output().writeln(\"onFileSave : document = \" + this.Title)"; Application.onNewDocument = "Output().writeln(\"onNewDocument : document = \" + this.Title)"; Application.onSyntaxChanged = function (old_syntax) { if (old_syntax != undefined) Output().writeln("onSyntaxChanged : document = " + this.Title + ", new_syntax = " + this.Syntax.Name + ", old_syntax = " + old_syntax.Name); else Output().writeln("onSyntaxChanged : document = " + this.Title + ", new_syntax = " + this.Syntax.Name); } Application.onCursorPosChange = function (pos) { // "this" corresponds to View object Output().writeln("onCursorPosChange : document = " + this.Document.Title + ", View Version = " + this.Version + ", position = (" + pos.Line + ", " + pos.Pos + ")"); } Application.onTextInsert = function (pos, text, action) { // "this" corresponds to Document object Output().writeln("onTextInsert : document = " + this.Title + ", Version = " + this.Version + ", position = (" + pos.Line + ", " + pos.Pos + ")" + ", text = \"" + text + "\", action = " + action); } Application.onEditOperation = function (action) { // "this" corresponds to Document object Output().writeln("onEditOperation : document = " + this.Title + ", Version = " + this.Version + ", action = " + action); } Application.onSettingsChange = function () { // "this" corresponds to Settings object Output().writeln("onSettingsChange : user_der = " + this.UserDirectory); } Application.onDocumentSwitch = function (document) { // "this" corresponds to Application object if (document != undefined) Output().writeln("onDocumentSwitch : document = " + document.Title); else Output().writeln("onDocumentSwitch"); } Application.onFocusSet = function () { // "this" corresponds to View object Output().writeln("onFocusSet : document = " + this.Document.Title + ", View Version = " + this.Version); } Application.onFocusLost = function () { // "this" corresponds to View object Output().writeln("onFocusLost : document = " + this.Document.Title + ", View Version = " + this.Version); } Application.onScroll = function (nScrollX, nScrollY) { // "this" corresponds to View object Output().writeln("onScroll : document = " + this.Document.Title + ", View Version = " + this.Version + ", scrollX = " + nScrollX + ", scrollY = " + nScrollY); } Application.onSelectionChange = function (selection, block_mode) { // "this" corresponds to View object Output().writeln("onSelectionChange : document = " + this.Document.Title + ", View Version = " + this.Version + ", selection = (" + selection.Left + "," + selection.Top + "," + selection.Right + "," + selection.Bottom + "), block_mode = " + block_mode); } //////////////////////////////////////////////////////////////////////// // UI Events handlers Application.onMenuCreate = function (command) { Output().writeln("onMenuCreate : command = " + command); if ( command == "Script.TestCommand" ) { this.AddItem("", vTestCMD); this.AddItem(); this.AddItem("", vTestCMD); } } //////////////////////////////////////////////////////////////////////// // Test Toolbar handlers Application.onInitToolbars = function (){ Output().writeln("onInitToolbars "); var MyToolbar = this.GetToolBar("ScriptTest", true); MyToolbar.Name = "ScriptTest"; MyToolbar.AddButton(vTestCMD); MyToolbar.AddButton(); MyToolbar.AddButton(vTestCMD); var StandardToolbar = this.GetToolBar("standard", false); if ( undefined != StandardToolbar ) { StandardToolbar.AddButton(); StandardToolbar.AddButton(vTestCMD); } } //////////////////////////////////////////////////////////////////////// // Test Main Menu handlers Application.onInitMainMenu = function (bUpdate){ Output().writeln("onInitMainMenu : " + this.ItemCount); if ( bUpdate == false ) { Output().writeln("onInitMainMenu : initialized"); var menu_location = this.GetMenuItemPos("Edit.DeleteDuplicates"); if ( menu_location.Menu != null && menu_location.Position != -1) { Output().writeln("onInitMainMenu : Insert command into position " + (menu_location.Position + 1)); menu_location.Menu.InsertItem(menu_location.Position + 1, "", vTestCMD); menu_location.Menu.InsertItem(menu_location.Position + 1); } } } Application.onMainSubmenuUpdate = function (){ Output().writeln("onMainSubmenuUpdate : " + this.ItemCount); } //////////////////////////////////////////////////////////////////////// // Test Context Menu handlers Application.onInitContextMenu = function (eStyle, view, nLine, nPos){ var sTrace = "onInitContextMenu : count = " + this.ItemCount + ", style = " + eStyle; if (view != undefined) sTrace += ", document = " + view.Document.Title + ", nLine = " + nLine + ", nPos = " + nPos; Output().writeln(sTrace); // add context menu item at "predefined" place this.AddItem("Test in Context Menu", vTestCMD); } //////////////////////////////////////////////////////////////////////// // Test Status Bar handlers Application.onInitStatusBar = function () { Output().writeln("onInitStatusBar : indicators = " + this.ItemCount); this.AddIndicator(vTestCMD, 50); this.AddIndicator(vTestCMD2, 50); } //////////////////////////////////////////////////////////////////////// // Command listeners // allows to be informed about standard commands and interrupt processing before or after function onBeforeExecute(command) { Output().writeln("onBeforeExecute : command = " + command); return true; } function onAfterExecute(command) { Output().writeln("onAfterExecute : command = " + command); return true; } Application.RegisterCommandListener("Edit.Find", new CommandListener(onBeforeExecute, onAfterExecute)); //////////////////////////////////////////////////////////////////////// // CodeTemplate handlers var vCodeTemplate = new CodeTemplate(null, "return \"SCRIPT-TEMPLATE\";", "return \"Script TEMPLATE Description\";", null); Application.RegisterCodeTemplate("tmpl+", vCodeTemplate);