home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Help / javaContextHelp.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  4.1 KB  |  143 lines

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