1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*******************************************************************************
* Copyright (c) 2008 Phil Muldoon <pkmuldoon@picobot.org>.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Phil Muldoon <pkmuldoon@picobot.org> - initial API.
*******************************************************************************/
package org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp;
import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.linuxtools.systemtap.ui.editor.ColorManager;
import org.eclipse.linuxtools.systemtap.ui.editor.PathEditorInput;
import org.eclipse.linuxtools.systemtap.ui.editor.SimpleEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
public class STPEditor extends SimpleEditor {
private ColorManager colorManager;
private ProjectionSupport stpProjectionSupport;
private Annotation[] stpOldAnnotations;
private ProjectionAnnotationModel stpAnnotationModel;
public static final String ID="org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor"; //$NON-NLS-1$
public STPEditor() {
super();
colorManager = new ColorManager();
setSourceViewerConfiguration(new STPConfiguration(colorManager,this));
}
@Override
protected void internalInit() {
configureInsertMode(SMART_INSERT, false);
setDocumentProvider(new STPDocumentProvider());
}
@Override
protected void doSetInput(IEditorInput input) throws CoreException {
if(input instanceof FileStoreEditorInput) {
input= new PathEditorInput(new Path(((FileStoreEditorInput) input).getURI().getPath()));
}
super.doSetInput(input);
}
@Override
public void createPartControl(Composite parent)
{
super.createPartControl(parent);
ProjectionViewer viewer =(ProjectionViewer)getSourceViewer();
stpProjectionSupport = new ProjectionSupport(viewer,getAnnotationAccess(),getSharedColors());
stpProjectionSupport.install();
viewer.doOperation(ProjectionViewer.TOGGLE);
stpAnnotationModel = viewer.getProjectionAnnotationModel();
}
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
ISourceViewer viewer = new ProjectionViewer(parent, ruler,
getOverviewRuler(), isOverviewRulerVisible(), styles);
getSourceViewerDecorationSupport(viewer);
return viewer;
}
public void updateFoldingStructure(ArrayList<Position> updatedPositions)
{
ProjectionAnnotation annotation;
Annotation[] updatedAnnotations = new Annotation[updatedPositions.size()];
HashMap<ProjectionAnnotation, Position> newAnnotations = new HashMap<>();
for(int i =0;i<updatedPositions.size();i++)
{
annotation = new ProjectionAnnotation();
newAnnotations.put(annotation,updatedPositions.get(i));
updatedAnnotations[i]=annotation;
}
stpAnnotationModel.modifyAnnotations(stpOldAnnotations,newAnnotations,null);
stpOldAnnotations = updatedAnnotations;
}
public ISourceViewer getMySourceViewer() {
return this.getSourceViewer();
}
@Override
public void dispose() {
colorManager.dispose();
super.dispose();
}
@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
addAction(menu, ITextEditorActionConstants.GROUP_EDIT,
ITextEditorActionConstants.SHIFT_RIGHT);
addAction(menu, ITextEditorActionConstants.GROUP_EDIT,
ITextEditorActionConstants.SHIFT_LEFT);
}
}
|