# HG changeset patch # User Eugene Ostroukhov # Date 1263333032 28800 # Node ID 50ffca984095b1788614ace892cd3d2fc5320df8 # Parent 315b47abf7f396a48548a8a987a6f31764b6125e Home button now works, launch configuration was renamed diff -r 315b47abf7f3 -r 50ffca984095 .hgignore --- /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 diff -r 315b47abf7f3 -r 50ffca984095 org.symbian.tools.wrttools.debug.core/launch/WRT Debugger.launch --- 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 315b47abf7f3 -r 50ffca984095 org.symbian.tools.wrttools/META-INF/MANIFEST.MF --- 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", diff -r 315b47abf7f3 -r 50ffca984095 org.symbian.tools.wrttools/META-INF/MANIFEST.MF-copy --- 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 diff -r 315b47abf7f3 -r 50ffca984095 org.symbian.tools.wrttools/launch/WRT IDE.launch --- /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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 315b47abf7f3 -r 50ffca984095 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java --- 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()) {