Skip to content

Commit 6cf5f30

Browse files
author
angelozerr
committed
Fix #78
1 parent 0e95670 commit 6cf5f30

File tree

6 files changed

+89
-31
lines changed

6 files changed

+89
-31
lines changed
Loading
Loading

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/TypeScriptUIMessages.java

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public class TypeScriptUIMessages extends NLS {
115115
public static String TypeScriptBuilder_enable_Error_message;
116116
public static String TypeScriptBuilder_disable_Error_message;
117117

118+
// Outline
119+
public static String TypeScriptContentOutlinePage_CollapseAllAction_label;
120+
public static String TypeScriptContentOutlinePage_CollapseAllAction_description;
121+
public static String TypeScriptContentOutlinePage_CollapseAllAction_tooltip;
118122

119123
public static ResourceBundle getResourceBundle() {
120124
try {

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/TypeScriptUIMessages.properties

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ TypeScriptSearchQuery_result= {0} matches - done in {1} ms.
8787
TypeScriptResources=TypeScript Resources
8888
DiscoverBuildPathDialog_title=Add TypeScript build paths
8989
DiscoverBuildPathDialog_message=Select folders to add to TypeScript build path. Build path folders are used to validate and compile *.ts(x) files.
90-
DiscoverBuildPathDialog_SearchBuildPathJob_name=Search tsconfig.json files job
90+
DiscoverBuildPathDialog_SearchBuildPathJob_name=Search tsconfig.json files job
91+
92+
# Outline
93+
TypeScriptContentOutlinePage_CollapseAllAction_label=Collapse All
94+
TypeScriptContentOutlinePage_CollapseAllAction_tooltip=Collapse All
95+
TypeScriptContentOutlinePage_CollapseAllAction_description=Collapse All

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/TypeScriptUIImageResource.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,23 @@ public class TypeScriptUIImageResource {
4444
private static final String URL_ELCL = "full/elcl16/";
4545
private static final String URL_OBJ = "full/obj16/";
4646
private static final String URL_OVR = "full/ovr16/";
47-
47+
4848
// General Object Images
4949
public static final String IMG_LOGO = "logo";
5050
public static final String IMG_TYPESCRIPT_RESOURCES = "tsresources_obj";
5151

5252
// Enabled/Disbaled
5353
public static final String IMG_STOP_ENABLED = "stop_enabled";
5454
public static final String IMG_STOP_DISABLED = "stop_disabled";
55+
public static final String IMG_COLLAPSE_ALL_ENABLED = "collapseall_enabled";
56+
public static final String IMG_COLLAPSE_ALL_DISABLED = "collapseall_disabled";
5557

5658
public static final String DESC_OVR_LIBRARY = "ovr_library";
57-
59+
5860
private static Map<ImageDescriptor, URL> fURLMap;
5961
private static final File fTempDir;
60-
private static int fImageCount;
61-
6262

63+
private static int fImageCount;
6364

6465
static {
6566
try {
@@ -150,7 +151,9 @@ protected static void initializeImageRegistry() {
150151

151152
registerImage(IMG_STOP_ENABLED, URL_ELCL + "launch_stop.gif");
152153
registerImage(IMG_STOP_DISABLED, URL_DLCL + "launch_stop.gif");
153-
154+
registerImage(IMG_COLLAPSE_ALL_ENABLED, URL_ELCL + "collapseall.gif");
155+
registerImage(IMG_COLLAPSE_ALL_DISABLED, URL_DLCL + "collapseall.gif");
156+
154157
registerImage(DESC_OVR_LIBRARY, URL_OVR + "library_ovr.gif");
155158
}
156159

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/outline/TypeScriptContentOutlinePage.java

+71-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
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+
*/
111
package ts.eclipse.ide.ui.outline;
212

313
import java.util.List;
414

515
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;
619
import org.eclipse.jface.viewers.ISelection;
720
import org.eclipse.jface.viewers.ISelectionChangedListener;
821
import org.eclipse.jface.viewers.StructuredSelection;
@@ -11,25 +24,38 @@
1124
import org.eclipse.swt.SWT;
1225
import org.eclipse.swt.widgets.Composite;
1326
import org.eclipse.swt.widgets.Control;
27+
import org.eclipse.ui.IActionBars;
1428
import org.eclipse.ui.navigator.CommonViewer;
1529
import org.eclipse.ui.part.Page;
1630
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
31+
import org.eclipse.ui.views.navigator.ToggleLinkingAction;
1732

1833
import ts.client.navbar.NavigationBarItem;
34+
import ts.eclipse.ide.internal.ui.TypeScriptUIMessages;
35+
import ts.eclipse.ide.ui.TypeScriptUIImageResource;
1936
import ts.eclipse.ide.ui.TypeScriptUIPlugin;
2037
import ts.resources.INavbarListener;
2138
import ts.resources.ITypeScriptFile;
2239

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 {
2446

2547
private static final String OUTLINE_COMMON_NAVIGATOR_ID = TypeScriptUIPlugin.PLUGIN_ID + ".outline"; //$NON-NLS-1$
2648

49+
private static final String EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE = "TypeScriptEditor.SyncOutlineOnCursorMove"; //$NON-NLS-1$
50+
2751
private CommonViewer fOutlineViewer;
2852
private ITypeScriptFile tsFile;
2953

3054
private ListenerList fSelectionChangedListeners = new ListenerList(ListenerList.IDENTITY);
3155
private ListenerList fPostSelectionChangedListeners = new ListenerList(ListenerList.IDENTITY);
3256

57+
private ToggleLinkingAction fToggleLinkingAction;
58+
3359
public TypeScriptContentOutlinePage() {
3460
}
3561

@@ -55,6 +81,10 @@ public void createControl(Composite parent) {
5581
}
5682

5783
fOutlineViewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
84+
fOutlineViewer.setUseHashlookup(true);
85+
86+
IActionBars actionBars = getSite().getActionBars();
87+
registerToolbarActions(actionBars);
5888

5989
}
6090

@@ -94,62 +124,44 @@ public void run() {
94124
}
95125
}
96126

97-
/*
98-
* @see
99-
* ISelectionProvider#addSelectionChangedListener(ISelectionChangedListener)
100-
*/
127+
@Override
101128
public void addSelectionChangedListener(ISelectionChangedListener listener) {
102129
if (fOutlineViewer != null)
103130
fOutlineViewer.addSelectionChangedListener(listener);
104131
else
105132
fSelectionChangedListeners.add(listener);
106133
}
107134

108-
/*
109-
* @see ISelectionProvider#removeSelectionChangedListener(
110-
* ISelectionChangedListener)
111-
*/
135+
@Override
112136
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
113137
if (fOutlineViewer != null)
114138
fOutlineViewer.removeSelectionChangedListener(listener);
115139
else
116140
fSelectionChangedListeners.remove(listener);
117141
}
118142

119-
/*
120-
* @see ISelectionProvider#setSelection(ISelection)
121-
*/
143+
@Override
122144
public void setSelection(ISelection selection) {
123145
if (fOutlineViewer != null)
124146
fOutlineViewer.setSelection(selection);
125147
}
126148

127-
/*
128-
* @see ISelectionProvider#getSelection()
129-
*/
149+
@Override
130150
public ISelection getSelection() {
131151
if (fOutlineViewer == null)
132152
return StructuredSelection.EMPTY;
133153
return fOutlineViewer.getSelection();
134154
}
135155

136-
/*
137-
* @see org.eclipse.jface.text.IPostSelectionProvider#
138-
* addPostSelectionChangedListener(org.eclipse.jface.viewers.
139-
* ISelectionChangedListener)
140-
*/
156+
@Override
141157
public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
142158
if (fOutlineViewer != null)
143159
fOutlineViewer.addPostSelectionChangedListener(listener);
144160
else
145161
fPostSelectionChangedListeners.add(listener);
146162
}
147163

148-
/*
149-
* @see org.eclipse.jface.text.IPostSelectionProvider#
150-
* removePostSelectionChangedListener(org.eclipse.jface.viewers.
151-
* ISelectionChangedListener)
152-
*/
164+
@Override
153165
public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
154166
if (fOutlineViewer != null)
155167
fOutlineViewer.removePostSelectionChangedListener(listener);
@@ -169,4 +181,38 @@ public void dispose() {
169181

170182
}
171183

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+
172218
}

0 commit comments

Comments
 (0)