Home button now works, launch configuration was renamed
authorEugene Ostroukhov <eostroukhov@symbian.org>
Tue, 12 Jan 2010 13:50:32 -0800
changeset 30 50ffca984095
parent 29 315b47abf7f3
child 31 05ef77be4f3a
Home button now works, launch configuration was renamed
.hgignore
org.symbian.tools.wrttools.debug.core/launch/WRT Debugger.launch
org.symbian.tools.wrttools/META-INF/MANIFEST.MF
org.symbian.tools.wrttools/META-INF/MANIFEST.MF-copy
org.symbian.tools.wrttools/launch/WRT IDE.launch
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue Jan 12 13:50:32 2010 -0800
@@ -0,0 +1,2 @@
+syntax: regexp
+^[\w\.]*/bin
\ No newline at end of file
--- a/org.symbian.tools.wrttools.debug.core/launch/WRT Debugger.launch	Tue Jan 12 13:42:37 2010 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench">
-<booleanAttribute key="append.args" value="true"/>
-<booleanAttribute key="askclear" value="true"/>
-<booleanAttribute key="automaticAdd" value="true"/>
-<booleanAttribute key="automaticValidate" value="false"/>
-<stringAttribute key="bad_container_name" value="\org.symbian.tools.wrttools.debug.core\launch"/>
-<stringAttribute key="bootstrap" value=""/>
-<stringAttribute key="checked" value="[NONE]"/>
-<booleanAttribute key="clearConfig" value="false"/>
-<booleanAttribute key="clearws" value="false"/>
-<booleanAttribute key="clearwslog" value="false"/>
-<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/WRT Debugger"/>
-<booleanAttribute key="default" value="true"/>
-<booleanAttribute key="includeOptional" value="true"/>
-<stringAttribute key="location" value="${workspace_loc}/../runtime-WRT-Debugger"/>
-<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
-<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
-</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms128m -Xmx768m -XX:MaxPermSize=192m"/>
-<stringAttribute key="pde.version" value="3.3"/>
-<stringAttribute key="product" value="org.eclipse.platform.ide"/>
-<booleanAttribute key="restart" value="false"/>
-<booleanAttribute key="show_selected_only" value="false"/>
-<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
-<booleanAttribute key="tracing" value="false"/>
-<booleanAttribute key="useDefaultConfig" value="true"/>
-<booleanAttribute key="useDefaultConfigArea" value="true"/>
-<booleanAttribute key="useProduct" value="true"/>
-<booleanAttribute key="usefeatures" value="false"/>
-</launchConfiguration>
--- a/org.symbian.tools.wrttools/META-INF/MANIFEST.MF	Tue Jan 12 13:42:37 2010 -0800
+++ b/org.symbian.tools.wrttools/META-INF/MANIFEST.MF	Tue Jan 12 13:50:32 2010 -0800
@@ -18,7 +18,9 @@
  org.eclipse.wst.jsdt.core;bundle-version="1.0.200",
  org.eclipse.wst.css.core;bundle-version="1.1.300",
  org.eclipse.ui.ide;bundle-version="3.5.0",
- org.eclipse.wst.validation;bundle-version="1.2.102"
+ org.eclipse.wst.validation;bundle-version="1.2.102",
+ org.eclipse.wst.sse.core;bundle-version="1.1.401",
+ org.eclipse.wst.xml.core;bundle-version="1.1.401"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
 Import-Package: org.apache.velocity;version="1.5.0",
--- a/org.symbian.tools.wrttools/META-INF/MANIFEST.MF-copy	Tue Jan 12 13:42:37 2010 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: org.symbian.tools.wrttools
-Bundle-SymbolicName: org.symbian.tools.wrttools
-Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.symbian.tools.wrttools.Activator
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime
-Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Import-Package: org.eclipse.core.resources,
- org.eclipse.jdt.ui,
- org.eclipse.ui.console,
- org.eclipse.ui.dialogs,
- org.eclipse.ui.ide
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/launch/WRT IDE.launch	Tue Jan 12 13:50:32 2010 -0800
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="askclear" value="true"/>
+<booleanAttribute key="automaticAdd" value="true"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bad_container_name" value="\org.symbian.tools.wrttools.debug.core\launch"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="false"/>
+<booleanAttribute key="clearws" value="false"/>
+<booleanAttribute key="clearwslog" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/WRT IDE"/>
+<booleanAttribute key="default" value="true"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="location" value="${workspace_loc}/../runtime-WRT-IDE"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms128m -Xmx768m -XX:MaxPermSize=192m"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<stringAttribute key="product" value="org.eclipse.platform.ide"/>
+<booleanAttribute key="restart" value="false"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
+<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useDefaultConfig" value="true"/>
+<booleanAttribute key="useDefaultConfigArea" value="true"/>
+<booleanAttribute key="useProduct" value="true"/>
+<booleanAttribute key="usefeatures" value="false"/>
+</launchConfiguration>
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Tue Jan 12 13:42:37 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Tue Jan 12 13:50:32 2010 -0800
@@ -50,14 +50,22 @@
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.statushandlers.StatusManager;
 import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
 import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
 import org.symbian.tools.wrttools.Activator;
 import org.symbian.tools.wrttools.dialogs.AptanaProjectSelectionDialog;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 public class ProjectUtils {
+	private static final String WRT_PREVIEW_MAIN_HTML = "wrt_preview_main.html";
 	public static final String PREVIEW_FOLDER = "preview";
 	public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html";
 
+	@SuppressWarnings("restriction")
 	public static IProject createWrtProject(String name, URI uri,
 			IProgressMonitor monitor) throws CoreException {
 		monitor.beginTask("Create project resources", 20);
@@ -97,11 +105,7 @@
 					stream.closeEntry();
 				}
 			}
-			IFile file = project.getFile(mainHtml + ".html");
-			if (file.exists()) {
-				file.copy(project.getFullPath().append("wrt_preview_main.html"), false, new NullProgressMonitor());
-			}
-			
+			createPreviewerHomePage(project, mainHtml);
 		} catch (IOException e) {
 			StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to add previewer to project"));
 		} catch (CoreException e) {
@@ -109,6 +113,45 @@
 		}
 	}
 
+	@SuppressWarnings("restriction")
+	private static void createPreviewerHomePage(IProject project, IPath mainHtml)
+			throws CoreException, IOException {
+		IFile file = project.getFile(mainHtml + ".html");
+		if (file.exists()) {
+			IFile newFile = project.getFile(WRT_PREVIEW_MAIN_HTML);
+			file.copy(newFile.getFullPath(), false, new NullProgressMonitor());
+			IModelManager modelManager = StructuredModelManager
+					.getModelManager();
+			IDOMModel model = (IDOMModel) modelManager
+					.getModelForEdit(newFile);
+			if (model != null) {
+				try {
+					addJS(model);
+				} finally {
+					model.releaseFromEdit();
+				}
+			}
+		}
+	}
+
+	@SuppressWarnings("restriction")
+	private static void addJS(IDOMModel model) throws IOException, CoreException {
+		IDOMDocument document = model.getDocument();
+		Element documentElement = document.getDocumentElement();
+		if (documentElement != null) {
+			NodeList elementsByTagName = documentElement.getElementsByTagName("head");
+			if (elementsByTagName.getLength() == 1) { // We do not want to handle malformed HTMLs
+				Element head = (Element) elementsByTagName.item(0);
+				Element script = document.createElement("script");
+				script.setAttribute("language", "JavaScript");
+				script.setAttribute("type", "text/javascript");
+				script.setAttribute("src", "preview/script/lib/loader.js");
+				head.insertBefore(script, head.getFirstChild());
+				model.save();
+			}
+		}
+	}
+
 	private static URI getPreviewerArchive() {
 		File file = getPreviewerZip();
 		if (file.isFile()) {