~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 * 
 
8
 *  Contributors:
 
9
 *     IBM Corporation - initial API and implementation
 
10
 *     QNX Software System
 
11
 *     Markus Schorn (Wind River Systems)
 
12
 *     Anton Leherbauer (Wind River Systems)
 
13
 *******************************************************************************/
 
14
package org.eclipse.cdt.internal.ui.editor;
 
15
 
 
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;
 
29
 
 
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;
 
38
 
 
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;
 
42
 
 
43
 
 
44
/**
 
45
 * Outline page for C/C++ translation units.
 
46
 */
 
47
public class CContentOutlinePage extends AbstractCModelOutlinePage {
 
48
        
 
49
        private Composite fParent;
 
50
        private StackLayout fStackLayout;
 
51
        private Composite fOutlinePage;
 
52
        private Control fStatusPage;
 
53
        private boolean fScalabilityMode;
 
54
 
 
55
        public CContentOutlinePage(CEditor editor) {
 
56
                super("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
 
57
        }
 
58
 
 
59
        /**
 
60
         * Provides access to the CEditor corresponding to this CContentOutlinePage.
 
61
         * @returns the CEditor corresponding to this CContentOutlinePage.
 
62
         */
 
63
        public CEditor getEditor() {
 
64
                return (CEditor)fEditor;
 
65
        }
 
66
 
 
67
        @Override
 
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);
 
76
                updateVisiblePage();
 
77
        }
 
78
 
 
79
        @Override
 
80
        public Control getControl() {
 
81
                return fParent;
 
82
        }
 
83
 
 
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() {
 
89
                        @Override
 
90
                        public void widgetSelected(SelectionEvent e) {
 
91
                                PreferencesUtil.createPreferenceDialogOn(link.getShell(), "org.eclipse.cdt.ui.preferences.CScalabilityPreferences", null, null).open(); //$NON-NLS-1$
 
92
                        }
 
93
                });
 
94
                return link;
 
95
        }
 
96
 
 
97
        @Override
 
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);
 
104
                } else {
 
105
                        fScalabilityMode = false;
 
106
                        super.setInput(unit);
 
107
                }
 
108
                updateVisiblePage();
 
109
        }
 
110
 
 
111
        private void updateVisiblePage() {
 
112
                if (fStackLayout == null) {
 
113
                        return;
 
114
                }
 
115
                if (fScalabilityMode) {
 
116
                        if (fStackLayout.topControl != fStatusPage) {
 
117
                                fStackLayout.topControl = fStatusPage;
 
118
                                fParent.layout();
 
119
                        }
 
120
                } else {
 
121
                        if (fStackLayout.topControl != fOutlinePage) {
 
122
                                fStackLayout.topControl = fOutlinePage;
 
123
                                fParent.layout();
 
124
                        }
 
125
                }
 
126
        }
 
127
 
 
128
        @Override
 
129
        protected ActionGroup createSearchActionGroup() {
 
130
                return new SelectionSearchGroup(this);
 
131
        }
 
132
 
 
133
        @Override
 
134
        protected ActionGroup createOpenViewActionGroup() {
 
135
                OpenViewActionGroup ovag= new OpenViewActionGroup(this, getEditor());
 
136
                ovag.setEnableIncludeBrowser(true);
 
137
                return ovag;
 
138
        }
 
139
 
 
140
        @Override
 
141
        protected ActionGroup createRefactoringActionGroup() {
 
142
                return new CRefactoringActionGroup(this);
 
143
        }
 
144
        
 
145
 
 
146
        @Override
 
147
        protected ActionGroup createSourceActionGroup() {
 
148
                return new GenerateActionGroup(this);
 
149
        }
 
150
 
 
151
        @Override
 
152
        protected ActionGroup createCustomFiltersActionGroup() {
 
153
                return new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
 
154
        }
 
155
 
 
156
        @Override
 
157
        protected ActionGroup createMemberFilterActionGroup() {
 
158
                return new MemberFilterActionGroup(getTreeViewer(), "COutlineViewer"); //$NON-NLS-1$
 
159
        }
 
160
        
 
161
        /**
 
162
         * This action toggles namespace grouping
 
163
         * 
 
164
         * @since 5.2
 
165
         */
 
166
        protected static class NamespaceGroupingAction extends Action {
 
167
 
 
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));
 
174
 
 
175
                        boolean enabled= isNamspacesGroupingEnabled();
 
176
                        setChecked(enabled);
 
177
                }
 
178
 
 
179
                /**
 
180
                 * Runs the action.
 
181
                 */
 
182
                @Override
 
183
                public void run() {
 
184
                        PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, isChecked());
 
185
                }
 
186
 
 
187
                public boolean isNamspacesGroupingEnabled () {
 
188
                        return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES);
 
189
                }
 
190
        }
 
191
        
 
192
        /**
 
193
         * This action toggles member definition grouping
 
194
         * 
 
195
         * @since 5.2
 
196
         */
 
197
        protected static class MemberGroupingAction extends Action {
 
198
 
 
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);
 
204
 
 
205
                        boolean enabled= isMemberGroupingEnabled();
 
206
                        setChecked(enabled);
 
207
                }
 
208
 
 
209
                /**
 
210
                 * Runs the action.
 
211
                 */
 
212
                @Override
 
213
                public void run() {
 
214
                        PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, isChecked());
 
215
                }
 
216
 
 
217
                public boolean isMemberGroupingEnabled () {
 
218
                        return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS);
 
219
                }
 
220
        }
 
221
        
 
222
        @Override
 
223
        protected void registerActionBars(IActionBars actionBars) {
 
224
                super.registerActionBars(actionBars);
 
225
                IMenuManager menu= actionBars.getMenuManager();
 
226
 
 
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$
 
230
 
 
231
                // add actions directly instead
 
232
                menu.add(new MemberGroupingAction(this));
 
233
                menu.add(new NamespaceGroupingAction(this));
 
234
        }
 
235
 
 
236
}