Skip to content

Commit 7b0ee12

Browse files
Show problem status in editor icon
1 parent e6bfd03 commit 7b0ee12

File tree

8 files changed

+441
-0
lines changed

8 files changed

+441
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
* Lorenzo Dalla Vecchia <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.jsdt.internal.ui;
12+
13+
import org.eclipse.jface.resource.ImageDescriptor;
14+
import org.eclipse.jface.resource.JFaceResources;
15+
import org.eclipse.jface.viewers.DecorationOverlayIcon;
16+
import org.eclipse.swt.graphics.Image;
17+
import org.eclipse.ui.ISharedImages;
18+
import org.eclipse.ui.PlatformUI;
19+
import org.eclipse.ui.plugin.AbstractUIPlugin;
20+
import org.osgi.framework.Bundle;
21+
22+
/**
23+
* Image registry for JSDT TypeScript UI plugin.
24+
*/
25+
public enum JSDTTypeScriptUIImages {
26+
27+
TSFILE("icons/full/obj16/ts.png"),
28+
29+
TSFILE_W_ERROR(TSFILE, null, null, getSharedImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR), null),
30+
31+
TSFILE_W_WARNING(TSFILE, null, null, getSharedImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), null),
32+
33+
;
34+
35+
private JSDTTypeScriptUIImages(String path) {
36+
Bundle bundle = JSDTTypeScriptUIPlugin.getDefault().getBundle();
37+
ImageDescriptor descr = AbstractUIPlugin.imageDescriptorFromPlugin(bundle.getSymbolicName(), path);
38+
JFaceResources.getImageRegistry().put(key(), descr);
39+
}
40+
41+
private JSDTTypeScriptUIImages(JSDTTypeScriptUIImages base, ImageDescriptor tlOverlay, ImageDescriptor trOverlay,
42+
ImageDescriptor blOverlay, ImageDescriptor brOverlay) {
43+
ImageDescriptor descr = new DecorationOverlayIcon(base.get(),
44+
new ImageDescriptor[] { tlOverlay, trOverlay, blOverlay, brOverlay });
45+
JFaceResources.getImageRegistry().put(key(), descr);
46+
}
47+
48+
private static ImageDescriptor getSharedImageDescriptor(String key) {
49+
return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(key);
50+
}
51+
52+
private String key() {
53+
return JSDTTypeScriptUIImages.class.getName() + "." + name();
54+
}
55+
56+
/**
57+
* Gets the image object associated with this image type.
58+
*
59+
* @return
60+
*/
61+
public Image get() {
62+
return JFaceResources.getImageRegistry().get(key());
63+
}
64+
65+
/**
66+
* Gets the image descriptor object associated with this image type.
67+
*
68+
* @return
69+
*/
70+
public ImageDescriptor getDescriptor() {
71+
return JFaceResources.getImageRegistry().getDescriptor(key());
72+
}
73+
74+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
* Lorenzo Dalla Vecchia <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.jsdt.internal.ui.editor;
12+
13+
import java.util.Objects;
14+
import java.util.Set;
15+
16+
import org.eclipse.core.resources.IMarker;
17+
import org.eclipse.core.resources.IResource;
18+
import org.eclipse.core.runtime.CoreException;
19+
import org.eclipse.swt.graphics.Image;
20+
import org.eclipse.ui.IEditorInput;
21+
22+
import ts.eclipse.ide.core.TypeScriptCorePlugin;
23+
import ts.eclipse.ide.core.resources.problems.IProblemChangeListener;
24+
import ts.eclipse.ide.jsdt.internal.ui.JSDTTypeScriptUIImages;
25+
import ts.eclipse.ide.jsdt.internal.ui.JSDTTypeScriptUIPlugin;
26+
27+
final class ProblemTickUpdater {
28+
29+
private final TypeScriptEditor editor;
30+
private final IProblemChangeListener problemChangeListener;
31+
32+
ProblemTickUpdater(TypeScriptEditor editor) {
33+
this.editor = Objects.requireNonNull(editor);
34+
this.problemChangeListener = new IProblemChangeListener() {
35+
@Override
36+
public void problemsChanged(Set<IResource> changedResources) {
37+
handleChangedProblems(changedResources);
38+
}
39+
};
40+
TypeScriptCorePlugin.getProblemManager().addProblemChangedListener(problemChangeListener);
41+
}
42+
43+
void dispose() {
44+
TypeScriptCorePlugin.getProblemManager().removeProblemChangedListener(problemChangeListener);
45+
}
46+
47+
public void update() {
48+
updateTitleImageForResource(getEditorInputResource());
49+
}
50+
51+
private void handleChangedProblems(Set<IResource> changedResources) {
52+
IResource inputResource = getEditorInputResource();
53+
if (changedResources.contains(inputResource)) {
54+
updateTitleImageForResource(inputResource);
55+
}
56+
}
57+
58+
private IResource getEditorInputResource() {
59+
IEditorInput input = editor.getEditorInput();
60+
if (input == null) {
61+
return null;
62+
}
63+
return input.getAdapter(IResource.class);
64+
}
65+
66+
private void updateTitleImageForResource(IResource resource) {
67+
if (resource == null || !resource.isAccessible()) {
68+
editor.updateTitleImage(null);
69+
return;
70+
}
71+
72+
// Determine the current maximum problem severity
73+
int severity;
74+
try {
75+
severity = resource.findMaxProblemSeverity(IMarker.PROBLEM, true, 0);
76+
} catch (CoreException e) {
77+
JSDTTypeScriptUIPlugin.log(e);
78+
return;
79+
}
80+
81+
// Prepare the image
82+
Image image;
83+
if (severity == IMarker.SEVERITY_ERROR) {
84+
image = JSDTTypeScriptUIImages.TSFILE_W_ERROR.get();
85+
} else if (severity == IMarker.SEVERITY_WARNING) {
86+
image = JSDTTypeScriptUIImages.TSFILE_W_WARNING.get();
87+
} else {
88+
image = JSDTTypeScriptUIImages.TSFILE.get();
89+
}
90+
91+
editor.updateTitleImage(image);
92+
}
93+
94+
}

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptEditor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
10+
* Lorenzo Dalla Vecchia <[email protected]> - problem tick in title image
1011
*/
1112
package ts.eclipse.ide.jsdt.internal.ui.editor;
1213

@@ -56,6 +57,7 @@
5657
import org.eclipse.jface.viewers.SelectionChangedEvent;
5758
import org.eclipse.swt.SWT;
5859
import org.eclipse.swt.custom.StyledText;
60+
import org.eclipse.swt.graphics.Image;
5961
import org.eclipse.swt.widgets.Composite;
6062
import org.eclipse.ui.IEditorInput;
6163
import org.eclipse.ui.IWindowListener;
@@ -182,6 +184,13 @@ public void selectionChanged(SelectionChangedEvent event) {
182184
*/
183185
private TypeScriptContentOutlinePage contentOutlinePage;
184186

187+
private final ProblemTickUpdater problemTickUpdater;
188+
189+
public TypeScriptEditor() {
190+
super();
191+
this.problemTickUpdater = new ProblemTickUpdater(this);
192+
}
193+
185194
protected ActionGroup getActionGroup() {
186195
return fActionGroups;
187196
}
@@ -291,6 +300,8 @@ public void editorContextMenuAboutToShow(IMenuManager menu) {
291300
public void dispose() {
292301
super.dispose();
293302

303+
problemTickUpdater.dispose();
304+
294305
if (fActionGroups != null) {
295306
fActionGroups.dispose();
296307
fActionGroups = null;
@@ -308,6 +319,10 @@ public void dispose() {
308319
}
309320
}
310321

322+
void updateTitleImage(Image titleImage) {
323+
setTitleImage(titleImage);
324+
}
325+
311326
@Override
312327
protected void initializeEditor() {
313328
super.initializeEditor();
@@ -856,6 +871,7 @@ private Object getLockObject(IAnnotationModel annotationModel) {
856871
@Override
857872
protected void doSetInput(IEditorInput input) throws CoreException {
858873
super.doSetInput(input);
874+
problemTickUpdater.update();
859875
configureToggleCommentAction();
860876
// try {
861877
// //IDocument document = getSourceViewer().getDocument();

eclipse/ts.eclipse.ide.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Export-Package: ts.eclipse.ide.core,
3131
ts.eclipse.ide.core.resources,
3232
ts.eclipse.ide.core.resources.buildpath,
3333
ts.eclipse.ide.core.resources.jsconfig,
34+
ts.eclipse.ide.core.resources.problems,
3435
ts.eclipse.ide.core.resources.watcher,
3536
ts.eclipse.ide.core.tslint,
3637
ts.eclipse.ide.core.utils

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/TypeScriptCorePlugin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
10+
* Lorenzo Dalla Vecchia <[email protected]> - getter for ProblemManager
1011
*/
1112
package ts.eclipse.ide.core;
1213

@@ -23,10 +24,12 @@
2324
import ts.eclipse.ide.core.nodejs.INodejsInstallManager;
2425
import ts.eclipse.ide.core.repository.IIDETypeScriptRepositoryManager;
2526
import ts.eclipse.ide.core.resources.ITypeScriptElementChangedListener;
27+
import ts.eclipse.ide.core.resources.problems.IProblemManager;
2628
import ts.eclipse.ide.core.resources.watcher.IResourcesWatcher;
2729
import ts.eclipse.ide.internal.core.nodejs.NodejsInstallManager;
2830
import ts.eclipse.ide.internal.core.repository.IDETypeScriptRepositoryManager;
2931
import ts.eclipse.ide.internal.core.resources.IDEResourcesManager;
32+
import ts.eclipse.ide.internal.core.resources.problems.ProblemManager;
3033
import ts.eclipse.ide.internal.core.resources.watcher.ResourcesWatcher;
3134
import ts.resources.ConfigurableTypeScriptResourcesManager;
3235

@@ -126,6 +129,10 @@ public static IResourcesWatcher getResourcesWatcher() {
126129
return ResourcesWatcher.getInstance();
127130
}
128131

132+
public static IProblemManager getProblemManager() {
133+
return ProblemManager.getInstance();
134+
}
135+
129136
public void addTypeScriptElementChangedListener(ITypeScriptElementChangedListener listener) {
130137
IDEResourcesManager.getInstance().addTypeScriptElementChangedListener(listener);
131138
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
* Lorenzo Dalla Vecchia <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.core.resources.problems;
12+
13+
import java.util.Set;
14+
15+
import org.eclipse.core.resources.IResource;
16+
17+
/**
18+
* Listener that is notified after changes occur in the TypeScript problems of
19+
* workspace resources.
20+
*/
21+
public interface IProblemChangeListener {
22+
23+
/**
24+
* Called when problems change.
25+
*
26+
* @param changedResources
27+
* set of resources on which problems have changed. This also
28+
* includes containers where the <i>combined</i> problem status
29+
* may have changed because of changes in the contained files or
30+
* sub-containers.
31+
*/
32+
public void problemsChanged(Set<IResource> changedResources);
33+
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
* Lorenzo Dalla Vecchia <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.core.resources.problems;
12+
13+
/**
14+
* Manager for getting updates about the global state of TypeScript problems on
15+
* workspace resources.
16+
*/
17+
public interface IProblemManager {
18+
19+
/**
20+
* Adds a listener to be notified when problems change on workspace
21+
* resources.
22+
*
23+
* @param listener
24+
* listener to notify.
25+
*/
26+
public void addProblemChangedListener(IProblemChangeListener listener);
27+
28+
/**
29+
* Removes a problem change listener previously added via
30+
* {@link #addProblemChangedListener}.
31+
*
32+
* @param listener
33+
* listener to remove.
34+
*/
35+
public void removeProblemChangedListener(IProblemChangeListener listener);
36+
37+
}

0 commit comments

Comments
 (0)