1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

2004-09-11 Alain Magloire

Allow grouping of namespace in the outliner.
	See the appereance namespace.

	* src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
	* src/org/eclipse/cdt/internal/ui/editor/CContentOutlinerProvider.java
	* src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java
	* src/org/eclipse/cdt/ui/CElementGrouping.java
	* src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java
	* src/org/eclipse/cdt/ui/NamespacesGrouping.java
	* src/org/eclipse/cdt/ui/PreferenceConstants.java
This commit is contained in:
Alain Magloire 2004-09-12 03:11:26 +00:00
parent 9a9ffd59c2
commit 40fe9c9707
9 changed files with 193 additions and 8 deletions

View file

@ -1,3 +1,16 @@
2004-09-11 Alain Magloire
Allow grouping of namespace in the outliner.
See the appereance namespace.
* src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
* src/org/eclipse/cdt/internal/ui/editor/CContentOutlinerProvider.java
* src/org/eclipse/cdt/internal/ui/preferences/AppearancePreferencePage.java
* src/org/eclipse/cdt/ui/CElementGrouping.java
* src/org/eclipse/cdt/ui/CUIPreferenceInitializer.java
* src/org/eclipse/cdt/ui/NamespacesGrouping.java
* src/org/eclipse/cdt/ui/PreferenceConstants.java
2004-09-09 David Inglis
Fix large gap between image and text in CView and ProjectView

View file

@ -6,7 +6,9 @@ package org.eclipse.cdt.internal.ui;
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
@ -20,6 +22,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IInclude;
import org.eclipse.cdt.core.model.INamespace;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ISourceRoot;
@ -28,6 +31,7 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CElementGrouping;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IncludesGrouping;
import org.eclipse.cdt.ui.NamespacesGrouping;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@ -64,6 +68,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
protected boolean fProvideMembers= false;
protected boolean fProvideWorkingCopy= false;
protected boolean fIncludesGrouping= false;
protected boolean fNamespacesGrouping= false;
public BaseCElementContentProvider() {
this(false, false);
@ -122,6 +127,22 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
fIncludesGrouping = b;
}
/**
* Can elements be group.
* @return
*/
public boolean areNamespacesGroup() {
return fNamespacesGrouping;
}
/**
* Allow Elements to be group.
* @param b
*/
public void setNamespacesGrouping(boolean b) {
fNamespacesGrouping = b;
}
/* (non-Cdoc)
* Method declared on IContentProvider.
*/
@ -324,12 +345,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
}
protected Object[] getTranslationUnitChildren(ITranslationUnit unit) throws CModelException {
Object[] children = unit.getChildren();
if (fIncludesGrouping) {
boolean hasInclude = false;
ICElement[] children = unit.getChildren();
ArrayList list = new ArrayList(children.length);
for (int i = 0; i < children.length; i++) {
if (children[i].getElementType() != ICElement.C_INCLUDE) {
if (!(children[i] instanceof IInclude)) {
list.add(children[i]);
} else {
hasInclude = true;
@ -338,9 +359,42 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
if (hasInclude) {
list.add (0, new IncludesGrouping(unit));
}
return list.toArray();
children = list.toArray();
}
return unit.getChildren();
if (fNamespacesGrouping) {
// check if there is another namespace with the same name for the same parent
List list = new ArrayList(children.length);
Map map = new HashMap();
for (int i = 0; i < children.length; ++i) {
if (children[i] instanceof INamespace) {
INamespace n1 = (INamespace)children[i];
NamespacesGrouping namespacesGrouping = (NamespacesGrouping)map.get(n1.getElementName());
if (namespacesGrouping == null) {
for (int j = i + 1; j < children.length; ++j) {
if (children[j] instanceof INamespace) {
INamespace n2 = (INamespace)children[j];
if (n1.getElementName().equals(n2.getElementName())) {
if (namespacesGrouping == null) {
namespacesGrouping = new NamespacesGrouping(unit, n1);
map.put(n1.getElementName(), namespacesGrouping);
}
namespacesGrouping.addNamespace(n2);
}
}
}
if (namespacesGrouping == null) {
list.add(n1);
} else {
list.add(namespacesGrouping);
}
}
} else {
list.add(children[i]);
}
}
children = list.toArray();
}
return children;
}
protected Object[] getCResources(ICContainer container) throws CModelException {
@ -359,7 +413,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return concatenate(children, objects);
}
private Object[] getResources(IProject project) {
protected Object[] getResources(IProject project) {
try {
return project.members();
} catch (CoreException e) {
@ -367,7 +421,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return NO_CHILDREN;
}
private Object[] getResources(IFolder folder) throws CModelException {
protected Object[] getResources(IFolder folder) throws CModelException {
ICProject cproject = CoreModel.getDefault().create(folder.getProject());
Object[] members = null;
try {

View file

@ -112,6 +112,17 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
}
}
}
} else if (prop.equals(PreferenceConstants.OUTLINE_GROUP_NAMESPACES)) {
Object newValue = event.getNewValue();
if (newValue instanceof Boolean) {
boolean value = ((Boolean)newValue).booleanValue();
if (areNamespacesGroup() != value) {
setNamespacesGrouping(value);
if (fOutliner != null) {
fOutliner.contentUpdated();
}
}
}
}
}

View file

@ -43,10 +43,12 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
private static final String SHOW_TU_CHILDREN= PreferenceConstants.PREF_SHOW_CU_CHILDREN;
private static final String OUTLINE_GROUP_INCLUDES = PreferenceConstants.OUTLINE_GROUP_INCLUDES;
private static final String OUTLINE_GROUP_NAMESPACES = PreferenceConstants.OUTLINE_GROUP_NAMESPACES;
private static final String CVIEW_GROUP_INCLUDES = PreferenceConstants.CVIEW_GROUP_INCLUDES;
private SelectionButtonDialogField fShowTUChildren;
private SelectionButtonDialogField fOutlineGroupIncludes;
private SelectionButtonDialogField fOutlineGroupNamespaces;
private SelectionButtonDialogField fCViewGroupIncludes;
public AppearancePreferencePage() {
@ -67,6 +69,10 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fOutlineGroupIncludes.setDialogFieldListener(listener);
fOutlineGroupIncludes.setLabelText(PreferencesMessages.getString("AppearancePreferencePage.outlineGroupIncludes.label")); //$NON-NLS-1$
fOutlineGroupNamespaces= new SelectionButtonDialogField(SWT.CHECK);
fOutlineGroupNamespaces.setDialogFieldListener(listener);
fOutlineGroupNamespaces.setLabelText(PreferencesMessages.getString("AppearancePreferencePage.outlineGroupNamespaces.label")); //$NON-NLS-1$
fCViewGroupIncludes= new SelectionButtonDialogField(SWT.CHECK);
fCViewGroupIncludes.setDialogFieldListener(listener);
fCViewGroupIncludes.setLabelText(PreferencesMessages.getString("AppearancePreferencePage.cviewGroupIncludes.label")); //$NON-NLS-1$
@ -78,6 +84,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fShowTUChildren.setSelection(prefs.getBoolean(SHOW_TU_CHILDREN));
fCViewGroupIncludes.setSelection(prefs.getBoolean(CVIEW_GROUP_INCLUDES));
fOutlineGroupIncludes.setSelection(prefs.getBoolean(OUTLINE_GROUP_INCLUDES));
fOutlineGroupNamespaces.setSelection(prefs.getBoolean(OUTLINE_GROUP_NAMESPACES));
}
/*
@ -105,6 +112,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fShowTUChildren.doFillIntoGrid(result, nColumns);
fCViewGroupIncludes.doFillIntoGrid(result, nColumns);
fOutlineGroupIncludes.doFillIntoGrid(result, nColumns);
fOutlineGroupNamespaces.doFillIntoGrid(result, nColumns);
new Separator().doFillIntoGrid(result, nColumns);
@ -151,6 +159,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
prefs.setValue(SHOW_TU_CHILDREN, fShowTUChildren.isSelected());
prefs.setValue(CVIEW_GROUP_INCLUDES, fCViewGroupIncludes.isSelected());
prefs.setValue(OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected());
prefs.setValue(OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected());
CUIPlugin.getDefault().savePluginPreferences();
return super.performOk();
}
@ -163,6 +172,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fShowTUChildren.setSelection(prefs.getDefaultBoolean(SHOW_TU_CHILDREN));
fCViewGroupIncludes.setSelection(prefs.getDefaultBoolean(CVIEW_GROUP_INCLUDES));
fOutlineGroupIncludes.setSelection(prefs.getDefaultBoolean(OUTLINE_GROUP_INCLUDES));
fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(OUTLINE_GROUP_NAMESPACES));
super.performDefaults();
}
}

View file

@ -187,6 +187,7 @@ AppearancePreferencePage.description= Appearance of C elements in viewers:
AppearancePreferencePage.showTUChildren.label= Show translation unit members
AppearancePreferencePage.cviewGroupIncludes.label= Group the includes in the C/C++ projects view
AppearancePreferencePage.outlineGroupIncludes.label= Group the includes in the outliner
AppearancePreferencePage.outlineGroupNamespaces.label= Group the namespaces in the outliner
AppearancePreferencePage.note=Note:
AppearancePreferencePage.preferenceOnlyEffectiveForNewPerspectives=This preference may only take effect on new perspectives

View file

@ -42,7 +42,7 @@ public abstract class CElementGrouping extends WorkbenchAdapter implements IAdap
public String getLabel(Object object) {
switch (type) {
case INCLUDES_GROUPING:
return "include directives";
return "include directives"; //$NON-NLS-1$
}
return super.getLabel(object);
}
@ -54,6 +54,8 @@ public abstract class CElementGrouping extends WorkbenchAdapter implements IAdap
switch (type) {
case INCLUDES_GROUPING:
return CPluginImages.DESC_OBJS_INCCONT;
case NAMESPACE_GROUPING:
return CPluginImages.DESC_OBJS_NAMESPACE;
}
return super.getImageDescriptor(object);
}

View file

@ -35,7 +35,6 @@ public class CUIPreferenceInitializer extends AbstractPreferenceInitializer {
PreferenceConstants.initializeDefaultValues(store);
EditorsUI.useAnnotationsPreferencePage(store);
PreferenceConstants.initializeDefaultValues(store);
EditorsUI.useAnnotationsPreferencePage(store);
AbstractDecoratedTextEditorPreferenceConstants.initializeDefaultValues(store);
CPluginPreferencePage.initDefaults(store);

View file

@ -0,0 +1,85 @@
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.INamespace;
import org.eclipse.cdt.core.model.ITranslationUnit;
/**
* NamespacesGrouping
*/
public class NamespacesGrouping extends CElementGrouping {
protected ITranslationUnit fUnit;
protected String fName;
protected INamespace[] fNamespaces;
public NamespacesGrouping(ITranslationUnit unit, INamespace namespace) {
super(CElementGrouping.NAMESPACE_GROUPING);
fUnit = unit;
fNamespaces = new INamespace[] { namespace };
fName = namespace.getElementName();
}
public String getLabel(Object object) {
return fName;
}
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
*/
public Object[] getChildren(Object object) {
ArrayList list = new ArrayList();
for (int i = 0; i < fNamespaces.length; ++i) {
INamespace nspace = fNamespaces[i];
try {
Object[] objs = nspace.getChildren();
list.addAll(Arrays.asList(objs));
} catch (CModelException e) {
//
}
}
return list.toArray();
}
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
*/
public Object getParent(Object object) {
return fUnit;
}
public void addNamespace(INamespace nspace) {
INamespace[] newNS = new INamespace[fNamespaces.length + 1];
System.arraycopy(fNamespaces, 0, newNS, 0, fNamespaces.length);
newNS[fNamespaces.length] = nspace;
fNamespaces = newNS;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof IncludesGrouping) {
return fUnit.equals(((IncludesGrouping)obj).getParent(obj)) ;
} else if (obj instanceof NamespacesGrouping) {
NamespacesGrouping other = (NamespacesGrouping)obj;
return fUnit.equals(other.getParent(obj)) && fName.equals(other.getLabel(obj));
}
return super.equals(obj);
}
}

View file

@ -278,6 +278,16 @@ public class PreferenceConstants {
*/
public static final String OUTLINE_GROUP_INCLUDES= "org.eclipse.cdt.ui.outline.groupincludes"; //$NON-NLS-1$
/**
* A named preference that controls if the Outline view.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @see #LINK_PACKAGES_TO_EDITOR
*/
public static final String OUTLINE_GROUP_NAMESPACES= "org.eclipse.cdt.ui.outline.groupnamespaces"; //$NON-NLS-1$
/**
* A named preference that controls if the CView.
* <p>