1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

2005-06-08 Alain Magloire

Move to the IContentTypeManager framework: PR 86645
	* src/org/eclipse/cdt/internal/ui/CFileElementWorkingCopy.java
	* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
	+ src/org/eclipse/cdt/internal/ui/preferences/CFileTypeAssociation.java
	* src/org/eclipse/cdt/internal/ui/preferences/CFileTypeDialog.java
	* src/org/eclipse/cdt/internal/ui/preferences/CFileTypesPreferenceBlock.java
	* src/org/eclipse/cdt/internal/ui/preferences/CFileTypesPreferencePage.java
	* src/org/eclipse/cdt/internal/ui/preferences/CFileTypesPropertyPage.java
	* src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
	* src/org/eclipse/cdt/internal/ui/text/CFormattingStrategy.java
	* src/org/eclipse/cdt/internal/ui/text/contentassist/SearchCompletionContributor.java
	* plugin.xml
This commit is contained in:
Alain Magloire 2005-06-09 16:06:54 +00:00
parent 579397f2af
commit 18d3837fe0
12 changed files with 685 additions and 172 deletions

View file

@ -1,3 +1,17 @@
2005-06-08 Alain Magloire
Move to the IContentTypeManager framework: PR 86645
* src/org/eclipse/cdt/internal/ui/CFileElementWorkingCopy.java
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
+ src/org/eclipse/cdt/internal/ui/preferences/CFileTypeAssociation.java
* src/org/eclipse/cdt/internal/ui/preferences/CFileTypeDialog.java
* src/org/eclipse/cdt/internal/ui/preferences/CFileTypesPreferenceBlock.java
* src/org/eclipse/cdt/internal/ui/preferences/CFileTypesPreferencePage.java
* src/org/eclipse/cdt/internal/ui/preferences/CFileTypesPropertyPage.java
* src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
* src/org/eclipse/cdt/internal/ui/text/CFormattingStrategy.java
* src/org/eclipse/cdt/internal/ui/text/contentassist/SearchCompletionContributor.java
* plugin.xml
2005-06-08 Vladimir Hirsl
Fix for NPE in CPElement.java

View file

@ -522,19 +522,23 @@
<editor
default="true"
name="%CEditor.name"
extensions="c,C,cc,cpp,cxx,h,hh,hpp"
icon="icons/obj16/c_file_obj.gif"
class="org.eclipse.cdt.internal.ui.editor.CEditor"
contributorClass="org.eclipse.cdt.internal.ui.editor.CEditorActionContributor"
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
id="org.eclipse.cdt.ui.editor.CEditor">
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.cSource"/>
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.cxxSource"/>
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.cxxHeader"/>
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.cHeader"/>
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.cSource"/>
</editor>
<editor
name="%AsmEditor.name"
extensions="s,asm,S"
icon="icons/obj16/s_file_obj.gif"
class="org.eclipse.cdt.internal.ui.editor.asm.AsmTextEditor"
id="org.eclipse.cdt.ui.editor.asm.AsmEditor">
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.asmSource"/>
</editor>
<editor
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
@ -738,7 +742,6 @@
<extension
point="org.eclipse.compare.structureCreators">
<structureCreator
extensions="c,cc,cpp,cxx,h,hpp"
class="org.eclipse.cdt.internal.ui.compare.CStructureCreator"
id="org.eclipse.cdt.ui.compare.CStructureCreator">
</structureCreator>
@ -762,7 +765,6 @@
<extension
point="org.eclipse.compare.contentMergeViewers">
<viewer
extensions="c,cc,cpp,cxx,h,c2,hpp"
class="org.eclipse.cdt.internal.ui.compare.CContentViewerCreator"
id="org.eclipse.cdt.ui.compare.CContentViewerCreator">
</viewer>

View file

@ -20,7 +20,7 @@ public class CFileElementWorkingCopy extends WorkingCopy {
* Creates a working copy of this element
*/
public CFileElementWorkingCopy(ITranslationUnit unit) throws CoreException {
super(unit.getParent(), unit.getPath(), null);
super(unit.getParent(), unit.getPath(), unit.getContentTypeId(), null);
this.unit = unit;
}

View file

@ -11,7 +11,6 @@ import java.util.Iterator;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
@ -44,6 +43,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
@ -606,8 +606,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
if (originalElement instanceof IFileEditorInput) {
IFile file= ((IFileEditorInput) originalElement).getFile();
if (file != null) {
ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
oldLanguage = type.getLanguage().getId();
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName());
if (type != null) {
oldLanguage = type.getId();
}
if (oldLanguage == null) {
return false;
}
@ -618,8 +620,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
if (movedElement instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) movedElement).getFile();
if (file != null) {
ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
newLanguage = type.getLanguage().getId();
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName());
if (type != null) {
newLanguage = type.getId();
}
if (newLanguage == null) {
return false;
}

View file

@ -0,0 +1,92 @@
/**********************************************************************
* Copyright (c) 2005 QNX Software System 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 System - Initial implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
import org.eclipse.core.runtime.content.IContentType;
public class CFileTypeAssociation {
private String fSpec;
private int fType;
private IContentType fContentType;
/**
* @param spec
* @param type
* @param settings
*/
public CFileTypeAssociation(String spec, int type, IContentType contentType) {
super();
fSpec = spec;
fType = type;
fContentType = contentType;
}
/**
* @return Returns the fSettings.
*/
public IContentType getContentType() {
return fContentType;
}
/**
* @return Returns the fSpec.
*/
public String getSpec() {
return fSpec;
}
public String getPattern() {
String pattern = getSpec();
if (isExtSpec()) {
return "*." + pattern; //$NON-NLS-1$
}
return pattern;
}
/**
* @return
*/
public boolean isFileSpec() {
return (fType & IContentType.FILE_NAME_SPEC) != 0;
}
/**
* @return
*/
public boolean isExtSpec() {
return (fType & IContentType.FILE_EXTENSION_SPEC) != 0;
}
/**
* @return
*/
public boolean isPredefined() {
return (fType & IContentType.IGNORE_USER_DEFINED) != 0;
}
/**
* @return
*/
public boolean isUserDefined() {
return (fType & IContentType.IGNORE_PRE_DEFINED) != 0;
}
/**
* @return Returns the description.
*/
public String getDescription() {
return fContentType.getName();
}
}

View file

@ -10,9 +10,12 @@
***********************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.IResolverModel;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
@ -38,7 +41,7 @@ public class CFileTypeDialog extends Dialog {
private Combo fComboType;
private String fPattern;
private ICFileType fType;
private IContentType fType;
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
@ -99,23 +102,30 @@ public class CFileTypeDialog extends Dialog {
return fPattern;
}
public void setType(ICFileType type) {
fType = type;
}
public ICFileType getType() {
public IContentType getContentType() {
return fType;
}
private void populateTypesCombo() {
ICFileType[] types = getResolverModel().getFileTypes();
int index = -1;
for (int i = 0; i < types.length; i++) {
fComboType.add(types[i].getName());
IContentTypeManager manager = Platform.getContentTypeManager();
String[] ids = CoreModel.getRegistedContentTypeIds();
ArrayList list = new ArrayList(ids.length);
for (int i = 0; i < ids.length; i++) {
IContentType ctype = manager.getContentType(ids[i]);
if (ctype != null) {
list.add(ctype);
}
}
fComboType.setData(types);
IContentType[] ctypes = new IContentType[list.size()];
list.toArray(ctypes);
int index = -1;
for (int i = 0; i < ctypes.length; i++) {
fComboType.add(ctypes[i].getName());
}
fComboType.setData(ctypes);
if (null != fType) {
index = fComboType.indexOf(fType.getName());
@ -124,10 +134,6 @@ public class CFileTypeDialog extends Dialog {
fComboType.select((index < 0) ? 0 : index);
}
private IResolverModel getResolverModel() {
return CCorePlugin.getDefault().getResolverModel();
}
Button getOkayButton() {
return getButton(IDialogConstants.OK_ID);
}
@ -136,21 +142,20 @@ public class CFileTypeDialog extends Dialog {
return fTextPattern.getText().trim();
}
private ICFileType getTypeFromControl() {
String typeId = null;
private IContentType getTypeFromControl() {
IContentType type = null;
int index = fComboType.getSelectionIndex();
if (-1 != index) {
String name = fComboType.getItem(index);
ICFileType[] types = (ICFileType[]) fComboType.getData();
IContentType[] types = (IContentType[]) fComboType.getData();
for (int i = 0; i < types.length; i++) {
if (name.equals(types[i].getName())) {
typeId = types[i].getId();
type = types[i];
}
}
}
return getResolverModel().getFileTypeById(typeId);
return type;
}
protected void okPressed() {

View file

@ -12,13 +12,19 @@ package org.eclipse.cdt.internal.ui.preferences;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
import org.eclipse.cdt.core.filetype.IResolverModel;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.ui.util.PixelConverter;
import org.eclipse.cdt.internal.ui.util.SWTUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jface.util.ListenerList;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ILabelProvider;
@ -53,12 +59,13 @@ public class CFileTypesPreferenceBlock {
private static final int COL_PATTERN = 0;
private static final int COL_DESCRIPTION = 1;
private static final int COL_LANGUAGE = 2;
private static final int COL_STATUS = 2;
private ICFileTypeResolver fResolverWorkingCopy;
private ArrayList fAddAssoc;
private ArrayList fRemoveAssoc;
private boolean fDirty = false;
private ArrayList fAddAssoc;
private ArrayList fRemoveAssoc;
private boolean fDirty = false;
private IProject fInput;
private IContentType[] fContentTypes;
private TableViewer fAssocViewer;
private Button fBtnNew;
@ -66,9 +73,9 @@ public class CFileTypesPreferenceBlock {
private class AssocSorter extends ViewerSorter {
public int category(Object element) {
if (element instanceof ICFileTypeAssociation) {
ICFileTypeAssociation assoc = (ICFileTypeAssociation) element;
if (-1 != assoc.getPattern().indexOf('*')) {
if (element instanceof CFileTypeAssociation) {
CFileTypeAssociation assoc = (CFileTypeAssociation) element;
if (assoc.isExtSpec()) {
return 10;
}
return 20;
@ -78,7 +85,7 @@ public class CFileTypesPreferenceBlock {
}
private class AssocContentProvider implements IStructuredContentProvider {
ICFileTypeAssociation[] assocs;
CFileTypeAssociation[] assocs;
public Object[] getElements(Object inputElement) {
return assocs;
@ -89,8 +96,8 @@ public class CFileTypesPreferenceBlock {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput instanceof ICFileTypeAssociation[]) {
assocs = (ICFileTypeAssociation[]) newInput;
if (newInput instanceof CFileTypeAssociation[]) {
assocs = (CFileTypeAssociation[]) newInput;
}
}
}
@ -99,9 +106,8 @@ public class CFileTypesPreferenceBlock {
private ListenerList listeners = new ListenerList();
public Image getColumnImage(Object element, int columnIndex) {
if (element instanceof ICFileTypeAssociation) {
if (element instanceof CFileTypeAssociation) {
if (COL_PATTERN == columnIndex) {
// TODO: add image support to table
return null;
}
}
@ -109,17 +115,22 @@ public class CFileTypesPreferenceBlock {
}
public String getColumnText(Object element, int columnIndex) {
if (element instanceof ICFileTypeAssociation) {
ICFileTypeAssociation assoc = (ICFileTypeAssociation) element;
if (element instanceof CFileTypeAssociation) {
CFileTypeAssociation assoc = (CFileTypeAssociation) element;
switch (columnIndex) {
case COL_PATTERN:
return assoc.getPattern();
case COL_DESCRIPTION:
return assoc.getType().getName();
return assoc.getDescription();
case COL_LANGUAGE:
return assoc.getType().getLanguage().getName();
case COL_STATUS:
if (assoc.isUserDefined()) {
return PreferencesMessages.getString("CFileTypesPreferencePage.userDefined"); //$NON-NLS-1$
} else if (assoc.isPredefined()) {
return PreferencesMessages.getString("CFileTypesPreferencePage.preDefined"); //$NON-NLS-1$
}
return new String();
}
}
return element.toString();
@ -152,10 +163,14 @@ public class CFileTypesPreferenceBlock {
}
public CFileTypesPreferenceBlock(ICFileTypeResolver input) {
public CFileTypesPreferenceBlock() {
this(null);
}
public CFileTypesPreferenceBlock(IProject input) {
fAddAssoc = new ArrayList();
fRemoveAssoc = new ArrayList();
setResolver(input);
fInput = input;
setDirty(false);
}
@ -208,7 +223,7 @@ public class CFileTypesPreferenceBlock {
col.setText(PreferencesMessages.getString("CFileTypesPreferencePage.colTitleDescription")); //$NON-NLS-1$
col = new TableColumn(table, SWT.LEFT);
col.setText(PreferencesMessages.getString("CFileTypesPreferencePage.colTitleLanguage")); //$NON-NLS-1$
col.setText(PreferencesMessages.getString("CFileTypesPreferencePage.colTitleStatus")); //$NON-NLS-1$
// Create the button pane
@ -260,7 +275,7 @@ public class CFileTypesPreferenceBlock {
fAssocViewer.setSorter(new AssocSorter());
fAssocViewer.setContentProvider(new AssocContentProvider());
fAssocViewer.setLabelProvider(new AssocLabelProvider());
fAssocViewer.setInput(getResolverWorkingCopy().getFileTypeAssociations());
fAssocViewer.setInput(getCFileTypeAssociations());
fAssocViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
@ -280,25 +295,32 @@ public class CFileTypesPreferenceBlock {
setDirty(enabled);
}
public void setResolver(ICFileTypeResolver resolver) {
public void setInput(IProject input) {
fAddAssoc.clear();
fRemoveAssoc.clear();
fResolverWorkingCopy = resolver.createWorkingCopy();
fInput = input;
if (null != fAssocViewer) {
fAssocViewer.setInput(fResolverWorkingCopy.getFileTypeAssociations());
fAssocViewer.setInput(getCFileTypeAssociations());
}
setDirty(true);
}
public ICFileTypeResolver getResolverWorkingCopy() {
return fResolverWorkingCopy;
public void setInputWithCopy(IProject input) {
fAddAssoc.clear();
fRemoveAssoc.clear();
fInput = null;
if (null != fAssocViewer) {
fAssocViewer.setInput(getCFileTypeAssociations());
}
fInput = input;
setDirty(true);
}
public void setDirty(boolean dirty) {
private void setDirty(boolean dirty) {
fDirty = dirty;
}
public boolean isDirty() {
private boolean isDirty() {
return fDirty;
}
@ -306,36 +328,165 @@ public class CFileTypesPreferenceBlock {
boolean changed = fDirty;
if (fDirty) {
ICFileTypeAssociation[] add = (ICFileTypeAssociation[]) fAddAssoc.toArray(new ICFileTypeAssociation[fAddAssoc.size()]);
ICFileTypeAssociation[] rem = (ICFileTypeAssociation[]) fRemoveAssoc.toArray(new ICFileTypeAssociation[fRemoveAssoc.size()]);
CFileTypeAssociation[] add = (CFileTypeAssociation[]) fAddAssoc.toArray(new CFileTypeAssociation[fAddAssoc.size()]);
CFileTypeAssociation[] rem = (CFileTypeAssociation[]) fRemoveAssoc.toArray(new CFileTypeAssociation[fRemoveAssoc.size()]);
fResolverWorkingCopy.adjustAssociations(add, rem);
adjustAssociations(add, rem);
fAddAssoc.clear();
fRemoveAssoc.clear();
setDirty(false);
}
return changed;
}
private CFileTypeAssociation[] getCFileTypeAssociations() {
ArrayList list = new ArrayList();
if (fInput == null) {
fillWithUserDefinedCFileTypeAssociations(list);
fillWithPredefinedCFileTypeAssociations(list);
} else {
fillWithProjectCFileTypeAssociations(list, fInput);
}
CFileTypeAssociation[] assocs = new CFileTypeAssociation[list.size()];
list.toArray(assocs);
return assocs;
}
private void adjustAssociations(CFileTypeAssociation[] add, CFileTypeAssociation[] rem) {
IScopeContext context = null;
if (fInput != null) {
context = new ProjectScope(fInput);
}
addAssociations(add, context);
removeAssociations(rem, context);
}
private void addAssociations(CFileTypeAssociation[] add, IScopeContext context) {
for (int i = 0; i < add.length; ++i) {
CFileTypeAssociation assoc = add[i];
String spec = assoc.getSpec();
IContentType contentType = assoc.getContentType();
int type = IContentType.FILE_NAME_SPEC;
if (assoc.isExtSpec()) {
type = IContentType.FILE_EXTENSION_SPEC;
}
addAssociation(context, contentType, spec, type);
}
}
protected void addAssociation(IScopeContext context, IContentType contentType, String spec, int type) {
try {
IContentTypeSettings settings = contentType.getSettings(context);
settings.addFileSpec(spec, type);
} catch (CoreException e) {
// ignore ??
}
}
private void removeAssociations(CFileTypeAssociation[] rem, IScopeContext context) {
for (int i = 0; i < rem.length; ++i) {
CFileTypeAssociation assoc = rem[i];
IContentType contentType = assoc.getContentType();
String spec = assoc.getSpec();
int type = IContentType.FILE_NAME_SPEC;
if (assoc.isExtSpec()) {
type = IContentType.FILE_EXTENSION_SPEC;
}
removeAssociation(context, contentType, spec, type);
}
}
protected void removeAssociation(IScopeContext context, IContentType contentType, String spec, int type) {
try {
IContentTypeSettings settings = contentType.getSettings(context);
settings.removeFileSpec(spec, type);
} catch (CoreException e) {
// ignore ??
}
}
private IContentType[] getRegistedContentTypes() {
if (fContentTypes == null) {
String [] ids = CoreModel.getRegistedContentTypeIds();
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType [] ctypes = new IContentType[ids.length];
for (int i = 0; i < ids.length; i++) {
ctypes[i] = manager.getContentType(ids[i]);
}
fContentTypes = ctypes;
}
return fContentTypes;
}
private void fillWithUserDefinedCFileTypeAssociations(ArrayList list) {
IContentType[] ctypes = getRegistedContentTypes();
fillWithCFileTypeAssociations(ctypes, null, IContentType.IGNORE_PRE_DEFINED | IContentType.FILE_EXTENSION_SPEC, list);
fillWithCFileTypeAssociations(ctypes, null, IContentType.IGNORE_PRE_DEFINED | IContentType.FILE_NAME_SPEC, list);
}
private void fillWithPredefinedCFileTypeAssociations(ArrayList list) {
IContentType[] ctypes = getRegistedContentTypes();
fillWithCFileTypeAssociations(ctypes, null, IContentType.IGNORE_USER_DEFINED | IContentType.FILE_EXTENSION_SPEC, list);
fillWithCFileTypeAssociations(ctypes, null, IContentType.IGNORE_USER_DEFINED | IContentType.FILE_NAME_SPEC, list);
}
private void fillWithProjectCFileTypeAssociations(ArrayList list, IProject project) {
IContentType[] ctypes = getRegistedContentTypes();
IScopeContext context = new ProjectScope(project);
fillWithCFileTypeAssociations(ctypes, context, IContentType.IGNORE_PRE_DEFINED | IContentType.FILE_EXTENSION_SPEC, list);
fillWithCFileTypeAssociations(ctypes, context, IContentType.IGNORE_PRE_DEFINED | IContentType.FILE_NAME_SPEC, list);
}
private void fillWithCFileTypeAssociations(IContentType[] ctypes, IScopeContext context, int type, ArrayList list) {
for (int i = 0; i < ctypes.length; i++) {
try {
IContentType ctype = ctypes[i];
IContentTypeSettings setting = ctype.getSettings(context);
String[] specs = setting.getFileSpecs(type);
for (int j = 0; j < specs.length; j++) {
CFileTypeAssociation assoc = new CFileTypeAssociation(specs[j], type, ctype);
list.add(assoc);
}
} catch (CoreException e) {
// skip over it.
}
}
}
private CFileTypeAssociation createAssociation(String pattern, IContentType contentType) {
int type = IContentType.FILE_NAME_SPEC;
if (pattern.startsWith("*.")) { //$NON-NLS-1$
pattern = pattern.substring(2);
type = IContentType.FILE_EXTENSION_SPEC;
}
return new CFileTypeAssociation(pattern, type, contentType);
}
protected void handleSelectionChanged() {
IStructuredSelection sel = getSelection();
fBtnRemove.setEnabled(!sel.isEmpty());
}
private IResolverModel getResolverModel() {
return CCorePlugin.getDefault().getResolverModel();
if (sel.isEmpty()) {
fBtnRemove.setEnabled(false);
} else {
boolean enabled = true;
List elements = sel.toList();
for (Iterator i = elements.iterator(); i.hasNext();) {
CFileTypeAssociation assoc = (CFileTypeAssociation) i.next();
if (assoc.isPredefined())
enabled = false;
}
fBtnRemove.setEnabled(enabled);
}
}
protected void handleAdd() {
ICFileTypeAssociation assoc = null;
CFileTypeAssociation assoc = null;
CFileTypeDialog dlg = new CFileTypeDialog(fBtnNew.getParent().getShell());
if (Window.OK == dlg.open()) {
assoc = getResolverModel().createAssocation(dlg.getPattern(), dlg.getType());
assoc = createAssociation(dlg.getPattern(), dlg.getContentType());
if (null != assoc) {
fAssocViewer.add(assoc);
fAddAssoc.add(assoc);
@ -349,7 +500,7 @@ public class CFileTypesPreferenceBlock {
IStructuredSelection sel = getSelection();
if ((null != sel) && (!sel.isEmpty())) {
for (Iterator iter = sel.iterator(); iter.hasNext();) {
ICFileTypeAssociation assoc = (ICFileTypeAssociation) iter.next();
CFileTypeAssociation assoc = (CFileTypeAssociation) iter.next();
fAssocViewer.remove(assoc);
fAddAssoc.remove(assoc);
fRemoveAssoc.add(assoc);

View file

@ -16,10 +16,6 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
import org.eclipse.cdt.core.filetype.IResolverModel;
import org.eclipse.cdt.core.internal.filetype.WorkspaceResolver;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.Preferences;
@ -40,11 +36,11 @@ import org.eclipse.ui.PlatformUI;
public class CFileTypesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private CFileTypesPreferenceBlock fPrefsBlock;
private ICFileTypeResolver fResolver;
public CFileTypesPreferencePage() {
setDescription(PreferencesMessages.getString("CFileTypesPreferencePage.description")); //$NON-NLS-1$
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
//setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
noDefaultAndApplyButton();
}
/* (non-Javadoc)
@ -56,8 +52,9 @@ public class CFileTypesPreferencePage extends PreferencePage implements IWorkben
topPane.setLayout(new GridLayout());
topPane.setLayoutData(new GridData(GridData.FILL_BOTH));
fResolver = getResolverModel().getResolver();
fPrefsBlock = new CFileTypesPreferenceBlock(fResolver);
//fResolver = getResolverModel().getResolver();
// fPrefsBlock = new CFileTypesPreferenceBlock(fResolver);
fPrefsBlock = new CFileTypesPreferenceBlock(null);
PlatformUI.getWorkbench().getHelpSystem().setHelp( topPane, ICHelpContextIds.FILE_TYPES_PREF_PAGE );
return fPrefsBlock.createControl(topPane);
@ -73,11 +70,10 @@ public class CFileTypesPreferencePage extends PreferencePage implements IWorkben
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
*/
protected void performDefaults() {
Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_EXCLUSION);
prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_INCLUSION);
fPrefsBlock.setResolver(getResolverModel().getResolver());
// Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
// prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_EXCLUSION);
// prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_INCLUSION);
// fPrefsBlock.setResolver(getResolverModel().getResolver());
super.performDefaults();
}
@ -87,36 +83,36 @@ public class CFileTypesPreferencePage extends PreferencePage implements IWorkben
public boolean performOk() {
if (fPrefsBlock.performOk()) {
ICFileTypeAssociation[] oldAssocs = fResolver.getFileTypeAssociations();
ICFileTypeResolver workingCopy = fPrefsBlock.getResolverWorkingCopy();
ICFileTypeAssociation[] newAssocs = workingCopy.getFileTypeAssociations();
// compare
List delList = new ArrayList();
List addList = new ArrayList();
for (int i = 0; i < oldAssocs.length; i++) {
if (Arrays.binarySearch(newAssocs, oldAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
delList.add(oldAssocs[i]);
}
}
for (int i = 0; i < newAssocs.length; i++) {
if (Arrays.binarySearch(oldAssocs, newAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
addList.add(newAssocs[i]);
}
}
ICFileTypeAssociation[] addAssocs = (ICFileTypeAssociation[]) addList.toArray(new ICFileTypeAssociation[addList.size()]);
ICFileTypeAssociation[] delAssocs = (ICFileTypeAssociation[]) delList.toArray(new ICFileTypeAssociation[delList.size()]);
fResolver.adjustAssociations(addAssocs, delAssocs);
// ICFileTypeAssociation[] oldAssocs = fResolver.getFileTypeAssociations();
//
// ICFileTypeResolver workingCopy = fPrefsBlock.getResolverWorkingCopy();
// ICFileTypeAssociation[] newAssocs = workingCopy.getFileTypeAssociations();
//
// // compare
// List delList = new ArrayList();
// List addList = new ArrayList();
//
// for (int i = 0; i < oldAssocs.length; i++) {
// if (Arrays.binarySearch(newAssocs, oldAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
// delList.add(oldAssocs[i]);
// }
// }
//
// for (int i = 0; i < newAssocs.length; i++) {
// if (Arrays.binarySearch(oldAssocs, newAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
// addList.add(newAssocs[i]);
// }
// }
//
// ICFileTypeAssociation[] addAssocs = (ICFileTypeAssociation[]) addList.toArray(new ICFileTypeAssociation[addList.size()]);
// ICFileTypeAssociation[] delAssocs = (ICFileTypeAssociation[]) delList.toArray(new ICFileTypeAssociation[delList.size()]);
// fResolver.adjustAssociations(addAssocs, delAssocs);
}
return super.performOk();
}
private IResolverModel getResolverModel() {
return CCorePlugin.getDefault().getResolverModel();
}
// private IResolverModel getResolverModel() {
// return CCorePlugin.getDefault().getResolverModel();
// }
}

View file

@ -11,11 +11,22 @@
package org.eclipse.cdt.internal.ui.preferences;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
import org.eclipse.cdt.core.filetype.IResolverModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -26,6 +37,8 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PropertyPage;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
/*
* The preference page used for displaying/editing CDT file
@ -33,13 +46,119 @@ import org.eclipse.ui.dialogs.PropertyPage;
*/
public class CFileTypesPropertyPage extends PropertyPage {
private Button fUseWorkspace;
private Button fUseProject;
protected ICFileTypeResolver fResolver;
/**
* FIXME: This class should be remove when PR #99060
* Since ContentTypeSettings.removeFileSpec() is buggy.
*/
class FixCFileTypesPreferenceBlock extends CFileTypesPreferenceBlock {
public FixCFileTypesPreferenceBlock() {
super();
}
public FixCFileTypesPreferenceBlock(IProject input) {
super(input);
}
String toListString(Object[] list, String separator) {
if (list == null || list.length == 0) {
return null;
}
StringBuffer result = new StringBuffer();
for (int i = 0; i < list.length; i++) {
if (i != 0) {
result.append(separator);
}
result.append(list[i]);
}
// ignore last comma
return result.toString();
}
List parseItemsIntoList(String string, String separator) {
ArrayList list = new ArrayList();
if (string != null) {
String[] items = string.split(separator);
list.addAll(Arrays.asList(items));
}
return list;
}
String getPreferenceKey(int type) {
if ((type & IContentType.FILE_EXTENSION_SPEC) != 0)
return PREF_FILE_EXTENSIONS;
if ((type & IContentType.FILE_NAME_SPEC) != 0)
return PREF_FILE_NAMES;
throw new IllegalArgumentException("Unknown type: "); //$NON-NLS-1$
}
private IContentTypeManager.ContentTypeChangeEvent newContentTypeChangeEvent(IContentType source, IScopeContext context) {
return new IContentTypeManager.ContentTypeChangeEvent(source, context);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.ui.preferences.CFileTypesPreferenceBlock#addAssociation(org.eclipse.core.runtime.preferences.IScopeContext, org.eclipse.core.runtime.content.IContentType, java.lang.String, int)
*/
protected void addAssociation(IScopeContext context, IContentType contentType, String spec, int type) {
super.addAssociation(context, contentType, spec, type);
// We do not call flush here it will be call in the perform OK.
//contentTypeNode.flush();
CModelManager.getDefault().contentTypeChanged(newContentTypeChangeEvent(contentType, context));
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.ui.preferences.CFileTypesPreferenceBlock#removeAssociation(org.eclipse.core.runtime.preferences.IScopeContext, org.eclipse.core.runtime.content.IContentType, java.lang.String, int)
*/
protected void removeAssociation(IScopeContext context, IContentType contentType, String spec, int type) {
String contentTypeId = contentType.getId();
Preferences contentTypeNode = context.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE).node(contentTypeId);
String key = getPreferenceKey(type);
String existing = contentTypeNode.get(key, null);
if (existing == null)
// content type has no settings - nothing to do
return;
List existingValues = parseItemsIntoList(contentTypeNode.get(key, null), PREF_SEPARATOR); //$NON-NLS-1$
int index = -1;
for (int j = 0; j < existingValues.size(); j++)
if (((String) existingValues.get(j)).equalsIgnoreCase(spec))
index = j;
if (index == -1)
// did not find the file spec to be removed - nothing to do
return;
existingValues.remove(index);
// set new preference value
String newValue = toListString(existingValues.toArray(), PREF_SEPARATOR);
if (newValue == null) {
contentTypeNode.remove(key);
} else {
contentTypeNode.put(key, newValue);
}
// We do not call flush here it will be call in the perform OK.
//contentTypeNode.flush();
CModelManager.getDefault().contentTypeChanged(newContentTypeChangeEvent(contentType, context));
}
}
private static final String CONTENT_TYPE_PREF_NODE = "content-types"; //$NON-NLS-1$
private static final String FULLPATH_CONTENT_TYPE_PREF_NODE = Platform.PI_RUNTIME + IPath.SEPARATOR + CONTENT_TYPE_PREF_NODE;
private static final String PREF_LOCAL_CONTENT_TYPE_SETTINGS = "enabled"; //$NON-NLS-1$
private final static String PREF_FILE_EXTENSIONS = "file-extensions"; //$NON-NLS-1$
private final static String PREF_FILE_NAMES = "file-names"; //$NON-NLS-1$
private final static String PREF_SEPARATOR = ","; //$NON-NLS-1$
private static final Preferences PROJECT_SCOPE = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
//private static final InstanceScope INSTANCE_SCOPE = new InstanceScope();
protected Button fUseWorkspace;
protected Button fUseProject;
protected CFileTypesPreferenceBlock fPrefsBlock;
public CFileTypesPropertyPage(){
super();
noDefaultAndApplyButton();
}
/* (non-Javadoc)
@ -62,33 +181,41 @@ public class CFileTypesPropertyPage extends PropertyPage {
fUseWorkspace.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useWorkspaceSettings")); //$NON-NLS-1$
fUseWorkspace.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
fPrefsBlock.setResolver(getResolverModel().getResolver());
fPrefsBlock.setEnabled(false);
if (fUseWorkspace.getSelection()) {
fPrefsBlock.setInput(null);
fPrefsBlock.setEnabled(false);
}
}
});
final IProject project = getProject();
boolean custom = isProjectSpecificContentType(project.getName());
fUseProject = new Button(radioPane, SWT.RADIO);
fUseProject.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useProjectSettings")); //$NON-NLS-1$
fUseProject.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
fPrefsBlock.setResolver(fResolver);
fPrefsBlock.setEnabled(true);
if (fUseProject.getSelection()) {
if (isProjectSpecificContentType(project.getName())) {
fPrefsBlock.setInput(project);
} else {
fPrefsBlock.setInputWithCopy(project);
}
fPrefsBlock.setEnabled(true);
}
}
});
// Resolver block
IProject project = getProject();
IResolverModel model = getResolverModel();
fResolver = model.getResolver(project);
boolean custom = model.hasCustomResolver(project);
Composite blockPane = new Composite(topPane, SWT.NONE);
blockPane.setLayout(new GridLayout());
blockPane.setLayoutData(new GridData(GridData.FILL_BOTH));
fPrefsBlock = new CFileTypesPreferenceBlock(fResolver);
if (custom) {
fPrefsBlock = new FixCFileTypesPreferenceBlock(project);
} else {
fPrefsBlock = new FixCFileTypesPreferenceBlock();
}
fPrefsBlock.createControl(blockPane);
@ -106,7 +233,7 @@ public class CFileTypesPropertyPage extends PropertyPage {
protected void performDefaults() {
fUseWorkspace.setSelection(true);
fUseProject.setSelection(false);
fPrefsBlock.setResolver(getResolverModel().getResolver());
fPrefsBlock.setInput(null);
fPrefsBlock.setEnabled(false);
super.performDefaults();
}
@ -118,16 +245,34 @@ public class CFileTypesPropertyPage extends PropertyPage {
if (fUseProject.getSelection()) {
IProject project = getProject();
IResolverModel model = getResolverModel();
ICFileTypeResolver workingCopy = fPrefsBlock.getResolverWorkingCopy();
if (fPrefsBlock.performOk()) {
model.createCustomResolver(project, workingCopy);
ProjectScope projectScope = new ProjectScope(project);
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
if (! isProjectSpecificContentType(project.getName())) {
// enable project-specific settings for this project
contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, true);
// Copy the InstanceScope information to the projectScope
copyInstanceToProjectScope(project);
}
fPrefsBlock.performOk();
try {
contentTypePrefs.flush();
} catch (BackingStoreException e) {
// ignore ??
}
} else if (fUseWorkspace.getSelection()) {
IProject project = getProject();
IResolverModel model = getResolverModel();
if (model.hasCustomResolver(project)) {
model.removeCustomResolver(project);
if (isProjectSpecificContentType(project.getName())) {
// ProjectScope projectScope = new ProjectScope(project);
// Preferences contentTypePrefs = projectScope.getNode(FULLPATN_CONTENT_TYPE_PREF_NODE);
// // enable project-specific settings for this project
// contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
// try {
// contentTypePrefs.flush();
// } catch (BackingStoreException e) {
// // ignore ??
// }
clearSpecs(project);
}
}
return super.performOk();
@ -137,15 +282,124 @@ public class CFileTypesPropertyPage extends PropertyPage {
Object element = getElement();
IProject project = null;
if ((null != element) && (element instanceof IProject)) {
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project= (IProject) ((IAdaptable)element).getAdapter(IProject.class);
}
return project;
}
protected IResolverModel getResolverModel() {
return CCorePlugin.getDefault().getResolverModel();
protected static boolean isProjectSpecificContentType(String projectName) {
try {
// be careful looking up for our node so not to create any nodes as side effect
Preferences node = PROJECT_SCOPE;
//TODO once bug 90500 is fixed, should be simpler
// for now, take the long way
if (!node.nodeExists(projectName))
return false;
node = node.node(projectName);
if (!node.nodeExists(Platform.PI_RUNTIME))
return false;
node = node.node(Platform.PI_RUNTIME);
if (!node.nodeExists(CONTENT_TYPE_PREF_NODE))
return false;
node = node.node(CONTENT_TYPE_PREF_NODE);
return node.getBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
} catch (BackingStoreException e) {
// exception treated when retrieving the project preferences
}
return false;
}
void clearSpecs(IProject project) {
IScopeContext projectScope = new ProjectScope(project);
// Calculate the events to tell the clients of changes
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType[] ctypes = manager.getAllContentTypes();
ArrayList list = new ArrayList(ctypes.length);
for (int i = 0; i < ctypes.length; i++) {
IContentType ctype = ctypes[i];
try {
IContentTypeSettings projectSettings = ctype.getSettings(projectScope);
String[] globalSpecs = ctypes[i].getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
String[] projectSpecs = projectSettings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
if (isSpecsChanged(globalSpecs, projectSpecs)) {
list.add(ctype);
} else {
globalSpecs = ctypes[i].getFileSpecs(IContentType.FILE_NAME_SPEC);
projectSpecs = projectSettings.getFileSpecs(IContentType.FILE_NAME_SPEC);
if (isSpecsChanged(globalSpecs, projectSpecs)) {
list.add(ctype);
}
}
} catch (CoreException e) {
// ignore ?
}
}
// Delete the "content-type" node.
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
try {
Preferences parent = contentTypePrefs.parent();
contentTypePrefs.removeNode();
parent.flush();
} catch (BackingStoreException e) {
// ignore ??
} catch (IllegalStateException e) {
e.printStackTrace();
}
// fire the events
for (int i = 0; i < list.size(); ++i) {
IContentType source = (IContentType)list.get(i);
IContentTypeManager.ContentTypeChangeEvent event = new IContentTypeManager.ContentTypeChangeEvent(source, projectScope);
CModelManager.getDefault().contentTypeChanged(event);
}
}
boolean isSpecsChanged(String[] newSpecs, String[] oldSpecs) {
if (newSpecs.length != oldSpecs.length) {
return true;
}
for (int i = 0; i < newSpecs.length; ++i) {
String newSpec = newSpecs[i];
boolean found = false;
for (int j = 0; j < oldSpecs.length; ++j) {
String oldSpec = oldSpecs[j];
if (newSpec.equalsIgnoreCase(oldSpec)) {
found = true;
break;
}
}
if (!found) {
return true;
}
}
return false;
}
void copyInstanceToProjectScope(IProject project) {
IScopeContext projectScope = new ProjectScope(project);
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType[] globalTypes = manager.getAllContentTypes();
for (int i = 0; i < globalTypes.length; i++) {
IContentType globalType = globalTypes[i];
try {
IContentTypeSettings settings = globalType.getSettings(projectScope);
String[] specs = globalType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
for (int j = 0; j < specs.length; j++) {
settings.addFileSpec(specs[j], IContentType.FILE_EXTENSION_SPEC);
}
specs = globalType.getFileSpecs(IContentType.FILE_NAME_SPEC);
for (int j = 0; j < specs.length; j++) {
settings.addFileSpec(specs[j], IContentType.FILE_NAME_SPEC);
}
} catch (CoreException e) {
// ignore ?
}
}
}
}

View file

@ -143,7 +143,9 @@ CFileTypesPreferenceBlock.New...=New...
CFileTypesPreferenceBlock.Remove=Remove
CFileTypesPreferencePage.colTitlePattern=Filename
CFileTypesPreferencePage.colTitleDescription=Description
CFileTypesPreferencePage.colTitleLanguage=Language
CFileTypesPreferencePage.colTitleStatus=Status
CFileTypesPreferencePage.userDefined=User Defined
CFileTypesPreferencePage.preDefined=Locked
CFileTypesPropertyPage.useWorkspaceSettings=Use workspace settings
CFileTypesPropertyPage.useProjectSettings=Use project settings

View file

@ -18,8 +18,6 @@ import java.util.LinkedList;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.cdt.core.formatter.CodeFormatterConstants;
import org.eclipse.cdt.core.model.CoreModel;
@ -134,16 +132,14 @@ public class CFormattingStrategy extends ContextBasedFormattingStrategy {
if(null != activeFile) {
IProject currentProject = activeFile.getProject();
Assert.isNotNull(currentProject);
String filename = activeFile.getFullPath().lastSegment();
// pick the language
if (CoreModel.hasCCNature(currentProject)) {
if (CoreModel.isValidCXXHeaderUnitName(currentProject, filename)
|| CoreModel.isValidCXXSourceUnitName(currentProject, filename)) {
language = ParserLanguage.CPP;
} else {
// for C project try to guess.
ICFileType type = CCorePlugin.getDefault().getFileType(currentProject,
activeFile.getFullPath().lastSegment());
String lid = type.getLanguage().getId();
if(lid != null && lid.equals(ICFileTypeConstants.LANG_C))
language = ParserLanguage.C;
language = ParserLanguage.C;
}
preferences= new HashMap(CoreModel.getDefault().create(
activeFile.getProject()).getOptions(true));

View file

@ -15,8 +15,6 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.search.BasicSearchMatch;
@ -37,11 +35,10 @@ public class SearchCompletionContributor implements ICompletionContributor {
IWorkingCopy workingCopy, ASTCompletionNode completionNode,
List proposals)
{
ICFileType fileType = CCorePlugin.getDefault().getFileType(workingCopy.getCProject().getProject(), workingCopy.getElementName());
// and only for C source files
if (fileType.isHeader() || ! fileType.getLanguage().getId().equals(ICFileTypeConstants.LANG_C))
return;
if (workingCopy.isHeaderUnit() || !workingCopy.isCLanguage()) {
return;
}
if (completionNode != null) {
IASTName[] names = completionNode.getNames();
for (int i = 0; i < names.length; i++) {