Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2016-07-01 10:02:21 +0000
committerAlexander Kurtakov2016-07-01 10:02:21 +0000
commitc8c00efac57d2c0572f5476bd7e171bcc46a10b5 (patch)
treef480f90cce5023e323778d38294e59e6bc216183 /build/org.eclipse.cdt.autotools.ui
parentafb47aa104be1d1af761e12d78612d1104ebfa6a (diff)
downloadorg.eclipse.cdt-c8c00efac57d2c0572f5476bd7e171bcc46a10b5.tar.gz
org.eclipse.cdt-c8c00efac57d2c0572f5476bd7e171bcc46a10b5.tar.xz
org.eclipse.cdt-c8c00efac57d2c0572f5476bd7e171bcc46a10b5.zip
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>
Diffstat (limited to 'build/org.eclipse.cdt.autotools.ui')
-rw-r--r--build/org.eclipse.cdt.autotools.ui/plugin.xml20
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ShowOutlineHandler.java34
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/ContainsFilter.java58
-rw-r--r--build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/QuickOutlineDialog.java166
4 files changed, 271 insertions, 7 deletions
diff --git a/build/org.eclipse.cdt.autotools.ui/plugin.xml b/build/org.eclipse.cdt.autotools.ui/plugin.xml
index 8f47dc17084..2b3f23049b6 100644
--- a/build/org.eclipse.cdt.autotools.ui/plugin.xml
+++ b/build/org.eclipse.cdt.autotools.ui/plugin.xml
@@ -37,8 +37,6 @@
<content-type id="org.eclipse.cdt.autotools.ui.automake" name="%Automake.name"
base-type="org.eclipse.core.runtime.text"
priority="high"/>
- </extension>
- <extension point="org.eclipse.core.contenttype.contentTypes">
<file-association
content-type="org.eclipse.cdt.autotools.ui.automake"
file-names="Makefile.am"
@@ -54,11 +52,6 @@
icon="icons/autoconf.gif"
id="org.eclipse.cdt.autotools.ui.editor.autoconf"
name="%Autoconf.editor.name"/>
- </extension>
- <extension
- id="org.eclipse.cdt.make.editor"
- name="MakefileEditor"
- point="org.eclipse.ui.editors">
<editor
class="org.eclipse.cdt.internal.autotools.ui.editors.automake.AutomakeEditor"
contributorClass="org.eclipse.cdt.internal.autotools.ui.editors.automake.MakefileEditorActionContributor"
@@ -86,6 +79,11 @@
contextId="org.eclipse.cdt.autotools.ui.editor.scope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
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
point="org.eclipse.ui.commands">
@@ -417,6 +415,10 @@
id="org.eclipse.cdt.autotools.ui.command.reconfigure"
name="%Reconfigure.label">
</command>
+ <command
+ categoryId="org.eclipse.cdt.autotools.ui.category.invokeAutotools"
+ id="org.eclipse.cdt.autotools.ui.command.showOutline"
+ name="Show Outline"/>
</extension>
<extension
point="org.eclipse.ui.handlers">
@@ -469,6 +471,10 @@
<reference definitionId="org.eclipse.cdt.autotools.ui.handlerEnablement"/>
</enabledWhen>
</handler>
+ <handler
+ class="org.eclipse.cdt.internal.autotools.ui.actions.ShowOutlineHandler"
+ commandId="org.eclipse.cdt.autotools.ui.command.showOutline">
+ </handler>
</extension>
<extension
point="org.eclipse.cdt.core.templates">
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ShowOutlineHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ShowOutlineHandler.java
new file mode 100644
index 00000000000..59962354391
--- /dev/null
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ShowOutlineHandler.java
@@ -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;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/ContainsFilter.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/ContainsFilter.java
new file mode 100644
index 00000000000..61fc413c6c9
--- /dev/null
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/ContainsFilter.java
@@ -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;
+ }
+}
diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/QuickOutlineDialog.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/QuickOutlineDialog.java
new file mode 100644
index 00000000000..ec2102bcc24
--- /dev/null
+++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/QuickOutlineDialog.java
@@ -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();
+ }
+}

Back to the top