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
+ */
1
11
package ts .eclipse .ide .ui .outline ;
2
12
3
13
import java .util .List ;
4
14
5
15
import org .eclipse .core .runtime .ListenerList ;
16
+ import org .eclipse .jface .action .Action ;
17
+ import org .eclipse .jface .action .IToolBarManager ;
18
+ import org .eclipse .jface .viewers .IPostSelectionProvider ;
6
19
import org .eclipse .jface .viewers .ISelection ;
7
20
import org .eclipse .jface .viewers .ISelectionChangedListener ;
8
21
import org .eclipse .jface .viewers .StructuredSelection ;
11
24
import org .eclipse .swt .SWT ;
12
25
import org .eclipse .swt .widgets .Composite ;
13
26
import org .eclipse .swt .widgets .Control ;
27
+ import org .eclipse .ui .IActionBars ;
14
28
import org .eclipse .ui .navigator .CommonViewer ;
15
29
import org .eclipse .ui .part .Page ;
16
30
import org .eclipse .ui .views .contentoutline .IContentOutlinePage ;
31
+ import org .eclipse .ui .views .navigator .ToggleLinkingAction ;
17
32
18
33
import ts .client .navbar .NavigationBarItem ;
34
+ import ts .eclipse .ide .internal .ui .TypeScriptUIMessages ;
35
+ import ts .eclipse .ide .ui .TypeScriptUIImageResource ;
19
36
import ts .eclipse .ide .ui .TypeScriptUIPlugin ;
20
37
import ts .resources .INavbarListener ;
21
38
import ts .resources .ITypeScriptFile ;
22
39
23
- public class TypeScriptContentOutlinePage extends Page implements IContentOutlinePage , INavbarListener {
40
+ /**
41
+ * TypeScript Outline.
42
+ *
43
+ */
44
+ public class TypeScriptContentOutlinePage extends Page
45
+ implements IContentOutlinePage , IPostSelectionProvider , INavbarListener {
24
46
25
47
private static final String OUTLINE_COMMON_NAVIGATOR_ID = TypeScriptUIPlugin .PLUGIN_ID + ".outline" ; //$NON-NLS-1$
26
48
49
+ private static final String EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE = "TypeScriptEditor.SyncOutlineOnCursorMove" ; //$NON-NLS-1$
50
+
27
51
private CommonViewer fOutlineViewer ;
28
52
private ITypeScriptFile tsFile ;
29
53
30
54
private ListenerList fSelectionChangedListeners = new ListenerList (ListenerList .IDENTITY );
31
55
private ListenerList fPostSelectionChangedListeners = new ListenerList (ListenerList .IDENTITY );
32
56
57
+ private ToggleLinkingAction fToggleLinkingAction ;
58
+
33
59
public TypeScriptContentOutlinePage () {
34
60
}
35
61
@@ -55,6 +81,10 @@ public void createControl(Composite parent) {
55
81
}
56
82
57
83
fOutlineViewer .setAutoExpandLevel (TreeViewer .ALL_LEVELS );
84
+ fOutlineViewer .setUseHashlookup (true );
85
+
86
+ IActionBars actionBars = getSite ().getActionBars ();
87
+ registerToolbarActions (actionBars );
58
88
59
89
}
60
90
@@ -94,62 +124,44 @@ public void run() {
94
124
}
95
125
}
96
126
97
- /*
98
- * @see
99
- * ISelectionProvider#addSelectionChangedListener(ISelectionChangedListener)
100
- */
127
+ @ Override
101
128
public void addSelectionChangedListener (ISelectionChangedListener listener ) {
102
129
if (fOutlineViewer != null )
103
130
fOutlineViewer .addSelectionChangedListener (listener );
104
131
else
105
132
fSelectionChangedListeners .add (listener );
106
133
}
107
134
108
- /*
109
- * @see ISelectionProvider#removeSelectionChangedListener(
110
- * ISelectionChangedListener)
111
- */
135
+ @ Override
112
136
public void removeSelectionChangedListener (ISelectionChangedListener listener ) {
113
137
if (fOutlineViewer != null )
114
138
fOutlineViewer .removeSelectionChangedListener (listener );
115
139
else
116
140
fSelectionChangedListeners .remove (listener );
117
141
}
118
142
119
- /*
120
- * @see ISelectionProvider#setSelection(ISelection)
121
- */
143
+ @ Override
122
144
public void setSelection (ISelection selection ) {
123
145
if (fOutlineViewer != null )
124
146
fOutlineViewer .setSelection (selection );
125
147
}
126
148
127
- /*
128
- * @see ISelectionProvider#getSelection()
129
- */
149
+ @ Override
130
150
public ISelection getSelection () {
131
151
if (fOutlineViewer == null )
132
152
return StructuredSelection .EMPTY ;
133
153
return fOutlineViewer .getSelection ();
134
154
}
135
155
136
- /*
137
- * @see org.eclipse.jface.text.IPostSelectionProvider#
138
- * addPostSelectionChangedListener(org.eclipse.jface.viewers.
139
- * ISelectionChangedListener)
140
- */
156
+ @ Override
141
157
public void addPostSelectionChangedListener (ISelectionChangedListener listener ) {
142
158
if (fOutlineViewer != null )
143
159
fOutlineViewer .addPostSelectionChangedListener (listener );
144
160
else
145
161
fPostSelectionChangedListeners .add (listener );
146
162
}
147
163
148
- /*
149
- * @see org.eclipse.jface.text.IPostSelectionProvider#
150
- * removePostSelectionChangedListener(org.eclipse.jface.viewers.
151
- * ISelectionChangedListener)
152
- */
164
+ @ Override
153
165
public void removePostSelectionChangedListener (ISelectionChangedListener listener ) {
154
166
if (fOutlineViewer != null )
155
167
fOutlineViewer .removePostSelectionChangedListener (listener );
@@ -169,4 +181,38 @@ public void dispose() {
169
181
170
182
}
171
183
184
+ /**
185
+ * Register toolbar actions.
186
+ *
187
+ * @param actionBars
188
+ */
189
+ private void registerToolbarActions (IActionBars actionBars ) {
190
+ IToolBarManager toolBarManager = actionBars .getToolBarManager ();
191
+ toolBarManager .add (new CollapseAllAction (this .fOutlineViewer ));
192
+ }
193
+
194
+ /**
195
+ * Collapse all action
196
+ *
197
+ */
198
+ private class CollapseAllAction extends Action {
199
+
200
+ private final TreeViewer viewer ;
201
+
202
+ CollapseAllAction (TreeViewer viewer ) {
203
+ super (TypeScriptUIMessages .TypeScriptContentOutlinePage_CollapseAllAction_label );
204
+ setDescription (TypeScriptUIMessages .TypeScriptContentOutlinePage_CollapseAllAction_description );
205
+ setToolTipText (TypeScriptUIMessages .TypeScriptContentOutlinePage_CollapseAllAction_tooltip );
206
+ super .setImageDescriptor (
207
+ TypeScriptUIImageResource .getImageDescriptor (TypeScriptUIImageResource .IMG_COLLAPSE_ALL_ENABLED ));
208
+ super .setDisabledImageDescriptor (
209
+ TypeScriptUIImageResource .getImageDescriptor (TypeScriptUIImageResource .IMG_COLLAPSE_ALL_DISABLED ));
210
+ this .viewer = viewer ;
211
+ }
212
+
213
+ public void run () {
214
+ this .viewer .collapseAll ();
215
+ }
216
+ }
217
+
172
218
}
0 commit comments