HTML Kit site requirements.

HTML editor / Support Document
HomeHTML-Kit downloadsAdd-ins that update and extend HTML-Kit's capabilitiesSoftware and authoring support channelsRegister -- download add-ons and support HTML-KitOnline tools for HTML-Kit users
 

Support Document

 Home > Support > Support Documents > Plugins > How to: Write context me...
 
 
How to: Write context menu plugins
The information in this document applies to:
 Summary

Starting with HTML-Kit Build 292, the editor context menu can be dynamically updated using plugins. This document contains sample code that can be used to create right-click menu plugins and with dynamically created icons.
 
 Details

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 ---
 
 References
hkClickAndLink
With this plugin you can create links by right clicking the editor and picking the file that you want to link to. If you select some text before right clicking, hkClickAndLink will use it as the link text. Information about the selected file (such as...
 
 
 
Document ID: H000138
Reviewed On: 04-Feb-2002
THE INFORMATION IN THIS DOCUMENT IS PROVIDED ON AN AS-IS BASIS WITHOUT WARRANTY OF ANY KIND. PROVIDER SPECIFICALLY DISCLAIMS ANY OTHER WARRANTY, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL PROVIDER BE LIABLE FOR ANY CONSEQUENTIAL, INDIRECT, SPECIAL OR INCIDENTAL DAMAGES, EVEN IF PROVIDER HAS BEEN ADVISED BY "USER" OF THE POSSIBILITY OF SUCH POTENTIAL LOSS OR DAMAGE. "USER" AGREES TO HOLD PROVIDER HARMLESS FROM AND AGAINST ANY AND ALL CLAIMS, LOSSES, LIABILITIES AND EXPENSES.