Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2007-10-24 06:02:44 -0400
committerAnton Leherbauer2007-10-24 06:02:44 -0400
commit50fd24cadc229bd66fa664a1b0e56051f8517856 (patch)
treefa133143df9eb61af9763972b9b14163a55750e3
parent18fa1c4fc2912b1ba641fe9daa2c739e17d2199d (diff)
downloadorg.eclipse.cdt-50fd24cadc229bd66fa664a1b0e56051f8517856.tar.gz
org.eclipse.cdt-50fd24cadc229bd66fa664a1b0e56051f8517856.tar.xz
org.eclipse.cdt-50fd24cadc229bd66fa664a1b0e56051f8517856.zip
Fix for 206288: Provide outline view for assembly files
-rw-r--r--core/org.eclipse.cdt.ui/icons/obj16/label_obj.gifbin0 -> 868 bytes
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml11
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java563
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java520
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java138
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/ASMEditorActionContributor.java61
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmContentOutlinePage.java48
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmReconcilingStrategy.java98
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java30
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java411
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java23
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java5
13 files changed, 1238 insertions, 672 deletions
diff --git a/core/org.eclipse.cdt.ui/icons/obj16/label_obj.gif b/core/org.eclipse.cdt.ui/icons/obj16/label_obj.gif
new file mode 100644
index 00000000000..1d2912b6984
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/icons/obj16/label_obj.gif
Binary files differ
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 519cf5dc363..bd8b187f166 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -131,7 +131,7 @@
class="org.eclipse.cdt.internal.ui.filters.NonCElementFilter"
id="org.eclipse.cdt.internal.ui.CView.NonCElementFilter">
</filter>
-<!-- Outline Page -->
+<!-- C/C++ Outline Page -->
<filter
targetId="org.eclipse.cdt.ui.COutlinePage"
name="%HideUsingDirective.label"
@@ -148,6 +148,15 @@
class="org.eclipse.cdt.internal.ui.filters.MacroDirectiveFilter"
id="org.eclipse.cdt.ui.COutlinePage.MacroDirectiveFilter">
</filter>
+<!-- Asm Outline Page -->
+ <filter
+ targetId="org.eclipse.cdt.ui.AsmOutlinePage"
+ name="%HideMacroDirective.label"
+ enabled="false"
+ description="%HideMacroDirective.description"
+ class="org.eclipse.cdt.internal.ui.filters.MacroDirectiveFilter"
+ id="org.eclipse.cdt.ui.AsmOutlinePage.MacroDirectiveFilter">
+ </filter>
</extension>
<extension
point="org.eclipse.cdt.ui.textHovers">
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java
index e32ba30e1ec..bd2db334535 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java
@@ -81,6 +81,7 @@ public class CPluginImages {
public static final String IMG_OBJS_VAR_DECLARATION= NAME_PREFIX + "var_declaration_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_INCLUDE= NAME_PREFIX + "include_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_MACRO= NAME_PREFIX + "define_obj.gif"; //$NON-NLS-1$
+ public static final String IMG_OBJS_LABEL= NAME_PREFIX + "label_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_TUNIT= NAME_PREFIX + "c_file_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_TUNIT_HEADER= NAME_PREFIX + "h_file_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_TUNIT_ASM= NAME_PREFIX + "s_file_obj.gif"; //$NON-NLS-1$
@@ -161,6 +162,7 @@ public class CPluginImages {
public static final ImageDescriptor DESC_OBJS_VAR_DECLARARION= createManaged(T_OBJ, IMG_OBJS_VAR_DECLARATION);
public static final ImageDescriptor DESC_OBJS_INCLUDE= createManaged(T_OBJ, IMG_OBJS_INCLUDE);
public static final ImageDescriptor DESC_OBJS_MACRO= createManaged(T_OBJ, IMG_OBJS_MACRO);
+ public static final ImageDescriptor DESC_OBJS_LABEL= createManaged(T_OBJ, IMG_OBJS_LABEL);
public static final ImageDescriptor DESC_OBJS_TUNIT= createManaged(T_OBJ, IMG_OBJS_TUNIT);
public static final ImageDescriptor DESC_OBJS_TUNIT_HEADER= createManaged(T_OBJ, IMG_OBJS_TUNIT_HEADER);
public static final ImageDescriptor DESC_OBJS_TUNIT_ASM= createManaged(T_OBJ, IMG_OBJS_TUNIT_ASM);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java
new file mode 100644
index 00000000000..490ba8efe80
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java
@@ -0,0 +1,563 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * QNX Software System
+ * Markus Schorn (Wind River Systems)
+ * Anton Leherbauer (Wind River Systems)
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.editor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.util.CElementBaseLabels;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
+
+import org.eclipse.cdt.internal.ui.CPluginImages;
+import org.eclipse.cdt.internal.ui.ICHelpContextIds;
+import org.eclipse.cdt.internal.ui.IContextMenuConstants;
+import org.eclipse.cdt.internal.ui.actions.AbstractToggleLinkingAction;
+import org.eclipse.cdt.internal.ui.actions.ActionMessages;
+import org.eclipse.cdt.internal.ui.cview.SelectionTransferDragAdapter;
+import org.eclipse.cdt.internal.ui.cview.SelectionTransferDropAdapter;
+import org.eclipse.cdt.internal.ui.dnd.CDTViewerDragAdapter;
+import org.eclipse.cdt.internal.ui.dnd.DelegatingDropAdapter;
+import org.eclipse.cdt.internal.ui.dnd.TransferDragSourceListener;
+import org.eclipse.cdt.internal.ui.dnd.TransferDropTargetListener;
+import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
+import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
+import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
+import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
+
+/**
+ * Abstract outline page based on CModel.
+ *
+ * @since 5.0
+ */
+public abstract class AbstractCModelOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener {
+
+ protected static class IncludeGroupingAction extends Action {
+ AbstractCModelOutlinePage fOutLinePage;
+
+ public IncludeGroupingAction(AbstractCModelOutlinePage outlinePage) {
+ super(ActionMessages.getString("IncludesGroupingAction.label")); //$NON-NLS-1$
+ setDescription(ActionMessages.getString("IncludesGroupingAction.description")); //$NON-NLS-1$
+ setToolTipText(ActionMessages.getString("IncludeGroupingAction.tooltip")); //$NON-NLS-1$
+ CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_GROUP_INCLUDE);
+
+ boolean enabled= isIncludesGroupingEnabled();
+ setChecked(enabled);
+ fOutLinePage = outlinePage;
+ }
+
+ /**
+ * Runs the action.
+ */
+ public void run() {
+ boolean oldValue = isIncludesGroupingEnabled();
+ PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, isChecked());
+ if (oldValue != isChecked()) {
+ fOutLinePage.contentUpdated();
+ }
+ }
+
+ public boolean isIncludesGroupingEnabled () {
+ return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES);
+ }
+
+ }
+
+ /**
+ * This action toggles whether this C Outline page links
+ * its selection to the active editor.
+ *
+ * @since 3.0
+ */
+ public class ToggleLinkingAction extends AbstractToggleLinkingAction {
+
+ /**
+ * Constructs a new action.
+ */
+ public ToggleLinkingAction() {
+ setChecked(isLinkingEnabled());
+ }
+
+ /**
+ * Runs the action.
+ */
+ public void run() {
+ boolean checked = isChecked();
+ PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_LINK_TO_EDITOR, checked);
+ if (checked && fEditor != null)
+ synchronizeSelectionWithEditor();
+ }
+ }
+
+ private static final int TEXT_FLAGS = AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementBaseLabels.F_APP_TYPE_SIGNATURE | CElementBaseLabels.M_APP_RETURNTYPE;
+ private static final int IMAGE_FLAGS = AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS;
+ protected ITextEditor fEditor;
+ protected ITranslationUnit fInput;
+ private ProblemTreeViewer fTreeViewer;
+ private ListenerList fSelectionChangedListeners = new ListenerList(ListenerList.IDENTITY);
+ protected TogglePresentationAction fTogglePresentation;
+ protected String fContextMenuId;
+ private Menu fMenu;
+ protected OpenIncludeAction fOpenIncludeAction;
+ private IncludeGroupingAction fIncludeGroupingAction;
+ private ToggleLinkingAction fToggleLinkingAction;
+ private ActionGroup fMemberFilterActionGroup;
+ private SelectionSearchGroup fSelectionSearchGroup;
+ private ActionGroup fRefactoringActionGroup;
+ private OpenViewActionGroup fOpenViewActionGroup;
+ /**
+ * Custom filter action group.
+ * @since 3.0
+ */
+ private ActionGroup fCustomFiltersActionGroup;
+
+ /**
+ * Create a new outline page for the given editor.
+ * @param contextMenuId The id of this page's context menu
+ * @param editor the editor associated with this outline page
+ */
+ public AbstractCModelOutlinePage(String contextMenuId, ITextEditor editor) {
+ super();
+ fEditor= editor;
+ fInput= null;
+ fContextMenuId= contextMenuId;
+
+ fTogglePresentation= new TogglePresentationAction();
+ fTogglePresentation.setEditor(editor);
+
+ fOpenIncludeAction= new OpenIncludeAction(this);
+ }
+
+ public boolean isLinkingEnabled() {
+ return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_LINK_TO_EDITOR);
+ }
+
+ public ICElement getRoot() {
+ return fInput;
+ }
+
+ /**
+ * Called by the editor to signal that the content has updated.
+ */
+ public void contentUpdated() {
+ if (fInput != null) {
+ final TreeViewer treeViewer= getTreeViewer();
+ if (treeViewer != null && !treeViewer.getControl().isDisposed()) {
+ treeViewer.getControl().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (!treeViewer.getControl().isDisposed()) {
+ ISelection sel= treeViewer.getSelection();
+ treeViewer.setSelection(updateSelection(sel));
+ treeViewer.refresh();
+ }
+ }
+ });
+ }
+ }
+ }
+
+ protected ISelection updateSelection(ISelection sel) {
+ ArrayList newSelection= new ArrayList();
+ if (sel instanceof IStructuredSelection) {
+ Iterator iter= ((IStructuredSelection)sel).iterator();
+ for (;iter.hasNext();) {
+ //ICElement elem= fInput.findEqualMember((ICElement)iter.next());
+ Object o = iter.next();
+ if (o instanceof ICElement) {
+ newSelection.add(o);
+ }
+ }
+ }
+ return new StructuredSelection(newSelection);
+ }
+
+ /**
+ * Sets the selected element to the one at the current cursor position in the editor.
+ */
+ public void synchronizeSelectionWithEditor() {
+ if(fInput == null || fEditor == null || fTreeViewer == null)
+ return;
+
+ ITextSelection editorSelection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+ if(editorSelection == null)
+ return;
+
+ int offset = editorSelection.getOffset();
+
+ ICElement editorElement;
+ try {
+ editorElement = fInput.getElementAtOffset(offset);
+ } catch (CModelException e) {
+ return;
+ }
+
+ if (editorElement != null) {
+ IStructuredSelection selection = new StructuredSelection(editorElement);
+ fTreeViewer.setSelection(selection, true);
+ }
+ }
+
+ /**
+ * called to create the context menu of the outline
+ */
+ protected void contextMenuAboutToShow(IMenuManager menu) {
+ CUIPlugin.createStandardGroups(menu);
+
+ ISelection selection= getSelection();
+ if (fOpenViewActionGroup != null && OpenViewActionGroup.canActionBeAdded(selection)){
+ fOpenViewActionGroup.fillContextMenu(menu);
+ }
+
+ if (OpenIncludeAction.canActionBeAdded(selection)) {
+ menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenIncludeAction);
+ }
+
+ if (fSelectionSearchGroup != null && SelectionSearchGroup.canActionBeAdded(selection)){
+ fSelectionSearchGroup.fillContextMenu(menu);
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ if (fRefactoringActionGroup != null) {
+ fRefactoringActionGroup.fillContextMenu(menu);
+ }
+ }
+
+ protected CContentOutlinerProvider createContentProvider(TreeViewer viewer) {
+ IWorkbenchPart part= getSite().getPage().getActivePart();
+ if (part == null) {
+ return new CContentOutlinerProvider(viewer);
+ }
+ return new CContentOutlinerProvider(viewer, part.getSite());
+ }
+
+ protected ProblemTreeViewer createTreeViewer(Composite parent) {
+ fTreeViewer = new ProblemTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ fTreeViewer.setContentProvider(createContentProvider(fTreeViewer));
+ fTreeViewer.setLabelProvider(new DecoratingCLabelProvider(new AppearanceAwareLabelProvider(TEXT_FLAGS, IMAGE_FLAGS), true));
+ fTreeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
+ fTreeViewer.setUseHashlookup(true);
+ fTreeViewer.addSelectionChangedListener(this);
+ return fTreeViewer;
+ }
+
+ public void createControl(Composite parent) {
+ fTreeViewer = createTreeViewer(parent);
+ initDragAndDrop();
+
+ MenuManager manager= new MenuManager(fContextMenuId);
+ manager.setRemoveAllWhenShown(true);
+ manager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ contextMenuAboutToShow(manager);
+ }
+ });
+ Control control= fTreeViewer.getControl();
+ fMenu= manager.createContextMenu(control);
+ control.setMenu(fMenu);
+
+ fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ if (fOpenIncludeAction != null) {
+ fOpenIncludeAction.run();
+ }
+ }
+ });
+ // register global actions
+ IPageSite site= getSite();
+ site.registerContextMenu(fContextMenuId, manager, fTreeViewer);
+ site.setSelectionProvider(fTreeViewer);
+
+ IActionBars bars= site.getActionBars();
+ bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
+
+ fSelectionSearchGroup = createSearchActionGroup();
+ fOpenViewActionGroup = createOpenViewActionGroup();
+ fRefactoringActionGroup= createRefactoringActionGroup();
+ // Custom filter group
+ fCustomFiltersActionGroup= createCustomFiltersActionGroup();
+
+ // Do this before setting input but after the initializations of the fields filtering
+ registerActionBars(bars);
+
+ fTreeViewer.setInput(fInput);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(control, ICHelpContextIds.COUTLINE_VIEW);
+ }
+
+ public void dispose() {
+ if (fTreeViewer != null) {
+ fTreeViewer.removeSelectionChangedListener(this);
+ fTreeViewer= null;
+ }
+
+ if (fTogglePresentation != null) {
+ fTogglePresentation.setEditor(null);
+ fTogglePresentation= null;
+ }
+
+ if (fMemberFilterActionGroup != null) {
+ fMemberFilterActionGroup.dispose();
+ fMemberFilterActionGroup= null;
+ }
+
+ if (fOpenViewActionGroup != null) {
+ fOpenViewActionGroup.dispose();
+ fOpenViewActionGroup= null;
+ }
+
+ if (fRefactoringActionGroup != null) {
+ fRefactoringActionGroup.dispose();
+ fRefactoringActionGroup= null;
+ }
+
+ if (fSelectionSearchGroup != null) {
+ fSelectionSearchGroup.dispose();
+ fSelectionSearchGroup= null;
+ }
+
+ if (fCustomFiltersActionGroup != null) {
+ fCustomFiltersActionGroup.dispose();
+ fCustomFiltersActionGroup= null;
+ }
+
+ if (fSelectionChangedListeners != null) {
+ fSelectionChangedListeners.clear();
+ // don't set the listeners to null, the outline page may be reused.
+ }
+
+ if (fMenu != null && !fMenu.isDisposed()) {
+ fMenu.dispose();
+ fMenu= null;
+ }
+
+ fInput= null;
+
+ super.dispose();
+ }
+
+ /**
+ * Register actions to the action bars.
+ *
+ * @param actionBars
+ */
+ protected void registerActionBars(IActionBars actionBars) {
+ IToolBarManager toolBarManager= actionBars.getToolBarManager();
+
+ LexicalSortingAction action= new LexicalSortingAction(getTreeViewer());
+ toolBarManager.add(action);
+
+ fMemberFilterActionGroup= createMemberFilterActionGroup();
+ if (fMemberFilterActionGroup != null) {
+ fMemberFilterActionGroup.fillActionBars(actionBars);
+ }
+ if (fCustomFiltersActionGroup != null) {
+ fCustomFiltersActionGroup.fillActionBars(actionBars);
+ }
+ if (fOpenViewActionGroup != null) {
+ fOpenViewActionGroup.fillActionBars(actionBars);
+ }
+ if (fRefactoringActionGroup != null) {
+ fRefactoringActionGroup.fillActionBars(actionBars);
+ }
+
+ IMenuManager menu= actionBars.getMenuManager();
+ menu.add(new Separator("EndFilterGroup")); //$NON-NLS-1$
+
+ fToggleLinkingAction= new ToggleLinkingAction();
+ menu.add(fToggleLinkingAction);
+ fIncludeGroupingAction= new IncludeGroupingAction(this);
+ menu.add(fIncludeGroupingAction);
+ }
+
+ /**
+ * return an ActionGroup contributing search actions or
+ * <code>null</code> if search is not supported
+ */
+ protected SelectionSearchGroup createSearchActionGroup() {
+ // default: no search action group
+ return null;
+ }
+
+ /**
+ * @return an OpenViewActionGroup contributing open view actions or
+ * <code>null</code> if open view actions are not wanted
+ */
+ protected OpenViewActionGroup createOpenViewActionGroup() {
+ // default: no open view action group
+ return null;
+ }
+
+ /**
+ * @return an ActionGroup contributing refactoring actions or
+ * <code>null</code> if refactoring is not supported
+ */
+ protected ActionGroup createRefactoringActionGroup() {
+ // default: no refactoring actions
+ return null;
+ }
+
+ /**
+ * @return an ActionGroup instance to provide custom filters or
+ * <code>null</code> if this action group is not wanted
+ */
+ protected ActionGroup createCustomFiltersActionGroup() {
+ // default: no custom filters
+ return null;
+ }
+
+ /**
+ * @return an ActionGroup contributing member filters or <code>null</code>
+ * if member filters are not wanted
+ */
+ protected ActionGroup createMemberFilterActionGroup() {
+ // default: no member filters
+ return null;
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ fSelectionChangedListeners.add(listener);
+ }
+
+ /**
+ * Fires a selection changed event.
+ *
+ * @param selection the new selection
+ */
+ protected void fireSelectionChanged(ISelection selection) {
+ // create an event
+ SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
+
+ // fire the event
+ Object[] listeners = fSelectionChangedListeners.getListeners();
+ for (int i = 0; i < listeners.length; ++i) {
+ ((ISelectionChangedListener) listeners[i]).selectionChanged(event);
+ }
+ if (fRefactoringActionGroup != null) {
+ fRefactoringActionGroup.setContext(new ActionContext(selection));
+ fRefactoringActionGroup.updateActionBars();
+ }
+ }
+
+ public Control getControl() {
+ if (fTreeViewer == null)
+ return null;
+ return fTreeViewer.getControl();
+ }
+
+ public ISelection getSelection() {
+ if (fTreeViewer == null)
+ return StructuredSelection.EMPTY;
+ return fTreeViewer.getSelection();
+ }
+
+ /**
+ * Returns this page's tree viewer.
+ *
+ * @return this page's tree viewer, or <code>null</code> if
+ * <code>createControl</code> has not been called yet
+ */
+ protected TreeViewer getTreeViewer() {
+ return fTreeViewer;
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ fSelectionChangedListeners.remove(listener);
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ fireSelectionChanged(event.getSelection());
+ }
+
+ /**
+ * Sets focus to a part in the page.
+ */
+ public void setFocus() {
+ fTreeViewer.getControl().setFocus();
+ }
+
+ public void setSelection(ISelection selection) {
+ if (fTreeViewer != null)
+ fTreeViewer.setSelection(selection);
+ }
+
+ /**
+ * Set the current input to the content provider.
+ * @param unit
+ */
+ public void setInput(ITranslationUnit unit) {
+ fInput = unit;
+ if (fTreeViewer != null) {
+ fTreeViewer.setInput (fInput);
+ }
+ }
+
+ private void initDragAndDrop() {
+ int ops= DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+ Transfer[] transfers= new Transfer[] {
+ LocalSelectionTransfer.getInstance()
+ };
+
+ // Drop Adapter
+ TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] {
+ new SelectionTransferDropAdapter(fTreeViewer)
+ };
+ fTreeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, new DelegatingDropAdapter(dropListeners));
+
+ // Drag Adapter
+ TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
+ new SelectionTransferDragAdapter(fTreeViewer)
+ };
+ fTreeViewer.addDragSupport(ops, transfers, new CDTViewerDragAdapter(fTreeViewer, dragListeners));
+ }
+
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
index 06a2645c97c..50ab6a64b52 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
@@ -13,531 +13,53 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.AbstractTreeViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionGroup;
-import org.eclipse.ui.part.IPageSite;
-import org.eclipse.ui.part.Page;
-import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
-import org.eclipse.cdt.core.model.CModelException;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.core.model.util.CElementBaseLabels;
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
-import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
-import org.eclipse.cdt.internal.ui.CPluginImages;
-import org.eclipse.cdt.internal.ui.ICHelpContextIds;
-import org.eclipse.cdt.internal.ui.IContextMenuConstants;
-import org.eclipse.cdt.internal.ui.actions.AbstractToggleLinkingAction;
-import org.eclipse.cdt.internal.ui.actions.ActionMessages;
-import org.eclipse.cdt.internal.ui.cview.SelectionTransferDragAdapter;
-import org.eclipse.cdt.internal.ui.cview.SelectionTransferDropAdapter;
-import org.eclipse.cdt.internal.ui.dnd.CDTViewerDragAdapter;
-import org.eclipse.cdt.internal.ui.dnd.DelegatingDropAdapter;
-import org.eclipse.cdt.internal.ui.dnd.TransferDragSourceListener;
-import org.eclipse.cdt.internal.ui.dnd.TransferDropTargetListener;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
-import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
-import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
-import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
-
-public class CContentOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener {
- private static final int TEXT_FLAGS = AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementBaseLabels.F_APP_TYPE_SIGNATURE | CElementBaseLabels.M_APP_RETURNTYPE;
- private static final int IMAGE_FLAGS = AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS;
-
- private CEditor fEditor;
- private ITranslationUnit fInput;
- private ProblemTreeViewer fTreeViewer;
- private ListenerList selectionChangedListeners = new ListenerList(ListenerList.IDENTITY);
- private TogglePresentationAction fTogglePresentation;
- private String fContextMenuId;
- private Menu fMenu;
-
- protected OpenIncludeAction fOpenIncludeAction;
- private IncludeGroupingAction fIncludeGroupingAction;
- private ToggleLinkingAction fToggleLinkingAction;
-
- private MemberFilterActionGroup fMemberFilterActionGroup;
-
- private ActionGroup fSelectionSearchGroup;
- private OpenViewActionGroup fOpenViewActionGroup;
- private ActionGroup fRefactoringActionGroup;
-
- /**
- * Custom filter action group.
- * @since 3.0
- */
- private CustomFiltersActionGroup fCustomFiltersActionGroup;
-
- public class IncludeGroupingAction extends Action {
- CContentOutlinePage outLine;
-
- public IncludeGroupingAction(CContentOutlinePage outlinePage) {
- super(ActionMessages.getString("IncludesGroupingAction.label")); //$NON-NLS-1$
- setDescription(ActionMessages.getString("IncludesGroupingAction.description")); //$NON-NLS-1$
- setToolTipText(ActionMessages.getString("IncludeGroupingAction.tooltip")); //$NON-NLS-1$
- CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_GROUP_INCLUDE);
-
- boolean enabled= isIncludesGroupingEnabled();
- setChecked(enabled);
- outLine = outlinePage;
- }
-
- /**
- * Runs the action.
- */
- public void run() {
- boolean oldValue = isIncludesGroupingEnabled();
- PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, isChecked());
- if (oldValue != isChecked()) {
- outLine.contentUpdated();
- }
- }
- public boolean isIncludesGroupingEnabled () {
- return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES);
- }
- }
-
- /**
- * This action toggles whether this C Outline page links
- * its selection to the active editor.
- *
- * @since 3.0
- */
- public class ToggleLinkingAction extends AbstractToggleLinkingAction {
-
- CContentOutlinePage fOutlinePage;
-
- /**
- * Constructs a new action.
- *
- * @param outlinePage the Java outline page
- */
- public ToggleLinkingAction(CContentOutlinePage outlinePage) {
- setChecked(isLinkingEnabled());
- fOutlinePage = outlinePage;
- }
-
- /**
- * Runs the action.
- */
- public void run() {
- boolean checked = isChecked();
- PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_LINK_TO_EDITOR, checked);
- if (checked && fEditor != null)
- synchronizeSelectionWithEditor();
- }
- }
-
-
- public boolean isLinkingEnabled() {
- return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_LINK_TO_EDITOR);
- }
-
+/**
+ * Outline page for C/C++ translation units.
+ */
+public class CContentOutlinePage extends AbstractCModelOutlinePage {
public CContentOutlinePage(CEditor editor) {
- this("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
- }
-
- public CContentOutlinePage(String contextMenuID, CEditor editor) {
- super();
- fEditor= editor;
- fInput= null;
- fContextMenuId = contextMenuID;
-
- fTogglePresentation= new TogglePresentationAction();
- fTogglePresentation.setEditor(editor);
-
- fOpenIncludeAction= new OpenIncludeAction(this);
- }
-
- public ICElement getRoot() {
- return fInput;
- }
-
- /**
- * Provide access to the CEditor corresponding to this CContentOutlinePage.
- * @returns the CEditor corresponding to this CContentOutlinePage.
- */
- public CEditor getEditor() {
- return fEditor;
- }
-
- /**
- * Called by the editor to signal that the content has updated.
- */
- public void contentUpdated() {
- if (fInput != null) {
- final TreeViewer treeViewer= getTreeViewer();
- if (treeViewer != null && !treeViewer.getControl().isDisposed()) {
- treeViewer.getControl().getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (!treeViewer.getControl().isDisposed()) {
- ISelection sel= treeViewer.getSelection();
- treeViewer.setSelection(updateSelection(sel));
- treeViewer.refresh();
- }
- }
- });
- }
- }
- }
-
- protected ISelection updateSelection(ISelection sel) {
- ArrayList newSelection= new ArrayList();
- if (sel instanceof IStructuredSelection) {
- Iterator iter= ((IStructuredSelection)sel).iterator();
- for (;iter.hasNext();) {
- //ICElement elem= fInput.findEqualMember((ICElement)iter.next());
- Object o = iter.next();
- if (o instanceof ICElement) {
- newSelection.add(o);
- }
- }
- }
- return new StructuredSelection(newSelection);
- }
-
-
- /**
- * Sets the selected element to the one at the current cursor position in the editor.
- */
- public void synchronizeSelectionWithEditor() {
- if(fInput == null || fEditor == null || fTreeViewer == null)
- return;
-
- ITextSelection editorSelection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
- if(editorSelection == null)
- return;
-
- int offset = editorSelection.getOffset();
-
- ICElement editorElement;
- try {
- editorElement = fInput.getElementAtOffset(offset);
- } catch (CModelException e) {
- return;
- }
-
- if (editorElement != null) {
- IStructuredSelection selection = new StructuredSelection(editorElement);
- fTreeViewer.setSelection(selection, true);
- }
- }
-
- /**
- * called to create the context menu of the outline
- */
- protected void contextMenuAboutToShow(IMenuManager menu) {
- CUIPlugin.createStandardGroups(menu);
-
- ISelection selection= getSelection();
- if (OpenViewActionGroup.canActionBeAdded(selection)){
- fOpenViewActionGroup.fillContextMenu(menu);
- }
-
- if (OpenIncludeAction.canActionBeAdded(selection)) {
- menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenIncludeAction);
- }
-
- if (SelectionSearchGroup.canActionBeAdded(selection)){
- fSelectionSearchGroup.fillContextMenu(menu);
- menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- }
-
- fRefactoringActionGroup.fillContextMenu(menu);
- }
-
- protected CContentOutlinerProvider createContentProvider(TreeViewer viewer) {
- IWorkbenchPart part= getSite().getPage().getActivePart();
- if (part == null) {
- return new CContentOutlinerProvider(viewer);
- }
- return new CContentOutlinerProvider(viewer, part.getSite());
- }
-
- protected ProblemTreeViewer createTreeViewer(Composite parent) {
- fTreeViewer = new ProblemTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- fTreeViewer.setContentProvider(createContentProvider(fTreeViewer));
- fTreeViewer.setLabelProvider(new DecoratingCLabelProvider(new AppearanceAwareLabelProvider(TEXT_FLAGS, IMAGE_FLAGS), true));
- fTreeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
- fTreeViewer.setUseHashlookup(true);
- fTreeViewer.addSelectionChangedListener(this);
- return fTreeViewer;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- public void createControl(Composite parent) {
- fTreeViewer = createTreeViewer(parent);
- initDragAndDrop();
-
- MenuManager manager= new MenuManager(fContextMenuId);
- manager.setRemoveAllWhenShown(true);
- manager.addMenuListener(new IMenuListener() {
- public void menuAboutToShow(IMenuManager manager) {
- contextMenuAboutToShow(manager);
- }
- });
- Control control= fTreeViewer.getControl();
- fMenu= manager.createContextMenu(control);
- control.setMenu(fMenu);
-
- fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
- */
- public void doubleClick(DoubleClickEvent event) {
- if (fOpenIncludeAction != null) {
- fOpenIncludeAction.run();
- }
- }
- });
- // register global actions
- IPageSite site= getSite();
- site.registerContextMenu(fContextMenuId, manager, fTreeViewer);
- site.setSelectionProvider(fTreeViewer);
-
- IActionBars bars= site.getActionBars();
- bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
-
- fSelectionSearchGroup = new SelectionSearchGroup(this);
- fOpenViewActionGroup = new OpenViewActionGroup(this);
- fOpenViewActionGroup.setEnableIncludeBrowser(true);
- fRefactoringActionGroup= new CRefactoringActionGroup(this);
- // Custom filter group
- fCustomFiltersActionGroup= new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
-
- // Do this before setting input but after the initializations of the fields filtering
- registerActionBars(bars);
-
- fTreeViewer.setInput(fInput);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(control, ICHelpContextIds.COUTLINE_VIEW);
- }
-
- public void dispose() {
- if (fTreeViewer != null) {
- fTreeViewer.removeSelectionChangedListener(this);
- fTreeViewer= null;
- }
-
- if (fTogglePresentation != null) {
- fTogglePresentation.setEditor(null);
- fTogglePresentation= null;
- }
-
- if (fMemberFilterActionGroup != null) {
- fMemberFilterActionGroup.dispose();
- fMemberFilterActionGroup= null;
- }
-
- if (fOpenViewActionGroup != null) {
- fOpenViewActionGroup.dispose();
- fOpenViewActionGroup= null;
- }
-
- if (fRefactoringActionGroup != null) {
- fRefactoringActionGroup.dispose();
- fRefactoringActionGroup= null;
- }
-
- if (fSelectionSearchGroup != null) {
- fSelectionSearchGroup.dispose();
- fSelectionSearchGroup= null;
- }
-
- if (fCustomFiltersActionGroup != null) {
- fCustomFiltersActionGroup.dispose();
- fCustomFiltersActionGroup= null;
- }
-
- if (selectionChangedListeners != null) {
- selectionChangedListeners.clear();
- // don't set the listeners to null, the outline page may be reused.
- }
-
- if (fMenu != null && !fMenu.isDisposed()) {
- fMenu.dispose();
- fMenu= null;
- }
-
- fInput= null;
-
- super.dispose();
- }
-
- private void registerActionBars(IActionBars actionBars) {
- IToolBarManager toolBarManager= actionBars.getToolBarManager();
-
- LexicalSortingAction action= new LexicalSortingAction(getTreeViewer());
- toolBarManager.add(action);
-
- fMemberFilterActionGroup= new MemberFilterActionGroup(fTreeViewer, "COutlineViewer"); //$NON-NLS-1$
- fMemberFilterActionGroup.fillActionBars(actionBars);
- fCustomFiltersActionGroup.fillActionBars(actionBars);
- fOpenViewActionGroup.fillActionBars(actionBars);
- fRefactoringActionGroup.fillActionBars(actionBars);
-
- IMenuManager menu= actionBars.getMenuManager();
- menu.add(new Separator("EndFilterGroup")); //$NON-NLS-1$
-
- fToggleLinkingAction= new ToggleLinkingAction(this);
- menu.add(fToggleLinkingAction);
- fIncludeGroupingAction= new IncludeGroupingAction(this);
- menu.add(fIncludeGroupingAction);
- }
-
- /* (non-Javadoc)
- * Method declared on ISelectionProvider.
- */
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- selectionChangedListeners.add(listener);
+ super("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
}
/**
- * Fires a selection changed event.
- *
- * @param selection the new selection
+ * Provide access to the CEditor corresponding to this CContentOutlinePage.
+ * @returns the CEditor corresponding to this CContentOutlinePage.
*/
- protected void fireSelectionChanged(ISelection selection) {
- // create an event
- SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
-
- // fire the event
- Object[] listeners = selectionChangedListeners.getListeners();
- for (int i = 0; i < listeners.length; ++i) {
- ((ISelectionChangedListener) listeners[i]).selectionChanged(event);
- }
- fRefactoringActionGroup.setContext(new ActionContext(selection));
- fRefactoringActionGroup.updateActionBars();
- }
-
- /* (non-Javadoc)
- * Method declared on IPage (and Page).
- */
- public Control getControl() {
- if (fTreeViewer == null)
- return null;
- return fTreeViewer.getControl();
- }
-
- /* (non-Javadoc)
- * Method declared on ISelectionProvider.
- */
- public ISelection getSelection() {
- if (fTreeViewer == null)
- return StructuredSelection.EMPTY;
- return fTreeViewer.getSelection();
- }
-
- /**
- * Returns this page's tree viewer.
- *
- * @return this page's tree viewer, or <code>null</code> if
- * <code>createControl</code> has not been called yet
- */
- protected TreeViewer getTreeViewer() {
- return fTreeViewer;
- }
-
- /* (non-Javadoc)
- * Method declared on ISelectionProvider.
- */
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- selectionChangedListeners.remove(listener);
+ public CEditor getEditor() {
+ return (CEditor)fEditor;
}
- /* (non-Javadoc)
- * Method declared on ISelectionChangeListener.
- * Gives notification that the tree selection has changed.
- */
- public void selectionChanged(SelectionChangedEvent event) {
- fireSelectionChanged(event.getSelection());
+ protected SelectionSearchGroup createSearchActionGroup() {
+ return new SelectionSearchGroup(this);
}
- /**
- * Sets focus to a part in the page.
- */
- public void setFocus() {
- fTreeViewer.getControl().setFocus();
+ protected OpenViewActionGroup createOpenViewActionGroup() {
+ OpenViewActionGroup ovag= new OpenViewActionGroup(this);
+ ovag.setEnableIncludeBrowser(true);
+ return ovag;
}
- /* (non-Javadoc)
- * Method declared on ISelectionProvider.
- */
- public void setSelection(ISelection selection) {
- if (fTreeViewer != null)
- fTreeViewer.setSelection(selection);
+ protected ActionGroup createRefactoringActionGroup() {
+ return new CRefactoringActionGroup(this);
}
- /**
- * Set the current input to the content provider.
- * @param unit
- */
- public void setInput(ITranslationUnit unit) {
- fInput = unit;
- if (fTreeViewer != null) {
- fTreeViewer.setInput (fInput);
- }
+ protected ActionGroup createCustomFiltersActionGroup() {
+ return new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
}
- private void initDragAndDrop() {
- int ops= DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
- Transfer[] transfers= new Transfer[] {
- LocalSelectionTransfer.getInstance()
- };
-
- // Drop Adapter
- TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] {
- new SelectionTransferDropAdapter(fTreeViewer)
- };
- fTreeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, new DelegatingDropAdapter(dropListeners));
-
- // Drag Adapter
- TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
- new SelectionTransferDragAdapter(fTreeViewer)
- };
- fTreeViewer.addDragSupport(ops, transfers, new CDTViewerDragAdapter(fTreeViewer, dragListeners));
+ protected ActionGroup createMemberFilterActionGroup() {
+ return new MemberFilterActionGroup(getTreeViewer(), "COutlineViewer"); //$NON-NLS-1$
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java
deleted file mode 100644
index 3ae547b0281..00000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Aug 12, 2003
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package org.eclipse.cdt.internal.ui.editor;
-
-import java.util.List;
-
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.internal.ui.CPluginImages;
-import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.search.ui.NewSearchUI;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-/**
- * @author bgheorgh
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class SearchDialogAction extends Action {
- private static final String PREFIX= "SearchDialogAction."; //$NON-NLS-1$
- private static final String C_SEARCH_PAGE_ID= "org.eclipse.cdt.ui.CSearchPage"; //$NON-NLS-1$
-
- private ISelectionProvider fSelectionProvider;
- private ITextEditor fEditor;
- private IWorkbenchWindow fWorkbenchWindow;
-
- public SearchDialogAction(ISelectionProvider provider, CEditor editor) {
- super(CUIPlugin.getResourceString(PREFIX + "label")); //$NON-NLS-1$
- setDescription(CUIPlugin.getResourceString(PREFIX + "description")); //$NON-NLS-1$
- setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip")); //$NON-NLS-1$
-
- if(provider instanceof CContentOutlinePage) {
- setImageDescriptor( CPluginImages.DESC_OBJS_CSEARCH );
- }
-
- fSelectionProvider= provider;
- fEditor = editor;
- }
-
- public SearchDialogAction(ISelectionProvider provider, IWorkbenchWindow window) {
-
- super(CUIPlugin.getResourceString(PREFIX + "label")); //$NON-NLS-1$
- setDescription(CUIPlugin.getResourceString(PREFIX + "description")); //$NON-NLS-1$
- setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip")); //$NON-NLS-1$
-
- if(provider instanceof CContentOutlinePage) {
- setImageDescriptor( CPluginImages.DESC_OBJS_CSEARCH );
- }
-
- fSelectionProvider= provider;
- fWorkbenchWindow = window;
- }
-
- public void run() {
- String search_name;
-
- ISelection selection= fSelectionProvider.getSelection();
- if(selection instanceof ITextSelection) {
- search_name = ((ITextSelection)selection).getText();
- if(search_name.length() == 0) return;
- } else {
- ICElement element= getElement(selection);
- if (element == null) {
- return;
- }
- search_name = element.getElementName();
- }
-
- if (fEditor != null){
- NewSearchUI.openSearchDialog(fEditor.getEditorSite().getWorkbenchWindow(),C_SEARCH_PAGE_ID);
- }
- else if (fWorkbenchWindow != null){
- NewSearchUI.openSearchDialog(fWorkbenchWindow,C_SEARCH_PAGE_ID);
- }
- }
-
-
- private static ICElement getElement(ISelection sel) {
- if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
- List list= ((IStructuredSelection)sel).toList();
- if (list.size() == 1) {
- Object element= list.get(0);
- if (element instanceof ICElement) {
- return (ICElement)element;
- }
- }
- }
- return null;
- }
-
- public static boolean canActionBeAdded(ISelection selection) {
- if(selection instanceof ITextSelection) {
- return (((ITextSelection)selection).getLength() > 0);
- } else {
- return getElement(selection) != null;
- }
- }
-
-
- public static String getEditorID(String name) {
- IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
- if (registry != null) {
- IEditorDescriptor descriptor = registry.getDefaultEditor(name);
- if (descriptor != null) {
- return descriptor.getId();
- } else {
- //getDefaultEditor is deprecated, The system external editor is the default editor
- return IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID;
-
- }
- }
- return null;
- }
-
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/ASMEditorActionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/ASMEditorActionContributor.java
index aaa498eae4e..aced3370ae8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/ASMEditorActionContributor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/ASMEditorActionContributor.java
@@ -1,9 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Wind River Systems, 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:
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor.asm;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.editors.text.TextEditorActionContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
-public class ASMEditorActionContributor extends
- TextEditorActionContributor {
+import org.eclipse.cdt.internal.ui.editor.TogglePresentationAction;
- // nothing for now
+public class ASMEditorActionContributor extends TextEditorActionContributor {
+
+ private TogglePresentationAction fTogglePresentation;
+
+ /**
+ * Default constructor is mandatory (executable extension).
+ */
+ public ASMEditorActionContributor() {
+ fTogglePresentation= new TogglePresentationAction();
+ fTogglePresentation.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY);
+ }
+
+ /*
+ * @see org.eclipse.ui.editors.text.TextEditorActionContributor#init(org.eclipse.ui.IActionBars)
+ */
+ public void init(IActionBars bars) {
+ super.init(bars);
+ bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
+ }
+
+ /*
+ * @see org.eclipse.ui.editors.text.TextEditorActionContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
+ */
+ public void setActiveEditor(IEditorPart part) {
+ super.setActiveEditor(part);
+ internalSetActiveEditor(part);
+ }
+
+ private void internalSetActiveEditor(IEditorPart part) {
+ ITextEditor textEditor= null;
+ if (part instanceof ITextEditor)
+ textEditor= (ITextEditor) part;
+
+ fTogglePresentation.setEditor(textEditor);
+ }
+
+ /*
+ * @see org.eclipse.ui.editors.text.TextEditorActionContributor#dispose()
+ */
+ public void dispose() {
+ internalSetActiveEditor(null);
+ super.dispose();
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmContentOutlinePage.java
new file mode 100644
index 00000000000..69ef32302c3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmContentOutlinePage.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Wind River Systems, 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:
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.editor.asm;
+
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
+import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
+
+import org.eclipse.cdt.internal.ui.editor.AbstractCModelOutlinePage;
+
+/**
+ * Content outline page for assembly translation units.
+ *
+ * @since 5.0
+ */
+public class AsmContentOutlinePage extends AbstractCModelOutlinePage {
+
+ /**
+ * Creates a new outline page for the given editor.
+ * @param editor
+ */
+ public AsmContentOutlinePage(ITextEditor editor) {
+ super("#ASMOutlineContext", editor); //$NON-NLS-1$
+ }
+
+ protected OpenViewActionGroup createOpenViewActionGroup() {
+ OpenViewActionGroup ovag= new OpenViewActionGroup(this);
+ ovag.setEnableIncludeBrowser(false);
+ ovag.setSuppressCallHierarchy(true);
+ ovag.setSuppressTypeHierarchy(true);
+ return ovag;
+ }
+
+ protected ActionGroup createCustomFiltersActionGroup() {
+ return new CustomFiltersActionGroup("org.eclipse.cdt.ui.AsmOutlinePage", getTreeViewer()); //$NON-NLS-1$
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmReconcilingStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmReconcilingStrategy.java
new file mode 100644
index 00000000000..df3a619059d
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmReconcilingStrategy.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Wind River Systems, 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:
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.editor.asm;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IWorkingCopyManager;
+
+/**
+ * Reconciling strategy for assembly translation units.
+ *
+ * @since 5.0
+ */
+public class AsmReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
+
+ private ITextEditor fEditor;
+
+ public AsmReconcilingStrategy(ITextEditor editor) {
+ fEditor= editor;
+ }
+
+ private IProgressMonitor fProgressMonitor;
+
+ /*
+ * @see IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
+ */
+ public void reconcile(IRegion partition) {
+ reconcile(false);
+ }
+
+ /*
+ * @see IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
+ */
+ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+ // unused - non-incremental reconciler
+ }
+
+ /*
+ * @see IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
+ */
+ public void setDocument(IDocument document) {
+ // no-op
+ }
+
+ /*
+ * @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor)
+ */
+ public void setProgressMonitor(IProgressMonitor monitor) {
+ fProgressMonitor= monitor;
+ }
+
+ /*
+ * @see IReconcilingStrategyExtension#initialReconcile()
+ */
+ public void initialReconcile() {
+ reconcile(true);
+ }
+
+ private void reconcile(final boolean initialReconcile) {
+ IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
+ IWorkingCopy workingCopy= fManager.getWorkingCopy(fEditor.getEditorInput());
+ if (workingCopy == null) {
+ return;
+ }
+ try {
+ // reconcile
+ synchronized (workingCopy) {
+ workingCopy.reconcile(false, true, fProgressMonitor);
+ }
+ } catch (OperationCanceledException oce) {
+ // document was modified while parsing
+ } catch (CModelException e) {
+ IStatus status= new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.OK, "Error in CDT UI during reconcile", e); //$NON-NLS-1$
+ CUIPlugin.getDefault().log(status);
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
index 1091388a353..4ec5ce466a0 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java
@@ -12,15 +12,20 @@
package org.eclipse.cdt.internal.ui.editor.asm;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
@@ -29,16 +34,27 @@ import org.eclipse.cdt.internal.ui.text.PartitionDamager;
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
private AsmTextTools fAsmTextTools;
+ private ITextEditor fTextEditor;
/**
* Constructor for AsmSourceViewerConfiguration
*/
public AsmSourceViewerConfiguration(AsmTextTools tools, IPreferenceStore store) {
super(store);
+ fTextEditor= null;
fAsmTextTools = tools;
}
/**
+ * Constructor for AsmSourceViewerConfiguration
+ */
+ public AsmSourceViewerConfiguration(ITextEditor editor, IPreferenceStore store) {
+ super(store);
+ fTextEditor= editor;
+ fAsmTextTools= CUIPlugin.getDefault().getAsmTextTools();
+ }
+
+ /**
* Returns the ASM multiline comment scanner for this configuration.
*
* @return the ASM multiline comment scanner
@@ -130,7 +146,19 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
ICPartitions.C_PREPROCESSOR};
}
-
+ /*
+ * @see org.eclipse.ui.editors.text.TextSourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IReconciler getReconciler(ISourceViewer sourceViewer) {
+ if (fTextEditor != null) {
+ MonoReconciler reconciler= new MonoReconciler(new AsmReconcilingStrategy(fTextEditor), false);
+ reconciler.setIsIncrementalReconciler(false);
+ reconciler.setProgressMonitor(new NullProgressMonitor());
+ reconciler.setDelay(500);
+ return reconciler;
+ }
+ return super.getReconciler(sourceViewer);
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java
index 8bd4dc68232..9e096ddfd7b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java
@@ -12,25 +12,75 @@
package org.eclipse.cdt.internal.ui.editor.asm;
+import java.util.Iterator;
+
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewerExtension5;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorActionBarContributor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPartService;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.navigator.ICommonMenuConstants;
+import org.eclipse.ui.part.EditorActionBarContributor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ISourceRange;
+import org.eclipse.cdt.core.model.ISourceReference;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
+import org.eclipse.cdt.internal.ui.editor.AbstractCModelOutlinePage;
+import org.eclipse.cdt.internal.ui.editor.CAnnotationIterator;
+import org.eclipse.cdt.internal.ui.editor.ICAnnotation;
/**
- * Assembly text editor
+ * Assembly text editor.
*/
-public class AsmTextEditor extends TextEditor {
+public class AsmTextEditor extends TextEditor implements ISelectionChangedListener {
+
+ /**
+ * Updates the outline page selection and this editor's range indicator.
+ */
+ private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
+ /*
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ AsmTextEditor.this.selectionChanged();
+ }
+ }
+
+ private AbstractCModelOutlinePage fOutlinePage;
+ private EditorSelectionChangedListener fEditorSelectionChangedListener;
+
/**
- * Creates a new text editor.
+ * Creates a new assembly text editor.
*/
public AsmTextEditor() {
super();
@@ -39,9 +89,8 @@ public class AsmTextEditor extends TextEditor {
* Initializes this editor.
*/
protected void initializeEditor() {
- AsmTextTools textTools= CUIPlugin.getDefault().getAsmTextTools();
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
- setSourceViewerConfiguration(new AsmSourceViewerConfiguration(textTools, store));
+ setSourceViewerConfiguration(new AsmSourceViewerConfiguration(this, store));
setDocumentProvider(CUIPlugin.getDefault().getDocumentProvider());
// FIXME: Should this editor have a different preference store ?
// For now we are sharing with the CEditor and any changes in the
@@ -51,7 +100,44 @@ public class AsmTextEditor extends TextEditor {
setRulerContextMenuId("#ASMEditorRulerContext"); //$NON-NLS-1$
//setOutlinerContextMenuId("#ASMEditorOutlinerContext"); //$NON-NLS-1$
}
-
+
+ /*
+ * @see org.eclipse.ui.editors.text.TextEditor#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (IContentOutlinePage.class.equals(adapter)) {
+ return getOutlinePage();
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICHelpContextIds.ASMEDITOR_VIEW);
+
+ fEditorSelectionChangedListener = new EditorSelectionChangedListener();
+ fEditorSelectionChangedListener.install(getSelectionProvider());
+ }
+
+ /*
+ * @see org.eclipse.ui.editors.text.TextEditor#dispose()
+ */
+ public void dispose() {
+ if (fOutlinePage != null) {
+ fOutlinePage.dispose();
+ fOutlinePage = null;
+ }
+ if (fEditorSelectionChangedListener != null) {
+ fEditorSelectionChangedListener.uninstall(getSelectionProvider());
+ fEditorSelectionChangedListener = null;
+ }
+ super.dispose();
+ }
+
/*
* @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
* Pulled in from 2.0
@@ -59,9 +145,9 @@ public class AsmTextEditor extends TextEditor {
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
boolean affects= false;
AsmTextTools textTools= CUIPlugin.getDefault().getAsmTextTools();
- affects |= textTools.affectsBehavior(event);
+ affects= textTools.affectsBehavior(event);
- return affects ? affects : super.affectsTextPresentation(event);
+ return affects || super.affectsTextPresentation(event);
}
/*
@@ -76,4 +162,313 @@ public class AsmTextEditor extends TextEditor {
super.editorContextMenuAboutToShow(menu);
}
+
+ /**
+ * Gets the outline page for this editor.
+ * @return Outline page.
+ */
+ public AbstractCModelOutlinePage getOutlinePage() {
+ if (fOutlinePage == null) {
+ fOutlinePage = new AsmContentOutlinePage(this);
+ fOutlinePage.addSelectionChangedListener(this);
+ }
+ setOutlinePageInput(fOutlinePage, getEditorInput());
+ return fOutlinePage;
+ }
+
+ /**
+ * Sets an input for the outline page.
+ * @param page Page to set the input.
+ * @param input Input to set.
+ */
+ public static void setOutlinePageInput(AbstractCModelOutlinePage page, IEditorInput input) {
+ if (page != null) {
+ IWorkingCopyManager manager = CUIPlugin.getDefault().getWorkingCopyManager();
+ page.setInput(manager.getWorkingCopy(input));
+ }
+ }
+
+ /**
+ * React to changed selection in the editor.
+ */
+ protected void selectionChanged() {
+ if (getSelectionProvider() == null)
+ return;
+ ISourceReference element= computeHighlightRangeSourceReference();
+ updateStatusLine();
+ synchronizeOutlinePage();
+ setSelection(element, false);
+ }
+
+ /**
+ * Synchronizes the outline view selection with the given element
+ * position in the editor.
+ */
+ protected void synchronizeOutlinePage() {
+ if(fOutlinePage != null && fOutlinePage.isLinkingEnabled()) {
+ fOutlinePage.removeSelectionChangedListener(this);
+ fOutlinePage.synchronizeSelectionWithEditor();
+ fOutlinePage.addSelectionChangedListener(this);
+ }
+ }
+
+ protected void updateStatusLine() {
+ ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
+ Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength());
+ setStatusLineErrorMessage(null);
+ setStatusLineMessage(null);
+ if (annotation != null) {
+ updateMarkerViews(annotation);
+ if (annotation instanceof ICAnnotation && ((ICAnnotation) annotation).isProblem())
+ setStatusLineMessage(annotation.getText());
+ }
+ }
+
+ /**
+ * Returns the annotation overlapping with the given range or <code>null</code>.
+ *
+ * @param offset the region offset
+ * @param length the region length
+ * @return the found annotation or <code>null</code>
+ */
+ private Annotation getAnnotation(int offset, int length) {
+ IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
+ Iterator e = new CAnnotationIterator(model, true, true);
+ while (e.hasNext()) {
+ Annotation a = (Annotation) e.next();
+ if (!isNavigationTarget(a))
+ continue;
+
+ Position p = model.getPosition(a);
+ if (p != null && p.overlapsWith(offset, length))
+ return a;
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the StatusLineManager.
+ */
+ protected IStatusLineManager getStatusLineManager() {
+ IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor();
+ if (contributor instanceof EditorActionBarContributor) {
+ return ((EditorActionBarContributor) contributor).getActionBars().getStatusLineManager();
+ }
+ return null;
+ }
+
+
+ /**
+ * Computes and returns the source reference that includes the caret and
+ * serves as provider for the outline page selection and the editor range
+ * indication.
+ *
+ * @return the computed source reference
+ */
+ protected ISourceReference computeHighlightRangeSourceReference() {
+ ISourceViewer sourceViewer= getSourceViewer();
+ if (sourceViewer == null)
+ return null;
+
+ StyledText styledText= sourceViewer.getTextWidget();
+ if (styledText == null)
+ return null;
+
+ int caret= 0;
+ if (sourceViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension= (ITextViewerExtension5)sourceViewer;
+ caret= extension.widgetOffset2ModelOffset(styledText.getSelection().x);
+ } else {
+ int offset= sourceViewer.getVisibleRegion().getOffset();
+ caret= offset + styledText.getSelection().x;
+ }
+
+ ICElement element= getElementAt(caret, false);
+
+ if ( !(element instanceof ISourceReference))
+ return null;
+
+ return (ISourceReference) element;
+ }
+
+ /**
+ * Returns the most narrow element including the given offset. If <code>reconcile</code>
+ * is <code>true</code> the editor's input element is reconciled in advance. If it is
+ * <code>false</code> this method only returns a result if the editor's input element
+ * does not need to be reconciled.
+ *
+ * @param offset the offset included by the retrieved element
+ * @param reconcile <code>true</code> if working copy should be reconciled
+ * @return the most narrow element which includes the given offset
+ */
+ protected ICElement getElementAt(int offset, boolean reconcile) {
+ ITranslationUnit unit= (ITranslationUnit)getInputCElement();
+
+ if (unit != null) {
+ try {
+ if (reconcile && unit instanceof IWorkingCopy) {
+ synchronized (unit) {
+ ((IWorkingCopy) unit).reconcile();
+ }
+ return unit.getElementAtOffset(offset);
+ } else if (unit.isConsistent()) {
+ return unit.getElementAtOffset(offset);
+ }
+ } catch (CModelException x) {
+ CUIPlugin.getDefault().log(x.getStatus());
+ // nothing found, be tolerant and go on
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the C element wrapped by this editors input.
+ *
+ * @return the C element wrapped by this editors input.
+ */
+ public ICElement getInputCElement () {
+ return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput());
+ }
+
+ /**
+ * React to changed selection in the outline view.
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection sel = event.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object obj = selection.getFirstElement();
+ if (obj instanceof ISourceReference) {
+ try {
+ ISourceRange range = ((ISourceReference) obj).getSourceRange();
+ if (range != null) {
+ setSelection(range, !isActivePart());
+ }
+ } catch (CModelException e) {
+ // Selection change not applied.
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks is the editor active part.
+ * @return <code>true</code> if editor is the active part of the workbench.
+ */
+ private boolean isActivePart() {
+ IWorkbenchWindow window = getSite().getWorkbenchWindow();
+ IPartService service = window.getPartService();
+ return (this == service.getActivePart());
+ }
+
+ /**
+ * Sets selection for C element.
+ * @param element Element to select.
+ */
+ public void setSelection(ICElement element) {
+ if (element instanceof ISourceReference && !(element instanceof ITranslationUnit)) {
+ ISourceReference reference = (ISourceReference) element;
+ // set hightlight range
+ setSelection(reference, true);
+ }
+ }
+
+ /**
+ * Sets selection for source reference.
+ * @param element Source reference to set.
+ * @param moveCursor Should cursor be moved.
+ */
+ public void setSelection(ISourceReference element, boolean moveCursor) {
+ if (element != null) {
+ StyledText textWidget = null;
+
+ ISourceViewer sourceViewer = getSourceViewer();
+ if (sourceViewer != null)
+ textWidget = sourceViewer.getTextWidget();
+
+ if (textWidget == null)
+ return;
+
+ try {
+ setSelection(element.getSourceRange(), moveCursor);
+ } catch (CModelException e) {
+ // Selection not applied.
+ }
+ }
+ }
+
+ /**
+ * Sets the current editor selection to the source range. Optionally
+ * sets the current editor position.
+ *
+ * @param element the source range to be shown in the editor, can be null.
+ * @param moveCursor if true the editor is scrolled to show the range.
+ */
+ public void setSelection(ISourceRange element, boolean moveCursor) {
+
+ if (element == null) {
+ return;
+ }
+
+ try {
+ IRegion alternateRegion = null;
+ int start = element.getStartPos();
+ int length = element.getLength();
+
+ // Sanity check sometimes the parser may throw wrong numbers.
+ if (start < 0 || length < 0) {
+ start = 0;
+ length = 0;
+ }
+
+ // 0 length and start and non-zero start line says we know
+ // the line for some reason, but not the offset.
+ if (length == 0 && start == 0 && element.getStartLine() > 0) {
+ // We have the information in term of lines, we can work it out.
+ // Binary elements return the first executable statement so we have to substract -1
+ start = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getStartLine() - 1);
+ if (element.getEndLine() > 0) {
+ length = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getEndLine()) - start;
+ } else {
+ length = start;
+ }
+ // create an alternate region for the keyword highlight.
+ alternateRegion = getDocumentProvider().getDocument(getEditorInput()).getLineInformation(element.getStartLine() - 1);
+ if (start == length || length < 0) {
+ if (alternateRegion != null) {
+ start = alternateRegion.getOffset();
+ length = alternateRegion.getLength();
+ }
+ }
+ }
+ setHighlightRange(start, length, moveCursor);
+
+ if (moveCursor) {
+ start = element.getIdStartPos();
+ length = element.getIdLength();
+ if (start == 0 && length == 0 && alternateRegion != null) {
+ start = alternateRegion.getOffset();
+ length = alternateRegion.getLength();
+ }
+ if (start > -1 && getSourceViewer() != null) {
+ getSourceViewer().revealRange(start, length);
+ getSourceViewer().setSelectedRange(start, length);
+ }
+ updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION);
+ }
+ return;
+ } catch (IllegalArgumentException x) {
+ // No information to the user
+ } catch (BadLocationException e) {
+ // No information to the user
+ }
+
+ if (moveCursor)
+ resetHighlightRange();
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java
index bd3d4dcc762..5824eb649d9 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2007 IBM Corporation 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
@@ -8,16 +8,14 @@
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.util;
import java.util.ArrayList;
-import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage;
-import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
@@ -35,7 +33,6 @@ import org.eclipse.swt.widgets.Widget;
public class ProblemTreeViewer extends TreeViewer {
protected ResourceToItemsMapper fResourceToItemsMapper;
- private CEditor editor = null;
/*
* @see TreeViewer#TreeViewer(Composite)
@@ -152,21 +149,5 @@ public class ProblemTreeViewer extends TreeViewer {
return cp.hasChildren(element);
}
- /* (non-Javadoc)
- * Method declared on ISelectionProvider.
- */
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- super.addSelectionChangedListener(listener);
- if (listener instanceof CContentOutlinePage) {
- editor =((CContentOutlinePage)listener).getEditor();
- }
- }
-
- /**
- * This returns the editor corresponding to the opened CEditor that is listening to the selection changes on the Outline View.
- */
- public CEditor getEditor() {
- return editor;
- }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java
index 297f7c82991..733e116b1a2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java
@@ -225,7 +225,10 @@ public class CElementImageProvider {
case ICElement.C_USING:
return CPluginImages.DESC_OBJS_USING;
- }
+
+ case ICElement.ASM_LABEL:
+ return CPluginImages.DESC_OBJS_LABEL;
+}
return null;
}

Back to the top