Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/intro/IntroEditor.java |
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/intro/IntroEditor.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/intro/IntroEditor.java |
| index e25967f4be5f89f88e1dab71804f12263a81b0f6..91ee76e2db596124787117d3e2344f8997a05cfa 100644 |
| --- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/intro/IntroEditor.java |
| +++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/intro/IntroEditor.java |
| @@ -1,5 +1,5 @@ |
| /* |
| - * Copyright 2011 Google Inc. |
| + * Copyright 2012 Google Inc. |
| * |
| * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except |
| * in compliance with the License. You may obtain a copy of the License at |
| @@ -13,26 +13,31 @@ |
| */ |
| package com.google.dart.tools.ui.internal.intro; |
| -import com.google.dart.tools.ui.DartToolsPlugin; |
| +import com.google.dart.tools.core.DartCore; |
| +import com.google.dart.tools.ui.internal.handlers.OpenFileHandler; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| -import org.eclipse.jface.layout.GridDataFactory; |
| import org.eclipse.jface.resource.ImageDescriptor; |
| -import org.eclipse.jface.resource.JFaceResources; |
| import org.eclipse.swt.SWT; |
| +import org.eclipse.swt.browser.Browser; |
| +import org.eclipse.swt.browser.BrowserFunction; |
| +import org.eclipse.swt.browser.LocationAdapter; |
| +import org.eclipse.swt.browser.LocationEvent; |
| import org.eclipse.swt.layout.GridData; |
| +import org.eclipse.swt.layout.GridLayout; |
| +import org.eclipse.swt.program.Program; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.IEditorInput; |
| import org.eclipse.ui.IEditorSite; |
| import org.eclipse.ui.IPersistableElement; |
| -import org.eclipse.ui.forms.IFormColors; |
| -import org.eclipse.ui.forms.widgets.FormText; |
| import org.eclipse.ui.forms.widgets.FormToolkit; |
| -import org.eclipse.ui.forms.widgets.TableWrapData; |
| -import org.eclipse.ui.forms.widgets.TableWrapLayout; |
| import org.eclipse.ui.part.EditorPart; |
| +import java.io.File; |
| +import java.text.MessageFormat; |
| +import java.util.List; |
| + |
| /** |
| * A "fake" editor for showing intro content to first time users. |
| */ |
| @@ -78,14 +83,6 @@ public class IntroEditor extends EditorPart { |
| }; |
| } |
| - private static String bold(String str) { |
| - return "<span font=\"header\">" + str + "</span>"; |
| - } |
| - |
| - private static String img(String imgName) { |
| - return " <img href=\"" + imgName + "\"/> "; |
| - } |
| - |
| private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); |
| public IntroEditor() { |
| @@ -104,12 +101,10 @@ public class IntroEditor extends EditorPart { |
| @Override |
| public void doSave(IProgressMonitor monitor) { |
| - //no-op |
| } |
| @Override |
| public void doSaveAs() { |
| - //no-op |
| } |
| @Override |
| @@ -131,52 +126,86 @@ public class IntroEditor extends EditorPart { |
| @Override |
| public void setFocus() { |
| - //do nothing on focus gain |
| } |
| private Composite createIntroContent(Composite parent) { |
| Composite composite = new Composite(parent, SWT.NONE); |
| composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
| - |
| - TableWrapLayout layout = new TableWrapLayout(); |
| - layout.verticalSpacing = 0; |
| - layout.horizontalSpacing = 0; |
| - layout.bottomMargin = 0; |
| - layout.topMargin = 20; |
| - layout.rightMargin = 0; |
| - layout.leftMargin = 20; |
| - composite.setLayout(layout); |
| + composite.setLayout(new GridLayout()); |
| toolkit.adapt(composite); |
| - |
| - FormText formText = toolkit.createFormText(composite, true); |
| - formText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)); |
| - |
| - StringBuffer buf = new StringBuffer(); |
| - buf.append("<form>"); |
| - buf.append("<p>"); |
| - buf.append("<span color=\"header\" font=\"header\">" + "Getting started is easy!</span>"); |
| - buf.append("</p>"); |
| - buf.append("<p>" + bold("1. Click ") + img("new_lib_image") + bold("to create an application.") |
| - + "</p>"); |
| - buf.append("<p>" + bold("2. Look around. Click ") + img("run_image") + bold(" to run.") |
| - + "</p>"); |
| - buf.append("<li style=\"text\" bindent=\"20\" indent=\"20\">" |
| - + "<span color=\"header\">(compiles to JavaScript and runs in Chrome)</span></li>"); |
| - buf.append("<p>" + bold("3. Have fun. Write awesome code.") + "</p>"); |
| - buf.append("</form>"); |
| - |
| - formText.setWhitespaceNormalized(true); |
| - TableWrapData twd_formText = new TableWrapData(TableWrapData.FILL); |
| - twd_formText.grabHorizontal = true; |
| - formText.setLayoutData(twd_formText); |
| - formText.setImage("new_lib_image", |
| - DartToolsPlugin.getImage("icons/full/dart16/library_new.png")); |
| - formText.setImage("run_image", DartToolsPlugin.getImage("icons/full/dart16/run_client.png")); |
| - |
| - formText.setColor("header", toolkit.getColors().getColor(IFormColors.TITLE)); |
| - formText.setFont("header", JFaceResources.getHeaderFont()); |
| - |
| - formText.setText(buf.toString(), true, false); |
| + // use Browser |
| + try { |
| + final List<SampleDescription> descriptions = SampleDescriptionHelper.getDescriptions(); |
| + // prepare HTML |
| + String html; |
| + { |
| + StringBuilder sb = new StringBuilder(); |
| + // header |
| + sb.append("<html><body>"); |
| + sb.append("<p>"); |
| + sb.append("Dart is a new class-based programming language for creating" |
| + + " structured web applications. Developed with the goals of simplicity, efficiency," |
| + + " and scalability, the Dart language combines powerful new language features with" |
| + + " familiar language constructs into a clear, readable syntax." |
| + + " See <a href='http://www.dartlang.org'>dartlang.org</a> for more information."); |
|
danrubel
2012/02/07 06:00:46
Can all of this be moved into a welcome.html file
scheglov
2012/02/08 16:07:22
Ah... Good idea!
Done.
|
| + sb.append("</p>"); |
| + // samples |
| + sb.append("<hr/>"); |
| + sb.append("<p>"); |
| + sb.append("Samples: (click to load)"); |
| + sb.append("</p>"); |
| + for (int i = 0; i < descriptions.size(); i++) { |
| + SampleDescription description = descriptions.get(i); |
| + sb.append("<div style='display: inline-block; margin: 5px; cursor: hand;'" |
| + + " onclick='openSample(\"" + i + "\")'>"); |
| + sb.append(description.name); |
| + sb.append("<br/>"); |
| + sb.append(MessageFormat.format( |
| + "<a><img style=''border: 1 red solid;'' src=''{0}'' title=''{1}''/></a>", |
| + description.logo.toURI(), description.description.trim())); |
| + sb.append("</div>"); |
| + } |
| + // footer |
| + sb.append("<hr/>"); |
| + sb.append(" You can read also <a href='http://www.dartlang.org/support/faq.html'>FAQ</a>" |
| + + " and <a href='http://www.dartlang.org/articles/index.html'>articles</a>."); |
| + sb.append("</body></html>"); |
| + html = sb.toString(); |
| + } |
| + // create Browser |
| + Browser browser = new Browser(composite, SWT.WEBKIT); |
| + browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
| + browser.setText(html); |
| + browser.addLocationListener(new LocationAdapter() { |
| + @Override |
| + public void changing(LocationEvent event) { |
| + event.doit = false; |
| + Program.launch(event.location); |
| + } |
| + }); |
| + // register JavaScript function |
| + new BrowserFunction(browser, "openSample") { |
| + @Override |
| + public Object function(Object[] arguments) { |
| + String indexString = (String) arguments[0]; |
| + int index = Integer.parseInt(indexString); |
| + SampleDescription description = descriptions.get(index); |
| + openSample(new File(description.directory, description.file)); |
| + return null; |
| + } |
| + }; |
| + } catch (Throwable e) { |
| + DartCore.logError(e); |
| + } |
| + // done |
| return composite; |
| } |
| + |
| + private void openSample(File file) { |
| + try { |
| + OpenFileHandler.openFile(getEditorSite().getShell(), file); |
| + } catch (Throwable e) { |
| + DartCore.logError(e); |
| + } |
| + } |
| } |