mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 225944 - Organize items by namespace in Outline, fixes also bug 262785
This commit is contained in:
parent
6e17efadde
commit
003975782e
23 changed files with 871 additions and 145 deletions
|
@ -69,4 +69,9 @@ public class CModelBuilderBugsTest extends BaseTestCase {
|
|||
assertEquals("decl", functions[1].getElementName());
|
||||
}
|
||||
|
||||
public void testModelBuilderBug262785() throws Exception {
|
||||
assertNotNull(fTU.getElement("Unknown1::method"));
|
||||
assertNotNull(fTU.getElement("Unknown2::method"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,3 +10,6 @@ namespace nsTest {
|
|||
void nsTest::inlined2() {}; // wrong label in outline: nsTest::inlined(): void
|
||||
void nsTest::decl2(); // label in outline (ok): decl(): void
|
||||
}
|
||||
//http://bugs.eclipse.org/262785
|
||||
void Unknown1::method() {} // no qualifier in outline
|
||||
void Unknown2::method() {} // no qualifier in outline
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2003, 2009 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
|
||||
|
@ -46,6 +46,13 @@ public class CElementBaseLabels {
|
|||
*/
|
||||
public final static int M_PARAMETER_TYPES= 1 << 0;
|
||||
|
||||
/**
|
||||
* Method definition names without qualifier.
|
||||
* e.g. <code>foo(int)</code>
|
||||
* @since 5.1
|
||||
*/
|
||||
public final static int M_SIMPLE_NAME= 1 << 1;
|
||||
|
||||
/**
|
||||
* Method names contain thrown exceptions.
|
||||
* e.g. <code>foo throw( IOException )</code>
|
||||
|
@ -82,6 +89,13 @@ public class CElementBaseLabels {
|
|||
*/
|
||||
public final static int TEMPLATE_PARAMETERS= 1 << 7;
|
||||
|
||||
/**
|
||||
* Static field names without qualifier.
|
||||
* e.g. <code>fHello</code>
|
||||
* @since 5.1
|
||||
*/
|
||||
public final static int F_SIMPLE_NAME= 1 << 8;
|
||||
|
||||
/**
|
||||
* Field names contain the declared type (appended)
|
||||
* e.g. <code>fHello: int</code>
|
||||
|
@ -349,7 +363,11 @@ public class CElementBaseLabels {
|
|||
}
|
||||
}
|
||||
|
||||
buf.append( method.getElementName() );
|
||||
if (getFlag(flags, M_SIMPLE_NAME)) {
|
||||
buf.append(getSimpleName(method.getElementName()));
|
||||
} else {
|
||||
buf.append(method.getElementName());
|
||||
}
|
||||
|
||||
//template parameters
|
||||
if (method instanceof ITemplate) {
|
||||
|
@ -413,6 +431,20 @@ public class CElementBaseLabels {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip any qualifier from the given name.
|
||||
*
|
||||
* @param elementName
|
||||
* @return a "simple" name
|
||||
*/
|
||||
private static String getSimpleName(String elementName) {
|
||||
int idx = elementName.indexOf("::"); //$NON-NLS-1$
|
||||
if (idx >= 0) {
|
||||
return elementName.substring(idx+2);
|
||||
}
|
||||
return elementName;
|
||||
}
|
||||
|
||||
private static void getTemplateParameters(ITemplate template, int flags, StringBuffer buf) {
|
||||
if (getFlag(flags, TEMPLATE_PARAMETERS)) {
|
||||
String[] types = template.getTemplateParameterTypes();
|
||||
|
@ -452,7 +484,11 @@ public class CElementBaseLabels {
|
|||
}
|
||||
}
|
||||
|
||||
buf.append( field.getElementName() );
|
||||
if (getFlag(flags, F_SIMPLE_NAME)) {
|
||||
buf.append(getSimpleName(field.getElementName()));
|
||||
} else {
|
||||
buf.append(field.getElementName());
|
||||
}
|
||||
|
||||
if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && field.exists()) {
|
||||
buf.append( DECL_STRING );
|
||||
|
|
|
@ -72,6 +72,7 @@ import org.eclipse.cdt.core.index.IIndexManager;
|
|||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
import org.eclipse.cdt.core.model.IProblemRequestor;
|
||||
import org.eclipse.cdt.core.model.IStructure;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
@ -812,7 +813,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
|
||||
final IASTDeclSpecifier declSpecifier= functionDeclaration.getDeclSpecifier();
|
||||
|
||||
final String functionName= ASTStringUtil.getSimpleName(name);
|
||||
final String simpleName= ASTStringUtil.getSimpleName(name);
|
||||
final String[] parameterTypes= ASTStringUtil.getParameterSignatureArray(declarator);
|
||||
final String returnType= ASTStringUtil.getReturnTypeString(declSpecifier, declarator);
|
||||
|
||||
|
@ -822,12 +823,12 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||
|
||||
final ICPPASTFunctionDeclarator cppFunctionDeclarator= (ICPPASTFunctionDeclarator)declarator;
|
||||
final IASTName simpleName;
|
||||
final IASTName simpleAstName;
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
final ICPPASTQualifiedName quName= (ICPPASTQualifiedName)name;
|
||||
simpleName= quName.getLastName();
|
||||
simpleAstName= quName.getLastName();
|
||||
} else {
|
||||
simpleName= name;
|
||||
simpleAstName= name;
|
||||
}
|
||||
IScope scope= null;
|
||||
// try to avoid expensive resolution of scope and binding
|
||||
|
@ -843,8 +844,8 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
}
|
||||
}
|
||||
if (!isMethod) {
|
||||
scope= CPPVisitor.getContainingScope(simpleName);
|
||||
isMethod= scope instanceof ICPPClassScope || simpleName.resolveBinding() instanceof ICPPMethod;
|
||||
scope= CPPVisitor.getContainingScope(simpleAstName);
|
||||
isMethod= scope instanceof ICPPClassScope || simpleAstName.resolveBinding() instanceof ICPPMethod;
|
||||
}
|
||||
}
|
||||
if (isMethod) {
|
||||
|
@ -870,7 +871,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
info= methodInfo;
|
||||
ICPPMethod methodBinding= null;
|
||||
if (scope != null) {
|
||||
final IBinding binding= simpleName.resolveBinding();
|
||||
final IBinding binding= simpleAstName.resolveBinding();
|
||||
if (binding instanceof ICPPMethod) {
|
||||
methodBinding= (ICPPMethod)binding;
|
||||
}
|
||||
|
@ -897,19 +898,34 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
final boolean isConstructor;
|
||||
if (scope != null) {
|
||||
isConstructor= CPPVisitor.isConstructor(scope, declarator);
|
||||
} else if (parent instanceof IStructure) {
|
||||
isConstructor= parent.getElementName().equals(simpleName);
|
||||
} else if (name instanceof ICPPASTQualifiedName) {
|
||||
final ICPPASTQualifiedName quName= (ICPPASTQualifiedName)name;
|
||||
final IASTName[] names= quName.getNames();
|
||||
isConstructor= names.length >= 2 && simpleName.equals(ASTStringUtil.getSimpleName(names[names.length-2]));
|
||||
} else {
|
||||
isConstructor= parent.getElementName().equals(functionName);
|
||||
isConstructor= false;
|
||||
}
|
||||
methodElement.setConstructor(isConstructor);
|
||||
methodElement.setDestructor(functionName.charAt(0) == '~');
|
||||
methodElement.setDestructor(simpleName.charAt(0) == '~');
|
||||
}
|
||||
} else {
|
||||
String functionName= ASTStringUtil.getQualifiedName(name);
|
||||
// strip namespace qualifier if parent is same namespace
|
||||
if (name instanceof ICPPASTQualifiedName && parent instanceof INamespace) {
|
||||
final ICPPASTQualifiedName quName= (ICPPASTQualifiedName)name;
|
||||
final IASTName[] names= quName.getNames();
|
||||
if (names.length >= 2 && parent.getElementName().equals(ASTStringUtil.getSimpleName(names[names.length-2]))) {
|
||||
functionName= simpleName;
|
||||
}
|
||||
}
|
||||
if (isTemplate) {
|
||||
// template function
|
||||
element= new FunctionTemplate(parent, ASTStringUtil.getSimpleName(name));
|
||||
element= new FunctionTemplate(parent, functionName);
|
||||
} else {
|
||||
// function
|
||||
element= new Function(parent, ASTStringUtil.getSimpleName(name));
|
||||
element= new Function(parent, functionName);
|
||||
}
|
||||
element.setParameterTypes(parameterTypes);
|
||||
element.setReturnType(returnType);
|
||||
|
@ -918,6 +934,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
}
|
||||
|
||||
} else {
|
||||
final String functionName= ASTStringUtil.getQualifiedName(name);
|
||||
element= new Function(parent, functionName);
|
||||
element.setParameterTypes(parameterTypes);
|
||||
element.setReturnType(returnType);
|
||||
|
@ -1205,7 +1222,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
* @return the scope or <code>null</code>
|
||||
*/
|
||||
private static IScope getScope(IASTName astName) {
|
||||
IBinding binding= astName.getBinding();
|
||||
IBinding binding= astName.resolveBinding();
|
||||
if (binding != null) {
|
||||
try {
|
||||
return binding.getScope();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2009 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
|
||||
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.ui.tests.buildconsole.BuildConsoleTests;
|
|||
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.chelp.CHelpTest;
|
||||
import org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.outline.OutlineTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.quickfix.AssistQuickFixTest;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.search.SearchTestSuite;
|
||||
|
@ -51,6 +52,9 @@ public class AutomatedSuite extends TestSuite {
|
|||
// tests from package org.eclipse.cdt.ui.tests.text
|
||||
addTest(TextTestSuite.suite());
|
||||
|
||||
// tests from package org.eclipse.cdt.ui.tests.outline
|
||||
addTest(OutlineTestSuite.suite());
|
||||
|
||||
// tests for package org.eclipse.cdt.ui.tests.viewsupport
|
||||
addTest(ViewSupportTestSuite.suite());
|
||||
|
||||
|
|
|
@ -0,0 +1,280 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 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:
|
||||
* Wind River Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.outline;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
|
||||
/**
|
||||
* Basic outline view tests.
|
||||
*/
|
||||
public class BasicOutlineTest extends BaseUITestCase {
|
||||
|
||||
private static final int INDEXER_WAIT_TIME = 10000;
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(BasicOutlineTest.class);
|
||||
}
|
||||
|
||||
private ICProject fCProject;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
restoreAllParts();
|
||||
fCProject = CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
closeAllEditors();
|
||||
PreferenceConstants.getPreferenceStore().setToDefault(PreferenceConstants.OUTLINE_GROUP_MEMBERS);
|
||||
PreferenceConstants.getPreferenceStore().setToDefault(PreferenceConstants.OUTLINE_GROUP_NAMESPACES);
|
||||
if(fCProject != null) {
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected CEditor openEditor(IFile file) throws PartInitException {
|
||||
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
CEditor editor= (CEditor) IDE.openEditor(page, file);
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 1000, 10);
|
||||
runEventQueue(500);
|
||||
return editor;
|
||||
}
|
||||
|
||||
protected ICProject getProject() {
|
||||
return fCProject;
|
||||
}
|
||||
|
||||
private void waitForIndexer(IProject project, IFile source) throws Exception, CoreException {
|
||||
waitForIndexer(CCorePlugin.getIndexManager().getIndex(fCProject), source, INDEXER_WAIT_TIME);
|
||||
}
|
||||
|
||||
private void checkTreeItems(TreeItem[] items, String... labels) {
|
||||
assertEquals(items.length, labels.length);
|
||||
int i=0;
|
||||
for (TreeItem treeItem : items) {
|
||||
assertEquals(labels[i++], treeItem.getText());
|
||||
}
|
||||
}
|
||||
|
||||
//#include "user.h"
|
||||
//#include <system.h>
|
||||
//#define MACRO
|
||||
//int main(int argc, char** argv) {}
|
||||
public void testSimpleOutlineContent() throws Exception {
|
||||
StringBuffer[] contents= getContentsForTest(1);
|
||||
IProject project= getProject().getProject();
|
||||
IFile source= createFile(project, "source.cpp", contents[0].toString());
|
||||
waitForIndexer(project, source);
|
||||
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
openEditor(source);
|
||||
|
||||
Tree tree= checkTreeNode(outline, 0, "user.h").getParent();
|
||||
checkTreeNode(tree, 1, "system.h");
|
||||
checkTreeNode(tree, 2, "MACRO");
|
||||
checkTreeNode(tree, 3, "main(int, char**) : int");
|
||||
}
|
||||
|
||||
//class Foo {
|
||||
// static int field;
|
||||
// void bar();
|
||||
// void foo();
|
||||
//};
|
||||
|
||||
//#include "header.h"
|
||||
//void Foo::bar() {}
|
||||
//int Foo::field = 5;
|
||||
//void Foo::foo() {}
|
||||
public void testGroupedMembers() throws Exception {
|
||||
StringBuffer[] contents= getContentsForTest(2);
|
||||
IProject project= getProject().getProject();
|
||||
IFile header= createFile(project, "header.h", contents[0].toString());
|
||||
IFile source= createFile(project, "source.cpp", contents[1].toString());
|
||||
waitForIndexer(project, source);
|
||||
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
openEditor(source);
|
||||
|
||||
Tree tree= checkTreeNode(outline, 0, "header.h").getParent();
|
||||
checkTreeNode(tree, 1, "Foo::bar() : void");
|
||||
checkTreeNode(tree, 2, "Foo::field : int");
|
||||
checkTreeNode(tree, 3, "Foo::foo() : void");
|
||||
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, true);
|
||||
runEventQueue(500);
|
||||
|
||||
tree= checkTreeNode(outline, 0, "header.h").getParent();
|
||||
expandTreeItem(checkTreeNode(outline, 1, "Foo"));
|
||||
checkTreeNode(tree, 1, 0, "bar() : void");
|
||||
checkTreeNode(tree, 1, 1, "field : int");
|
||||
checkTreeNode(tree, 1, 2, "foo() : void");
|
||||
}
|
||||
|
||||
//namespace ns {
|
||||
//class Foo {
|
||||
// static int field;
|
||||
// void bar();
|
||||
// void foo();
|
||||
//};
|
||||
//};
|
||||
|
||||
//#include "header.h"
|
||||
//namespace ns {
|
||||
//void Foo::bar() {}
|
||||
//}
|
||||
//namespace ns {
|
||||
//int Foo::field = 5;
|
||||
//void Foo::foo() {}
|
||||
//}
|
||||
public void testGroupedMembersInNamespace() throws Exception {
|
||||
StringBuffer[] contents= getContentsForTest(2);
|
||||
IProject project= getProject().getProject();
|
||||
IFile header= createFile(project, "header.h", contents[0].toString());
|
||||
IFile source= createFile(project, "source.cpp", contents[1].toString());
|
||||
waitForIndexer(project, source);
|
||||
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
openEditor(source);
|
||||
|
||||
TreeItem item= checkTreeNode(outline, 0, "header.h");
|
||||
Tree tree= item.getParent();
|
||||
expandTreeItem(checkTreeNode(tree, 1, "ns"));
|
||||
checkTreeNode(tree, 1, 0, "Foo::bar() : void");
|
||||
expandTreeItem(checkTreeNode(tree, 2, "ns"));
|
||||
checkTreeNode(tree, 2, 0, "Foo::field : int");
|
||||
checkTreeNode(tree, 2, 1, "Foo::foo() : void");
|
||||
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, true);
|
||||
runEventQueue(500);
|
||||
|
||||
checkTreeNode(outline, 0, "header.h");
|
||||
expandTreeItem(checkTreeNode(tree, 1, "ns"));
|
||||
expandTreeItem(item= checkTreeNode(tree, 1, 0, "Foo"));
|
||||
checkTreeItems(item.getItems(), "bar() : void");
|
||||
expandTreeItem(checkTreeNode(tree, 2, "ns"));
|
||||
expandTreeItem(item= checkTreeNode(tree, 2, 0, "Foo"));
|
||||
checkTreeItems(item.getItems(), "field : int", "foo() : void");
|
||||
}
|
||||
|
||||
//namespace ns {
|
||||
//class Foo {
|
||||
// static int field;
|
||||
// void bar();
|
||||
// void foo();
|
||||
//};
|
||||
//};
|
||||
|
||||
//#include "header.h"
|
||||
//namespace ns {
|
||||
//void Foo::bar() {}
|
||||
//}
|
||||
//namespace ns {
|
||||
//int Foo::field = 5;
|
||||
//void Foo::foo() {}
|
||||
//}
|
||||
public void testGroupedNamespaces() throws Exception {
|
||||
StringBuffer[] contents= getContentsForTest(2);
|
||||
IProject project= getProject().getProject();
|
||||
IFile header= createFile(project, "header.h", contents[0].toString());
|
||||
IFile source= createFile(project, "source.cpp", contents[1].toString());
|
||||
waitForIndexer(project, source);
|
||||
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
openEditor(source);
|
||||
|
||||
TreeItem item= checkTreeNode(outline, 0, "header.h");
|
||||
Tree tree= item.getParent();
|
||||
expandTreeItem(checkTreeNode(tree, 1, "ns"));
|
||||
checkTreeNode(tree, 1, 0, "Foo::bar() : void");
|
||||
expandTreeItem(checkTreeNode(tree, 2, "ns"));
|
||||
checkTreeNode(tree, 2, 0, "Foo::field : int");
|
||||
checkTreeNode(tree, 2, 1, "Foo::foo() : void");
|
||||
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, true);
|
||||
runEventQueue(500);
|
||||
|
||||
checkTreeNode(outline, 0, "header.h");
|
||||
expandTreeItem(checkTreeNode(tree, 1, "ns"));
|
||||
checkTreeNode(tree, 1, 0, "Foo::bar() : void");
|
||||
checkTreeNode(tree, 1, 1, "Foo::field : int");
|
||||
checkTreeNode(tree, 1, 2, "Foo::foo() : void");
|
||||
}
|
||||
|
||||
//namespace ns {
|
||||
//class Foo {
|
||||
// static int field;
|
||||
// void bar();
|
||||
// void foo();
|
||||
//};
|
||||
//};
|
||||
|
||||
//#include "header.h"
|
||||
//namespace ns {
|
||||
//void Foo::bar() {}
|
||||
//}
|
||||
//namespace ns {
|
||||
//int Foo::field = 5;
|
||||
//void Foo::foo() {}
|
||||
//}
|
||||
public void testGroupedMembersInGroupedNamespaces() throws Exception {
|
||||
StringBuffer[] contents= getContentsForTest(2);
|
||||
IProject project= getProject().getProject();
|
||||
IFile header= createFile(project, "header.h", contents[0].toString());
|
||||
IFile source= createFile(project, "source.cpp", contents[1].toString());
|
||||
waitForIndexer(project, source);
|
||||
|
||||
final IViewPart outline= activateView(IPageLayout.ID_OUTLINE);
|
||||
openEditor(source);
|
||||
|
||||
TreeItem item= checkTreeNode(outline, 0, "header.h");
|
||||
Tree tree= item.getParent();
|
||||
expandTreeItem(checkTreeNode(tree, 1, "ns"));
|
||||
checkTreeNode(tree, 1, 0, "Foo::bar() : void");
|
||||
expandTreeItem(checkTreeNode(tree, 2, "ns"));
|
||||
checkTreeNode(tree, 2, 0, "Foo::field : int");
|
||||
checkTreeNode(tree, 2, 1, "Foo::foo() : void");
|
||||
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, true);
|
||||
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, true);
|
||||
runEventQueue(500);
|
||||
|
||||
checkTreeNode(outline, 0, "header.h");
|
||||
expandTreeItem(checkTreeNode(tree, 1, "ns"));
|
||||
expandTreeItem(item= checkTreeNode(tree, 1, 0, "Foo"));
|
||||
checkTreeItems(item.getItems(), "bar() : void", "field : int", "foo() : void");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 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 implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.outline;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class OutlineTestSuite extends TestSuite {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new OutlineTestSuite();
|
||||
}
|
||||
|
||||
public OutlineTestSuite() {
|
||||
super(OutlineTestSuite.class.getName());
|
||||
addTest(BasicOutlineTest.suite());
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 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
|
||||
|
@ -38,6 +38,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.IMember;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
|
@ -77,6 +78,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
protected boolean fProvideWorkingCopy= false;
|
||||
protected boolean fIncludesGrouping= false;
|
||||
protected boolean fNamespacesGrouping= false;
|
||||
protected boolean fMemberGrouping= false;
|
||||
|
||||
public BaseCElementContentProvider() {
|
||||
this(false, false);
|
||||
|
@ -89,7 +91,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
|
||||
/**
|
||||
* Returns whether the members are provided when asking
|
||||
* for a TU's or ClassFile's children.
|
||||
* for a TU's children.
|
||||
*/
|
||||
public boolean getProvideMembers() {
|
||||
return fProvideMembers;
|
||||
|
@ -97,7 +99,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
|
||||
/**
|
||||
* Returns whether the members are provided when asking
|
||||
* for a TU's or ClassFile's children.
|
||||
* for a TU's children.
|
||||
*/
|
||||
public void setProvideMembers(boolean b) {
|
||||
fProvideMembers= b;
|
||||
|
@ -149,6 +151,21 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
fNamespacesGrouping = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether grouping of members is enabled
|
||||
*/
|
||||
public boolean isMemberGroupingEnabled() {
|
||||
return fMemberGrouping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable member grouping by common namespace.
|
||||
* @param enable
|
||||
*/
|
||||
public void setMemberGrouping(boolean enable) {
|
||||
fMemberGrouping = enable;
|
||||
}
|
||||
|
||||
/* (non-Cdoc)
|
||||
* Method declared on IContentProvider.
|
||||
*/
|
||||
|
@ -205,6 +222,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
return ((IArchive)element).getChildren();
|
||||
} else if (element instanceof IBinaryModule) {
|
||||
return ((IBinaryModule)element).getChildren();
|
||||
} else if (element instanceof INamespace) {
|
||||
return getNamespaceChildren((INamespace) element);
|
||||
} else if (element instanceof ISourceReference && element instanceof IParent) {
|
||||
return ((IParent)element).getChildren();
|
||||
} else if (element instanceof IProject) {
|
||||
|
@ -265,6 +284,11 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (element instanceof CElementGrouping) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Object[] children= getChildren(element);
|
||||
return (children != null) && children.length > 0;
|
||||
}
|
||||
|
@ -317,7 +341,28 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof INamespace && fNamespacesGrouping) {
|
||||
final INamespace namespace = (INamespace)parent;
|
||||
final NamespacesGrouping grouping = new NamespacesGrouping(namespace.getTranslationUnit(), namespace, fMemberGrouping);
|
||||
if (grouping.getNamespaces().length > 2) {
|
||||
parent = grouping;
|
||||
}
|
||||
}
|
||||
if (parent instanceof IMember && fMemberGrouping) {
|
||||
final IMember member = (IMember)parent;
|
||||
final String ns = getElementNamespace(member);
|
||||
if (ns != null) {
|
||||
Object parentParent = member.getParent();
|
||||
if (parentParent instanceof INamespace && fNamespacesGrouping) {
|
||||
final INamespace namespace = (INamespace)parent;
|
||||
final NamespacesGrouping grouping = new NamespacesGrouping(namespace.getTranslationUnit(), namespace);
|
||||
if (grouping.getNamespaces().length > 2) {
|
||||
parentParent = grouping;
|
||||
}
|
||||
}
|
||||
return new MembersGrouping(parentParent, ns);
|
||||
}
|
||||
}
|
||||
// if we are doing grouping for the includes return the grouping container.
|
||||
if (element instanceof IInclude && fIncludesGrouping) {
|
||||
parent = new IncludesGrouping(((IInclude)element).getTranslationUnit());
|
||||
|
@ -382,31 +427,21 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
}
|
||||
children = list.toArray();
|
||||
}
|
||||
Map<String, NamespacesGrouping> nsmap = new HashMap<String, NamespacesGrouping>();
|
||||
if (fNamespacesGrouping) {
|
||||
// check if there is another namespace with the same name for the same parent
|
||||
List<Object> list = new ArrayList<Object>(children.length);
|
||||
Map<String, NamespacesGrouping> map = new HashMap<String, NamespacesGrouping>();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
if (children[i] instanceof INamespace) {
|
||||
INamespace n1 = (INamespace)children[i];
|
||||
NamespacesGrouping namespacesGrouping = map.get(n1.getElementName());
|
||||
NamespacesGrouping namespacesGrouping = nsmap.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 {
|
||||
namespacesGrouping = new NamespacesGrouping(unit, n1, fMemberGrouping);
|
||||
if (namespacesGrouping.getNamespaces().length > 1) {
|
||||
nsmap.put(n1.getElementName(), namespacesGrouping);
|
||||
list.add(namespacesGrouping);
|
||||
} else {
|
||||
list.add(children[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -415,9 +450,67 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
}
|
||||
children = list.toArray();
|
||||
}
|
||||
if (fMemberGrouping) {
|
||||
// check if there is another member with the same namespace for the same parent
|
||||
List<Object> list = new ArrayList<Object>(children.length);
|
||||
Map<String, MembersGrouping> map = new HashMap<String, MembersGrouping>();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
if (children[i] instanceof IMember) {
|
||||
final ICElement member = (ICElement)children[i];
|
||||
String namespace = getElementNamespace(member);
|
||||
MembersGrouping memberGrouping = map.get(namespace);
|
||||
if (memberGrouping == null) {
|
||||
memberGrouping = new MembersGrouping(unit, namespace);
|
||||
map.put(namespace, memberGrouping);
|
||||
list.add(memberGrouping);
|
||||
}
|
||||
} else if (fNamespacesGrouping && children[i] instanceof INamespace) {
|
||||
if (!nsmap.containsKey(((INamespace) children[i]).getElementName())) {
|
||||
list.add(children[i]);
|
||||
}
|
||||
} else {
|
||||
list.add(children[i]);
|
||||
}
|
||||
}
|
||||
children = list.toArray();
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
protected Object[] getNamespaceChildren(IParent element) throws CModelException {
|
||||
Object[] children = element.getChildren();
|
||||
if (fMemberGrouping) {
|
||||
// check if there is another member with the same namespace for the same parent
|
||||
List<Object> list = new ArrayList<Object>(children.length);
|
||||
Map<String, MembersGrouping> map = new HashMap<String, MembersGrouping>();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
if (children[i] instanceof IMember) {
|
||||
final ICElement member = (ICElement)children[i];
|
||||
String namespace = getElementNamespace(member);
|
||||
MembersGrouping memberGrouping = map.get(namespace);
|
||||
if (memberGrouping == null) {
|
||||
memberGrouping = new MembersGrouping(element, namespace);
|
||||
map.put(namespace, memberGrouping);
|
||||
list.add(memberGrouping);
|
||||
}
|
||||
} else {
|
||||
list.add(children[i]);
|
||||
}
|
||||
}
|
||||
children = list.toArray();
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
private static String getElementNamespace(ICElement member) {
|
||||
String name = member.getElementName();
|
||||
int idx = name.lastIndexOf("::"); //$NON-NLS-1$
|
||||
if (idx < 0) {
|
||||
return null;
|
||||
}
|
||||
return name.substring(0, idx);
|
||||
}
|
||||
|
||||
protected Object[] getCResources(ICContainer container) throws CModelException {
|
||||
Object[] objects = null;
|
||||
Object[] children = container.getChildren();
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 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:
|
||||
* Wind River Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IMember;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.ui.CElementGrouping;
|
||||
import org.eclipse.cdt.ui.NamespacesGrouping;
|
||||
|
||||
/**
|
||||
* Grouping for members in the same namespace.
|
||||
*/
|
||||
public class MembersGrouping extends CElementGrouping {
|
||||
|
||||
private final Object fParent;
|
||||
private final String fNamespace;
|
||||
|
||||
public MembersGrouping(Object parent, String namespace) {
|
||||
super(CElementGrouping.CLASS_GROUPING);
|
||||
assert parent instanceof ICElement || parent instanceof NamespacesGrouping;
|
||||
fParent= parent;
|
||||
fNamespace= namespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(Object object) {
|
||||
return fNamespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object object) {
|
||||
List<ICElement> nsMembers = new ArrayList<ICElement>();
|
||||
if (fParent instanceof IParent) {
|
||||
try {
|
||||
nsMembers.addAll(getNamespaceChildren(((IParent)fParent).getChildren()));
|
||||
} catch (CModelException exc) {
|
||||
}
|
||||
} else if (fParent instanceof NamespacesGrouping) {
|
||||
NamespacesGrouping nsGrouping = (NamespacesGrouping) fParent;
|
||||
INamespace[] namespaces = nsGrouping.getNamespaces();
|
||||
for (INamespace iNamespace : namespaces) {
|
||||
try {
|
||||
nsMembers.addAll(getNamespaceChildren(iNamespace.getChildren()));
|
||||
} catch (CModelException exc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return nsMembers.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param iNamespace
|
||||
* @return
|
||||
*/
|
||||
private Collection<? extends ICElement> getNamespaceChildren(ICElement[] icElements) {
|
||||
List<ICElement> members = new ArrayList<ICElement>(icElements.length);
|
||||
for (ICElement icElement : icElements) {
|
||||
if (icElement instanceof IMember) {
|
||||
String name = icElement.getElementName();
|
||||
int idx = name.lastIndexOf("::"); //$NON-NLS-1$
|
||||
if (idx < 0) {
|
||||
continue;
|
||||
}
|
||||
String namespace = name.substring(0, idx);
|
||||
if (fNamespace.equals(namespace)) {
|
||||
members.add(icElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object object) {
|
||||
return fParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof MembersGrouping) {
|
||||
final MembersGrouping other= (MembersGrouping)obj;
|
||||
return fParent.equals(other.fParent) && fNamespace.equals(other.fNamespace);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return fParent.hashCode() * 17 + fNamespace.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fNamespace;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 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
|
||||
|
@ -22,6 +22,7 @@ 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.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
|
@ -60,8 +61,8 @@ 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.CElementGrouping;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IncludesGrouping;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
|
||||
|
@ -79,6 +80,7 @@ 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.CUILabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
|
||||
|
||||
/**
|
||||
|
@ -88,6 +90,49 @@ import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
|
|||
*/
|
||||
public abstract class AbstractCModelOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener, IAdaptable {
|
||||
|
||||
/**
|
||||
* The default label provider for the outline.
|
||||
*/
|
||||
protected static class COutlineLabelProvider extends AppearanceAwareLabelProvider {
|
||||
|
||||
/**
|
||||
* Flag whether to show member definitions with qualified or simple names.
|
||||
*/
|
||||
private boolean fSimpleName;
|
||||
|
||||
public COutlineLabelProvider(int textFlags, int imageFlags) {
|
||||
super(textFlags, imageFlags);
|
||||
PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this);
|
||||
fSimpleName= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int evaluateTextFlags(Object element) {
|
||||
if (fSimpleName) {
|
||||
return super.evaluateTextFlags(element) | CElementBaseLabels.M_SIMPLE_NAME | CElementBaseLabels.F_SIMPLE_NAME;
|
||||
}
|
||||
return super.evaluateTextFlags(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if (PreferenceConstants.OUTLINE_GROUP_MEMBERS.equals(event.getProperty())) {
|
||||
final Object newValue = event.getNewValue();
|
||||
if (newValue instanceof Boolean) {
|
||||
fSimpleName= ((Boolean) newValue).booleanValue();
|
||||
} else {
|
||||
fSimpleName= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A specialized tree viewer for outline content.
|
||||
*
|
||||
|
@ -106,8 +151,8 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
if (node instanceof Item) {
|
||||
Item i= (Item) node;
|
||||
final Object data = i.getData();
|
||||
// don't expand groupings by default
|
||||
if (data instanceof CElementGrouping) {
|
||||
// don't expand include grouping by default
|
||||
if (data instanceof IncludesGrouping) {
|
||||
return;
|
||||
} else if (data instanceof ICElement) {
|
||||
if (!shouldExpandElement((ICElement)data)) {
|
||||
|
@ -375,13 +420,17 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
protected ProblemTreeViewer createTreeViewer(Composite parent) {
|
||||
fTreeViewer = new OutlineTreeViewer(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.setLabelProvider(new DecoratingCLabelProvider(createLabelProvider(), true));
|
||||
fTreeViewer.setAutoExpandLevel(3);
|
||||
fTreeViewer.setUseHashlookup(true);
|
||||
fTreeViewer.addSelectionChangedListener(this);
|
||||
return fTreeViewer;
|
||||
}
|
||||
|
||||
private CUILabelProvider createLabelProvider() {
|
||||
return new COutlineLabelProvider(TEXT_FLAGS, IMAGE_FLAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
fTreeViewer = createTreeViewer(parent);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2009 QNX Software Systems 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
|
||||
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.editor;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
|
@ -72,7 +73,10 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
|||
public CContentOutlinerProvider(TreeViewer viewer, IWorkbenchPartSite site) {
|
||||
super(true, true);
|
||||
treeViewer = viewer;
|
||||
setIncludesGrouping(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
|
||||
final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
|
||||
setIncludesGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
|
||||
setNamespacesGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
|
||||
setMemberGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -349,6 +353,15 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
|
|||
contentUpdated();
|
||||
}
|
||||
}
|
||||
} else if (prop.equals(PreferenceConstants.OUTLINE_GROUP_MEMBERS)) {
|
||||
Object newValue = event.getNewValue();
|
||||
if (newValue instanceof Boolean) {
|
||||
boolean value = ((Boolean) newValue).booleanValue();
|
||||
if (isMemberGroupingEnabled() != value) {
|
||||
setMemberGrouping(value);
|
||||
contentUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2009 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
|
||||
|
@ -12,22 +12,21 @@
|
|||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
|
@ -47,6 +46,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
private SelectionButtonDialogField fOutlineGroupNamespaces;
|
||||
private SelectionButtonDialogField fCViewGroupIncludes;
|
||||
private SelectionButtonDialogField fCViewSeparateHeaderAndSource;
|
||||
private SelectionButtonDialogField fOutlineGroupMembers;
|
||||
|
||||
public AppearancePreferencePage() {
|
||||
setPreferenceStore(PreferenceConstants.getPreferenceStore());
|
||||
|
@ -70,6 +70,10 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fOutlineGroupNamespaces.setDialogFieldListener(listener);
|
||||
fOutlineGroupNamespaces.setLabelText(PreferencesMessages.AppearancePreferencePage_outlineGroupNamespaces_label);
|
||||
|
||||
fOutlineGroupMembers= new SelectionButtonDialogField(SWT.CHECK);
|
||||
fOutlineGroupMembers.setDialogFieldListener(listener);
|
||||
fOutlineGroupMembers.setLabelText(PreferencesMessages.AppearancePreferencePage_outlineGroupMethods_label);
|
||||
|
||||
fCViewGroupIncludes= new SelectionButtonDialogField(SWT.CHECK);
|
||||
fCViewGroupIncludes.setDialogFieldListener(listener);
|
||||
fCViewGroupIncludes.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupIncludes_label);
|
||||
|
@ -86,6 +90,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fCViewSeparateHeaderAndSource.setSelection(prefs.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE));
|
||||
fOutlineGroupIncludes.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
|
||||
fOutlineGroupNamespaces.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
|
||||
fOutlineGroupMembers.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -116,6 +121,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fCViewGroupIncludes.doFillIntoGrid(result, nColumns);
|
||||
fOutlineGroupIncludes.doFillIntoGrid(result, nColumns);
|
||||
fOutlineGroupNamespaces.doFillIntoGrid(result, nColumns);
|
||||
fOutlineGroupMembers.doFillIntoGrid(result, nColumns);
|
||||
|
||||
new Separator().doFillIntoGrid(result, nColumns);
|
||||
|
||||
|
@ -164,7 +170,12 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
prefs.setValue(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE, fCViewSeparateHeaderAndSource.isSelected());
|
||||
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected());
|
||||
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected());
|
||||
CUIPlugin.getDefault().savePluginPreferences();
|
||||
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, fOutlineGroupMembers.isSelected());
|
||||
try {
|
||||
new InstanceScope().getNode(CUIPlugin.PLUGIN_ID).flush();
|
||||
} catch (BackingStoreException exc) {
|
||||
CUIPlugin.log(exc);
|
||||
}
|
||||
return super.performOk();
|
||||
}
|
||||
|
||||
|
@ -179,6 +190,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fCViewSeparateHeaderAndSource.setSelection(prefs.getDefaultBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE));
|
||||
fOutlineGroupIncludes.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
|
||||
fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
|
||||
fOutlineGroupMembers.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS));
|
||||
super.performDefaults();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2009 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
|
||||
|
@ -136,6 +136,7 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String AppearancePreferencePage_cviewGroupIncludes_label;
|
||||
public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label;
|
||||
public static String AppearancePreferencePage_outlineGroupIncludes_label;
|
||||
public static String AppearancePreferencePage_outlineGroupMethods_label;
|
||||
public static String AppearancePreferencePage_outlineGroupNamespaces_label;
|
||||
public static String AppearancePreferencePage_note;
|
||||
public static String AppearancePreferencePage_preferenceOnlyForNewViews;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
# Copyright (c) 2000, 2009 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
|
||||
|
@ -150,6 +150,7 @@ AppearancePreferencePage_showTUChildren_label= Show translation unit members
|
|||
AppearancePreferencePage_cviewGroupIncludes_label= Group include directives in Project Explorer and C/C++ Projects view
|
||||
AppearancePreferencePage_cviewSeparateHeaderAndSource_label= Sort header files before source files in Project Explorer and C/C++ Projects view
|
||||
AppearancePreferencePage_outlineGroupIncludes_label= Group include directives in the Outline view
|
||||
AppearancePreferencePage_outlineGroupMethods_label=Group method definitions in the Outline view
|
||||
AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view
|
||||
AppearancePreferencePage_note=Note:
|
||||
AppearancePreferencePage_preferenceOnlyForNewViews=This preference does not affect open views
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2009 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
|
||||
|
@ -26,16 +26,11 @@ public class AppearanceAwareLabelProvider extends CUILabelProvider implements IP
|
|||
public final static int DEFAULT_TEXTFLAGS= CElementBaseLabels.M_PARAMETER_TYPES | CElementBaseLabels.PROJECT_POST_QUALIFIED;
|
||||
public final static int DEFAULT_IMAGEFLAGS= CElementImageProvider.OVERLAY_ICONS;
|
||||
|
||||
private int fTextFlagMask;
|
||||
private int fImageFlagMask;
|
||||
|
||||
/**
|
||||
* Constructor for AppearanceAwareLabelProvider.
|
||||
*/
|
||||
public AppearanceAwareLabelProvider(int textFlags, int imageFlags) {
|
||||
super(textFlags, imageFlags);
|
||||
initMasks();
|
||||
// PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,40 +40,10 @@ public class AppearanceAwareLabelProvider extends CUILabelProvider implements IP
|
|||
this(DEFAULT_TEXTFLAGS, DEFAULT_IMAGEFLAGS);
|
||||
}
|
||||
|
||||
private void initMasks() {
|
||||
fTextFlagMask= -1;
|
||||
fImageFlagMask= -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#dispose()
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
// PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CUILabelProvider#evaluateImageFlags()
|
||||
*/
|
||||
@Override
|
||||
protected int evaluateImageFlags(Object element) {
|
||||
return getImageFlags() & fImageFlagMask;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CUILabelProvider#evaluateTextFlags()
|
||||
*/
|
||||
@Override
|
||||
protected int evaluateTextFlags(Object element) {
|
||||
return getTextFlags() & fTextFlagMask;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2009 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
|
||||
|
@ -18,8 +18,8 @@ import org.eclipse.ui.PlatformUI;
|
|||
public class DecoratingCLabelProvider extends DecoratingLabelProvider {
|
||||
|
||||
/**
|
||||
* Decorating label provider for Java. Combines a JavaUILabelProvider
|
||||
* with problem and override indicuator with the workbench decorator (label
|
||||
* Decorating label provider for C/C++. Combines a CUILabelProvider
|
||||
* with problem and override indicator with the workbench decorator (label
|
||||
* decorator extension point).
|
||||
*/
|
||||
public DecoratingCLabelProvider(CUILabelProvider labelProvider) {
|
||||
|
@ -27,7 +27,7 @@ public class DecoratingCLabelProvider extends DecoratingLabelProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Decorating label provider for Java. Combines a JavaUILabelProvider
|
||||
* Decorating label provider for C/C++. Combines a CUILabelProvider
|
||||
* (if enabled with problem indicator) with the workbench
|
||||
* decorator (label decorator extension point).
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2009 QNX Software Systems 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
|
||||
|
@ -60,6 +60,8 @@ public abstract class CElementGrouping extends WorkbenchAdapter implements IAdap
|
|||
return CPluginImages.DESC_OBJS_INCCONT;
|
||||
case NAMESPACE_GROUPING:
|
||||
return CPluginImages.DESC_OBJS_NAMESPACE;
|
||||
case CLASS_GROUPING:
|
||||
return CPluginImages.DESC_OBJS_CLASS;
|
||||
}
|
||||
return super.getImageDescriptor(object);
|
||||
}
|
||||
|
@ -74,4 +76,11 @@ public abstract class CElementGrouping extends WorkbenchAdapter implements IAdap
|
|||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getLabel(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 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
|
||||
|
@ -47,6 +47,8 @@ import org.eclipse.cdt.core.model.ISourceRoot;
|
|||
* 6 Source roots
|
||||
* 5 C Elements
|
||||
* 6 non C Elements
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
*/
|
||||
public class CElementSorter extends ViewerSorter {
|
||||
|
||||
|
@ -66,12 +68,16 @@ public class CElementSorter extends ViewerSorter {
|
|||
protected static final int BINARIES = 23;
|
||||
protected static final int ARCHIVES = 24;
|
||||
|
||||
protected static final int INCLUDES = 30;
|
||||
protected static final int MACROS = 31;
|
||||
protected static final int INCLUDES = 28;
|
||||
protected static final int MACROS = 29;
|
||||
protected static final int USINGS = 30;
|
||||
protected static final int NAMESPACES = 32;
|
||||
protected static final int NAMESPACES_RESERVED = 33;
|
||||
protected static final int NAMESPACES_SYSTEM = 34;
|
||||
protected static final int USINGS = 35;
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
protected static final int TYPES = 35;
|
||||
protected static final int VARIABLEDECLARATIONS = 36;
|
||||
protected static final int FUNCTIONDECLARATIONS = 37;
|
||||
protected static final int VARIABLES = 38;
|
||||
|
@ -179,8 +185,7 @@ public class CElementSorter extends ViewerSorter {
|
|||
case ICElement.C_TEMPLATE_UNION:
|
||||
case ICElement.C_TEMPLATE_UNION_DECLARATION:
|
||||
case ICElement.C_ENUMERATION:
|
||||
// TODO need own categories
|
||||
return NAMESPACES;
|
||||
return TYPES;
|
||||
case ICElement.C_FUNCTION_DECLARATION:
|
||||
case ICElement.C_TEMPLATE_FUNCTION_DECLARATION:
|
||||
return FUNCTIONDECLARATIONS;
|
||||
|
@ -223,7 +228,7 @@ public class CElementSorter extends ViewerSorter {
|
|||
case CElementGrouping.INCLUDES_GROUPING:
|
||||
return INCLUDES;
|
||||
case CElementGrouping.CLASS_GROUPING:
|
||||
return VARIABLES;
|
||||
return TYPES;
|
||||
case CElementGrouping.NAMESPACE_GROUPING:
|
||||
return NAMESPACES;
|
||||
case CElementGrouping.LIBRARY_REF_CONTAINER:
|
||||
|
@ -289,17 +294,6 @@ public class CElementSorter extends ViewerSorter {
|
|||
return compareWithLabelProvider(viewer, e1, e2);
|
||||
}
|
||||
|
||||
if (cat1 == NAMESPACES) {
|
||||
// workaround for missing category for classes, structs, etc.
|
||||
int type1 = ((ICElement) e1).getElementType();
|
||||
int type2 = ((ICElement) e2).getElementType();
|
||||
if (type1 != type2) {
|
||||
if (type1 == ICElement.C_NAMESPACE || type2 == ICElement.C_NAMESPACE) {
|
||||
return type1 - type2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String ns1 = ""; //$NON-NLS-1$
|
||||
String ns2 = ns1;
|
||||
|
||||
|
@ -327,7 +321,7 @@ public class CElementSorter extends ViewerSorter {
|
|||
name2 = name2.substring(idx + 2);
|
||||
}
|
||||
if (name2.length() > 0 && name2.charAt(0) == '~') {
|
||||
name2 = name1.substring(1);
|
||||
name2 = name2.substring(1);
|
||||
}
|
||||
} else {
|
||||
name2 = e2.toString();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2009 QNX Software Systems 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
|
||||
|
@ -52,9 +52,12 @@ public class IncludesGrouping extends CElementGrouping {
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IncludesGrouping) {
|
||||
return tu.equals(((IncludesGrouping)obj).getParent(obj)) ;
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
if (obj instanceof IncludesGrouping) {
|
||||
return tu.equals(((IncludesGrouping)obj).tu) ;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2009 QNX Software Systems 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
|
||||
|
@ -13,27 +13,49 @@ package org.eclipse.cdt.ui;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IMember;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.MembersGrouping;
|
||||
|
||||
/**
|
||||
* NamespacesGrouping
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
*/
|
||||
public class NamespacesGrouping extends CElementGrouping {
|
||||
|
||||
protected ITranslationUnit fUnit;
|
||||
protected String fName;
|
||||
protected INamespace[] fNamespaces;
|
||||
private final boolean fMemberGrouping;
|
||||
|
||||
public NamespacesGrouping(ITranslationUnit unit, INamespace namespace) {
|
||||
this(unit, namespace, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new namespace grouping and optional member grouping.
|
||||
*
|
||||
* @param unit the parent translation unit
|
||||
* @param namespace the namespace
|
||||
* @param memberGrouping whether member grouping is enabled
|
||||
* @since 5.1
|
||||
*/
|
||||
public NamespacesGrouping(ITranslationUnit unit, INamespace namespace, boolean memberGrouping) {
|
||||
super(CElementGrouping.NAMESPACE_GROUPING);
|
||||
fUnit = unit;
|
||||
fNamespaces = new INamespace[] { namespace };
|
||||
fName = namespace.getElementName();
|
||||
fMemberGrouping = memberGrouping;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,19 +68,70 @@ public class NamespacesGrouping extends CElementGrouping {
|
|||
*/
|
||||
@Override
|
||||
public Object[] getChildren(Object object) {
|
||||
List<ICElement> list = new ArrayList<ICElement>();
|
||||
for (int i = 0; i < fNamespaces.length; ++i) {
|
||||
INamespace nspace = fNamespaces[i];
|
||||
Set<Object> list = new LinkedHashSet<Object>();
|
||||
try {
|
||||
ICElement[] objs = nspace.getChildren();
|
||||
list.addAll(Arrays.asList(objs));
|
||||
} catch (CModelException e) {
|
||||
//
|
||||
INamespace[] namespaces = getNamespaces();
|
||||
for (INamespace iNamespace : namespaces) {
|
||||
list.addAll(getNamespaceChildren(iNamespace));
|
||||
}
|
||||
} catch (CModelException exc) {
|
||||
// ignore at this point
|
||||
}
|
||||
|
||||
return list.toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
public INamespace[] getNamespaces() {
|
||||
List<INamespace> list = new ArrayList<INamespace>();
|
||||
try {
|
||||
List<ICElement> namespaces = fUnit.getChildrenOfType(ICElement.C_NAMESPACE);
|
||||
for (ICElement icElement : namespaces) {
|
||||
if (fName.equals(icElement.getElementName())) {
|
||||
INamespace nspace = (INamespace) icElement;
|
||||
list.add(nspace);
|
||||
}
|
||||
}
|
||||
} catch (CModelException exc) {
|
||||
// ignore at this point
|
||||
}
|
||||
|
||||
return list.toArray(new INamespace[list.size()]);
|
||||
}
|
||||
|
||||
private Collection<Object> getNamespaceChildren(INamespace nspace) throws CModelException {
|
||||
Object[] children = nspace.getChildren();
|
||||
if (!fMemberGrouping) {
|
||||
return Arrays.asList(children);
|
||||
}
|
||||
List<Object> list = new ArrayList<Object>(children.length);
|
||||
// check if there is another member with the same namespace for the same parent
|
||||
Map<String, MembersGrouping> map = new HashMap<String, MembersGrouping>();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
if (children[i] instanceof IMember) {
|
||||
final ICElement member = (ICElement)children[i];
|
||||
String name = member.getElementName();
|
||||
int idx = name.lastIndexOf("::"); //$NON-NLS-1$
|
||||
if (idx < 0) {
|
||||
continue;
|
||||
}
|
||||
String namespace = name.substring(0, idx);
|
||||
MembersGrouping memberGrouping = map.get(namespace);
|
||||
if (memberGrouping == null) {
|
||||
memberGrouping = new MembersGrouping(this, namespace);
|
||||
map.put(namespace, memberGrouping);
|
||||
list.add(memberGrouping);
|
||||
}
|
||||
} else {
|
||||
list.add(children[i]);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
|
||||
*/
|
||||
|
@ -67,11 +140,12 @@ public class NamespacesGrouping extends CElementGrouping {
|
|||
return fUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nspace
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
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)
|
||||
|
@ -79,13 +153,29 @@ public class NamespacesGrouping extends CElementGrouping {
|
|||
*/
|
||||
@Override
|
||||
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));
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
if (obj instanceof NamespacesGrouping) {
|
||||
NamespacesGrouping other = (NamespacesGrouping)obj;
|
||||
return fUnit.equals(other.fUnit) && fName.equals(other.fName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return fUnit.hashCode() * 17 + fName.hashCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.CElementGrouping#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return fName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 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
|
||||
|
@ -747,6 +747,14 @@ public class PreferenceConstants {
|
|||
*/
|
||||
public static final String OUTLINE_GROUP_NAMESPACES= "org.eclipse.cdt.ui.outline.groupnamespaces"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the Outline view should group member definitions.
|
||||
* <p>
|
||||
* Value is of type <code>Boolean</code>.
|
||||
* </p>
|
||||
* @since 5.1
|
||||
*/
|
||||
public static final String OUTLINE_GROUP_MEMBERS= "org.eclipse.cdt.ui.outline.groupmembers"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that controls whether the Outline view
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 25 KiB |
|
@ -13,7 +13,7 @@
|
|||
<h1>Appearance preferences</h1>
|
||||
|
||||
<p>Use the <b>Appearance</b> panel of the Preferences window to customize the appearance of C elements in the viewers.</p>
|
||||
<p><img src="../images/view_appearance_prefs.png" width="635" height="544"></p>
|
||||
<p><img src="../images/view_appearance_prefs.png" ></p>
|
||||
|
||||
<table width="700px" cellpadding="5" cellspacing="0" border="1" >
|
||||
<caption>
|
||||
|
@ -40,6 +40,10 @@
|
|||
<td valign="top"><b>Group namespaces in the Outline view </b></td>
|
||||
<td valign="top">Select this option to group namespace declarations in the Outline view. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><b>Group method definitions in the Outline view </b></td>
|
||||
<td valign="top">Select this option to group method definitions for the same type in the Outline view. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><b>Sort header files before source files in Project Explorer and C/C++ Projects view </b></td>
|
||||
<td valign="top">Select this option to separate header and source files in Project Explorer and C/C++ Projects view. </td>
|
||||
|
|
Loading…
Add table
Reference in a new issue