home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
-
- /**
- @Tool: htmlContextHelp~lets you get help from Windows Html help files.
- To use it select a keyword in a HTML document and then hit F1, the tool bar
- help button or run this script. This script will also be invoked for document
- types based on the HTML type such as the HTM file type. If you want to access
- HTML help from another document type then assign this script a hot key.
- @Paragraph: Use the htmlHelp script in Tools/Configuration to set the location
- of your HTML help file.
- @EndTool:
- @Summary: htmlContextHelp~lets you get help from Windows Html help files
- */
-
- function DoCommand()
- {
- var useWin32Help = getMapFileValue("Preferences", "Use win32 help", false);
- if (useWin32Help)
- {
- Win32Help();
- }
- else
- {
- // Use built-in help
- var keyword = "";
- var editor = getActiveEditor();
- if (editor)
- {
- var selection = editor.getSelection();
- if (selection.empty())
- {
- var keyword = GetKeywordAtCaret(editor, selection)
- ShowHelp(keyword);
- }
- else
- {
- var keyword = editor.copy(selection);
- ShowHelp(keyword);
- }
- }
- }
- }
-
- function ShowHelp(keyword)
- {
- if (Application.isMindsInstalled())
- {
- if (Application.isMindsLoaded())
- {
- if (keyword == "" || !Application.showHelp(keyword, "java"))
- {
- alert("No help found for \"" + keyword + "\"");
- }
- }
- else
- {
- alert("The MINDS engine not yet loaded.\r\nTry again when MINDS is loaded.");
- }
- }
- else
- {
- var message = "The MINDS engine is not installed. To use MINDS\r\n";
- message += "restart the IDE without the /nominds option. To use\r\n";
- message += "winHelp turn on the option \"Use win32 help\".\r\n";
- alert(message);
- }
- }
-
- function GetBeginingOfWord(lineData, index)
- {
- while (index >= 0) // cm19991005 changed '=' to '>='
- {
- var c = lineData.charAt(index); //cm19990725
- if (c == ' ' || c == '\t' || c == '.'
- || c == '[' || c == '('
- || c == '"' || c == "'")
- {
- index += 1;
- break;
- }
- index -= 1;
- }
- return index >= 0 ? index : 0;
- }
-
- function GetKeywordAtCaret(editor, selection)
- {
- var lineData = editor.copy(selection.startLineIndex);
- var index = selection.startCharIndex;
- index = GetBeginingOfWord(lineData, index);
- //gOutput.writeLine("Index = " + index);
- var result = searchInString(lineData, "[A-Z|a-z|0-9]*", index, true);
- if (result)
- {
- return result.key;
- }
- return "";
- }
-
- function Win32Help()
- {
- var helpers = getMapFile("ApplicationHelpers");
- if (helpers)
- {
- var htmlHelp = helpers.lookup("html-help");
- if (htmlHelp && htmlHelp.exists)
- {
- var editor = getActiveEditor();
- if (editor)
- {
- var selection = editor.getSelection();
- var keyword = editor.copy(selection);
- winHelp("Keyword", htmlHelp.path, keyword);
- }
- else
- {
- winHelp("Contents", htmlHelp.path);
- }
- }
- else
- {
- var result = confirm("You need to run the Html help setup script\n"
- + "before you can use this command.\n" +
- "Do you want to run the setup script now?");
- if (result)
- {
- run("Configuration\\HtmlHelp");
- }
- }
- }
- }
-
- !!/Script
-