Author Topic: Script Plugins, Eventing, UI integration  (Read 6706 times)

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Script Plugins, Eventing, UI integration
« on: November 07, 2011, 03:53:33 am »
Hi All,

from version 1.50.722 it is now possible to create "script plugins" - this is a rich version of scripts (another type is tool script), similar to real binary plugins, which starts automatically, live in background and react on user interaction as keystroke, menu or toolbar selection.

The easiest way to try it out, download plugin file, save it somewhere on your disk, and run it once with Execute... command from Tools menu. After first run, plugin is installed and enabled. If you would like to disable (unload) it you can do it in Tools->Options->Plugins. This test plugin subscribes on most of of HE public events, register commands and adds its own menu, toolbar and status bar items. To get more details check the code of the plugin (open it in editor) - it is self explanatory and rather easy.

Nevertheless, here I will explain some code blocks and their results.

Handlers
First of all, main difference of the script plugin from tool script, that code is not executed directly as it done on script plugin, but you register handlers, that are called some when later, reacting on user interaction or editor command. Such handlers can be presented or as functions
Code: Javascript
  1. Application.onDocumentNameChanged = function (old_name, new_name, rename) {
  2.         Output().writeln("onDocumentNameChanged : old_name = " + old_name + ", new_name = " + new_name + ", rename = " + rename);
  3. }
or be assigned directly as inline code:
Code: Javascript
  1. Application.onDocumentListUpdate = "Output().writeln(\"onDocumentListUpdate\")";
Handlers always have this object, that represent source of event and can have parameters, which forward additional information to handler. And of course you can always access Application object - it is global.
Code: Javascript
  1. Application.onModifiedChanged = function (modified) {
  2.         Output().writeln("onModifiedChanged : document = " + this.Title + ", modified = " + modified); 
  3. }

Commands
Commands - is a handler, associated with icon, title, description, enable state, check state etc. Mentioned properties can be as static as dynamic.
You need commands to get a shortcut registered with your handler, to put your handler into menu or toolbar, or to associate the handler with status bar indicator.
This is a typical code, necessary to create a command:
Code: Javascript
  1. function onTestCommand()[attachimg=2]
  2. {
  3.         alert(this.Name + " called!" + "\r\nStored Value: " + readStorage("val1", 25));
  4. }
  5.  
  6. var vTestCMD = Application.CreateCommand("Script.TestCommand", "Test", "I will show alert box", nIconTable, onTestCommand);
  7. Application.RegisterCommand(vTestCMD);
In the example:
"Script.TestCommand" - unique identifier of the command. Not script specific, so be careful that you select name that nobody else will choose.
"Test" - title of the command, to be displayed in menu or as button tooltip or in status bar
"I will show alert box" - command description, prompt
nIconTable - icon index, can be -1, if you do not want an icon to be assigned with command
onTestCommand - handler itself. Can be as function name as inline code
If you would skip last line (RegisterCommand) the command object will not appear in command list in Tools->Options->Keyboard and you will be not able to assign a shortcut to it.

Icons
There are several places in framework, where you need to have icons: command handlers and dialogs.
Code: Javascript
  1. var nIconTable = Application.RegisterIconString(
  2. 'R0lGODlhEAAQAMQAAABIAMPN1gBaxQAbis3w/7vFz///AA6iDm14gwCZ/ygzP////0pTXi+6He3y \
  3. 9yKs/67h/wBDsM3V3nuIlFDVPgBdAODl57/J0xeuEWJqdYyVmgBmzPf5/BytHtbz/////yH5BAEH \
  4. AB8ALAAAAAAQABAAAAWD4CaMQkKW57ZBBOElXvvGBKQ++JPkOr9Fg6BwOIxoFsiFJalkaiZMSZQ5 \
  5. mUgC2Cs2oOVOEAuOOBDmMJEIsJhzWS8q8MoiHSjYL5fl22CQLzILDoIFDm9wBh1xgEkFSBV8iA19 \
  6. DAqVlnsHBxibFR+en54AABUUDRWioKkfj6aqqqKoHyEAOw=='
  7. );
This code registers new icon and returns in variable nIconTable its identifier. You can use it later in all functions that expect icon ids, in particularly when you register new command.
The way you see in example, is registering of inline image. Inline image it is just an image file (bmp, jpg, png, gif, ico) encoded with base64 encoding and pasted as a string into script. You can register icon also directly from file, but for this you need to use RegisterIconPath function. Icon image should have 16x16 pixel size.
All necessary stuff is available online: first go to some online image repository  and find icon you want filtering them by name and save it as a file. Then go to some online base64 converter upload a file you save and convert it to base64. Copy resulting string into script, escape line breaks if necessary, pass to register code, get an id and you are done.

Options pages
Script plugins as reach binary plugins can have their own options pages integrated in Options Dialog UI. So, if you want to add to your script some settings, you do not need to create a dialog and call it by some handler, but you need to create an Options Page and register it.
Code: Javascript
  1. var bval1 = true;
  2.  
  3. function readStorage(key, def_val)
  4. {
  5.         var vStorage = GetStorage(eStorageTypeWorkspace, "", eAccessTypeRead);
  6.         if ( vStorage != undefined )
  7.         {
  8.                 var val1 = vStorage.read(key);
  9.                 if (val1 != undefined) return val1;    
  10.         }
  11.         return def_val;  
  12. }
  13.  
  14. function onOptionsInit()
  15. {
  16.         this.Layout =
  17.         '@<dialog> \
  18.            <group> \
  19.                <paragraph text="Value:"/> \
  20.                    <edit id="val1" minwidth="10"/> \
  21.            </group> \
  22.            <checkbox id="bval1" title="Check Me"/> \
  23.         </dialog>';
  24.        
  25.         // read "setting" from persistent storage
  26.         this.Parameters.write("val1", readStorage("val1", 25));
  27. }
  28.  
  29. function onOptionsApply()
  30. {
  31.         var val1 = this.Parameters.read("val1");
  32.         Output().writeln("val1 : " + val1);
  33.         Output().writeln("Variable bval1: " + bval1);
  34.        
  35.         // store new "setting" value in persistent storage
  36.         GetStorage(eStorageTypeWorkspace, "", eAccessTypeWrite).write("val1", val1);
  37. }
  38.  
  39. function onOptionsContextHelp(varID)
  40. {
  41.         Output().writeln("varID : " + varID);
  42.         return "I am test description for field: " + varID;
  43. }
  44.  
  45. // here we register script settings options page, passing call back functions
  46. // which will be called when option page is created
  47. // Init is required, Apply is needed if you do not use global options variables, ContextHelp handler is optional
  48. Application.RegisterOptionsPage("Service Script", onOptionsInit, onOptionsApply, onOptionsContextHelp);
  49.  
To register Options Page, you need to define minimum two handlers:
 - to initialize options page (function onOptionsInit()), where you set page layout and initialize variables
 - to apply changes (function onOptionsApply()) where you read new settings and apply or persist them. You can skip even this handler, if you are using only global script variables (like var bval1) as data bindings in your dialog layout.
Third handler (onOptionsContextHelp(varID)) needed, if you want to provide additional information for some controls, when user use context help in dialog.

This is how result looks like:


UI Events basics
There is no way to modify UI directly from any part of code. UI can be changed only during dedicated events, that provide you helper objects and ensure that UI modifications are done in right sequence, objects you want to modify already available and actions you did in code can be undone.

Toolbar items
With following sample:
  • script first subscribes to onInitToolbars event (line 1), later when called,
  • creates new toolbar with id "ScriptTest" and makes it visible by default (line 3).
    Creating registering of the new toolbar, automatically adds new commands for displaying of the toolbar (shortcuts can be assigned) and adds menu items under View->Toolbars menu.
  • Names newly created toolbar "ScriptTest" (line 4)
  • adds buttons to toolbar, using previously created handlers (5,7)
  • searches for existing "standard" (toolbar id) toolbar and adds button to it also (lines 8-13).

Code: Javascript
  1. Application.onInitToolbars = function (){
  2.         Output().writeln("onInitToolbars ");
  3.         var MyToolbar = this.GetToolBar("ScriptTest", true);
  4.         MyToolbar.Name = "ScriptTest";
  5.         MyToolbar.AddButton(vTestCMD);
  6.         MyToolbar.AddButton();
  7.         MyToolbar.AddButton(vTestCMD);
  8.         var StandardToolbar = this.GetToolBar("standard", false);
  9.         if ( undefined != StandardToolbar )
  10.         {
  11.                 StandardToolbar.AddButton();
  12.                 StandardToolbar.AddButton(vTestCMD);
  13.         }
  14. }

Added toolbar items looks like this:

first marked button item added to "standard" toolbar, second marking correspond to newly created "ScriptTest" toolbar.

Main Menu extensions
Main menu can be modified in two ways: statically, if item set is known and should not be changed at runtime; or dynamically, if item set is unknown, depends from some conditions or can be changed (like recent list for example).

Static case covered withing onInitMainMenu event. In provided example, scripts insertss command handler after command "Edit.DeleteDuplicates" (found in Format menu) and separate it by separator.
nUpdate parameter indicates that menu is only updated (some times can happen), but normally, static items should be added only one update is false.
Code: Javascript
  1. Application.onInitMainMenu = function (bUpdate){
  2.         Output().writeln("onInitMainMenu : " + this.ItemsCount);
  3.         if ( bUpdate == false )
  4.         {
  5.                 Output().writeln("onInitMainMenu : initialized");
  6.                 var menu_location = this.GetMenuItemPos("Edit.DeleteDuplicates");
  7.                 if ( menu_location.Menu != null && menu_location.Position != -1)
  8.                 {
  9.                         Output().writeln("onInitMainMenu : Insert command into position " + (menu_location.Position + 1));
  10.                         menu_location.Menu.InsertItem(menu_location.Position + 1, "", vTestCMD);
  11.                         menu_location.Menu.InsertItem(menu_location.Position + 1);
  12.                 }
  13.         }
  14. }
  15. }

Snapshot shows added static item, after Edit.DeleteDuplicates item.


Adding of the dynamic items should be added withing onMainSubmenuUpdate event. It called every time, user activates one of top main menu entries (File, Edit Format etc).
Because menu keeps it state, you need to delete old your entries first, and then re-add them.
The menu can be recognized by Name property. 
Code: Javascript
  1. Application.onMainSubmenuUpdate = function (){
  2.         Output().writeln("onMainSubmenuUpdate : " + this.ItemsCount);
  3. }

Context Menu Extension
The following code add new item to context menu, using previously created command handler.
Item added to predefined place - designed by editor (sometimes, sometimes this is just bottom). You can also add items to top, bottom of menu or in specific place. The menu is rebuild on every context menu call.
Parameter eStyle indicates type of the context menu (standard, read-only, format, margin, tab etc).
view, nLine, nPos - indicates current view and location of cursor. Optional - depends on context menu style.
Code: Javascript
  1. Application.onInitContextMenu = function (eStyle, view, nLine, nPos){  
  2.         var sTrace = "onInitContextMenu : count = " + this.ItemsCount + ", style = " + eStyle;
  3.         if (view != undefined) sTrace += ", document = " + view.Document.Title + ", nLine = " + nLine + ", nPos = " + nPos;
  4.         Output().writeln(sTrace);
  5.  
  6.         // add context menu item at "predefined" place
  7.         this.AddItem("Test in Context Menu", vTestCMD);
  8. }
  9.  

This is example of standard context menu. Marked is added in predefined place item.


Status Bar Extension
The following sample code adds to new indicators to status bar using already registered command handlers (vTestCMD and vTestCMD2).
By default, click on indicator will execute the command. If you want to show menu as for vTestCMD you need to register onMenuCreate event and add items when corresponding command will be triggered.
If indicator are not visible initially, enable them with status bar context menu.
Code: Javascript
  1. Application.onInitStatusBar = function () {
  2.         Output().writeln("onInitStatusBar : indicators = " + this.ItemsCount);
  3.         this.AddIndicator(vTestCMD, 50);
  4.         this.AddIndicator(vTestCMD2, 50);
  5. }
  6. Application.onMenuCreate = function (command) {
  7.         Output().writeln("onMenuCreate : command = " + command);
  8.         if ( command == "Script.TestCommand" )
  9.         {
  10.                 this.AddItem("", vTestCMD);
  11.                 this.AddItem();
  12.                 this.AddItem("", vTestCMD);
  13.         }
  14. }

This is a result of the script execution.


Generic (not UI) events
In addition to UI events, there are of course, normal, functional events informing you about internal processes as: changing of cursor position, changing of active document, closing of the workspace, change of global  settings etc.
Code: Javascript
  1. Application.onCursorPosChange = function (pos) {
  2.         // "this" corresponds to View object
  3.         Output().writeln("onCursorPosChange : document = " + this.Document.Title + ", View Version = " + this.Version + ", position = (" + pos.Line + ", " + pos.Pos + ")");
  4. }
  5. Application.onDocumentSwitch = function (document) {
  6.         // "this" corresponds to Application object
  7.         if (document != undefined)
  8.                 Output().writeln("onDocumentSwitch : document = " + document.Title);
  9.         else
  10.                 Output().writeln("onDocumentSwitch");
  11. }
  12. Application.onWorkspaceClose = function (bSaveState) {
  13.         Output().writeln("onWorkspaceClose : save_state = " + bSaveState);
  14. }
  15. Application.onSettingsChange = function () {
  16.         // "this" corresponds to Settings object
  17.         Output().writeln("onSettingsChange : user_der = " + this.UserDirectory);
  18. }
Given above template subscribes to mentioned events, and outputs details about event to default Output pane.

Command listeners
Command listeners allows script:
  • to be informed about standard commands and interrupt processing before or after it
  • execute some code code before or after standard (or any registered) command
  • replace execution of standard code by own code (for example commenting or processing)

To be notified, script should register command listener, with assigned handlers for before and after execution.
Code: Javascript
  1. function onBeforeExecute(command)
  2. {
  3.         Output().writeln("onBeforeExecute : command = " + command);
  4.         return true;
  5. }
  6.  
  7. function onAfterExecute(command)
  8. {
  9.         Output().writeln("onAfterExecute : command = " + command);
  10.         return true;
  11. }
  12. Application.RegisterCommandListener("Edit.Find", Application.CreateCommandListener(onBeforeExecute, onAfterExecute));

Script Code Templates

Code: Javascript
  1. var vCodeTemplate = Application.CreateCodeTemplate("return \"SCRIPT-TEMPLATE\";", "return \"Script TEMPLATE Description\";", null);
  2. Application.RegisterCodeTemplate("tmpl+", vCodeTemplate);

to be continued...
« Last Edit: January 04, 2012, 09:32:42 pm by alex »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #1 on: November 07, 2011, 04:44:00 pm »
Please delete this post )or move it) if it wrong here.

I just have my lunch break while reading this and was thinking "what a bunch of news, how should i be able to manage to understand that all?"

But then i saw quickly what is it about, see pictures:

ila_rendered

ila_rendered



Still know nothing, but i will play with this for sure. Thanks.

EDIT:
To remove this modifications from that plugin, simply restart HippoEDIT.  Was false assuming. See below.

EDIT:
Exchange screen shots.
« Last Edit: November 07, 2011, 11:38:17 pm by Stefan »

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Script Plugins, Eventing, UI integration
« Reply #2 on: November 07, 2011, 08:54:36 pm »
Hi Stefan,

thanks for help with explanations: I just have no time to describe everything, but it would come - you have seen to be contunued at the end of the post ;)

Was not sure about this your sentence "To remove this modifications from that plugin, simply restart HippoEDIT."
Generally, if you once started (Execute...) the script plugin file, it is automatically restarted next time you start hippoedit.
To disable it, you need to go to Tools->Options->Plugins and uncheck check box in-front of the plugin name. Same as for normal plugins and similar to syntax enablement.


And in your investigations you have not noticed, I think: main menu entry (Format->Test), two status bar indicators (maybe they by default hidden, check context menu of the status bar) and editor context menu, that also got new entry ;)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #3 on: November 07, 2011, 10:19:51 pm »
Alex> Was not sure about this your sentence "To remove this modifications from that plugin, simply restart HippoEDIT."
Alex> Generally, if you once started (Execute...) the script plugin file, it is automatically restarted next time you start hippoedit.
Alex> To disable it, you need to go to Tools->Options->Plugins and uncheck check box in-front of the plugin name.
Ahh there!. I disabled instead the checkbox before "Check me" but the output don't stop  ::)  Of course as i see now  ;D
But after an re-launch of HE the menu bar button and the test command are gone and the output has stopped.
(don't know why, didn't tested further. Note: i had no admin-rights)


Alex> And in your investigations you have not noticed,
I had not more time while at the job ATM  ;) . Just my launch break.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Script Plugins, Eventing, UI integration
« Reply #4 on: November 07, 2011, 11:45:01 pm »
This "Check Me" was added to the page only as example, you can access than updated value in script (see onOptionsApply). Probably the check me is example of global variables updating. It updates bVal variable, defined in global scope.

Yo do not need admin rights to install a plugin. Neither binary or script. So, this should not be a problem.
But what can be a problem, is write access to your settings (workspace file and hippoedit.config). Inside of them information about the registration stored.
If will not work further, I need to check.

Next days (till end of the week) I will have not too much time, to answer all question and update the HOW-TO, but will definitely answer everything after.
And, I think, now it is already good time to start with adopting your scripts for HE, because as  wrote some where, I think this is more or less final stage for scripting development.

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #5 on: November 07, 2011, 11:57:30 pm »
OK, i updated my screen shots above.  Nice work Alex, well done !

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #6 on: November 08, 2011, 12:03:32 am »
I was able to disable the plugin as indented from option.
Then i enabled plugin again and re-launched HE. Service plugin is not anymore in plugin list. I have to execute service.hejs again.
I have checked as "portable" during installation. I have admin-rights on this pc. I have full access to ini on both pcs.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Script Plugins, Eventing, UI integration
« Reply #7 on: November 08, 2011, 12:59:33 am »
this is generally strange.. The only problem can be that you save the file service.hejs in plugins folder... In this case explicit file names are no stored, because there is automatic harvesting for plugins in plugins folder or in user folder/plugins ... But not for script plugins... Because if you will use includes, and place them aside, I do not see easy way now to recognize that file is include but not a standalone plugin...
Where you saved a file?

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #8 on: November 08, 2011, 11:14:35 am »
I use "hippou150_pdb (DL 2011-11-07) 722 723.exe" Installed to "h:\Program Files\HippoEDIT150\" with option "portable" checked.
I have executed "h:\Program Files\HippoEDIT150\SCRIPTing\service.hejs".
All features are there as show above in screen shots.
I use File > Exit.
I go double clicking "h:\Program Files\HippoEDIT150\HippoEdit.exe"
All features are gone and the "service.hejs" is missing from Options > Plugins
I had to re-execute "service.hejs"

- - -

For an test I disabled "Output" and "Search" plugin to see if i have write access, clicked at [Apply] then HE crashed to me.
But after relaunch those plugins are disabled (and "service.hejs" is missed).  So storing that info works.



The runtimes should be recent as i have used the installer.  (But maybe i install 723 fresh in an not used folder? The last installation was to the "old working" folder)


hippoedit.config   2.148   08.11.2011 08:10   -a--
uninst.exe   204.480   07.11.2011 13:11   -a--
CrashReport.exe   77.824   07.11.2011 13:11   -a--
ShellReg.dll   57.344   07.11.2011 13:11   -a--
HippoEdit.exe   3.321.856   06.11.2011 16:54   -a--
HippoEdit.pdb   95.210.496   06.11.2011 16:54   -a--
EditLibu.dll   3.039.232   06.11.2011 16:46   -a--
GuiLibu.dll   602.112   06.11.2011 16:44   -a--
ToolsLibu.dll   385.024   06.11.2011 16:44   -a--
HippoEDIT.chm   309.547   06.11.2011 16:38   -a--
EditLibu.pdb   28.584.960   20.07.2011 00:31   -a--
GuiLibu.pdb   8.981.504   20.07.2011 00:28   -a--
ToolsLibu.pdb   5.164.032   20.07.2011 00:27   -a--
msvcr80.dll   632.656   14.05.2011 01:17   -a--
msvcp80.dll   554.832   14.05.2011 01:17   -a--
mfc80u.dll   1.093.120   13.05.2011 19:04   -a--
Microsoft.VC80.MFC.manifest   2.372   13.05.2011 19:04   -a--
Microsoft.VC80.CRT.manifest   1.870   13.05.2011 16:59   -a--
license.dat   2.048   12.07.2010 15:40   -a--
HippoEDIT.url   107   11.09.2009 23:58   -a--
license.txt   6.496   02.09.2008 18:39   -a--
license.xUSSR.txt   2.789   02.09.2008 18:39   -a--

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Script Plugins, Eventing, UI integration
« Reply #9 on: November 08, 2011, 09:21:33 pm »
Hi  Stefan,

Try to place service.hejs somew here outside of the hippoedit folder and execute it from there. Just for test.

Disabling of output or search was a bad idea - try some others ;) While these plugins are essential for some core functions. For example tracing messages from script. I need to put more checks there.

Br,Alex

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #10 on: November 08, 2011, 10:29:48 pm »
OK, moved service.hejs somewhere outside of the hippoedit folder and all works as you told.
I can restart HE and plugin is still there. I can disable plugin, restart, and plugin is still there.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Script Plugins, Eventing, UI integration
« Reply #11 on: November 09, 2011, 12:13:43 pm »
Hi Stefan,

thanks for the investigation. Yes, this is what I meant. That engine throws away all entries in hippoedit deriectory. Generally, may be it was better to limit such logic only for plugins dir, but I have decided (because scripting plugins treated as normal plugins) to search for binary plugins everywhere, while, who knows where user will drop the file. And he can disable it, if he wants, later if it will be activated adn he does not like it.

The only thing, that is definitly wrong, is that in your case, because you have explictly "install" the plugin, it should not be thrown away, even if it is located somewhere under HE directories. I will correct it. And also will try to enhance the logic for autoamic findings of the script plugins, and to determine where is an include and where is a main file (this is difficult, because I need first to start the script, to determine if it is a plugin or not, and it will execute automatically, what is bad if it is not a plugin :/ ).

Of course, now everything is rather raw, and can crash when you play around, but I will try to fix all this stuuf asap.

Best regards,
Alex.

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #12 on: November 09, 2011, 06:00:26 pm »
Just my thought:
Plugins should be only taken as plugins if they are in the plugins sub-folder. Even an script as plugin.
For scripts meant to be an include for others, maybe define that there has to be a specific header line? Like: //include
Maybe the same for plugins: //plugin

If //include is found on an scan don't take this file as an stand alone script.
Only If //plugin is found on an scan execute this script as an plugin.

All other files without such line are meant as an script.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: Script Plugins, Eventing, UI integration
« Reply #13 on: November 14, 2011, 10:53:44 pm »
OK, I have changed the logic, to check only plugins folders located in install or user directory.

The problem with includes is vice verse -  HE needs to recognize, that a file is include, but not a plugin, without instantiating it. But nevertheless,  I do not like solutions with "magic" strings, I will try to avoid them, if other way exist. But I will see.

Thanks any way for ideas!

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Script Plugins, Eventing, UI integration
« Reply #14 on: November 15, 2011, 11:04:04 pm »
If the plugins are located in an dedicated sub-folder
there is no need to "flag" an include-file, since only the user has to know that an file is meant to be an include-file.

Only if you see an problem for e.g. parsing the folder for script files to show them in an menu
and want to exclude the include files from that view, then i see only three ways:
* special file name-part for include files ( incFileName.ext  or  filename.inc.ext)
* dedicated folder for include files (\Scripts\Includes)
* magic string in header line (//i am an include file)


BTW, maybe you like to know my thought and want to consider this in your code :
i often have the need to "hide"/disable temporarily script file (e.g. tests, or to don't overload the menu, or to have scripts only for special tasks)
So, will you skip files which have no know script extension ( like .txt, or .disabled or .vbs_ )

And in the same meaning: i guess you will show all the scripts from script folder in an menu.
Since i have used a lot of scripts i had always the wish to be allowed to have sub-folders in the script folder
and the menu will show the sub-folder as pop-up/sub-menu in the main menu.
I mean: i f i have "Scripts\Test"  and  "Scripts\TextMani", i would like to have this sub categories in the menu too automatically.

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
3643 Views
Last post February 23, 2009, 03:11:01 pm
by alex
3 Replies
5907 Views
Last post April 24, 2009, 03:57:52 pm
by alex
12 Replies
5881 Views
Last post April 20, 2009, 06:57:53 am
by timohayes
1 Replies
2622 Views
Last post September 27, 2009, 07:47:24 pm
by Stefan
10 Replies
2857 Views
Last post May 12, 2011, 02:58:40 pm
by alex