home *** CD-ROM | disk | FTP | other *** search
- !!script
- // Copyright ⌐ 1997-1999 - Modelworks Software
- // @Modified build 273 cm19990307 - added OpenUrl(path) function
- // @Modified build 284 cm19990328 - encoded special characters
-
- /**
- @Tool: runHtmlBrowser~launches your default HTML browser using either the current
- document if it is a HTML or VRML type or a document returned by the choose file dialog. Use the
- Tools/Configuration/htmlBrowser script to set or change your default HTML browser.
- @EndTool:
- @Summary: runHtnlBrowser~launches your default HTML browser
- */
-
- var output = getOutput();
-
- function DoCommand()
- {
- saveAll(false);
-
- var path = "";
-
- // If the current document is a HTML file then use that file
- var editor = getActiveEditor();
- if (editor)
- {
- var fileType = editor.getFile().fileType.toLowerCase();
- if (fileType == "htm" || fileType == "html" || fileType == "wrl" || fileType == "htp")
- {
- path = editor.path;
- }
- }
-
- // Else ask the user to locate a HTML or VRML file
- if (path == "")
- {
- var file =
- chooseFile("Choose a HTML or VRML file to open in your browser",
- "HTML/VRML files", "*.htm*;*.wrl;*.htp");
- if (file && file.exists)
- {
- path = "file://" + file.urlpath;
- }
- }
-
- if (path.length > 0)
- {
- RunHtmlBrowser(path);
- }
- }
-
- function RunHtmlBrowser(path)
- {
- var helpers = getMapFile("ApplicationHelpers");
-
- // Get the HTML browser file object
- var browser = helpers.lookup("DefaultHtmlBrowser");
-
-
- if (browser && browser.exists)
- {
- output.clear();
- output.writeLine("Starting HTML Browser for " + path);
-
- var openHtmlInANewWindow = getMapFileValue("Preferences", "Open html files in a new browser window", false);
- if (openHtmlInANewWindow)
- {
- shellExecute("open", path, browser.path);
- }
- else if (searchInString(browser.path, "Netscape", 0, false))
- {
- var message = path + encodeHex(0,1) +
- ",text/html" + encodeHex(0,1) + "," + encodeHex(-1,4);
- if (sendDDEMessage("NSShell","WWW_ShowFile", message))
- {
- // This message is not needed for Netscape 4.x
- // sendDDEMessage("Netscape","WWW_Activate",
- // encodeHex(-1,4) + "," + encodeHex(0,4));
- }
- else if (sendDDEMessage("Netscape","WWW_ShowFile", message))
- {
- // Netscape does not process this message correctly
- // sendDDEMessage("Netscape","WWW_Activate",
- // encodeHex(-1,4) + "," + encodeHex(0,4));
- }
- else
- {
- shellExecute("open", path, browser.path);
- }
- }
- else
- {
- var message = "\"" + path + "\",text/html,-1,";
- if (sendDDEMessage("IExplore","WWW_ShowFile", message))
- {
- sendDDEMessage("IExplore","WWW_Activate", "0xFFFFFFFF,0")
- }
- else
- {
- shellExecute("open", path, browser.path);
- }
- }
- }
- else
- {
- var result = confirm("You need to run the HtmlBrowser setup script\n"
- + "before you can use this command.\n" +
- "Do you want to run the setup script now?");
- if (result)
- {
- run("Configuration\\HtmlBrowser");
- }
- }
- }
-
- function OpenUrl(url)
- {
- var helpers = getMapFile("ApplicationHelpers");
-
- // Get the HTML browser file object
- var browser = helpers.lookup("DefaultHtmlBrowser");
-
- if (browser && browser.exists)
- {
- //output.clear();
- //output.writeLine("Starting HTML Browser for " + url);
-
- if (searchInString(browser.path, "Netscape", 0, false))
- {
- var message = url + encodeHex(0,1) +
- ",text/html" + encodeHex(0,1) + "," + encodeHex(-1,4);
- if (sendDDEMessage("NSShell","WWW_OpenURL", message))
- {
- // This message is not needed for Netscape 4.x
- // sendDDEMessage("Netscape","WWW_Activate",
- // encodeHex(-1,4) + "," + encodeHex(0,4));
- }
- else if (sendDDEMessage("Netscape","WWW_OpenURL", message))
- {
- // Netscape does not process this message correctly
- // sendDDEMessage("Netscape","WWW_Activate",
- // encodeHex(-1,4) + "," + encodeHex(0,4));
- }
- else
- {
- shellExecute("open", url, browser.path);
- }
- }
- else
- {
- // IE does not appear to accept a <path>#<target> when using the
- // WWW_ShowFile. So we create a temporary file and put the link
- // <path>#<target> in the temporary file in a Refresh command.
-
- // Create a html file with a jump to the correct <path>#<target>
- var tempPath = File.getDataPath() + "\\Temp\\runHtmlBrowserUrl.html";
- var editor = newEditor(tempPath, false);
- if (editor)
- {
- url = EncodeSpecialCharacters(url); //cm19990328
-
- editor.removeAll();
-
- editor.append("<html> <head> <meta http-equiv=\"Refresh\" content=\"0; url='");
- editor.append(url);
- editor.append("'\"></head><body></body></html>");
- editor.close(true,false);
-
- var message = "\"" + tempPath + "\",text/html,-1,,,,,";
- if (sendDDEMessage("IExplore","WWW_ShowFile", message))
- {
- sendDDEMessage("IExplore","WWW_Activate", "0xFFFFFFFF,0")
- }
- else
- {
- shellExecute("open", url, browser.path);
- }
-
- }
- }
- }
- else
- {
- var result = confirm("You need to run the HtmlBrowser setup script\n"
- + "before you can use this command.\n" +
- "Do you want to run the setup script now?");
- if (result)
- {
- run("Configuration\\HtmlBrowser");
- }
- }
- }
-
- function EncodeSpecialCharacters(url) //cm19990328
- {
- var index = url.indexOf(' ');
- while (index > -1)
- {
- url = replaceInString(url, index, 1, "%20");
- index = url.indexOf(' ');
- }
-
- index = url.indexOf(':');
- while (index > -1)
- {
- url = replaceInString(url, index, 1, "%3A");
- index = url.indexOf(':');
- }
-
- index = url.indexOf('\\');
- while (index > -1)
- {
- url = replaceInString(url, index, 1, "%5C");
- index = url.indexOf('\\');
- }
-
- index = url.indexOf(',');
- while (index > -1)
- {
- url = replaceInString(url, index, 1, "%2C");
- index = url.indexOf(',');
- }
-
- index = url.indexOf('(');
- while (index > -1)
- {
- url = replaceInString(url, index, 1, "%28");
- index = url.indexOf('(');
- }
-
- index = url.indexOf(')');
- while (index > -1)
- {
- url = replaceInString(url, index, 1, "%29");
- index = url.indexOf(')');
- }
- return url;
- }
-
- !!/script
-
-