1 /*******************************************************************************
2 * Copyright (c) 2005, 2010 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
11 * Markus Schorn (Wind River Systems)
12 * Anton Leherbauer (Wind River Systems)
13 *******************************************************************************/
14 package org.eclipse.cdt.internal.ui.editor;
16 import org.eclipse.jface.action.Action;
17 import org.eclipse.jface.action.IMenuManager;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.custom.StackLayout;
20 import org.eclipse.swt.events.SelectionAdapter;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.layout.FillLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Link;
26 import org.eclipse.ui.IActionBars;
27 import org.eclipse.ui.actions.ActionGroup;
28 import org.eclipse.ui.dialogs.PreferencesUtil;
30 import org.eclipse.cdt.core.model.ITranslationUnit;
31 import org.eclipse.cdt.ui.CDTSharedImages;
32 import org.eclipse.cdt.ui.PreferenceConstants;
33 import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
34 import org.eclipse.cdt.ui.actions.GenerateActionGroup;
35 import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
36 import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
37 import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
39 import org.eclipse.cdt.internal.ui.CPluginImages;
40 import org.eclipse.cdt.internal.ui.actions.ActionMessages;
41 import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
45 * Outline page for C/C++ translation units.
47 public class CContentOutlinePage extends AbstractCModelOutlinePage {
49 private Composite fParent;
50 private StackLayout fStackLayout;
51 private Composite fOutlinePage;
52 private Control fStatusPage;
53 private boolean fScalabilityMode;
55 public CContentOutlinePage(CEditor editor) {
56 super("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
60 * Provides access to the CEditor corresponding to this CContentOutlinePage.
61 * @returns the CEditor corresponding to this CContentOutlinePage.
63 public CEditor getEditor() {
64 return (CEditor)fEditor;
68 public void createControl(Composite parent) {
69 fParent = new Composite(parent, SWT.NONE);
70 fStackLayout = new StackLayout();
71 fParent.setLayout(fStackLayout);
72 fOutlinePage = new Composite(fParent, SWT.NONE);
73 fOutlinePage.setLayout(new FillLayout());
74 super.createControl(fOutlinePage);
75 fStatusPage = createStatusPage(fParent);
80 public Control getControl() {
84 private Control createStatusPage(Composite parent) {
85 final Link link= new Link(parent, SWT.NONE);
86 link.setText(CEditorMessages.Scalability_outlineDisabled);
87 link.setToolTipText(CEditorMessages.Scalability_linkToolTip);
88 link.addSelectionListener(new SelectionAdapter() {
90 public void widgetSelected(SelectionEvent e) {
91 PreferencesUtil.createPreferenceDialogOn(link.getShell(), "org.eclipse.cdt.ui.preferences.CScalabilityPreferences", null, null).open(); //$NON-NLS-1$
98 public void setInput(ITranslationUnit unit) {
99 final CEditor editor= getEditor();
100 if (editor.isEnableScalablilityMode()
101 && PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_RECONCILER)) {
102 fScalabilityMode = true;
103 super.setInput(null);
105 fScalabilityMode = false;
106 super.setInput(unit);
111 private void updateVisiblePage() {
112 if (fStackLayout == null) {
115 if (fScalabilityMode) {
116 if (fStackLayout.topControl != fStatusPage) {
117 fStackLayout.topControl = fStatusPage;
121 if (fStackLayout.topControl != fOutlinePage) {
122 fStackLayout.topControl = fOutlinePage;
129 protected ActionGroup createSearchActionGroup() {
130 return new SelectionSearchGroup(this);
134 protected ActionGroup createOpenViewActionGroup() {
135 OpenViewActionGroup ovag= new OpenViewActionGroup(this, getEditor());
136 ovag.setEnableIncludeBrowser(true);
141 protected ActionGroup createRefactoringActionGroup() {
142 return new CRefactoringActionGroup(this);
147 protected ActionGroup createSourceActionGroup() {
148 return new GenerateActionGroup(this);
152 protected ActionGroup createCustomFiltersActionGroup() {
153 return new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
157 protected ActionGroup createMemberFilterActionGroup() {
158 return new MemberFilterActionGroup(getTreeViewer(), "COutlineViewer"); //$NON-NLS-1$
162 * This action toggles namespace grouping
166 protected static class NamespaceGroupingAction extends Action {
168 public NamespaceGroupingAction(AbstractCModelOutlinePage outlinePage) {
169 super(ActionMessages.NamespacesGroupingAction_label);
170 setDescription(ActionMessages.NamespacesGroupingAction_description);
171 setToolTipText(ActionMessages.NamespacesGroupingAction_tooltip);
172 this.setImageDescriptor(CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_NAMESPACE));
173 this.setDisabledImageDescriptor(CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_NAMESPACE));
175 boolean enabled= isNamspacesGroupingEnabled();
184 PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, isChecked());
187 public boolean isNamspacesGroupingEnabled () {
188 return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES);
193 * This action toggles member definition grouping
197 protected static class MemberGroupingAction extends Action {
199 public MemberGroupingAction(AbstractCModelOutlinePage outlinePage) {
200 super(ActionMessages.MemberGroupingAction_label);
201 setDescription(ActionMessages.MemberGroupingAction_description);
202 setToolTipText(ActionMessages.MemberGroupingAction_tooltip);
203 CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_PUBLIC);
205 boolean enabled= isMemberGroupingEnabled();
214 PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, isChecked());
217 public boolean isMemberGroupingEnabled () {
218 return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS);
223 protected void registerActionBars(IActionBars actionBars) {
224 super.registerActionBars(actionBars);
225 IMenuManager menu= actionBars.getMenuManager();
227 // appendToGroup does not work reliably (bug 326748)
228 // menu.appendToGroup("group.layout", new MemberGroupingAction(this)); //$NON-NLS-1$
229 // menu.appendToGroup("group.layout", new NamespaceGroupingAction(this)); //$NON-NLS-1$
231 // add actions directly instead
232 menu.add(new MemberGroupingAction(this));
233 menu.add(new NamespaceGroupingAction(this));