Skip to content

Commit fb131a7

Browse files
author
angelozerr
committed
Initialize custom TypeScriptEditor which uses syntax coloration of JSDT.
See #41
1 parent dab1d1e commit fb131a7

16 files changed

+573
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src/"/>
6+
<classpathentry kind="output" path="target/classes"/>
7+
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin
2+
/target
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>ts.eclipse.ide.ui.editor</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.m2e.core.maven2Builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
31+
<nature>org.eclipse.pde.PluginNature</nature>
32+
<nature>org.eclipse.jdt.core.javanature</nature>
33+
</natures>
34+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: %pluginName
4+
Bundle-Vendor: %providerName
5+
Bundle-Localization: plugin
6+
Bundle-SymbolicName: ts.eclipse.ide.ui.editor;singleton:=true
7+
Bundle-Version: 1.0.0.qualifier
8+
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
9+
Require-Bundle: org.eclipse.ui,
10+
org.eclipse.core.runtime,
11+
org.eclipse.core.resources,
12+
ts.eclipse.ide.core,
13+
ts.core,
14+
org.eclipse.ui.ide,
15+
org.eclipse.ui.console,
16+
org.eclipse.ui.editors,
17+
org.eclipse.jface.text,
18+
org.eclipse.ui.workbench.texteditor,
19+
ts.eclipse,
20+
org.eclipse.core.expressions,
21+
org.eclipse.ui.views,
22+
org.eclipse.ui.navigator,
23+
org.eclipse.ui.forms,
24+
org.eclipse.core.filesystem,
25+
org.eclipse.wst.jsdt.ui;bundle-version="1.1.601"
26+
Bundle-ActivationPolicy: lazy
27+
Bundle-Activator: ts.eclipse.ide.ui.editor.TypeScriptUIEditorPlugin
28+
Import-Package: com.eclipsesource.json;version="[0.9.4,0.9.5)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
###############################################################################
2+
# Copyright (c) 2015-2016 Angelo Zerr and others.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Angelo Zerr <[email protected]> - Initial API and implementation
10+
###############################################################################
11+
source.. = src/
12+
output.. = bin/
13+
bin.includes = META-INF/,\
14+
.,\
15+
plugin.properties,\
16+
plugin.xml,\
17+
icons/,\
18+
css/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Font definitions */
2+
html { font-family: sans-serif; font-size: 9pt; font-style: normal; font-weight: normal; }
3+
body, h1, h2, h3, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt { font-size: 1em; }
4+
pre { font-family: monospace; }
5+
6+
/* Margins */
7+
body { overflow: auto; margin-top: 0px; margin-bottom: 0.5em; margin-left: 0.3em; margin-right: 0px; }
8+
h1 { margin-top: 0.3em; margin-bottom: 0.04em; }
9+
h2 { margin-top: 2em; margin-bottom: 0.25em; }
10+
h3 { margin-top: 1.7em; margin-bottom: 0.25em; }
11+
h4 { margin-top: 2em; margin-bottom: 0.3em; }
12+
h5 { margin-top: 0px; margin-bottom: 0px; }
13+
p { margin-top: 1em; margin-bottom: 1em; }
14+
pre { margin-left: 0.6em; }
15+
ul { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em;}
16+
li { margin-top: 0px; margin-bottom: 0px; }
17+
li p { margin-top: 0px; margin-bottom: 0px; }
18+
ol { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em; }
19+
dl { margin-top: 0px; margin-bottom: 1em; }
20+
dt { margin-top: 0px; margin-bottom: 0px; font-weight: bold; }
21+
dd { margin-top: 0px; margin-bottom: 0px; }
22+
23+
/* Styles and colors */
24+
a:link { color: #0000FF; }
25+
a:hover { color: #000080; }
26+
a:visited { text-decoration: underline; }
27+
a.header:link { text-decoration: none; color: InfoText }
28+
a.header:visited { text-decoration: none; color: InfoText }
29+
a.header:hover { text-decoration: underline; color: #000080; }
30+
h4 { font-style: italic; }
31+
strong { font-weight: bold; }
32+
em { font-style: italic; }
33+
var { font-style: italic; }
34+
th { font-weight: bold; }
35+
36+
/* Workarounds for new Javadoc stylesheet (1.7) */
37+
ul.blockList li.blockList, ul.blockListLast li.blockList {
38+
list-style:none;
39+
}
40+
ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
41+
list-style:none;
42+
}
43+
44+
/**
45+
* TypeScript use /n, etc for the quickInfo/@displayString
46+
*/
47+
pre.displayString { font-family: sans-serif; font-size: 1em; }
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
###############################################################################
2+
# Copyright (c) 2015-2016 Angelo Zerr and others.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License v1.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-v10.html
7+
#
8+
# Contributors:
9+
# Angelo Zerr <[email protected]> - Initial API and implementation
10+
###############################################################################
11+
pluginName=TypeScript - Eclipse - UI Editor
12+
providerName=Angelo ZERR
13+
14+
# TypeScript Hover
15+
TypeScriptEditor.name=TypeScript Editor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.0"?>
3+
<!--
4+
###############################################################################
5+
# Copyright (c) 2015-2016 Angelo Zerr and others.
6+
# All rights reserved. This program and the accompanying materials
7+
# are made available under the terms of the Eclipse Public License v1.0
8+
# which accompanies this distribution, and is available at
9+
# http://www.eclipse.org/legal/epl-v10.html
10+
#
11+
# Contributors:
12+
# Angelo Zerr <[email protected]> - Initial API and implementation
13+
###############################################################################
14+
-->
15+
<plugin>
16+
17+
<extension
18+
id="TypeScriptDocumentSetupParticipant"
19+
name="%javaDocumentSetupParticipant"
20+
point="org.eclipse.core.filebuffers.documentSetup">
21+
<participant
22+
contentTypeId="ts.eclipse.ide.jsdt.core.tsSource"
23+
extensions="ts,tsx,jsx"
24+
class="org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaDocumentSetupParticipant">
25+
</participant>
26+
</extension>
27+
28+
<extension
29+
point="org.eclipse.ui.editors">
30+
<editor
31+
name="%TypeScriptEditor.name"
32+
default="true"
33+
icon="$nl$/icons/full/obj16/ts.png"
34+
contributorClass="ts.eclipse.ide.ui.editor.internal.TypeScriptEditorActionContributor"
35+
class="ts.eclipse.ide.ui.editor.internal.TypeScriptEditor"
36+
symbolicFontName="org.eclipse.wst.jsdt.ui.editors.textfont"
37+
id="ts.eclipse.ide.ui.editor.TypeScriptEditor"
38+
extensions="ts,tsx,jsx">
39+
<contentTypeBinding contentTypeId="org.eclipse.wst.jsdt.core.tsSource" />
40+
<contentTypeBinding contentTypeId="org.eclipse.wst.jsdt.core.tsxSource" />
41+
<contentTypeBinding contentTypeId="org.eclipse.wst.jsdt.core.jsxSource" />
42+
</editor>
43+
</extension>
44+
45+
</plugin>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<artifactId>ts.eclipse.ide.ui.editor</artifactId>
4+
<packaging>eclipse-plugin</packaging>
5+
<parent>
6+
<groupId>fr.opensagres.js</groupId>
7+
<artifactId>eclipse</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.ui.editor;
12+
13+
import org.eclipse.core.runtime.IStatus;
14+
import org.eclipse.core.runtime.MultiStatus;
15+
import org.eclipse.core.runtime.Status;
16+
import org.eclipse.swt.widgets.Display;
17+
import org.eclipse.swt.widgets.Shell;
18+
import org.eclipse.ui.IWorkbenchPage;
19+
import org.eclipse.ui.IWorkbenchWindow;
20+
import org.eclipse.ui.forms.FormColors;
21+
import org.eclipse.ui.forms.widgets.FormToolkit;
22+
import org.eclipse.ui.plugin.AbstractUIPlugin;
23+
import org.eclipse.ui.texteditor.IDocumentProvider;
24+
import org.osgi.framework.BundleContext;
25+
26+
import ts.eclipse.ide.ui.editor.internal.TypeScriptDocumentProvider;
27+
import ts.eclipse.ide.ui.editor.internal.TypeScriptUIMessages;
28+
29+
/**
30+
* The activator class controls the plug-in life cycle
31+
*/
32+
public class TypeScriptUIEditorPlugin extends AbstractUIPlugin {
33+
34+
// The plug-in ID
35+
public static final String PLUGIN_ID = "ts.eclipse.ide.ui.editor"; //$NON-NLS-1$
36+
37+
private static final int INTERNAL_ERROR = 10001;
38+
39+
// The shared instance
40+
private static TypeScriptUIEditorPlugin plugin;
41+
42+
private FormToolkit fDialogsFormToolkit;
43+
44+
private TypeScriptDocumentProvider documentProvider;
45+
46+
/**
47+
* The constructor
48+
*/
49+
public TypeScriptUIEditorPlugin() {
50+
}
51+
52+
@Override
53+
public void start(BundleContext context) throws Exception {
54+
super.start(context);
55+
plugin = this;
56+
}
57+
58+
@Override
59+
public void stop(BundleContext context) throws Exception {
60+
try {
61+
if (fDialogsFormToolkit != null) {
62+
fDialogsFormToolkit.dispose();
63+
fDialogsFormToolkit = null;
64+
}
65+
} finally {
66+
plugin = null;
67+
super.stop(context);
68+
}
69+
}
70+
71+
/**
72+
* Returns the shared instance
73+
*
74+
* @return the shared instance
75+
*/
76+
public static TypeScriptUIEditorPlugin getDefault() {
77+
return plugin;
78+
}
79+
80+
public static IWorkbenchWindow getActiveWorkbenchWindow() {
81+
return getDefault().getWorkbench().getActiveWorkbenchWindow();
82+
}
83+
84+
public static Shell getActiveWorkbenchShell() {
85+
IWorkbenchWindow window = getActiveWorkbenchWindow();
86+
if (window != null) {
87+
return window.getShell();
88+
}
89+
return null;
90+
}
91+
92+
/**
93+
* @return Returns the active workbench window's currrent page.
94+
*/
95+
public static IWorkbenchPage getActivePage() {
96+
return getActiveWorkbenchWindow().getActivePage();
97+
}
98+
99+
public FormToolkit getDialogsFormToolkit() {
100+
if (fDialogsFormToolkit == null) {
101+
FormColors colors = new FormColors(Display.getCurrent());
102+
colors.setBackground(null);
103+
colors.setForeground(null);
104+
fDialogsFormToolkit = new FormToolkit(colors);
105+
}
106+
return fDialogsFormToolkit;
107+
}
108+
109+
public static void log(IStatus status) {
110+
getDefault().getLog().log(status);
111+
}
112+
113+
public static void logErrorMessage(String message) {
114+
log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, null));
115+
}
116+
117+
public static void logErrorStatus(String message, IStatus status) {
118+
if (status == null) {
119+
logErrorMessage(message);
120+
return;
121+
}
122+
MultiStatus multi = new MultiStatus(PLUGIN_ID, INTERNAL_ERROR, message, null);
123+
multi.add(status);
124+
log(multi);
125+
}
126+
127+
public static void log(String message, Throwable e) {
128+
log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, e));
129+
}
130+
131+
public static void log(Throwable e) {
132+
log(TypeScriptUIMessages.TypeScriptUIPlugin_internal_error, e);
133+
}
134+
135+
public synchronized IDocumentProvider getTypeScriptDocumentProvider() {
136+
if (documentProvider == null) {
137+
documentProvider = new TypeScriptDocumentProvider();
138+
}
139+
return documentProvider;
140+
}
141+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ts.eclipse.ide.ui.editor.internal;
2+
3+
import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
4+
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
5+
import org.eclipse.ui.texteditor.IDocumentProvider;
6+
import org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaDocumentSetupParticipant;
7+
import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions;
8+
9+
public class TypeScriptDocumentProvider extends TextFileDocumentProvider {
10+
11+
public TypeScriptDocumentProvider() {
12+
IDocumentProvider provider = new TextFileDocumentProvider();
13+
provider = new ForwardingDocumentProvider(IJavaScriptPartitions.JAVA_PARTITIONING,
14+
new JavaDocumentSetupParticipant(), provider);
15+
setParentDocumentProvider(provider);
16+
}
17+
}

0 commit comments

Comments
 (0)