mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 343552 - RFE: Quick Outline support for configure.ac editor
Implement quick outline for AutoconfEditor with search, navigation and etc. Small reorganizations in the plugin.xml to make it easier to navigate. Change-Id: Ibb13caa6f80ae2bbdfe3a78dec0eb033ee0c0482 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
This commit is contained in:
parent
afb47aa104
commit
c8c00efac5
4 changed files with 271 additions and 7 deletions
|
@ -37,8 +37,6 @@
|
||||||
<content-type id="org.eclipse.cdt.autotools.ui.automake" name="%Automake.name"
|
<content-type id="org.eclipse.cdt.autotools.ui.automake" name="%Automake.name"
|
||||||
base-type="org.eclipse.core.runtime.text"
|
base-type="org.eclipse.core.runtime.text"
|
||||||
priority="high"/>
|
priority="high"/>
|
||||||
</extension>
|
|
||||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
|
||||||
<file-association
|
<file-association
|
||||||
content-type="org.eclipse.cdt.autotools.ui.automake"
|
content-type="org.eclipse.cdt.autotools.ui.automake"
|
||||||
file-names="Makefile.am"
|
file-names="Makefile.am"
|
||||||
|
@ -54,11 +52,6 @@
|
||||||
icon="icons/autoconf.gif"
|
icon="icons/autoconf.gif"
|
||||||
id="org.eclipse.cdt.autotools.ui.editor.autoconf"
|
id="org.eclipse.cdt.autotools.ui.editor.autoconf"
|
||||||
name="%Autoconf.editor.name"/>
|
name="%Autoconf.editor.name"/>
|
||||||
</extension>
|
|
||||||
<extension
|
|
||||||
id="org.eclipse.cdt.make.editor"
|
|
||||||
name="MakefileEditor"
|
|
||||||
point="org.eclipse.ui.editors">
|
|
||||||
<editor
|
<editor
|
||||||
class="org.eclipse.cdt.internal.autotools.ui.editors.automake.AutomakeEditor"
|
class="org.eclipse.cdt.internal.autotools.ui.editors.automake.AutomakeEditor"
|
||||||
contributorClass="org.eclipse.cdt.internal.autotools.ui.editors.automake.MakefileEditorActionContributor"
|
contributorClass="org.eclipse.cdt.internal.autotools.ui.editors.automake.MakefileEditorActionContributor"
|
||||||
|
@ -86,6 +79,11 @@
|
||||||
contextId="org.eclipse.cdt.autotools.ui.editor.scope"
|
contextId="org.eclipse.cdt.autotools.ui.editor.scope"
|
||||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||||
sequence="F2"/>
|
sequence="F2"/>
|
||||||
|
<key
|
||||||
|
sequence="Ctrl+O"
|
||||||
|
commandId="org.eclipse.cdt.autotools.ui.command.showOutline"
|
||||||
|
contextId="org.eclipse.cdt.autotools.ui.editor.scope"
|
||||||
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.commands">
|
point="org.eclipse.ui.commands">
|
||||||
|
@ -417,6 +415,10 @@
|
||||||
id="org.eclipse.cdt.autotools.ui.command.reconfigure"
|
id="org.eclipse.cdt.autotools.ui.command.reconfigure"
|
||||||
name="%Reconfigure.label">
|
name="%Reconfigure.label">
|
||||||
</command>
|
</command>
|
||||||
|
<command
|
||||||
|
categoryId="org.eclipse.cdt.autotools.ui.category.invokeAutotools"
|
||||||
|
id="org.eclipse.cdt.autotools.ui.command.showOutline"
|
||||||
|
name="Show Outline"/>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.handlers">
|
point="org.eclipse.ui.handlers">
|
||||||
|
@ -469,6 +471,10 @@
|
||||||
<reference definitionId="org.eclipse.cdt.autotools.ui.handlerEnablement"/>
|
<reference definitionId="org.eclipse.cdt.autotools.ui.handlerEnablement"/>
|
||||||
</enabledWhen>
|
</enabledWhen>
|
||||||
</handler>
|
</handler>
|
||||||
|
<handler
|
||||||
|
class="org.eclipse.cdt.internal.autotools.ui.actions.ShowOutlineHandler"
|
||||||
|
commandId="org.eclipse.cdt.autotools.ui.command.showOutline">
|
||||||
|
</handler>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.cdt.core.templates">
|
point="org.eclipse.cdt.core.templates">
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2016 Red Hat Inc. and others.
|
||||||
|
* 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:
|
||||||
|
* Red Hat Inc. - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.autotools.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.autotools.ui.editors.AutoconfEditor;
|
||||||
|
import org.eclipse.cdt.internal.autotools.ui.editors.QuickOutlineDialog;
|
||||||
|
import org.eclipse.core.commands.AbstractHandler;
|
||||||
|
import org.eclipse.core.commands.ExecutionEvent;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.handlers.HandlerUtil;
|
||||||
|
|
||||||
|
public class ShowOutlineHandler extends AbstractHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(ExecutionEvent event) {
|
||||||
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
||||||
|
if (editor instanceof AutoconfEditor) {
|
||||||
|
QuickOutlineDialog quickOutlinePopupDialog = new QuickOutlineDialog(editor.getSite().getShell(), SWT.NONE,
|
||||||
|
(AutoconfEditor) editor);
|
||||||
|
quickOutlinePopupDialog.setVisible(true);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2016 Red Hat Inc. and others.
|
||||||
|
* 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:
|
||||||
|
* Red Hat Inc. - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.autotools.ui.editors;
|
||||||
|
|
||||||
|
import org.eclipse.jface.viewers.ILabelProvider;
|
||||||
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
|
import org.eclipse.jface.viewers.ViewerFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple filter that only check whether the label contains the given string to
|
||||||
|
* look for.
|
||||||
|
*/
|
||||||
|
public class ContainsFilter extends ViewerFilter {
|
||||||
|
|
||||||
|
private String lookFor;
|
||||||
|
|
||||||
|
public void setLookFor(String lookFor) {
|
||||||
|
this.lookFor = lookFor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||||
|
if (!(viewer instanceof TreeViewer)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
TreeViewer treeViewer = (TreeViewer) viewer;
|
||||||
|
String currentLabel = ((ILabelProvider) treeViewer.getLabelProvider())
|
||||||
|
.getText(element);
|
||||||
|
if (lookFor == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (currentLabel != null && currentLabel.toLowerCase().contains(lookFor)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return hasUnfilteredChild(treeViewer, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasUnfilteredChild(TreeViewer viewer, Object element) {
|
||||||
|
Object[] children = ((ITreeContentProvider) viewer.getContentProvider())
|
||||||
|
.getChildren(element);
|
||||||
|
for (Object child :children) {
|
||||||
|
if (select(viewer, element, child)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2016 Red Hat Inc. and others.
|
||||||
|
* 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:
|
||||||
|
* Red Hat Inc. - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.autotools.ui.editors;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.autotools.ui.editors.AutoconfEditor;
|
||||||
|
import org.eclipse.cdt.autotools.ui.editors.outline.AutoconfContentProvider;
|
||||||
|
import org.eclipse.cdt.autotools.ui.editors.outline.AutoconfLabelProvider;
|
||||||
|
import org.eclipse.cdt.autotools.ui.editors.parser.AutoconfElement;
|
||||||
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
|
import org.eclipse.jface.dialogs.PopupDialog;
|
||||||
|
import org.eclipse.jface.layout.GridDataFactory;
|
||||||
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
||||||
|
import org.eclipse.jface.viewers.ILabelProvider;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.events.KeyAdapter;
|
||||||
|
import org.eclipse.swt.events.KeyEvent;
|
||||||
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
|
import org.eclipse.swt.graphics.FontMetrics;
|
||||||
|
import org.eclipse.swt.graphics.GC;
|
||||||
|
import org.eclipse.swt.layout.GridData;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
import org.eclipse.swt.widgets.Tree;
|
||||||
|
import org.eclipse.ui.editors.text.TextEditor;
|
||||||
|
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||||
|
|
||||||
|
public class QuickOutlineDialog extends PopupDialog {
|
||||||
|
|
||||||
|
TreeViewer treeViewer;
|
||||||
|
private Text filterText;
|
||||||
|
|
||||||
|
private TextEditor editor;
|
||||||
|
private ContainsFilter treeViewerFilter;
|
||||||
|
|
||||||
|
public QuickOutlineDialog(Shell parent, int shellStyle, AutoconfEditor editor) {
|
||||||
|
super(parent, shellStyle, true, true, true, true, true, null, null);
|
||||||
|
this.editor = editor;
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisible(boolean visible) {
|
||||||
|
if (visible) {
|
||||||
|
open();
|
||||||
|
filterText.setFocus();
|
||||||
|
} else {
|
||||||
|
saveDialogBounds(getShell());
|
||||||
|
getShell().setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Control createDialogArea(Composite parent) {
|
||||||
|
createUIWidgetTreeViewer(parent);
|
||||||
|
createUIListenersTreeViewer();
|
||||||
|
return treeViewer.getControl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Control createTitleControl(Composite parent) {
|
||||||
|
filterText = new Text(parent, SWT.NONE);
|
||||||
|
GC gc = new GC(parent);
|
||||||
|
gc.setFont(parent.getFont());
|
||||||
|
FontMetrics fontMetrics = gc.getFontMetrics();
|
||||||
|
gc.dispose();
|
||||||
|
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
|
||||||
|
.hint(SWT.DEFAULT, Dialog.convertHeightInCharsToPixels(fontMetrics, 1)).applyTo(filterText);
|
||||||
|
|
||||||
|
filterText.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
if (e.keyCode == 0x0D) { // Enter pressed
|
||||||
|
gotoSelectedElement();
|
||||||
|
} else if (e.keyCode == SWT.ARROW_DOWN) {
|
||||||
|
treeViewer.getTree().setFocus();
|
||||||
|
} else if (e.keyCode == SWT.ARROW_UP) {
|
||||||
|
treeViewer.getTree().setFocus();
|
||||||
|
} else if (e.character == 0x1B) { // Escape pressed
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
filterText.addModifyListener(e -> {
|
||||||
|
String filterTextInput = ((Text) e.widget).getText().toLowerCase();
|
||||||
|
treeViewerFilter.setLookFor(filterTextInput);
|
||||||
|
stringMatcherUpdated();
|
||||||
|
});
|
||||||
|
return filterText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stringMatcherUpdated() {
|
||||||
|
treeViewer.getControl().setRedraw(false);
|
||||||
|
treeViewer.refresh();
|
||||||
|
treeViewer.expandAll();
|
||||||
|
if (treeViewer.getTree().getTopItem() != null && treeViewer.getTree().getTopItem().getItemCount() > 0) {
|
||||||
|
treeViewer.getTree().select(treeViewer.getTree().getTopItem().getItem(0));
|
||||||
|
} else if (treeViewer.getTree().getItemCount() > 0) {
|
||||||
|
treeViewer.getTree().select(treeViewer.getTree().getItem(0));
|
||||||
|
}
|
||||||
|
treeViewer.getControl().setRedraw(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUIWidgetTreeViewer(Composite parent) {
|
||||||
|
final int style = SWT.H_SCROLL | SWT.V_SCROLL;
|
||||||
|
final Tree widget = new Tree(parent, style);
|
||||||
|
final GridData data = new GridData(GridData.FILL_BOTH);
|
||||||
|
data.heightHint = widget.getItemHeight() * 12;
|
||||||
|
widget.setLayoutData(data);
|
||||||
|
treeViewer = new TreeViewer(widget);
|
||||||
|
treeViewerFilter = new ContainsFilter();
|
||||||
|
treeViewer.addFilter(treeViewerFilter);
|
||||||
|
|
||||||
|
ITreeContentProvider fOutlineContentProvider = new AutoconfContentProvider(editor);
|
||||||
|
ILabelProvider fTreeLabelProvider = new AutoconfLabelProvider();
|
||||||
|
treeViewer.setContentProvider(fOutlineContentProvider);
|
||||||
|
treeViewer.setLabelProvider(fTreeLabelProvider);
|
||||||
|
treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
|
||||||
|
treeViewer.setUseHashlookup(true);
|
||||||
|
treeViewer.setInput(editor.getAdapter(IContentOutlinePage.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUIListenersTreeViewer() {
|
||||||
|
final Tree tree = treeViewer.getTree();
|
||||||
|
tree.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void widgetDefaultSelected(SelectionEvent e) {
|
||||||
|
gotoSelectedElement();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void gotoSelectedElement() {
|
||||||
|
if (editor instanceof AutoconfEditor) {
|
||||||
|
final AutoconfElement curElement = (AutoconfElement) getSelectedElement();
|
||||||
|
if (curElement == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
editor.setHighlightRange(curElement.getStartOffset(), curElement.getLength(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getSelectedElement() {
|
||||||
|
if (treeViewer == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue