home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / HTMLCONTEXTHELP.SCRIPT < prev    next >
Encoding:
Text File  |  2000-10-26  |  3.5 KB  |  135 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: htmlContextHelp~lets you get help from Windows Html help files. 
  6. To use it select a keyword in a HTML document and then hit F1, the tool bar 
  7. help button or run this script. This script will also be invoked for document 
  8. types based on the HTML type such as the HTM file type. If you want to access 
  9. HTML help from another document type then assign this script a hot key. 
  10. @Paragraph: Use the htmlHelp script in Tools/Configuration to set the location 
  11. of your HTML help file. 
  12. @EndTool: 
  13. @Summary: htmlContextHelp~lets you get help from Windows Html help files
  14. */
  15.  
  16. function DoCommand()
  17. {
  18.     var useWin32Help = getMapFileValue("Preferences", "Use win32 help", false);
  19.     if (useWin32Help)
  20.     {
  21.         Win32Help();    
  22.     }
  23.     else
  24.     {        
  25.         // Use built-in help
  26.         var keyword = "";
  27.         var editor = getActiveEditor();
  28.         if (editor)
  29.         {
  30.             var selection = editor.getSelection();
  31.             if (selection.empty())
  32.             {
  33.                 var keyword = GetKeywordAtCaret(editor, selection)
  34.                 ShowHelp(keyword);
  35.             }
  36.             else
  37.             {
  38.                 var keyword = editor.copy(selection);
  39.                 ShowHelp(keyword);
  40.             }
  41.         }
  42.     }
  43. }
  44.  
  45. function ShowHelp(keyword)
  46. {
  47.     if (Application.isMindsInstalled())
  48.     {
  49.         if (Application.isMindsLoaded())
  50.         {
  51.             if (keyword == "" || !Application.showHelp(keyword, "java"))
  52.             {
  53.                 alert("No help found for \"" + keyword + "\"");
  54.             }
  55.         }
  56.         else
  57.         {
  58.             alert("The MINDS engine not yet loaded.\r\nTry again when MINDS is loaded.");
  59.         }
  60.     }
  61.     else
  62.     {
  63.         var message = "The MINDS engine is not installed. To use MINDS\r\n";
  64.         message += "restart the IDE without the /nominds option. To use\r\n";
  65.         message += "winHelp turn on the option \"Use win32 help\".\r\n";
  66.         alert(message);
  67.     }
  68. }
  69.  
  70. function GetBeginingOfWord(lineData, index)
  71. {
  72.     while (index >= 0) // cm19991005 changed '=' to '>='
  73.     {
  74.         var c = lineData.charAt(index); //cm19990725
  75.         if (c == ' ' || c == '\t' || c == '.' 
  76.             || c == '[' || c == '(' 
  77.             || c == '"' || c == "'")
  78.         {
  79.             index += 1;
  80.             break;
  81.         }
  82.         index -= 1;
  83.     }
  84.     return index >= 0 ? index : 0;
  85. }
  86.  
  87. function GetKeywordAtCaret(editor, selection)
  88. {
  89.     var lineData = editor.copy(selection.startLineIndex);
  90.     var index = selection.startCharIndex;
  91.     index = GetBeginingOfWord(lineData, index);
  92.     //gOutput.writeLine("Index = " + index);
  93.     var result = searchInString(lineData, "[A-Z|a-z|0-9]*", index, true);
  94.     if (result)
  95.     {
  96.         return result.key;
  97.     }
  98.     return "";
  99. }
  100.  
  101. function Win32Help()
  102. {
  103.     var helpers = getMapFile("ApplicationHelpers");   
  104.     if (helpers)
  105.     {
  106.         var htmlHelp = helpers.lookup("html-help");
  107.         if (htmlHelp && htmlHelp.exists)
  108.         {
  109.             var editor = getActiveEditor();
  110.             if (editor)
  111.             {
  112.                 var selection = editor.getSelection();
  113.                 var keyword = editor.copy(selection);
  114.                 winHelp("Keyword", htmlHelp.path, keyword);
  115.             }
  116.             else
  117.             {
  118.                 winHelp("Contents", htmlHelp.path);
  119.             }
  120.         }
  121.         else
  122.         {
  123.             var result = confirm("You need to run the Html help setup script\n"
  124.                 + "before you can use this command.\n" +
  125.                 "Do you want to run the setup script now?");
  126.             if (result)
  127.             {
  128.                 run("Configuration\\HtmlHelp");
  129.             }
  130.         }
  131.     }
  132. }
  133.  
  134. !!/Script
  135.