Skip to content

Commit 0671ea5

Browse files
author
angelozerr
committed
Bind Ctrl+O to future quick outline. See
#51
1 parent 59f0e5b commit 0671ea5

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.xml

+16-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,14 @@
226226
categoryId="org.eclipse.search.ui.category.search"
227227
id="ts.eclipse.ide.jsdt.ui.edit.text.java.search.references.in.project">
228228
</command>
229-
229+
<!-- navigate -->
230+
<command
231+
name="%ActionDefinition.show.outline.name"
232+
description="%ActionDefinition.show.outline.description"
233+
categoryId="org.eclipse.ui.category.navigate"
234+
id="ts.eclipse.ide.jsdt.ui.edit.text.java.show.outline">
235+
</command>
236+
230237
</extension>
231238

232239
<extension
@@ -252,7 +259,14 @@
252259
sequence="M1+M2+G"
253260
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
254261
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.search.references.in.project"
255-
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
262+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
263+
<!-- navigate -->
264+
<key
265+
sequence="M1+O"
266+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
267+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.show.outline"
268+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
269+
256270
</extension>
257271

258272
<!-- I don't know why, but startup should be done, otherwise TypeScriptCompletionProposalComputer is not registered? -->

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

+76
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@
1212

1313
import org.eclipse.jface.dialogs.IDialogSettings;
1414
import org.eclipse.jface.preference.IPreferenceStore;
15+
import org.eclipse.jface.text.AbstractInformationControlManager;
1516
import org.eclipse.jface.text.IDocument;
17+
import org.eclipse.jface.text.IInformationControl;
18+
import org.eclipse.jface.text.IInformationControlCreator;
1619
import org.eclipse.jface.text.contentassist.ContentAssistant;
1720
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
1821
import org.eclipse.jface.text.contentassist.IContentAssistant;
1922
import org.eclipse.jface.text.formatter.IContentFormatter;
23+
import org.eclipse.jface.text.information.IInformationPresenter;
24+
import org.eclipse.jface.text.information.IInformationProvider;
25+
import org.eclipse.jface.text.information.InformationPresenter;
2026
import org.eclipse.jface.text.source.ISourceViewer;
27+
import org.eclipse.swt.SWT;
28+
import org.eclipse.swt.widgets.Shell;
2129
import org.eclipse.ui.texteditor.ITextEditor;
2230
import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
2331
import org.eclipse.wst.jsdt.internal.ui.text.ContentAssistPreference;
@@ -29,6 +37,9 @@
2937

3038
import ts.eclipse.ide.jsdt.internal.ui.editor.contentassist.TypeScriptCompletionProcessor;
3139
import ts.eclipse.ide.jsdt.internal.ui.editor.format.TypeScriptContentFormatter;
40+
import ts.eclipse.ide.jsdt.ui.actions.ITypeScriptEditorActionDefinitionIds;
41+
import ts.eclipse.ide.ui.outline.TypeScriptElementProvider;
42+
import ts.eclipse.ide.ui.outline.TypeScriptQuickOutlineDialog;
3243
import ts.eclipse.ide.ui.utils.EditorUtils;
3344

3445
/**
@@ -103,4 +114,69 @@ private IDialogSettings getSettings(final String sectionName) {
103114
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
104115
return new TypeScriptContentFormatter(EditorUtils.getResource(getEditor()));
105116
}
117+
118+
/**
119+
* Returns the outline presenter which will determine and shown information
120+
* requested for the current cursor position.
121+
*
122+
* @param sourceViewer
123+
* the source viewer to be configured by this configuration
124+
* @param doCodeResolve
125+
* a boolean which specifies whether code resolve should be used
126+
* to compute the JavaScript element
127+
* @return an information presenter
128+
*
129+
*/
130+
@Override
131+
public IInformationPresenter getOutlinePresenter(final ISourceViewer sourceViewer, final boolean doCodeResolve) {
132+
InformationPresenter presenter = null;
133+
if (doCodeResolve) {
134+
// presenter = new
135+
// InformationPresenter(getOutlinePresenterControlCreator(sourceViewer,
136+
// ITypeScriptEditorActionDefinitionIds.OPEN_STRUCTURE));
137+
return null;
138+
} else {
139+
presenter = new InformationPresenter(
140+
getOutlinePresenterControlCreator(sourceViewer, ITypeScriptEditorActionDefinitionIds.SHOW_OUTLINE));
141+
}
142+
presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
143+
presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
144+
IInformationProvider provider = new TypeScriptElementProvider(getEditor());
145+
presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
146+
presenter.setInformationProvider(provider, IJavaScriptPartitions.JAVA_DOC);
147+
presenter.setInformationProvider(provider, IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT);
148+
presenter.setInformationProvider(provider, IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT);
149+
presenter.setInformationProvider(provider, IJavaScriptPartitions.JAVA_STRING);
150+
presenter.setInformationProvider(provider, IJavaScriptPartitions.JAVA_CHARACTER);
151+
presenter.setSizeConstraints(50, 20, true, false);
152+
return presenter;
153+
}
154+
155+
/**
156+
* Returns the outline presenter control creator. The creator is a factory
157+
* creating outline presenter controls for the given source viewer. This
158+
* implementation always returns a creator for
159+
* <code>JavaOutlineInformationControl</code> instances.
160+
*
161+
* @param sourceViewer
162+
* the source viewer to be configured by this configuration
163+
* @param commandId
164+
* the ID of the command that opens this control
165+
* @return an information control creator
166+
*
167+
*/
168+
private IInformationControlCreator getOutlinePresenterControlCreator(final ISourceViewer sourceViewer,
169+
final String commandId) {
170+
return new IInformationControlCreator() {
171+
public IInformationControl createInformationControl(final Shell parent) {
172+
int shellStyle = SWT.RESIZE;
173+
try {
174+
return new TypeScriptQuickOutlineDialog(parent, shellStyle,
175+
((TypeScriptEditor) getEditor()).getTypeScriptFile());
176+
} catch (Exception e) {
177+
return null;
178+
}
179+
}
180+
};
181+
}
106182
}

0 commit comments

Comments
 (0)