mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56: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:
parent
579397f2af
commit
18d3837fe0
12 changed files with 685 additions and 172 deletions
|
@ -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
|
2005-06-08 Vladimir Hirsl
|
||||||
Fix for NPE in CPElement.java
|
Fix for NPE in CPElement.java
|
||||||
|
|
||||||
|
|
|
@ -522,19 +522,23 @@
|
||||||
<editor
|
<editor
|
||||||
default="true"
|
default="true"
|
||||||
name="%CEditor.name"
|
name="%CEditor.name"
|
||||||
extensions="c,C,cc,cpp,cxx,h,hh,hpp"
|
|
||||||
icon="icons/obj16/c_file_obj.gif"
|
icon="icons/obj16/c_file_obj.gif"
|
||||||
class="org.eclipse.cdt.internal.ui.editor.CEditor"
|
class="org.eclipse.cdt.internal.ui.editor.CEditor"
|
||||||
contributorClass="org.eclipse.cdt.internal.ui.editor.CEditorActionContributor"
|
contributorClass="org.eclipse.cdt.internal.ui.editor.CEditorActionContributor"
|
||||||
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
|
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
|
||||||
id="org.eclipse.cdt.ui.editor.CEditor">
|
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>
|
||||||
<editor
|
<editor
|
||||||
name="%AsmEditor.name"
|
name="%AsmEditor.name"
|
||||||
extensions="s,asm,S"
|
|
||||||
icon="icons/obj16/s_file_obj.gif"
|
icon="icons/obj16/s_file_obj.gif"
|
||||||
class="org.eclipse.cdt.internal.ui.editor.asm.AsmTextEditor"
|
class="org.eclipse.cdt.internal.ui.editor.asm.AsmTextEditor"
|
||||||
id="org.eclipse.cdt.ui.editor.asm.AsmEditor">
|
id="org.eclipse.cdt.ui.editor.asm.AsmEditor">
|
||||||
|
<contentTypeBinding contentTypeId="org.eclipse.cdt.core.asmSource"/>
|
||||||
</editor>
|
</editor>
|
||||||
<editor
|
<editor
|
||||||
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
|
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
|
||||||
|
@ -738,7 +742,6 @@
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.compare.structureCreators">
|
point="org.eclipse.compare.structureCreators">
|
||||||
<structureCreator
|
<structureCreator
|
||||||
extensions="c,cc,cpp,cxx,h,hpp"
|
|
||||||
class="org.eclipse.cdt.internal.ui.compare.CStructureCreator"
|
class="org.eclipse.cdt.internal.ui.compare.CStructureCreator"
|
||||||
id="org.eclipse.cdt.ui.compare.CStructureCreator">
|
id="org.eclipse.cdt.ui.compare.CStructureCreator">
|
||||||
</structureCreator>
|
</structureCreator>
|
||||||
|
@ -762,7 +765,6 @@
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.compare.contentMergeViewers">
|
point="org.eclipse.compare.contentMergeViewers">
|
||||||
<viewer
|
<viewer
|
||||||
extensions="c,cc,cpp,cxx,h,c2,hpp"
|
|
||||||
class="org.eclipse.cdt.internal.ui.compare.CContentViewerCreator"
|
class="org.eclipse.cdt.internal.ui.compare.CContentViewerCreator"
|
||||||
id="org.eclipse.cdt.ui.compare.CContentViewerCreator">
|
id="org.eclipse.cdt.ui.compare.CContentViewerCreator">
|
||||||
</viewer>
|
</viewer>
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class CFileElementWorkingCopy extends WorkingCopy {
|
||||||
* Creates a working copy of this element
|
* Creates a working copy of this element
|
||||||
*/
|
*/
|
||||||
public CFileElementWorkingCopy(ITranslationUnit unit) throws CoreException {
|
public CFileElementWorkingCopy(ITranslationUnit unit) throws CoreException {
|
||||||
super(unit.getParent(), unit.getPath(), null);
|
super(unit.getParent(), unit.getPath(), unit.getContentTypeId(), null);
|
||||||
this.unit = unit;
|
this.unit = unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.CCorePreferenceConstants;
|
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.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.Preferences;
|
import org.eclipse.core.runtime.Preferences;
|
||||||
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
import org.eclipse.jface.action.IMenuManager;
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
import org.eclipse.jface.action.IStatusLineManager;
|
import org.eclipse.jface.action.IStatusLineManager;
|
||||||
|
@ -606,8 +606,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
if (originalElement instanceof IFileEditorInput) {
|
if (originalElement instanceof IFileEditorInput) {
|
||||||
IFile file= ((IFileEditorInput) originalElement).getFile();
|
IFile file= ((IFileEditorInput) originalElement).getFile();
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
|
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName());
|
||||||
oldLanguage = type.getLanguage().getId();
|
if (type != null) {
|
||||||
|
oldLanguage = type.getId();
|
||||||
|
}
|
||||||
if (oldLanguage == null) {
|
if (oldLanguage == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -618,8 +620,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
if (movedElement instanceof IFileEditorInput) {
|
if (movedElement instanceof IFileEditorInput) {
|
||||||
IFile file = ((IFileEditorInput) movedElement).getFile();
|
IFile file = ((IFileEditorInput) movedElement).getFile();
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
|
IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName());
|
||||||
newLanguage = type.getLanguage().getId();
|
if (type != null) {
|
||||||
|
newLanguage = type.getId();
|
||||||
|
}
|
||||||
if (newLanguage == null) {
|
if (newLanguage == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,9 +10,12 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.preferences;
|
package org.eclipse.cdt.internal.ui.preferences;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import java.util.ArrayList;
|
||||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
|
||||||
import org.eclipse.cdt.core.filetype.IResolverModel;
|
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.Dialog;
|
||||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
|
@ -29,7 +32,7 @@ import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
public class CFileTypeDialog extends Dialog {
|
public class CFileTypeDialog extends Dialog {
|
||||||
|
|
||||||
public CFileTypeDialog(Shell parentShell) {
|
public CFileTypeDialog(Shell parentShell) {
|
||||||
super(parentShell);
|
super(parentShell);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +41,7 @@ public class CFileTypeDialog extends Dialog {
|
||||||
private Combo fComboType;
|
private Combo fComboType;
|
||||||
|
|
||||||
private String fPattern;
|
private String fPattern;
|
||||||
private ICFileType fType;
|
private IContentType fType;
|
||||||
|
|
||||||
protected void configureShell(Shell newShell) {
|
protected void configureShell(Shell newShell) {
|
||||||
super.configureShell(newShell);
|
super.configureShell(newShell);
|
||||||
|
@ -99,23 +102,30 @@ public class CFileTypeDialog extends Dialog {
|
||||||
return fPattern;
|
return fPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(ICFileType type) {
|
public IContentType getContentType() {
|
||||||
fType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICFileType getType() {
|
|
||||||
return fType;
|
return fType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateTypesCombo() {
|
private void populateTypesCombo() {
|
||||||
ICFileType[] types = getResolverModel().getFileTypes();
|
IContentTypeManager manager = Platform.getContentTypeManager();
|
||||||
int index = -1;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < types.length; i++) {
|
IContentType[] ctypes = new IContentType[list.size()];
|
||||||
fComboType.add(types[i].getName());
|
list.toArray(ctypes);
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < ctypes.length; i++) {
|
||||||
|
fComboType.add(ctypes[i].getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
fComboType.setData(types);
|
fComboType.setData(ctypes);
|
||||||
|
|
||||||
if (null != fType) {
|
if (null != fType) {
|
||||||
index = fComboType.indexOf(fType.getName());
|
index = fComboType.indexOf(fType.getName());
|
||||||
|
@ -124,10 +134,6 @@ public class CFileTypeDialog extends Dialog {
|
||||||
fComboType.select((index < 0) ? 0 : index);
|
fComboType.select((index < 0) ? 0 : index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResolverModel getResolverModel() {
|
|
||||||
return CCorePlugin.getDefault().getResolverModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
Button getOkayButton() {
|
Button getOkayButton() {
|
||||||
return getButton(IDialogConstants.OK_ID);
|
return getButton(IDialogConstants.OK_ID);
|
||||||
}
|
}
|
||||||
|
@ -136,21 +142,20 @@ public class CFileTypeDialog extends Dialog {
|
||||||
return fTextPattern.getText().trim();
|
return fTextPattern.getText().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICFileType getTypeFromControl() {
|
private IContentType getTypeFromControl() {
|
||||||
String typeId = null;
|
IContentType type = null;
|
||||||
int index = fComboType.getSelectionIndex();
|
int index = fComboType.getSelectionIndex();
|
||||||
|
|
||||||
if (-1 != index) {
|
if (-1 != index) {
|
||||||
String name = fComboType.getItem(index);
|
String name = fComboType.getItem(index);
|
||||||
ICFileType[] types = (ICFileType[]) fComboType.getData();
|
IContentType[] types = (IContentType[]) fComboType.getData();
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
if (name.equals(types[i].getName())) {
|
if (name.equals(types[i].getName())) {
|
||||||
typeId = types[i].getId();
|
type = types[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return type;
|
||||||
return getResolverModel().getFileTypeById(typeId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void okPressed() {
|
protected void okPressed() {
|
||||||
|
|
|
@ -12,13 +12,19 @@ package org.eclipse.cdt.internal.ui.preferences;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
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.internal.ui.util.PixelConverter;
|
import org.eclipse.cdt.internal.ui.util.PixelConverter;
|
||||||
import org.eclipse.cdt.internal.ui.util.SWTUtil;
|
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.util.ListenerList;
|
||||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||||
import org.eclipse.jface.viewers.ILabelProvider;
|
import org.eclipse.jface.viewers.ILabelProvider;
|
||||||
|
@ -53,22 +59,23 @@ public class CFileTypesPreferenceBlock {
|
||||||
|
|
||||||
private static final int COL_PATTERN = 0;
|
private static final int COL_PATTERN = 0;
|
||||||
private static final int COL_DESCRIPTION = 1;
|
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 TableViewer fAssocViewer;
|
||||||
private Button fBtnNew;
|
private Button fBtnNew;
|
||||||
private Button fBtnRemove;
|
private Button fBtnRemove;
|
||||||
|
|
||||||
private class AssocSorter extends ViewerSorter {
|
private class AssocSorter extends ViewerSorter {
|
||||||
public int category(Object element) {
|
public int category(Object element) {
|
||||||
if (element instanceof ICFileTypeAssociation) {
|
if (element instanceof CFileTypeAssociation) {
|
||||||
ICFileTypeAssociation assoc = (ICFileTypeAssociation) element;
|
CFileTypeAssociation assoc = (CFileTypeAssociation) element;
|
||||||
if (-1 != assoc.getPattern().indexOf('*')) {
|
if (assoc.isExtSpec()) {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
return 20;
|
return 20;
|
||||||
|
@ -78,7 +85,7 @@ public class CFileTypesPreferenceBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AssocContentProvider implements IStructuredContentProvider {
|
private class AssocContentProvider implements IStructuredContentProvider {
|
||||||
ICFileTypeAssociation[] assocs;
|
CFileTypeAssociation[] assocs;
|
||||||
|
|
||||||
public Object[] getElements(Object inputElement) {
|
public Object[] getElements(Object inputElement) {
|
||||||
return assocs;
|
return assocs;
|
||||||
|
@ -89,8 +96,8 @@ public class CFileTypesPreferenceBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
if (newInput instanceof ICFileTypeAssociation[]) {
|
if (newInput instanceof CFileTypeAssociation[]) {
|
||||||
assocs = (ICFileTypeAssociation[]) newInput;
|
assocs = (CFileTypeAssociation[]) newInput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,9 +106,8 @@ public class CFileTypesPreferenceBlock {
|
||||||
private ListenerList listeners = new ListenerList();
|
private ListenerList listeners = new ListenerList();
|
||||||
|
|
||||||
public Image getColumnImage(Object element, int columnIndex) {
|
public Image getColumnImage(Object element, int columnIndex) {
|
||||||
if (element instanceof ICFileTypeAssociation) {
|
if (element instanceof CFileTypeAssociation) {
|
||||||
if (COL_PATTERN == columnIndex) {
|
if (COL_PATTERN == columnIndex) {
|
||||||
// TODO: add image support to table
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,17 +115,22 @@ public class CFileTypesPreferenceBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnText(Object element, int columnIndex) {
|
public String getColumnText(Object element, int columnIndex) {
|
||||||
if (element instanceof ICFileTypeAssociation) {
|
if (element instanceof CFileTypeAssociation) {
|
||||||
ICFileTypeAssociation assoc = (ICFileTypeAssociation) element;
|
CFileTypeAssociation assoc = (CFileTypeAssociation) element;
|
||||||
switch (columnIndex) {
|
switch (columnIndex) {
|
||||||
case COL_PATTERN:
|
case COL_PATTERN:
|
||||||
return assoc.getPattern();
|
return assoc.getPattern();
|
||||||
|
|
||||||
case COL_DESCRIPTION:
|
case COL_DESCRIPTION:
|
||||||
return assoc.getType().getName();
|
return assoc.getDescription();
|
||||||
|
|
||||||
case COL_LANGUAGE:
|
case COL_STATUS:
|
||||||
return assoc.getType().getLanguage().getName();
|
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();
|
return element.toString();
|
||||||
|
@ -151,11 +162,15 @@ public class CFileTypesPreferenceBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CFileTypesPreferenceBlock(ICFileTypeResolver input) {
|
public CFileTypesPreferenceBlock() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CFileTypesPreferenceBlock(IProject input) {
|
||||||
fAddAssoc = new ArrayList();
|
fAddAssoc = new ArrayList();
|
||||||
fRemoveAssoc = new ArrayList();
|
fRemoveAssoc = new ArrayList();
|
||||||
setResolver(input);
|
fInput = input;
|
||||||
setDirty(false);
|
setDirty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +223,7 @@ public class CFileTypesPreferenceBlock {
|
||||||
col.setText(PreferencesMessages.getString("CFileTypesPreferencePage.colTitleDescription")); //$NON-NLS-1$
|
col.setText(PreferencesMessages.getString("CFileTypesPreferencePage.colTitleDescription")); //$NON-NLS-1$
|
||||||
|
|
||||||
col = new TableColumn(table, SWT.LEFT);
|
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
|
// Create the button pane
|
||||||
|
|
||||||
|
@ -260,7 +275,7 @@ public class CFileTypesPreferenceBlock {
|
||||||
fAssocViewer.setSorter(new AssocSorter());
|
fAssocViewer.setSorter(new AssocSorter());
|
||||||
fAssocViewer.setContentProvider(new AssocContentProvider());
|
fAssocViewer.setContentProvider(new AssocContentProvider());
|
||||||
fAssocViewer.setLabelProvider(new AssocLabelProvider());
|
fAssocViewer.setLabelProvider(new AssocLabelProvider());
|
||||||
fAssocViewer.setInput(getResolverWorkingCopy().getFileTypeAssociations());
|
fAssocViewer.setInput(getCFileTypeAssociations());
|
||||||
|
|
||||||
fAssocViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
fAssocViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||||
public void selectionChanged(SelectionChangedEvent event) {
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
|
@ -280,25 +295,32 @@ public class CFileTypesPreferenceBlock {
|
||||||
setDirty(enabled);
|
setDirty(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResolver(ICFileTypeResolver resolver) {
|
public void setInput(IProject input) {
|
||||||
fAddAssoc.clear();
|
fAddAssoc.clear();
|
||||||
fRemoveAssoc.clear();
|
fRemoveAssoc.clear();
|
||||||
fResolverWorkingCopy = resolver.createWorkingCopy();
|
fInput = input;
|
||||||
if (null != fAssocViewer) {
|
if (null != fAssocViewer) {
|
||||||
fAssocViewer.setInput(fResolverWorkingCopy.getFileTypeAssociations());
|
fAssocViewer.setInput(getCFileTypeAssociations());
|
||||||
}
|
}
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICFileTypeResolver getResolverWorkingCopy() {
|
public void setInputWithCopy(IProject input) {
|
||||||
return fResolverWorkingCopy;
|
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;
|
fDirty = dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirty() {
|
private boolean isDirty() {
|
||||||
return fDirty;
|
return fDirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,36 +328,165 @@ public class CFileTypesPreferenceBlock {
|
||||||
boolean changed = fDirty;
|
boolean changed = fDirty;
|
||||||
|
|
||||||
if (fDirty) {
|
if (fDirty) {
|
||||||
ICFileTypeAssociation[] add = (ICFileTypeAssociation[]) fAddAssoc.toArray(new ICFileTypeAssociation[fAddAssoc.size()]);
|
CFileTypeAssociation[] add = (CFileTypeAssociation[]) fAddAssoc.toArray(new CFileTypeAssociation[fAddAssoc.size()]);
|
||||||
ICFileTypeAssociation[] rem = (ICFileTypeAssociation[]) fRemoveAssoc.toArray(new ICFileTypeAssociation[fRemoveAssoc.size()]);
|
CFileTypeAssociation[] rem = (CFileTypeAssociation[]) fRemoveAssoc.toArray(new CFileTypeAssociation[fRemoveAssoc.size()]);
|
||||||
|
|
||||||
fResolverWorkingCopy.adjustAssociations(add, rem);
|
adjustAssociations(add, rem);
|
||||||
|
|
||||||
fAddAssoc.clear();
|
fAddAssoc.clear();
|
||||||
fRemoveAssoc.clear();
|
fRemoveAssoc.clear();
|
||||||
|
|
||||||
setDirty(false);
|
setDirty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleSelectionChanged() {
|
private CFileTypeAssociation[] getCFileTypeAssociations() {
|
||||||
IStructuredSelection sel = getSelection();
|
ArrayList list = new ArrayList();
|
||||||
fBtnRemove.setEnabled(!sel.isEmpty());
|
if (fInput == null) {
|
||||||
|
fillWithUserDefinedCFileTypeAssociations(list);
|
||||||
|
fillWithPredefinedCFileTypeAssociations(list);
|
||||||
|
} else {
|
||||||
|
fillWithProjectCFileTypeAssociations(list, fInput);
|
||||||
|
}
|
||||||
|
CFileTypeAssociation[] assocs = new CFileTypeAssociation[list.size()];
|
||||||
|
list.toArray(assocs);
|
||||||
|
return assocs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResolverModel getResolverModel() {
|
private void adjustAssociations(CFileTypeAssociation[] add, CFileTypeAssociation[] rem) {
|
||||||
return CCorePlugin.getDefault().getResolverModel();
|
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();
|
||||||
|
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() {
|
protected void handleAdd() {
|
||||||
ICFileTypeAssociation assoc = null;
|
CFileTypeAssociation assoc = null;
|
||||||
|
|
||||||
CFileTypeDialog dlg = new CFileTypeDialog(fBtnNew.getParent().getShell());
|
CFileTypeDialog dlg = new CFileTypeDialog(fBtnNew.getParent().getShell());
|
||||||
|
|
||||||
if (Window.OK == dlg.open()) {
|
if (Window.OK == dlg.open()) {
|
||||||
assoc = getResolverModel().createAssocation(dlg.getPattern(), dlg.getType());
|
assoc = createAssociation(dlg.getPattern(), dlg.getContentType());
|
||||||
if (null != assoc) {
|
if (null != assoc) {
|
||||||
fAssocViewer.add(assoc);
|
fAssocViewer.add(assoc);
|
||||||
fAddAssoc.add(assoc);
|
fAddAssoc.add(assoc);
|
||||||
|
@ -349,7 +500,7 @@ public class CFileTypesPreferenceBlock {
|
||||||
IStructuredSelection sel = getSelection();
|
IStructuredSelection sel = getSelection();
|
||||||
if ((null != sel) && (!sel.isEmpty())) {
|
if ((null != sel) && (!sel.isEmpty())) {
|
||||||
for (Iterator iter = sel.iterator(); iter.hasNext();) {
|
for (Iterator iter = sel.iterator(); iter.hasNext();) {
|
||||||
ICFileTypeAssociation assoc = (ICFileTypeAssociation) iter.next();
|
CFileTypeAssociation assoc = (CFileTypeAssociation) iter.next();
|
||||||
fAssocViewer.remove(assoc);
|
fAssocViewer.remove(assoc);
|
||||||
fAddAssoc.remove(assoc);
|
fAddAssoc.remove(assoc);
|
||||||
fRemoveAssoc.add(assoc);
|
fRemoveAssoc.add(assoc);
|
||||||
|
|
|
@ -16,10 +16,6 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.runtime.Preferences;
|
import org.eclipse.core.runtime.Preferences;
|
||||||
|
@ -40,11 +36,11 @@ import org.eclipse.ui.PlatformUI;
|
||||||
public class CFileTypesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
|
public class CFileTypesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
|
||||||
|
|
||||||
private CFileTypesPreferenceBlock fPrefsBlock;
|
private CFileTypesPreferenceBlock fPrefsBlock;
|
||||||
private ICFileTypeResolver fResolver;
|
|
||||||
|
|
||||||
public CFileTypesPreferencePage() {
|
public CFileTypesPreferencePage() {
|
||||||
setDescription(PreferencesMessages.getString("CFileTypesPreferencePage.description")); //$NON-NLS-1$
|
setDescription(PreferencesMessages.getString("CFileTypesPreferencePage.description")); //$NON-NLS-1$
|
||||||
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
|
//setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
|
||||||
|
noDefaultAndApplyButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -56,8 +52,9 @@ public class CFileTypesPreferencePage extends PreferencePage implements IWorkben
|
||||||
topPane.setLayout(new GridLayout());
|
topPane.setLayout(new GridLayout());
|
||||||
topPane.setLayoutData(new GridData(GridData.FILL_BOTH));
|
topPane.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
|
|
||||||
fResolver = getResolverModel().getResolver();
|
//fResolver = getResolverModel().getResolver();
|
||||||
fPrefsBlock = new CFileTypesPreferenceBlock(fResolver);
|
// fPrefsBlock = new CFileTypesPreferenceBlock(fResolver);
|
||||||
|
fPrefsBlock = new CFileTypesPreferenceBlock(null);
|
||||||
|
|
||||||
PlatformUI.getWorkbench().getHelpSystem().setHelp( topPane, ICHelpContextIds.FILE_TYPES_PREF_PAGE );
|
PlatformUI.getWorkbench().getHelpSystem().setHelp( topPane, ICHelpContextIds.FILE_TYPES_PREF_PAGE );
|
||||||
return fPrefsBlock.createControl(topPane);
|
return fPrefsBlock.createControl(topPane);
|
||||||
|
@ -73,11 +70,10 @@ public class CFileTypesPreferencePage extends PreferencePage implements IWorkben
|
||||||
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
||||||
*/
|
*/
|
||||||
protected void performDefaults() {
|
protected void performDefaults() {
|
||||||
Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
|
// Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
|
||||||
prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_EXCLUSION);
|
// prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_EXCLUSION);
|
||||||
prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_INCLUSION);
|
// prefs.setToDefault(WorkspaceResolver.PREFS_ASSOCIATIONS_INCLUSION);
|
||||||
fPrefsBlock.setResolver(getResolverModel().getResolver());
|
// fPrefsBlock.setResolver(getResolverModel().getResolver());
|
||||||
|
|
||||||
super.performDefaults();
|
super.performDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,36 +83,36 @@ public class CFileTypesPreferencePage extends PreferencePage implements IWorkben
|
||||||
public boolean performOk() {
|
public boolean performOk() {
|
||||||
|
|
||||||
if (fPrefsBlock.performOk()) {
|
if (fPrefsBlock.performOk()) {
|
||||||
ICFileTypeAssociation[] oldAssocs = fResolver.getFileTypeAssociations();
|
// ICFileTypeAssociation[] oldAssocs = fResolver.getFileTypeAssociations();
|
||||||
|
//
|
||||||
ICFileTypeResolver workingCopy = fPrefsBlock.getResolverWorkingCopy();
|
// ICFileTypeResolver workingCopy = fPrefsBlock.getResolverWorkingCopy();
|
||||||
ICFileTypeAssociation[] newAssocs = workingCopy.getFileTypeAssociations();
|
// ICFileTypeAssociation[] newAssocs = workingCopy.getFileTypeAssociations();
|
||||||
|
//
|
||||||
// compare
|
// // compare
|
||||||
List delList = new ArrayList();
|
// List delList = new ArrayList();
|
||||||
List addList = new ArrayList();
|
// List addList = new ArrayList();
|
||||||
|
//
|
||||||
for (int i = 0; i < oldAssocs.length; i++) {
|
// for (int i = 0; i < oldAssocs.length; i++) {
|
||||||
if (Arrays.binarySearch(newAssocs, oldAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
|
// if (Arrays.binarySearch(newAssocs, oldAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
|
||||||
delList.add(oldAssocs[i]);
|
// delList.add(oldAssocs[i]);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for (int i = 0; i < newAssocs.length; i++) {
|
// for (int i = 0; i < newAssocs.length; i++) {
|
||||||
if (Arrays.binarySearch(oldAssocs, newAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
|
// if (Arrays.binarySearch(oldAssocs, newAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
|
||||||
addList.add(newAssocs[i]);
|
// addList.add(newAssocs[i]);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
ICFileTypeAssociation[] addAssocs = (ICFileTypeAssociation[]) addList.toArray(new ICFileTypeAssociation[addList.size()]);
|
// ICFileTypeAssociation[] addAssocs = (ICFileTypeAssociation[]) addList.toArray(new ICFileTypeAssociation[addList.size()]);
|
||||||
ICFileTypeAssociation[] delAssocs = (ICFileTypeAssociation[]) delList.toArray(new ICFileTypeAssociation[delList.size()]);
|
// ICFileTypeAssociation[] delAssocs = (ICFileTypeAssociation[]) delList.toArray(new ICFileTypeAssociation[delList.size()]);
|
||||||
fResolver.adjustAssociations(addAssocs, delAssocs);
|
// fResolver.adjustAssociations(addAssocs, delAssocs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.performOk();
|
return super.performOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResolverModel getResolverModel() {
|
// private IResolverModel getResolverModel() {
|
||||||
return CCorePlugin.getDefault().getResolverModel();
|
// return CCorePlugin.getDefault().getResolverModel();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,22 @@
|
||||||
package org.eclipse.cdt.internal.ui.preferences;
|
package org.eclipse.cdt.internal.ui.preferences;
|
||||||
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import java.util.ArrayList;
|
||||||
import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
|
import java.util.Arrays;
|
||||||
import org.eclipse.cdt.core.filetype.IResolverModel;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.core.resources.IProject;
|
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.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
|
@ -26,20 +37,128 @@ import org.eclipse.swt.widgets.Event;
|
||||||
import org.eclipse.swt.widgets.Listener;
|
import org.eclipse.swt.widgets.Listener;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.dialogs.PropertyPage;
|
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
|
* The preference page used for displaying/editing CDT file
|
||||||
* type associations for a project
|
* type associations for a project
|
||||||
*/
|
*/
|
||||||
public class CFileTypesPropertyPage extends PropertyPage {
|
public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
private Button fUseWorkspace;
|
/* (non-Javadoc)
|
||||||
private Button fUseProject;
|
* @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 ICFileTypeResolver fResolver;
|
*/
|
||||||
|
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;
|
protected CFileTypesPreferenceBlock fPrefsBlock;
|
||||||
|
|
||||||
public CFileTypesPropertyPage(){
|
public CFileTypesPropertyPage(){
|
||||||
super();
|
super();
|
||||||
|
noDefaultAndApplyButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -62,33 +181,41 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
fUseWorkspace.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useWorkspaceSettings")); //$NON-NLS-1$
|
fUseWorkspace.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useWorkspaceSettings")); //$NON-NLS-1$
|
||||||
fUseWorkspace.addListener(SWT.Selection, new Listener() {
|
fUseWorkspace.addListener(SWT.Selection, new Listener() {
|
||||||
public void handleEvent(Event e) {
|
public void handleEvent(Event e) {
|
||||||
fPrefsBlock.setResolver(getResolverModel().getResolver());
|
if (fUseWorkspace.getSelection()) {
|
||||||
fPrefsBlock.setEnabled(false);
|
fPrefsBlock.setInput(null);
|
||||||
|
fPrefsBlock.setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final IProject project = getProject();
|
||||||
|
boolean custom = isProjectSpecificContentType(project.getName());
|
||||||
|
|
||||||
fUseProject = new Button(radioPane, SWT.RADIO);
|
fUseProject = new Button(radioPane, SWT.RADIO);
|
||||||
fUseProject.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useProjectSettings")); //$NON-NLS-1$
|
fUseProject.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useProjectSettings")); //$NON-NLS-1$
|
||||||
fUseProject.addListener(SWT.Selection, new Listener() {
|
fUseProject.addListener(SWT.Selection, new Listener() {
|
||||||
public void handleEvent(Event e) {
|
public void handleEvent(Event e) {
|
||||||
fPrefsBlock.setResolver(fResolver);
|
if (fUseProject.getSelection()) {
|
||||||
fPrefsBlock.setEnabled(true);
|
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);
|
Composite blockPane = new Composite(topPane, SWT.NONE);
|
||||||
|
|
||||||
blockPane.setLayout(new GridLayout());
|
blockPane.setLayout(new GridLayout());
|
||||||
blockPane.setLayoutData(new GridData(GridData.FILL_BOTH));
|
blockPane.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
|
|
||||||
fPrefsBlock = new CFileTypesPreferenceBlock(fResolver);
|
if (custom) {
|
||||||
|
fPrefsBlock = new FixCFileTypesPreferenceBlock(project);
|
||||||
|
} else {
|
||||||
|
fPrefsBlock = new FixCFileTypesPreferenceBlock();
|
||||||
|
}
|
||||||
|
|
||||||
fPrefsBlock.createControl(blockPane);
|
fPrefsBlock.createControl(blockPane);
|
||||||
|
|
||||||
|
@ -106,7 +233,7 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
protected void performDefaults() {
|
protected void performDefaults() {
|
||||||
fUseWorkspace.setSelection(true);
|
fUseWorkspace.setSelection(true);
|
||||||
fUseProject.setSelection(false);
|
fUseProject.setSelection(false);
|
||||||
fPrefsBlock.setResolver(getResolverModel().getResolver());
|
fPrefsBlock.setInput(null);
|
||||||
fPrefsBlock.setEnabled(false);
|
fPrefsBlock.setEnabled(false);
|
||||||
super.performDefaults();
|
super.performDefaults();
|
||||||
}
|
}
|
||||||
|
@ -118,16 +245,34 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
if (fUseProject.getSelection()) {
|
if (fUseProject.getSelection()) {
|
||||||
IProject project = getProject();
|
IProject project = getProject();
|
||||||
IResolverModel model = getResolverModel();
|
ProjectScope projectScope = new ProjectScope(project);
|
||||||
ICFileTypeResolver workingCopy = fPrefsBlock.getResolverWorkingCopy();
|
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
|
||||||
if (fPrefsBlock.performOk()) {
|
if (! isProjectSpecificContentType(project.getName())) {
|
||||||
model.createCustomResolver(project, workingCopy);
|
// 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()) {
|
} else if (fUseWorkspace.getSelection()) {
|
||||||
IProject project = getProject();
|
IProject project = getProject();
|
||||||
IResolverModel model = getResolverModel();
|
if (isProjectSpecificContentType(project.getName())) {
|
||||||
if (model.hasCustomResolver(project)) {
|
// ProjectScope projectScope = new ProjectScope(project);
|
||||||
model.removeCustomResolver(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();
|
return super.performOk();
|
||||||
|
@ -137,15 +282,124 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
Object element = getElement();
|
Object element = getElement();
|
||||||
IProject project = null;
|
IProject project = null;
|
||||||
|
|
||||||
if ((null != element) && (element instanceof IProject)) {
|
if (element instanceof IProject) {
|
||||||
project = (IProject) element;
|
project = (IProject) element;
|
||||||
|
} else if (element instanceof IAdaptable) {
|
||||||
|
project= (IProject) ((IAdaptable)element).getAdapter(IProject.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IResolverModel getResolverModel() {
|
protected static boolean isProjectSpecificContentType(String projectName) {
|
||||||
return CCorePlugin.getDefault().getResolverModel();
|
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 ?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,9 @@ CFileTypesPreferenceBlock.New...=New...
|
||||||
CFileTypesPreferenceBlock.Remove=Remove
|
CFileTypesPreferenceBlock.Remove=Remove
|
||||||
CFileTypesPreferencePage.colTitlePattern=Filename
|
CFileTypesPreferencePage.colTitlePattern=Filename
|
||||||
CFileTypesPreferencePage.colTitleDescription=Description
|
CFileTypesPreferencePage.colTitleDescription=Description
|
||||||
CFileTypesPreferencePage.colTitleLanguage=Language
|
CFileTypesPreferencePage.colTitleStatus=Status
|
||||||
|
CFileTypesPreferencePage.userDefined=User Defined
|
||||||
|
CFileTypesPreferencePage.preDefined=Locked
|
||||||
|
|
||||||
CFileTypesPropertyPage.useWorkspaceSettings=Use workspace settings
|
CFileTypesPropertyPage.useWorkspaceSettings=Use workspace settings
|
||||||
CFileTypesPropertyPage.useProjectSettings=Use project settings
|
CFileTypesPropertyPage.useProjectSettings=Use project settings
|
||||||
|
|
|
@ -18,8 +18,6 @@ import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.CodeFormatter;
|
||||||
import org.eclipse.cdt.core.formatter.CodeFormatterConstants;
|
import org.eclipse.cdt.core.formatter.CodeFormatterConstants;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
@ -134,16 +132,14 @@ public class CFormattingStrategy extends ContextBasedFormattingStrategy {
|
||||||
if(null != activeFile) {
|
if(null != activeFile) {
|
||||||
IProject currentProject = activeFile.getProject();
|
IProject currentProject = activeFile.getProject();
|
||||||
Assert.isNotNull(currentProject);
|
Assert.isNotNull(currentProject);
|
||||||
|
String filename = activeFile.getFullPath().lastSegment();
|
||||||
// pick the language
|
// pick the language
|
||||||
if (CoreModel.hasCCNature(currentProject)) {
|
if (CoreModel.isValidCXXHeaderUnitName(currentProject, filename)
|
||||||
|
|| CoreModel.isValidCXXSourceUnitName(currentProject, filename)) {
|
||||||
language = ParserLanguage.CPP;
|
language = ParserLanguage.CPP;
|
||||||
} else {
|
} else {
|
||||||
// for C project try to guess.
|
// for C project try to guess.
|
||||||
ICFileType type = CCorePlugin.getDefault().getFileType(currentProject,
|
language = ParserLanguage.C;
|
||||||
activeFile.getFullPath().lastSegment());
|
|
||||||
String lid = type.getLanguage().getId();
|
|
||||||
if(lid != null && lid.equals(ICFileTypeConstants.LANG_C))
|
|
||||||
language = ParserLanguage.C;
|
|
||||||
}
|
}
|
||||||
preferences= new HashMap(CoreModel.getDefault().create(
|
preferences= new HashMap(CoreModel.getDefault().create(
|
||||||
activeFile.getProject()).getOptions(true));
|
activeFile.getProject()).getOptions(true));
|
||||||
|
|
|
@ -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.ASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
|
@ -37,11 +35,10 @@ public class SearchCompletionContributor implements ICompletionContributor {
|
||||||
IWorkingCopy workingCopy, ASTCompletionNode completionNode,
|
IWorkingCopy workingCopy, ASTCompletionNode completionNode,
|
||||||
List proposals)
|
List proposals)
|
||||||
{
|
{
|
||||||
ICFileType fileType = CCorePlugin.getDefault().getFileType(workingCopy.getCProject().getProject(), workingCopy.getElementName());
|
|
||||||
// and only for C source files
|
// and only for C source files
|
||||||
if (fileType.isHeader() || ! fileType.getLanguage().getId().equals(ICFileTypeConstants.LANG_C))
|
if (workingCopy.isHeaderUnit() || !workingCopy.isCLanguage()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (completionNode != null) {
|
if (completionNode != null) {
|
||||||
IASTName[] names = completionNode.getNames();
|
IASTName[] names = completionNode.getNames();
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue