home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1999 - Modelworks Software
-
- /**
- @Tool: createJavaHtmlView~creates a HTML file version of
- the active editor
- @EndTool:
- @Summary: reateJavaHtmlView~creates a HTML file view
- */
-
- var gOutput = getOutput();
- var gStyleHanderMap;
- var gTabSpaces = "";
-
- function DoCommand()
- {
- var editor = getActiveEditor();
- if (editor)
- {
- for (var i = 0; i < editor.tabWidth; i++)
- {
- gTabSpaces += " ";
- }
-
- DefineStyleHandlerMap();
- var htmlOut = newEditor(".html", true);
- WriteHeader(htmlOut, editor.path);
- var range = newRange(0,0,0,0);
- var lineCount = editor.getLineCount();
- for (var lineIndex = 0; lineIndex < lineCount; lineIndex++)
- {
- var lineLength = editor.getLineLength(lineIndex);
- var charIndex = 0;
- while (charIndex < lineLength)
- {
- var style = editor.getSyntaxColorStyle(lineIndex, charIndex, range);
- charIndex = range.endCharIndex + 1;
- ProcessRange(htmlOut, style, range, editor);
- }
- WriteNewLine(htmlOut);
- }
- WriteTrailer(htmlOut);
- htmlOut.setActive(); // make it visible if it is not already visible
- }
- }
-
- function ProcessRange(htmlOut, style, range, editor)
- {
- var handler = gStyleHanderMap.lookup(style);
- if (handler)
- {
- //gOutput.writeLine("Processing style: " + style);
- handler(htmlOut, style, range, editor);
- }
- else
- {
- WritePlainText(htmlOut, style, range, editor);
- }
- }
-
-
- // Handler map
- function DefineStyleHandlerMap()
- {
- gStyleHanderMap = newMap();
-
- // Headers
- gStyleHanderMap.add("plain text", WritePlainText);
- gStyleHanderMap.add("quoted string", WriteStringText);
- gStyleHanderMap.add("comment", WriteItalic);
- gStyleHanderMap.add("line comment", WriteItalic);
-
- gStyleHanderMap.add("java awt classes", WriteBold);
- gStyleHanderMap.add("java data types", WriteBold);
- gStyleHanderMap.add("java interfaces", WriteBold);
- gStyleHanderMap.add("java preprocessor", WriteBold);
- gStyleHanderMap.add("java reserved methods", WriteBold);
- gStyleHanderMap.add("java reserved words", WriteBold);
- gStyleHanderMap.add("java swing classes", WriteBold);
- gStyleHanderMap.add("java util classes", WriteBold);
- }
-
- function WritePlainText(htmlOut, style, range, editor)
- {
- var text = EncodeText(editor.copy(range));
- htmlOut.append(text);
- }
-
- function WriteStringText(htmlOut, style, range, editor)
- {
- var text = EncodeText(editor.copy(range));
- htmlOut.append("<i><b>" + text + "</b></i>");
- }
-
- function WriteBold(htmlOut, style, range, editor)
- {
- var text = EncodeText(editor.copy(range));
- htmlOut.append("<b>" + text + "</b>");
- }
-
- function WriteItalic(htmlOut, style, range, editor)
- {
- var text = EncodeText(editor.copy(range));
- htmlOut.append("<i>" + text + "</i>");
- }
-
- function WriteHeader(htmlOut, name)
- {
- htmlOut.append("<html>\n");
- htmlOut.append("<head>\n");
- htmlOut.append("<meta name=\"generator\" content=\"Modelworks IDE\">\n");
- htmlOut.append("<title>" + name +"</title>\n");
- htmlOut.append("</head>\n");
- htmlOut.append("<body bgcolor=\"#ffffff\">\n");
- htmlOut.append("<pre>\n");
- }
-
- function WriteNewLine(htmlOut)
- {
- htmlOut.append("\n");
- }
-
- function WriteTrailer(htmlOut)
- {
- htmlOut.append("</pre>\n");
- htmlOut.append("</body>\n");
- htmlOut.append("</html>\n");
- }
-
- function EncodeText(text)
- {
- var index = text.indexOf('\t');
- while (index > -1)
- {
- text = replaceInString(text, index, 1, gTabSpaces);
- index = text.indexOf('\t');
- }
-
- var index = text.indexOf('<');
- while (index > -1)
- {
- text = replaceInString(text, index, 1, "<");
- index = text.indexOf('<');
- }
-
- var index = text.indexOf('>');
- while (index > -1)
- {
- text = replaceInString(text, index, 1, ">");
- index = text.indexOf('>');
- }
-
- return text;
- }
-
-
- !!/Script
-
-