Following sample plugin will add two new options to the right-click menu. Paste the following code into a file named demoEditorContextMenu.hks and install it using the "Tools | Install | Plugin" main menu option. To test the plugin, open a document, right click and select one of the new options.
--- cut here ---
function hkp_Register(pDataIn, pDataOut)
{
hkp_DataSetGlobalSuffix("_1");
// name of the plugin, must be unique
hkp_DataAdd(pDataOut, "NAME", "demoEditorContextMenu");
// we don't need to display a button on the Actions Bar
hkp_DataAddInt(pDataOut, "BUTTON_VISIBLE", 0);
// enable support for editor context menu
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_VISIBLE", 1);
// caption of our right-click menu item
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_SECTION", "Date / Time");
// display a hint as well
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_HINT",
"Insert current date / time.");
// request right-click related events
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_EVENT_ONOPEN", 1);
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_EVENT_ONCLICK", 1);
hkp_DataSetGlobalSuffix("");
}
function hkp_Main(pDataIn, pDataOut)
{
var nEvent = 0, sOutput = "";
// get the plugin event
nEvent = hkp_DataGetInt(pDataIn, "EVENT", 0);
// populate our right-click menu
if(1201 == nEvent)
{
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_ITEM1",
"&Date -- "+gettime("d-mmm-yyyy") );
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_ITEM_HINT1",
"Insert current date.");
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_ITEM2",
"&Time -- "+gettime("hh:mm:ss") );
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_ITEM_HINT2",
"Insert current time.");
}
// handle our menu commands
if(1203 == nEvent)
{
var nMenuItem = 0;
nMenuItem = hkp_DataGetInt(pDataIn, "ARGV1", -1);
// send the date
if(1 == nMenuItem)
{
sOutput = gettime("d-mmm-yyyy");
}
// send the time
else if(2 == nMenuItem)
{
sOutput = gettime("hh:mm:ss");
}
hkp_DataAdd(pDataOut, "OUTPUT", sOutput);
}
hkp_DataAddInt(pDataOut, "MODE_OUTPUT", 1);
}
--- cut here ---
Following sample plugin demonstrates how to dynamically draw and update icons. Paste the following code into a file named demoDynamicContextMenuIcon.hks and as mentioned above. To test the plugin, open a document and right click.
--- cut here ---
// replace the icon at index "nIconIndex"
// with the new "sIconData" icon
function __IconReplace( nIconIndex, nIconMode, sIconData )
{
var nResult = 0, pIN = 0, pOUT = 0;
pIN = hkp_DataNew();
pOUT = hkp_DataNew();
hkp_DataAdd( pIN, "FUNC_NAME", "IconReplace" );
hkp_DataAddInt( pIN, "FUNC_PARAM1", 1 );
hkp_DataAddInt( pIN, "FUNC_PARAM2", nIconIndex );
hkp_DataAddInt( pIN, "FUNC_PARAM3", nIconMode );
hkp_DataAdd( pIN, "FUNC_PARAM4", sIconData );
if(hkp_Func(pIN, pOUT))
{
nResult = 1;
}
hkp_DataFree( pOUT );
hkp_DataFree( pIN );
return nResult;
}
function hkp_Register(pDataIn, pDataOut)
{
var sIcon1 =
"AAABAAEAEBAEAAAAAAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8A"
"AAD//wD/AAAA/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAEREREREAAAAREREREQA"
"AABES7u0RAAAAEREu0REAAAARES7REQAAABERLtERAAAAERLu0REAAAAREREREQAAABERL"
"tERAAAAEREREREAAAAREREREQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAO"
"AHAADgBwAA4AcAAOAHAADgBwAA4AcAAOAHAADgBwAA4AcAAOAHAADgBwAA//8AAP//AAD/"
"/wAA"
;
hkp_DataSetGlobalSuffix("_1");
hkp_DataAdd(pDataOut, "NAME", "demoDynamicContextMenuIcon");
hkp_DataAddInt(pDataOut, "MODE_ICON", 1);
// default icon -- add it twice as index 1 and 2
hkp_DataAdd(pDataOut, "ICON_INDEX1", sIcon1);
hkp_DataAdd(pDataOut, "ICON_INDEX2", sIcon1);
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_VISIBLE", 1);
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_SECTION", "Dynamic Icon");
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_ICONINDEX", 1);
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_EVENT_ONOPEN", 1);
hkp_DataSetGlobalSuffix("");
}
function hkp_Main(pDataIn, pDataOut)
{
var nEvent = 0;
nEvent = hkp_DataGetInt(pDataIn, "EVENT", 0);
// populate the menu
if(1201 == nEvent)
{
hkp_DataAdd(pDataOut, "CONTEXTMENU_EDITOR_ITEM1", "Another dynamically created icon");
hkp_DataAddInt(pDataOut, "CONTEXTMENU_EDITOR_ITEM_ICONINDEX1", 2);
// draw red, green and blue bars (BC=BrushColor, FR=FillRect)
var sIconRGB = "BC=#ff0000;FR=0,0,4,15;BC=#008000;FR=5,0,9,15;BC=#0000ff;FR=10,0,14,15;";
__IconReplace( 1, 4, sIconRGB );
// draw the number of seconds on the icon
// (PC=PenColor, MT=MoveTo, LT=LineTo, TO=TextOut)
var sIconSeconds = "";
sIconSeconds = "PC=#00ccff;MT=0,0;LT=15,0;PC=#0099cc;TO=1,1,2,"+gettime("ss")+";";
__IconReplace( 2, 4, sIconSeconds );
}
hkp_DataAddInt(pDataOut, "MODE_OUTPUT", 1);
}
--- cut here ---