mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
151850 (allow user to specify which parser/language to parse a given content type with)
Patch from Jason Montojo
This commit is contained in:
parent
696e4d156f
commit
e129ae7c03
19 changed files with 1391 additions and 442 deletions
|
@ -17,9 +17,12 @@ import junit.framework.Test;
|
|||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.CContentTypes;
|
||||
|
@ -43,6 +46,7 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
private ILanguage fLanguage2;
|
||||
|
||||
private IProject fProject;
|
||||
private ICConfigurationDescription fConfiguration;
|
||||
|
||||
public static Test suite() {
|
||||
return suite(LanguageInheritanceTests.class);
|
||||
|
@ -51,10 +55,12 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
protected void setUp() throws Exception {
|
||||
String name = getClass().getName() + "_" + getName();
|
||||
fCProject = CProjectHelper.createCCProject(name , BIN_FOLDER, IPDOMManager.ID_NO_INDEXER);
|
||||
|
||||
fProject = fCProject.getProject();
|
||||
fFile = fProject.getFile(FILE_NAME);
|
||||
|
||||
ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(fProject, false);
|
||||
fConfiguration = projectDescription.getActiveConfiguration();
|
||||
|
||||
fManager = LanguageManager.getInstance();
|
||||
fLanguage1 = fManager.getLanguage(GPPLanguage.ID);
|
||||
fLanguage2 = fManager.getLanguage(GCCLanguage.ID);
|
||||
|
@ -70,41 +76,41 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
public void testDirectFileMapping() throws Exception {
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile);
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile, fConfiguration);
|
||||
assertDifferentLanguages(originalLanguage, fLanguage1);
|
||||
|
||||
ProjectLanguageConfiguration config = fManager.getLanguageConfiguration(fCProject.getProject());
|
||||
config.addFileMapping(fFile, GPPLanguage.ID);
|
||||
config.addFileMapping(fConfiguration, fFile, GPPLanguage.ID);
|
||||
fManager.storeLanguageMappingConfiguration(fFile);
|
||||
|
||||
assertSameLanguage(fLanguage1, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(fLanguage1, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
|
||||
config.removeFileMapping(fFile);
|
||||
config.removeFileMapping(fConfiguration, fFile);
|
||||
fManager.storeLanguageMappingConfiguration(fFile);
|
||||
|
||||
assertSameLanguage(originalLanguage, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(originalLanguage, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
}
|
||||
|
||||
public void testDirectProjectContentTypeMapping() throws Exception {
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile);
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile, fConfiguration);
|
||||
assertDifferentLanguages(originalLanguage, fLanguage1);
|
||||
|
||||
String filename = fFile.getLocation().toString();
|
||||
IContentType contentType = CContentTypes.getContentType(fProject, filename);
|
||||
ProjectLanguageConfiguration config = fManager.getLanguageConfiguration(fCProject.getProject());
|
||||
config.addContentTypeMapping(contentType.getId(), GPPLanguage.ID);
|
||||
config.addContentTypeMapping(fConfiguration, contentType.getId(), GPPLanguage.ID);
|
||||
fManager.storeLanguageMappingConfiguration(fProject, EMPTY_CONTENT_TYPES);
|
||||
|
||||
assertSameLanguage(fLanguage1, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(fLanguage1, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
|
||||
config.removeContentTypeMapping(contentType.getId());
|
||||
config.removeContentTypeMapping(fConfiguration, contentType.getId());
|
||||
fManager.storeLanguageMappingConfiguration(fFile);
|
||||
|
||||
assertSameLanguage(originalLanguage, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(originalLanguage, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
}
|
||||
|
||||
public void testDirectWorkspaceContentTypeMapping() throws Exception {
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile);
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile, fConfiguration);
|
||||
assertDifferentLanguages(originalLanguage, fLanguage1);
|
||||
|
||||
String filename = fFile.getLocation().toString();
|
||||
|
@ -113,16 +119,16 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
config.addWorkspaceMapping(contentType.getId(), GPPLanguage.ID);
|
||||
fManager.storeWorkspaceLanguageConfiguration(EMPTY_CONTENT_TYPES);
|
||||
|
||||
assertEquals(fLanguage1, fManager.getLanguageForFile(fFile));
|
||||
assertEquals(fLanguage1, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
|
||||
config.removeWorkspaceMapping(contentType.getId());
|
||||
fManager.storeLanguageMappingConfiguration(fFile);
|
||||
|
||||
assertEquals(originalLanguage, fManager.getLanguageForFile(fFile));
|
||||
assertEquals(originalLanguage, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
}
|
||||
|
||||
public void testOverriddenWorkspaceContentTypeMapping1() throws Exception {
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile);
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile, fConfiguration);
|
||||
assertDifferentLanguages(originalLanguage, fLanguage1);
|
||||
|
||||
String filename = fFile.getLocation().toString();
|
||||
|
@ -135,14 +141,14 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
|
||||
// Override with project mapping
|
||||
ProjectLanguageConfiguration config2 = fManager.getLanguageConfiguration(fCProject.getProject());
|
||||
config2.addContentTypeMapping(contentType.getId(), GCCLanguage.ID);
|
||||
config2.addContentTypeMapping(fConfiguration, contentType.getId(), GCCLanguage.ID);
|
||||
fManager.storeLanguageMappingConfiguration(fProject, EMPTY_CONTENT_TYPES);
|
||||
|
||||
assertSameLanguage(fLanguage2, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(fLanguage2, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
}
|
||||
|
||||
public void testOverriddenWorkspaceContentTypeMapping2() throws Exception {
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile);
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile, fConfiguration);
|
||||
assertDifferentLanguages(originalLanguage, fLanguage1);
|
||||
|
||||
String filename = fFile.getLocation().toString();
|
||||
|
@ -155,14 +161,14 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
|
||||
// Override with file mapping
|
||||
ProjectLanguageConfiguration config2 = fManager.getLanguageConfiguration(fCProject.getProject());
|
||||
config2.addFileMapping(fFile, GCCLanguage.ID);
|
||||
config2.addFileMapping(fConfiguration, fFile, GCCLanguage.ID);
|
||||
fManager.storeLanguageMappingConfiguration(fFile);
|
||||
|
||||
assertSameLanguage(fLanguage2, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(fLanguage2, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
}
|
||||
|
||||
public void testOverriddenProjectContentTypeMapping() throws Exception {
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile);
|
||||
ILanguage originalLanguage = fManager.getLanguageForFile(fFile, fConfiguration);
|
||||
assertDifferentLanguages(originalLanguage, fLanguage1);
|
||||
|
||||
String filename = fFile.getLocation().toString();
|
||||
|
@ -170,15 +176,15 @@ public class LanguageInheritanceTests extends BaseTestCase {
|
|||
|
||||
// Set project mapping
|
||||
ProjectLanguageConfiguration config = fManager.getLanguageConfiguration(fCProject.getProject());
|
||||
config.addContentTypeMapping(contentType.getId(), GPPLanguage.ID);
|
||||
config.addContentTypeMapping(fConfiguration, contentType.getId(), GPPLanguage.ID);
|
||||
fManager.storeLanguageMappingConfiguration(fProject, EMPTY_CONTENT_TYPES);
|
||||
|
||||
// Override with file mapping
|
||||
ProjectLanguageConfiguration config2 = fManager.getLanguageConfiguration(fCProject.getProject());
|
||||
config2.addFileMapping(fFile, GCCLanguage.ID);
|
||||
config2.addFileMapping(fConfiguration, fFile, GCCLanguage.ID);
|
||||
fManager.storeLanguageMappingConfiguration(fFile);
|
||||
|
||||
assertSameLanguage(fLanguage2, fManager.getLanguageForFile(fFile));
|
||||
assertSameLanguage(fLanguage2, fManager.getLanguageForFile(fFile, fConfiguration));
|
||||
}
|
||||
|
||||
protected void assertSameLanguage(ILanguage expected, ILanguage actual) {
|
||||
|
|
|
@ -29,9 +29,11 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
|
@ -78,7 +80,9 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
ICProject cproject = strategy.getCProject();
|
||||
IASTTranslationUnit ast = strategy.getAst();
|
||||
try {
|
||||
language = LanguageManager.getInstance().getLanguageForFile(strategy.getAst().getFilePath(), cproject.getProject());
|
||||
IProject project = cproject.getProject();
|
||||
ICConfigurationDescription configuration = CoreModel.getDefault().getProjectDescription(project, false).getActiveConfiguration();
|
||||
language = LanguageManager.getInstance().getLanguageForFile(strategy.getAst().getFilePath(), project, configuration);
|
||||
} catch (CoreException e) {
|
||||
fail("Unexpected exception while getting language for file.");
|
||||
}
|
||||
|
@ -127,7 +131,9 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
ICProject cproject = strategy.getCProject();
|
||||
IASTTranslationUnit ast = strategy.getAst();
|
||||
try {
|
||||
language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), cproject.getProject());
|
||||
IProject project = cproject.getProject();
|
||||
ICConfigurationDescription configuration = CoreModel.getDefault().getProjectDescription(project, false).getActiveConfiguration();
|
||||
language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), project, configuration);
|
||||
} catch (CoreException e) {
|
||||
fail("Unexpected exception while getting language for file.");
|
||||
}
|
||||
|
|
|
@ -11,9 +11,12 @@
|
|||
package org.eclipse.cdt.core.language;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
|
@ -29,138 +32,246 @@ import org.eclipse.core.resources.IFile;
|
|||
* @since 4.0
|
||||
*/
|
||||
public class ProjectLanguageConfiguration {
|
||||
private static final String ALL_CONFIGURATIONS = ""; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Project-wide content type mappings (Configuration ID -> (Content Type ID -> Language ID)).
|
||||
*/
|
||||
private Map/*<String,Map<String,String>>*/ fConfigurationContentTypeMappings;
|
||||
|
||||
/**
|
||||
* Project-wide content type mappings.
|
||||
* Per-file mappings (Path -> (Configuration ID -> Language ID)).
|
||||
*/
|
||||
private Map fContentTypeMappings;
|
||||
|
||||
/**
|
||||
* Per-file mappings.
|
||||
*/
|
||||
private Map fFileMappings;
|
||||
private Map/*<String,Map<String,String>>*/ fFileConfigurationMappings;
|
||||
|
||||
/**
|
||||
* Creates a new <code>ProjectLanguageConfiguration</code> with no
|
||||
* language mappings defined.
|
||||
*/
|
||||
public ProjectLanguageConfiguration() {
|
||||
fContentTypeMappings = new TreeMap();
|
||||
fFileMappings = new TreeMap();
|
||||
fConfigurationContentTypeMappings = new TreeMap();
|
||||
fFileConfigurationMappings = new TreeMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a read-only copy of the project-wide content-type-specific language mappings.
|
||||
* @return a read-only copy of the project-wide content-type-specific language mappings.
|
||||
*/
|
||||
public Map getContentTypeMappings() {
|
||||
return Collections.unmodifiableMap(fContentTypeMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the language id that is mapped to the given content type.
|
||||
* @param contentTypeId
|
||||
* Returns the language id that is mapped to the given content type when
|
||||
* the given configurationis active.
|
||||
* If <code>configuration</code> is <code>null</code>, the configuration-agnostic
|
||||
* mapping is returned.
|
||||
* @return
|
||||
*/
|
||||
public String getLanguageForContentType(String contentTypeId) {
|
||||
return (String) fContentTypeMappings.get(contentTypeId);
|
||||
public String getLanguageForContentType(ICConfigurationDescription configuration, String contentTypeId) {
|
||||
String configurationId = getId(configuration);
|
||||
Map contentTypeMappings = (Map) fConfigurationContentTypeMappings.get(configurationId);
|
||||
if (contentTypeMappings == null) {
|
||||
return null;
|
||||
}
|
||||
return (String) contentTypeMappings.get(contentTypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the language id that is mapped to the given file.
|
||||
* @param file
|
||||
* Returns the language id that is mapped to the given file when the given
|
||||
* configuration is active.
|
||||
* If <code>configuration</code> is <code>null</code>, the configuration-agnostic
|
||||
* mapping is returned.
|
||||
* @return
|
||||
*/
|
||||
public String getLanguageForFile(IFile file) {
|
||||
return (String) fFileMappings.get(file.getProjectRelativePath().toPortableString());
|
||||
public String getLanguageForFile(ICConfigurationDescription configuration, IFile file) {
|
||||
return getLanguageForFile(configuration, file.getProjectRelativePath().toPortableString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the language id that is mapped to the given file.
|
||||
* Returns the language id that is mapped to the file located at the given path
|
||||
* when the given configuration is active.
|
||||
* If <code>configuration</code> is <code>null</code>, the configuration-agnostic
|
||||
* mapping is returned.
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public String getLanguageForFile(String path) {
|
||||
return (String) fFileMappings.get(path);
|
||||
public String getLanguageForFile(ICConfigurationDescription configuration, String path) {
|
||||
Map configurationMappings = (Map) fFileConfigurationMappings.get(path);
|
||||
if (configurationMappings == null) {
|
||||
return null;
|
||||
}
|
||||
String configurationId = getId(configuration);
|
||||
return (String) configurationMappings.get(configurationId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces the existing content-type-specific language mappings with the given
|
||||
* mappings. The given mappings should be between content type ids
|
||||
* (<code>String</code>) and language ids (<code>String</code>)
|
||||
* @param mappings
|
||||
*/
|
||||
public void setContentTypeMappings(Map/*<String, String>*/ mappings) {
|
||||
fContentTypeMappings = new TreeMap(mappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a content type id to a language id.
|
||||
* Sets the language for a content type.
|
||||
* If <code>configuration</code> is not <code>null</code>, the language mapping
|
||||
* will only apply when that configuration is active. Otherwise, the mapping
|
||||
* will apply for all configurations.
|
||||
* @param contentType
|
||||
* @param language
|
||||
*/
|
||||
public void addContentTypeMapping(String contentType, String language) {
|
||||
fContentTypeMappings.put(contentType, language);
|
||||
public void addContentTypeMapping(ICConfigurationDescription configuration, String contentType, String language) {
|
||||
String configurationId = getId(configuration);
|
||||
Map contentTypeMappings = (Map) fConfigurationContentTypeMappings.get(configurationId);
|
||||
if (contentTypeMappings == null) {
|
||||
contentTypeMappings = new TreeMap();
|
||||
fConfigurationContentTypeMappings.put(configurationId, contentTypeMappings);
|
||||
}
|
||||
contentTypeMappings.put(contentType, language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given content type mapping (if it exists).
|
||||
* If <code>configuration</code> is <code>null</code>, the configuration-agnostic
|
||||
* mapping is removed. Otherwise, the configuration-specific mapping is removed.
|
||||
* @param contentType
|
||||
*/
|
||||
public void removeContentTypeMapping(String contentType) {
|
||||
fContentTypeMappings.remove(contentType);
|
||||
public void removeContentTypeMapping(ICConfigurationDescription configuration, String contentType) {
|
||||
String configurationId = getId(configuration);
|
||||
Map contentTypeMappings = (Map) fConfigurationContentTypeMappings.get(configurationId);
|
||||
if (contentTypeMappings == null) {
|
||||
return;
|
||||
}
|
||||
contentTypeMappings.remove(contentType);
|
||||
if (contentTypeMappings.size() == 0) {
|
||||
fConfigurationContentTypeMappings.remove(configurationId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language for a file.
|
||||
* If <code>configuration</code> is not <code>null</code>, the language mapping
|
||||
* will only apply when that configuration is active. Otherwise, the mapping
|
||||
* will apply for all configurations.
|
||||
* @param file
|
||||
* @param language
|
||||
*/
|
||||
public void addFileMapping(IFile file, String language) {
|
||||
fFileMappings.put(file.getProjectRelativePath().toPortableString(), language);
|
||||
public void addFileMapping(ICConfigurationDescription configuration, IFile file, String language) {
|
||||
addFileMapping(configuration, file.getProjectRelativePath().toPortableString(), language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language for a file.
|
||||
* If <code>configuration</code> is not <code>null</code>, the language mapping
|
||||
* will only apply when that configuration is active. Otherwise, the mapping
|
||||
* will apply for all configurations.
|
||||
* @param filePath
|
||||
* @param language
|
||||
*/
|
||||
public void addFileMapping(String filePath, String language) {
|
||||
fFileMappings.put(filePath, language);
|
||||
public void addFileMapping(ICConfigurationDescription configuration, String filePath, String language) {
|
||||
Map configurationMappings = (Map) fFileConfigurationMappings.get(filePath);
|
||||
if (configurationMappings == null) {
|
||||
configurationMappings = new TreeMap();
|
||||
fFileConfigurationMappings.put(filePath, configurationMappings);
|
||||
}
|
||||
String configurationId = getId(configuration);
|
||||
configurationMappings.put(configurationId, language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given file mapping (if it exists).
|
||||
* If <code>configuration</code> is <code>null</code>, the configuration-agnostic
|
||||
* mapping is removed. Otherwise, the configuration-specific mapping is removed.
|
||||
* @param file
|
||||
*/
|
||||
public void removeFileMapping(IFile file) {
|
||||
fFileMappings.remove(file.getProjectRelativePath().toPortableString());
|
||||
public void removeFileMapping(ICConfigurationDescription configuration, IFile file) {
|
||||
removeFileMapping(configuration, file.getProjectRelativePath().toPortableString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given file mapping (if it exists).
|
||||
* If <code>configuration</code> is <code>null</code>, the configuration-agnostic
|
||||
* mapping is removed. Otherwise, the configuration-specific mapping is removed.
|
||||
* @param filePath
|
||||
*/
|
||||
public void removeFileMapping(String filePath) {
|
||||
fFileMappings.remove(filePath);
|
||||
public void removeFileMapping(ICConfigurationDescription configuration, String filePath) {
|
||||
Map fileMappings = (Map) fFileConfigurationMappings.get(filePath);
|
||||
if (fileMappings == null) {
|
||||
return;
|
||||
}
|
||||
String configurationId = getId(configuration);
|
||||
fileMappings.remove(configurationId);
|
||||
if (fileMappings.size() == 0) {
|
||||
fFileConfigurationMappings.remove(configurationId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a read-only copy of the file-specific language mappings.
|
||||
* @return a read-only copy of the file-specific language mappings.
|
||||
* Removes all language mappings for the given file.
|
||||
* @param filePath
|
||||
*/
|
||||
public Map getFileMappings() {
|
||||
return Collections.unmodifiableMap(fFileMappings);
|
||||
public void removeAllFileMappings(String filePath) {
|
||||
fFileConfigurationMappings.remove(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all language mappings for the given file.
|
||||
* @param filePath
|
||||
*/
|
||||
public void removeAllFileMappings(IFile file) {
|
||||
removeAllFileMappings(file.getProjectRelativePath().toPortableString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the existing file-specific language mappings with the given
|
||||
* mappings. The given mappings should be between full paths
|
||||
* (<code>String</code>) and language ids (<code>String</code>)
|
||||
* @param fileMappings
|
||||
* This method is used internally by CDT and should not be used outside of the CDT framework.
|
||||
* @return
|
||||
*/
|
||||
public void setFileMappings(Map/*<String, String>*/ fileMappings) {
|
||||
fFileMappings = new TreeMap(fileMappings);
|
||||
public Map getContentTypeMappings() {
|
||||
return copyLanguageMappings(fConfigurationContentTypeMappings, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used internally by CDT and should not be used outside of the CDT framework.
|
||||
*/
|
||||
public void setContentTypeMappings(Map mappings) {
|
||||
fConfigurationContentTypeMappings = copyLanguageMappings(mappings, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used internally by CDT and should not be used outside of the CDT framework.
|
||||
* @return
|
||||
*/
|
||||
public Map getFileMappings() {
|
||||
return copyLanguageMappings(fFileConfigurationMappings, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used internally by CDT and should not be used outside of the CDT framework.
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public void setFileMappings(IFile file, Map mappings) {
|
||||
fFileConfigurationMappings.put(file.getProjectRelativePath().toPortableString(), new TreeMap(mappings));
|
||||
}
|
||||
|
||||
private Map copyLanguageMappings(Map mappings, boolean isReadOnly) {
|
||||
Map result = new TreeMap();
|
||||
Iterator entries = mappings.entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Entry entry = (Entry) entries.next();
|
||||
Map map = (Map) entry.getValue();
|
||||
if (isReadOnly) {
|
||||
map = Collections.unmodifiableMap(map);
|
||||
} else {
|
||||
map = new TreeMap(map);
|
||||
}
|
||||
result.put(entry.getKey(), map);
|
||||
}
|
||||
if (isReadOnly) {
|
||||
result = Collections.unmodifiableMap(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used internally by CDT and should not be used outside of the CDT framework.
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public void setFileMappings(Map mappings) {
|
||||
fFileConfigurationMappings = copyLanguageMappings(mappings, false);
|
||||
}
|
||||
|
||||
private String getId(ICConfigurationDescription configuration) {
|
||||
if (configuration == null) {
|
||||
return ALL_CONFIGURATIONS;
|
||||
}
|
||||
return configuration.getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
|
||||
import org.eclipse.cdt.core.language.WorkspaceLanguageConfiguration;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.internal.core.CContentTypes;
|
||||
import org.eclipse.cdt.internal.core.language.LanguageMappingResolver;
|
||||
import org.eclipse.cdt.internal.core.language.LanguageMappingStore;
|
||||
|
@ -460,10 +461,11 @@ public class LanguageManager {
|
|||
* @return an ILanguage representing the language to be used for the given file
|
||||
* @param fullPathToFile the full path to the file for which the language is requested
|
||||
* @param project the IProject that this file is in the context of. This field cannot be null.
|
||||
* @param configuration the active build configuration, or <code>null</code> if build configurations
|
||||
* are not relevant to determining the language.
|
||||
* @throws CoreException
|
||||
* TODO: implement other mapping levels besides project level and content type level
|
||||
*/
|
||||
public ILanguage getLanguageForFile(String fullPathToFile, IProject project) throws CoreException {
|
||||
public ILanguage getLanguageForFile(String fullPathToFile, IProject project, ICConfigurationDescription configuration) throws CoreException {
|
||||
if (project == null)
|
||||
throw new IllegalArgumentException("project must not be null in call to LanguageManager.getLanguageForFile(String, IProject)"); //$NON-NLS-1$
|
||||
|
||||
|
@ -476,7 +478,7 @@ public class LanguageManager {
|
|||
|
||||
String contentTypeID = contentType.getId();
|
||||
|
||||
return LanguageMappingResolver.computeLanguage(project, fullPathToFile, contentTypeID, false)[0].language;
|
||||
return LanguageMappingResolver.computeLanguage(project, fullPathToFile, configuration, contentTypeID, false)[0].language;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -486,11 +488,13 @@ public class LanguageManager {
|
|||
* The path can be either workspace or project relative.
|
||||
* @param project the project that this file should be parsed in context of. This field is optional and may
|
||||
* be set to null. If the project is null then this method tries to determine the project context via workspace APIs.
|
||||
* @param configuration the active build configuration, or <code>null</code> if build configurations
|
||||
* are not relevant to determining the language.
|
||||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
public ILanguage getLanguageForFile(IPath pathToFile, IProject project) throws CoreException {
|
||||
return getLanguageForFile(pathToFile, project, null);
|
||||
public ILanguage getLanguageForFile(IPath pathToFile, IProject project, ICConfigurationDescription configuration) throws CoreException {
|
||||
return getLanguageForFile(pathToFile, project, configuration, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -500,11 +504,13 @@ public class LanguageManager {
|
|||
* The path can be either workspace or project relative.
|
||||
* @param project the project that this file should be parsed in context of. This field is optional and may
|
||||
* be set to null. If the project is null then this method tries to determine the project context via workspace APIs.
|
||||
* @param configuration the active build configuration, or <code>null</code> if build configurations
|
||||
* are not relevant to determining the language.
|
||||
* @param contentTypeID id of the content type, may be <code>null</code>.
|
||||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
public ILanguage getLanguageForFile(IPath pathToFile, IProject project, String contentTypeID) throws CoreException {
|
||||
public ILanguage getLanguageForFile(IPath pathToFile, IProject project, ICConfigurationDescription configuration, String contentTypeID) throws CoreException {
|
||||
if (project == null) {
|
||||
IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(pathToFile);
|
||||
if (resource == null) {
|
||||
|
@ -520,18 +526,20 @@ public class LanguageManager {
|
|||
contentTypeID= ct.getId();
|
||||
}
|
||||
|
||||
return LanguageMappingResolver.computeLanguage(project, pathToFile.toPortableString(), contentTypeID, false)[0].language;
|
||||
return LanguageMappingResolver.computeLanguage(project, pathToFile.toPortableString(), configuration, contentTypeID, false)[0].language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ILanguage representing the language to be used for the given file.
|
||||
* @return an ILanguage representing the language to be used for the given file
|
||||
* @param file the file for which the language is requested
|
||||
* @param configuration the active build configuration, or <code>null</code> if build configurations
|
||||
* are not relevant to determining the language.
|
||||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
public ILanguage getLanguageForFile(IFile file) throws CoreException {
|
||||
return getLanguageForFile(file, null);
|
||||
public ILanguage getLanguageForFile(IFile file, ICConfigurationDescription configuration) throws CoreException {
|
||||
return getLanguageForFile(file, configuration, null);
|
||||
}
|
||||
|
||||
|
||||
|
@ -539,11 +547,13 @@ public class LanguageManager {
|
|||
* Returns an ILanguage representing the language to be used for the given file.
|
||||
* @return an ILanguage representing the language to be used for the given file
|
||||
* @param file the file for which the language is requested
|
||||
* @param configuration the active build configuration, or <code>null</code> if build configurations
|
||||
* are not relevant to determining the language.
|
||||
* @param contentTypeID id of the content type, may be <code>null</code>.
|
||||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
public ILanguage getLanguageForFile(IFile file, String contentTypeId) throws CoreException {
|
||||
public ILanguage getLanguageForFile(IFile file, ICConfigurationDescription configuration, String contentTypeId) throws CoreException {
|
||||
IProject project = file.getProject();
|
||||
|
||||
if (contentTypeId == null) {
|
||||
|
@ -555,7 +565,7 @@ public class LanguageManager {
|
|||
contentTypeId= contentType.getId();
|
||||
}
|
||||
|
||||
return LanguageMappingResolver.computeLanguage(project, file.getProjectRelativePath().toPortableString(), contentTypeId, false)[0].language;
|
||||
return LanguageMappingResolver.computeLanguage(project, file.getProjectRelativePath().toPortableString(), configuration, contentTypeId, false)[0].language;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
|
||||
import org.eclipse.cdt.core.language.WorkspaceLanguageConfiguration;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
@ -48,8 +49,8 @@ public class LanguageMappingResolver {
|
|||
* @return the effective language for the file specified by the given path.
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static LanguageMapping[] computeLanguage(IProject project, String filePath, String contentTypeId, boolean fetchAll) throws CoreException {
|
||||
LanguageManager manager = LanguageManager.getInstance();
|
||||
public static LanguageMapping[] computeLanguage(IProject project, String filePath, ICConfigurationDescription configuration, String contentTypeId, boolean fetchAll) throws CoreException {
|
||||
LanguageManager manager = LanguageManager.getInstance();
|
||||
List inheritedLanguages = new LinkedList();
|
||||
|
||||
if (project != null) {
|
||||
|
@ -58,23 +59,49 @@ public class LanguageMappingResolver {
|
|||
if (mappings != null) {
|
||||
// File-level mappings
|
||||
if (filePath != null) {
|
||||
String id = mappings.getLanguageForFile(filePath);
|
||||
|
||||
String id = mappings.getLanguageForFile(configuration, filePath);
|
||||
if (id != null) {
|
||||
inheritedLanguages.add(new LanguageMapping(manager.getLanguage(id), FILE_MAPPING));
|
||||
if (!fetchAll) {
|
||||
return createLanguageMappingArray(inheritedLanguages);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for a file mapping that's global across all configurations in
|
||||
// the project.
|
||||
if (configuration != null) {
|
||||
id = mappings.getLanguageForFile(null, filePath);
|
||||
if (id != null) {
|
||||
inheritedLanguages.add(new LanguageMapping(manager.getLanguage(id), FILE_MAPPING));
|
||||
if (!fetchAll) {
|
||||
return createLanguageMappingArray(inheritedLanguages);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Project-level mappings
|
||||
String id = mappings.getLanguageForContentType(contentTypeId);
|
||||
String id = mappings.getLanguageForContentType(configuration, contentTypeId);
|
||||
if (id != null) {
|
||||
inheritedLanguages.add(new LanguageMapping(manager.getLanguage(id), PROJECT_MAPPING));
|
||||
if (!fetchAll) {
|
||||
return createLanguageMappingArray(inheritedLanguages);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for a content type mapping that's global across all configurations in
|
||||
// the project.
|
||||
if (configuration != null) {
|
||||
id = mappings.getLanguageForContentType(null, contentTypeId);
|
||||
if (id != null) {
|
||||
inheritedLanguages.add(new LanguageMapping(manager.getLanguage(id), PROJECT_MAPPING));
|
||||
if (!fetchAll) {
|
||||
return createLanguageMappingArray(inheritedLanguages);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ public class LanguageMappingStore {
|
|||
|
||||
private static final String ATTRIBUTE_LANGUAGE = "language"; //$NON-NLS-1$
|
||||
|
||||
private static final String ATTRIBUTE_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
||||
|
||||
public LanguageMappingStore() {
|
||||
}
|
||||
|
||||
|
@ -78,12 +80,31 @@ public class LanguageMappingStore {
|
|||
NodeList mappingElements = rootElement.getElementsByTagName(PROJECT_MAPPINGS);
|
||||
if (mappingElements.getLength() > 0) {
|
||||
Element element = (Element) mappingElements.item(0);
|
||||
config.setContentTypeMappings(decodeContentTypeMappings(element));
|
||||
config.setContentTypeMappings(decodeProjectContentTypeMappings(element));
|
||||
config.setFileMappings(decodeFileMappings(element));
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private Map decodeProjectContentTypeMappings(Element rootElement) {
|
||||
Map decodedMappings = new TreeMap();
|
||||
NodeList mappingElements = rootElement.getElementsByTagName(CONTENT_TYPE_MAPPING);
|
||||
for (int j = 0; j < mappingElements.getLength(); j++) {
|
||||
Element mapping = (Element) mappingElements.item(j);
|
||||
String configuration = mapping.getAttribute(ATTRIBUTE_CONFIGURATION);
|
||||
|
||||
Map contentTypeMappings = (Map) decodedMappings.get(configuration);
|
||||
if (contentTypeMappings == null) {
|
||||
contentTypeMappings = new TreeMap();
|
||||
decodedMappings.put(configuration, contentTypeMappings);
|
||||
}
|
||||
String contentType = mapping.getAttribute(ATTRIBUTE_CONTENT_TYPE);
|
||||
String language = mapping.getAttribute(ATTRIBUTE_LANGUAGE);
|
||||
contentTypeMappings.put(contentType, language);
|
||||
}
|
||||
return decodedMappings;
|
||||
}
|
||||
|
||||
protected ICDescriptor getProjectDescription(IProject project) throws CoreException {
|
||||
return CCorePlugin.getDefault().getCProjectDescription(project, true);
|
||||
}
|
||||
|
@ -93,7 +114,22 @@ public class LanguageMappingStore {
|
|||
}
|
||||
|
||||
private Map decodeFileMappings(Element rootElement) throws CoreException {
|
||||
return decodeMappings(rootElement, FILE_MAPPING, ATTRIBUTE_PATH, ATTRIBUTE_LANGUAGE);
|
||||
Map decodedMappings = new TreeMap();
|
||||
NodeList mappingElements = rootElement.getElementsByTagName(FILE_MAPPING);
|
||||
for (int j = 0; j < mappingElements.getLength(); j++) {
|
||||
Element mapping = (Element) mappingElements.item(j);
|
||||
String path = mapping.getAttribute(ATTRIBUTE_PATH);
|
||||
|
||||
Map configurationMappings = (Map) decodedMappings.get(path);
|
||||
if (configurationMappings == null) {
|
||||
configurationMappings = new TreeMap();
|
||||
decodedMappings.put(path, configurationMappings);
|
||||
}
|
||||
String configuration = mapping.getAttribute(ATTRIBUTE_CONFIGURATION);
|
||||
String language = mapping.getAttribute(ATTRIBUTE_LANGUAGE);
|
||||
configurationMappings.put(configuration, language);
|
||||
}
|
||||
return decodedMappings;
|
||||
}
|
||||
|
||||
private Map decodeMappings(Element rootElement, String category, String keyName, String valueName) {
|
||||
|
@ -117,11 +153,33 @@ public class LanguageMappingStore {
|
|||
Element projectMappings = document.createElement(PROJECT_MAPPINGS);
|
||||
rootElement.appendChild(projectMappings);
|
||||
|
||||
addContentTypeMappings(config.getContentTypeMappings(), projectMappings);
|
||||
addProjectContentTypeMappings(config.getContentTypeMappings(), projectMappings);
|
||||
addFileMappings(config.getFileMappings(), projectMappings);
|
||||
descriptor.saveProjectData();
|
||||
}
|
||||
|
||||
private void addProjectContentTypeMappings(Map contentTypeMappings, Element rootElement) {
|
||||
Document document = rootElement.getOwnerDocument();
|
||||
Iterator entries = contentTypeMappings.entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Entry entry = (Entry) entries.next();
|
||||
Element mapping = document.createElement(CONTENT_TYPE_MAPPING);
|
||||
|
||||
String configuration = (String) entry.getKey();
|
||||
Iterator contentTypeEntries = ((Map) entry.getValue()).entrySet().iterator();
|
||||
while (contentTypeEntries.hasNext()) {
|
||||
Entry configurationEntry = (Entry) contentTypeEntries.next();
|
||||
String contentType = (String) configurationEntry.getKey();
|
||||
String language = (String) configurationEntry.getValue();
|
||||
|
||||
mapping.setAttribute(ATTRIBUTE_CONTENT_TYPE, contentType);
|
||||
mapping.setAttribute(ATTRIBUTE_CONFIGURATION, configuration);
|
||||
mapping.setAttribute(ATTRIBUTE_LANGUAGE, language);
|
||||
rootElement.appendChild(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void storeMappings(WorkspaceLanguageConfiguration config) throws CoreException {
|
||||
try {
|
||||
// Encode mappings as XML and serialize as a String.
|
||||
|
@ -205,6 +263,24 @@ public class LanguageMappingStore {
|
|||
}
|
||||
|
||||
private void addFileMappings(Map mappings, Element rootElement) {
|
||||
addMappings(mappings, rootElement, FILE_MAPPING, ATTRIBUTE_PATH, ATTRIBUTE_LANGUAGE);
|
||||
Document document = rootElement.getOwnerDocument();
|
||||
Iterator entries = mappings.entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Entry entry = (Entry) entries.next();
|
||||
Element mapping = document.createElement(FILE_MAPPING);
|
||||
|
||||
String path = (String) entry.getKey();
|
||||
Iterator configurationEntries = ((Map) entry.getValue()).entrySet().iterator();
|
||||
while (configurationEntries.hasNext()) {
|
||||
Entry configurationEntry = (Entry) configurationEntries.next();
|
||||
String configuration = (String) configurationEntry.getKey();
|
||||
String language = (String) configurationEntry.getValue();
|
||||
|
||||
mapping.setAttribute(ATTRIBUTE_PATH, path);
|
||||
mapping.setAttribute(ATTRIBUTE_CONFIGURATION, configuration);
|
||||
mapping.setAttribute(ATTRIBUTE_LANGUAGE, language);
|
||||
rootElement.appendChild(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
|||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.internal.core.dom.NullCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
|
||||
|
@ -678,13 +680,27 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
|
||||
public ILanguage getLanguage() throws CoreException {
|
||||
ILanguage language = null;
|
||||
|
||||
|
||||
ICProject cProject = getCProject();
|
||||
IProject project= cProject.getProject();
|
||||
|
||||
ICProjectDescription description = CoreModel.getDefault().getProjectDescription(project, true);
|
||||
ICConfigurationDescription configuration;
|
||||
|
||||
if (description == null) {
|
||||
// TODO: Sometimes, CoreModel returns a null ICProjectDescription
|
||||
// so for now, fall back to configuration-less language determination.
|
||||
configuration = null;
|
||||
} else {
|
||||
configuration = description.getActiveConfiguration();
|
||||
}
|
||||
|
||||
IFile file= getFile();
|
||||
if (file != null) {
|
||||
language= LanguageManager.getInstance().getLanguageForFile(file, contentTypeId);
|
||||
language = LanguageManager.getInstance().getLanguageForFile(file, configuration, contentTypeId);
|
||||
}
|
||||
else {
|
||||
language = LanguageManager.getInstance().getLanguageForFile(getLocation(), getCProject().getProject(), contentTypeId);
|
||||
language = LanguageManager.getInstance().getLanguageForFile(getLocation(), getCProject().getProject(), configuration, contentTypeId);
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,11 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||
|
||||
|
@ -65,7 +67,9 @@ public class ResolveBindingTests extends BaseUITestCase {
|
|||
// get the language from the language manager
|
||||
ILanguage language = null;
|
||||
try {
|
||||
language = LanguageManager.getInstance().getLanguageForFile(astTU.getFilePath(), fCProject.getProject());
|
||||
IProject project = fCProject.getProject();
|
||||
ICConfigurationDescription configuration = CoreModel.getDefault().getProjectDescription(project, false).getActiveConfiguration();
|
||||
language = LanguageManager.getInstance().getLanguageForFile(astTU.getFilePath(), project, configuration);
|
||||
} catch (CoreException e) {
|
||||
fail("Unexpected exception while getting language for file.");
|
||||
}
|
||||
|
|
|
@ -11,23 +11,12 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.language;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
|
@ -35,7 +24,7 @@ import org.eclipse.cdt.core.model.LanguageManager;
|
|||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
|
||||
public class ContentTypeMappingDialog extends Dialog {
|
||||
public abstract class ContentTypeMappingDialog extends Dialog {
|
||||
|
||||
Combo fContentType;
|
||||
Combo fLanguage;
|
||||
|
@ -43,13 +32,13 @@ public class ContentTypeMappingDialog extends Dialog {
|
|||
String fSelectedContentTypeID;
|
||||
String fSelectedLanguageName;
|
||||
String fSelectedLanguageID;
|
||||
private Set fFilteredContentTypes;
|
||||
private HashMap fContentTypeNamesToIDsMap;
|
||||
private HashMap fLanguageNamesToIDsMap;
|
||||
String fSelectedConfigurationID;
|
||||
String fSelectedConfigurationName;
|
||||
HashMap fContentTypeNamesToIDsMap;
|
||||
HashMap fLanguageNamesToIDsMap;
|
||||
|
||||
public ContentTypeMappingDialog(Shell parentShell) {
|
||||
super(parentShell);
|
||||
fFilteredContentTypes = Collections.EMPTY_SET;
|
||||
fContentTypeNamesToIDsMap = new HashMap();
|
||||
fLanguageNamesToIDsMap = new HashMap();
|
||||
}
|
||||
|
@ -84,78 +73,7 @@ public class ContentTypeMappingDialog extends Dialog {
|
|||
getButton(IDialogConstants.OK_ID).setEnabled(false);
|
||||
}
|
||||
|
||||
private boolean isValidSelection() {
|
||||
return fContentType.getSelectionIndex() != -1
|
||||
&& fLanguage.getSelectionIndex() != -1;
|
||||
}
|
||||
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite area = new Composite(parent, SWT.NONE);
|
||||
area.setLayout(new GridLayout(2, false));
|
||||
|
||||
Label contentTypeLabel = new Label(area, SWT.TRAIL);
|
||||
contentTypeLabel
|
||||
.setText(PreferencesMessages.ContentTypeMappingsDialog_contentType);
|
||||
|
||||
fContentType = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fContentType
|
||||
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
configureContentTypes(fContentType);
|
||||
fContentType.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fSelectedContentTypeName = fContentType.getText();
|
||||
fSelectedContentTypeID = (String) fContentTypeNamesToIDsMap
|
||||
.get(fSelectedContentTypeName);
|
||||
getButton(IDialogConstants.OK_ID)
|
||||
.setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
|
||||
Label languageLabel = new Label(area, SWT.TRAIL);
|
||||
languageLabel
|
||||
.setText(PreferencesMessages.ContentTypeMappingsDialog_language);
|
||||
|
||||
fLanguage = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fLanguage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
fLanguage.setItems(getLanguages());
|
||||
fLanguage.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fSelectedLanguageName = fLanguage.getText();
|
||||
fSelectedLanguageID = (String) fLanguageNamesToIDsMap
|
||||
.get(fSelectedLanguageName);
|
||||
getButton(IDialogConstants.OK_ID)
|
||||
.setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private void configureContentTypes(Combo combo) {
|
||||
combo.removeAll();
|
||||
String[] contentTypesIDs = LanguageManager.getInstance()
|
||||
.getRegisteredContentTypeIds();
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform
|
||||
.getContentTypeManager();
|
||||
|
||||
for (int i = 0; i < contentTypesIDs.length; i++) {
|
||||
if (!fFilteredContentTypes.contains(contentTypesIDs[i])) {
|
||||
|
||||
String name = contentTypeManager.getContentType(
|
||||
contentTypesIDs[i]).getName();
|
||||
|
||||
combo.add(name);
|
||||
|
||||
// keep track of what ID this name corresponds to so that when
|
||||
// we setup the mapping
|
||||
// later based upon user selection, we'll know what ID to use
|
||||
fContentTypeNamesToIDsMap.put(name, contentTypesIDs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getLanguages() {
|
||||
protected String[] getLanguages() {
|
||||
ILanguage[] languages = LanguageManager.getInstance()
|
||||
.getRegisteredLanguages();
|
||||
String[] descriptions = new String[languages.length];
|
||||
|
@ -166,8 +84,5 @@ public class ContentTypeMappingDialog extends Dialog {
|
|||
return descriptions;
|
||||
}
|
||||
|
||||
public void setContentTypeFilter(Set contentTypes) {
|
||||
fFilteredContentTypes = contentTypes;
|
||||
}
|
||||
|
||||
protected abstract boolean isValidSelection();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -7,20 +17,32 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.jface.layout.TableColumnLayout;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CCombo;
|
||||
import org.eclipse.swt.custom.TableEditor;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Link;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.CContentTypes;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
|
@ -32,14 +54,28 @@ import org.eclipse.cdt.internal.ui.util.Messages;
|
|||
|
||||
public class FileLanguageMappingPropertyPage extends PropertyPage {
|
||||
|
||||
private Map fLanguageNamesToIDsMap;
|
||||
private Combo fLanguage;
|
||||
private static final int MINIMUM_COLUMN_WIDTH = 150;
|
||||
private static final int LANGUAGE_COLUMN = 1;
|
||||
private static final int CONFIGURATION_COLUMN = 0;
|
||||
|
||||
private static final int LANGUAGE_ID = 0;
|
||||
private static final int LANGUAGE_NAME = 1;
|
||||
|
||||
private static final String ALL_CONFIGURATIONS = ""; //$NON-NLS-1$
|
||||
|
||||
private IContentType fContentType;
|
||||
private Composite fContents;
|
||||
private Table fTable;
|
||||
private ILanguage[] fLanguages;
|
||||
private Map fLanguageIds;
|
||||
|
||||
public FileLanguageMappingPropertyPage() {
|
||||
super();
|
||||
fLanguageNamesToIDsMap = new TreeMap();
|
||||
fLanguages = LanguageManager.getInstance().getRegisteredLanguages();
|
||||
fLanguageIds = new TreeMap();
|
||||
for (int i = 0; i < fLanguages.length; i++) {
|
||||
fLanguageIds.put(fLanguages[i].getId(), fLanguages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected Control createContents(Composite parent) {
|
||||
|
@ -58,84 +94,225 @@ public class FileLanguageMappingPropertyPage extends PropertyPage {
|
|||
contentTypeDescriptionLabel.setText(fContentType.getName());
|
||||
contentTypeDescriptionLabel.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false));
|
||||
|
||||
Label languageLabel = new Label(fContents, SWT.NONE);
|
||||
languageLabel.setText(PreferencesMessages.FileLanguagesPropertyPage_languageLabel);
|
||||
languageLabel.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, false, false));
|
||||
|
||||
fLanguage = new Combo(fContents, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fLanguage.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false));
|
||||
refreshMappings();
|
||||
try {
|
||||
createMappingTable(fContents, file);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
||||
Link link = new Link(fContents, SWT.NONE);
|
||||
link.setText(PreferencesMessages.FileLanguagesPropertyPage_description);
|
||||
link.addListener(SWT.Selection, new LanguageMappingLinkListener(parent.getShell(), project) {
|
||||
protected void refresh() {
|
||||
refreshMappings();
|
||||
try {
|
||||
refreshMappings();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
link.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false, 2, 1));
|
||||
|
||||
fContents.pack();
|
||||
return fContents;
|
||||
}
|
||||
|
||||
private void refreshMappings() {
|
||||
private void createMappingTable(Composite contents, final IFile file) throws CoreException {
|
||||
Composite tableParent = new Composite(contents, SWT.NONE);
|
||||
tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
||||
|
||||
fTable = new Table(tableParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
||||
fTable.setHeaderVisible(true);
|
||||
fTable.setLinesVisible(true);
|
||||
|
||||
TableColumn contentTypeColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
contentTypeColumn.setText(PreferencesMessages.FileLanguagesPropertyPage_configurationColumn);
|
||||
|
||||
TableColumn languageColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
languageColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_languageColumn);
|
||||
|
||||
TableColumnLayout layout = new TableColumnLayout();
|
||||
layout.setColumnData(contentTypeColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
layout.setColumnData(languageColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
tableParent.setLayout(layout);
|
||||
|
||||
final TableEditor editor = new TableEditor(fTable);
|
||||
editor.grabHorizontal = true;
|
||||
editor.grabVertical = true;
|
||||
editor.setColumn(LANGUAGE_COLUMN);
|
||||
|
||||
final IProject project = file.getProject();
|
||||
|
||||
fTable.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
Control oldEditor = editor.getEditor();
|
||||
if (oldEditor != null) {
|
||||
oldEditor.dispose();
|
||||
}
|
||||
|
||||
TableItem item = (TableItem) event.item;
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LanguageTableData data = (LanguageTableData) item.getData();
|
||||
CCombo newEditor = new CCombo(fTable, SWT.READ_ONLY);
|
||||
populateLanguages(project, file, data.configuration, data.languageId, newEditor);
|
||||
|
||||
newEditor.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
CCombo combo = (CCombo) editor.getEditor();
|
||||
int index = combo.getSelectionIndex();
|
||||
if (index != -1) {
|
||||
TableItem item = editor.getItem();
|
||||
item.setText(LANGUAGE_COLUMN, combo.getText());
|
||||
|
||||
String selectedLanguage = ((String[]) combo.getData())[index];
|
||||
LanguageTableData data = (LanguageTableData) item.getData();
|
||||
data.languageId = selectedLanguage;
|
||||
|
||||
try {
|
||||
refreshMappings();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newEditor.setFocus();
|
||||
editor.setEditor(newEditor, item, LANGUAGE_COLUMN);
|
||||
}
|
||||
});
|
||||
|
||||
populateLanguageTable(fTable);
|
||||
refreshMappings();
|
||||
}
|
||||
|
||||
private void populateLanguageTable(Table table) throws CoreException {
|
||||
IFile file = getFile();
|
||||
IProject project = file.getProject();
|
||||
ICProjectDescription description = CoreModel.getDefault().getProjectDescription(project);
|
||||
ICConfigurationDescription[] configurations = description.getConfigurations();
|
||||
|
||||
TableItem defaultItem = new TableItem(table, SWT.NONE);
|
||||
defaultItem.setText(CONFIGURATION_COLUMN, PreferencesMessages.FileLanguagesPropertyPage_defaultMapping);
|
||||
|
||||
ProjectLanguageConfiguration config = LanguageManager.getInstance().getLanguageConfiguration(project);
|
||||
|
||||
String defaultLanguageId = config.getLanguageForFile(null, file);
|
||||
LanguageTableData defaultData = new LanguageTableData(null, defaultLanguageId );
|
||||
defaultItem.setData(defaultData);
|
||||
|
||||
for (int i = 0; i < configurations.length; i++) {
|
||||
TableItem item = new TableItem(table, SWT.NONE);
|
||||
item.setText(CONFIGURATION_COLUMN, configurations[i].getName());
|
||||
String languageId = config.getLanguageForFile(configurations[i], file);
|
||||
|
||||
if (languageId != null) {
|
||||
ILanguage language = (ILanguage) fLanguageIds.get(languageId);
|
||||
String languageName = language.getName();
|
||||
item.setText(LANGUAGE_COLUMN, languageName);
|
||||
}
|
||||
|
||||
LanguageTableData data = new LanguageTableData(configurations[i], languageId);
|
||||
item.setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void populateLanguages(IProject project, IFile file, ICConfigurationDescription configuration, String selectedLanguage, CCombo combo) {
|
||||
try {
|
||||
fLanguage.setItems(getLanguages());
|
||||
findSelection();
|
||||
String[][] languageInfo = getLanguages(project, file, configuration);
|
||||
combo.setItems(languageInfo[LANGUAGE_NAME]);
|
||||
combo.setData(languageInfo[LANGUAGE_ID]);
|
||||
|
||||
findSelection(configuration, selectedLanguage, combo);
|
||||
fContents.layout();
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void findSelection() throws CoreException {
|
||||
|
||||
private void refreshMappings() throws CoreException {
|
||||
IFile file = getFile();
|
||||
IProject project = file.getProject();
|
||||
|
||||
LanguageManager manager = LanguageManager.getInstance();
|
||||
ProjectLanguageConfiguration config = manager.getLanguageConfiguration(file.getProject());
|
||||
String languageId = config.getLanguageForFile(file);
|
||||
TableItem[] items = fTable.getItems();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
TableItem item = items[i];
|
||||
LanguageTableData data = (LanguageTableData) item.getData();
|
||||
if (data.languageId == null) {
|
||||
LanguageMapping mapping = computeInheritedMapping(project, file, data.configuration);
|
||||
item.setText(LANGUAGE_COLUMN, computeInheritedFrom(data.configuration, mapping));
|
||||
} else {
|
||||
ILanguage language = manager.getLanguage(data.languageId);
|
||||
item.setText(LANGUAGE_COLUMN, language.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void findSelection(ICConfigurationDescription configuration, String languageId, CCombo combo) throws CoreException {
|
||||
// if (languageId == null) {
|
||||
// TableItem[] items = fTable.getItems();
|
||||
// for (int i = 0; i < items.length; i++) {
|
||||
// LanguageTableData data = (LanguageTableData) items[i].getData();
|
||||
// if (configuration == null && data.configuration == null) {
|
||||
// languageId = data.languageId;
|
||||
// break;
|
||||
// } else if (configuration != null && data.configuration != null) {
|
||||
// languageId = data.languageId;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (languageId == null) {
|
||||
// No mapping was defined so we'll choose the default.
|
||||
fLanguage.select(0);
|
||||
combo.select(0);
|
||||
return;
|
||||
}
|
||||
|
||||
LanguageManager manager = LanguageManager.getInstance();
|
||||
ILanguage language = manager.getLanguage(languageId);
|
||||
String name = language.getName();
|
||||
|
||||
for (int i = 1; i < fLanguage.getItemCount(); i++) {
|
||||
if (name.equals(fLanguage.getItem(i))) {
|
||||
fLanguage.select(i);
|
||||
for (int i = 1; i < combo.getItemCount(); i++) {
|
||||
if (name.equals(combo.getItem(i))) {
|
||||
combo.select(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Couldn't find the mapping so we'll choose the default.
|
||||
fLanguage.select(0);
|
||||
combo.select(0);
|
||||
}
|
||||
|
||||
public boolean performOk() {
|
||||
String languageId;
|
||||
String selectedLanguageName = fLanguage.getText();
|
||||
languageId = (String) fLanguageNamesToIDsMap.get(selectedLanguageName);
|
||||
|
||||
try {
|
||||
IFile file = getFile();
|
||||
IProject project = file.getProject();
|
||||
LanguageManager manager = LanguageManager.getInstance();
|
||||
ProjectLanguageConfiguration config = manager.getLanguageConfiguration(project);
|
||||
String oldMapping = config.getLanguageForFile(file);
|
||||
|
||||
if (oldMapping == languageId) {
|
||||
// No changes. We're all done.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (languageId == null) {
|
||||
config.removeFileMapping(file);
|
||||
} else {
|
||||
config.addFileMapping(file, languageId);
|
||||
Map mappings = new TreeMap();
|
||||
TableItem[] items = fTable.getItems();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
TableItem item = items[i];
|
||||
LanguageTableData data = (LanguageTableData) item.getData();
|
||||
if (data.languageId == null) {
|
||||
continue;
|
||||
}
|
||||
String configurationId;
|
||||
if (data.configuration == null) {
|
||||
configurationId = ALL_CONFIGURATIONS;
|
||||
} else {
|
||||
configurationId = data.configuration.getId();
|
||||
}
|
||||
mappings.put(configurationId, data.languageId);
|
||||
}
|
||||
config.setFileMappings(file, mappings);
|
||||
manager.storeLanguageMappingConfiguration(file);
|
||||
return true;
|
||||
} catch (CoreException e) {
|
||||
|
@ -152,13 +329,35 @@ public class FileLanguageMappingPropertyPage extends PropertyPage {
|
|||
super.performDefaults();
|
||||
}
|
||||
|
||||
private String[] getLanguages() throws CoreException {
|
||||
ILanguage[] languages = LanguageManager.getInstance().getRegisteredLanguages();
|
||||
String[] descriptions = new String[languages.length];
|
||||
private String computeInheritedFrom(ICConfigurationDescription configuration, LanguageMapping mapping) throws CoreException {
|
||||
String inheritedFrom;
|
||||
ILanguage language;
|
||||
|
||||
IFile file = getFile();
|
||||
IProject project = file.getProject();
|
||||
LanguageMapping mappings[] = LanguageMappingResolver.computeLanguage(project, file.getProjectRelativePath().toPortableString(), fContentType.getId(), true);
|
||||
LanguageTableData data = (LanguageTableData) fTable.getItem(0).getData();
|
||||
if (configuration != null && data.languageId != null) {
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromFile;
|
||||
language = LanguageManager.getInstance().getLanguage(data.languageId);
|
||||
} else {
|
||||
language = mapping.language;
|
||||
switch (mapping.inheritedFrom) {
|
||||
case LanguageMappingResolver.DEFAULT_MAPPING:
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromSystem;
|
||||
break;
|
||||
case LanguageMappingResolver.PROJECT_MAPPING:
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromProject;
|
||||
break;
|
||||
case LanguageMappingResolver.WORKSPACE_MAPPING:
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromWorkspace;
|
||||
break;
|
||||
default:
|
||||
throw new CoreException(Util.createStatus(new IllegalArgumentException()));
|
||||
}
|
||||
}
|
||||
return Messages.format(inheritedFrom, language.getName());
|
||||
}
|
||||
|
||||
private LanguageMapping computeInheritedMapping(IProject project, IFile file, ICConfigurationDescription configuration) throws CoreException {
|
||||
LanguageMapping mappings[] = LanguageMappingResolver.computeLanguage(project, file.getProjectRelativePath().toPortableString(), configuration, fContentType.getId(), true);
|
||||
LanguageMapping inheritedMapping = mappings[0];
|
||||
|
||||
// Skip over the file mapping because we want to know what mapping the file
|
||||
|
@ -167,33 +366,35 @@ public class FileLanguageMappingPropertyPage extends PropertyPage {
|
|||
inheritedMapping = mappings[1];
|
||||
}
|
||||
|
||||
ILanguage inheritedLanguage = inheritedMapping.language;
|
||||
String inheritedFrom;
|
||||
switch (inheritedMapping.inheritedFrom) {
|
||||
case LanguageMappingResolver.DEFAULT_MAPPING:
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromSystem;
|
||||
break;
|
||||
case LanguageMappingResolver.PROJECT_MAPPING:
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromProject;
|
||||
break;
|
||||
case LanguageMappingResolver.WORKSPACE_MAPPING:
|
||||
inheritedFrom = PreferencesMessages.FileLanguagesPropertyPage_inheritedFromWorkspace;
|
||||
break;
|
||||
default:
|
||||
throw new CoreException(Util.createStatus(new IllegalArgumentException()));
|
||||
}
|
||||
return inheritedMapping;
|
||||
}
|
||||
|
||||
private String[][] getLanguages(IProject project, IFile file, ICConfigurationDescription configuration) throws CoreException {
|
||||
String[][] descriptions = new String[2][fLanguages.length + 1];
|
||||
|
||||
LanguageMapping inheritedMapping = computeInheritedMapping(project, file, configuration);
|
||||
|
||||
int index = 0;
|
||||
descriptions[index] = Messages.format(inheritedFrom, inheritedLanguage.getName());
|
||||
descriptions[LANGUAGE_ID][index] = null;
|
||||
descriptions[LANGUAGE_NAME][index] = computeInheritedFrom(configuration, inheritedMapping);
|
||||
|
||||
index++;
|
||||
for (int i = 0; i < languages.length; i++) {
|
||||
String id = languages[i].getId();
|
||||
if (!languages[i].equals(inheritedLanguage)) {
|
||||
descriptions[index] = languages[i].getName();
|
||||
fLanguageNamesToIDsMap.put(descriptions[index], id);
|
||||
index++;
|
||||
}
|
||||
for (int i = 0; i < fLanguages.length; i++) {
|
||||
descriptions[LANGUAGE_ID][index] = fLanguages[i].getId();
|
||||
descriptions[LANGUAGE_NAME][index] = fLanguages[i].getName();
|
||||
index++;
|
||||
}
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
private static class LanguageTableData {
|
||||
ICConfigurationDescription configuration;
|
||||
String languageId;
|
||||
|
||||
LanguageTableData(ICConfigurationDescription configuration, String languageId) {
|
||||
this.configuration = configuration;
|
||||
this.languageId = languageId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,51 +13,36 @@ package org.eclipse.cdt.internal.ui.language;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.eclipse.jface.layout.TableColumnLayout;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Link;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||
public abstract class LanguageMappingWidget {
|
||||
|
||||
public class LanguageMappingWidget {
|
||||
|
||||
private static final int MINIMUM_COLUMN_WIDTH = 150;
|
||||
private Table fTable;
|
||||
private HashMap fContentTypeNamesToIDsMap;
|
||||
private Set fAffectedContentTypes;
|
||||
private Composite fContents;
|
||||
private Map fContentTypeMappings;
|
||||
private boolean fIsReadOnly;
|
||||
private Set fOverriddenContentTypes;
|
||||
private Font fOverriddenFont;
|
||||
private LanguageMappingWidget fChild;
|
||||
private IAdaptable fElement;
|
||||
protected static final int MINIMUM_COLUMN_WIDTH = 150;
|
||||
protected Composite fContents;
|
||||
protected boolean fIsReadOnly;
|
||||
|
||||
protected Table fTable;
|
||||
protected HashMap fContentTypeNamesToIDsMap;
|
||||
protected Set fAffectedContentTypes;
|
||||
protected Font fOverriddenFont;
|
||||
protected LanguageMappingWidget fChild;
|
||||
protected IAdaptable fElement;
|
||||
|
||||
protected Set fOverriddenContentTypes;
|
||||
|
||||
public LanguageMappingWidget() {
|
||||
fOverriddenFont = JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT);
|
||||
|
@ -79,86 +64,34 @@ public class LanguageMappingWidget {
|
|||
fContentTypeNamesToIDsMap.put(name, contentTypesIDs[i]);
|
||||
}
|
||||
|
||||
fContentTypeMappings = new TreeMap();
|
||||
fAffectedContentTypes = new HashSet();
|
||||
}
|
||||
|
||||
public Composite createContents(Composite parent, String description) {
|
||||
fContents = new Composite(parent, SWT.NONE);
|
||||
fContents.setLayout(new GridLayout(2, false));
|
||||
|
||||
if (description != null) {
|
||||
createHeader(parent, description);
|
||||
}
|
||||
|
||||
Composite tableParent = new Composite(fContents, SWT.NONE);
|
||||
tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
fTable = new Table(tableParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
||||
fTable.setHeaderVisible(true);
|
||||
fTable.setLinesVisible(true);
|
||||
|
||||
TableColumn contentTypeColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
contentTypeColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_contentTypeColumn);
|
||||
|
||||
TableColumn languageColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
languageColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_languageColumn);
|
||||
|
||||
TableColumnLayout layout = new TableColumnLayout();
|
||||
layout.setColumnData(contentTypeColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
layout.setColumnData(languageColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
tableParent.setLayout(layout);
|
||||
|
||||
if (!fIsReadOnly) {
|
||||
Composite buttons = new Composite(fContents, SWT.NONE);
|
||||
buttons.setLayout(new GridLayout());
|
||||
buttons.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
|
||||
public IAdaptable getElement() {
|
||||
return fElement;
|
||||
}
|
||||
|
||||
Button addButton = new Button(buttons, SWT.PUSH);
|
||||
addButton.setText(PreferencesMessages.ProjectLanguagesPropertyPage_addMappingButton);
|
||||
addButton.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
ContentTypeMappingDialog dialog = new ContentTypeMappingDialog(fContents.getShell());
|
||||
dialog.setContentTypeFilter(fContentTypeMappings.keySet());
|
||||
dialog.setBlockOnOpen(true);
|
||||
public void setElement(IAdaptable element) {
|
||||
fElement = element;
|
||||
}
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
String contentType = dialog.getContentTypeID();
|
||||
String language = dialog.getLanguageID();
|
||||
fContentTypeMappings.put(contentType, language);
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
fAffectedContentTypes.add(contentTypeManager.getContentType(contentType));
|
||||
refreshMappings();
|
||||
}
|
||||
}
|
||||
});
|
||||
public void setOverriddenContentTypes(Set contentTypes) {
|
||||
fOverriddenContentTypes = contentTypes;
|
||||
}
|
||||
|
||||
Button removeButton = new Button(buttons, SWT.PUSH);
|
||||
removeButton.setText(PreferencesMessages.ProjectLanguagesPropertyPage_removeMappingButton);
|
||||
removeButton.addListener(SWT.Selection, new Listener() {
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
TableItem[] selection = fTable.getSelection();
|
||||
|
||||
for (int i = 0; i < selection.length; i++) {
|
||||
String contentType = (String) fContentTypeNamesToIDsMap.get(selection[i].getText(0));
|
||||
|
||||
fContentTypeMappings.remove(contentType);
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
fAffectedContentTypes.add(contentTypeManager.getContentType(contentType));
|
||||
}
|
||||
|
||||
refreshMappings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
refreshMappings();
|
||||
return fContents;
|
||||
public IContentType[] getAffectedContentTypes() {
|
||||
return (IContentType[]) fAffectedContentTypes.toArray(new IContentType[fAffectedContentTypes.size()]);
|
||||
}
|
||||
|
||||
private void createHeader(Composite parent, String description) {
|
||||
public void setReadOnly(boolean isReadOnly) {
|
||||
fIsReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
public void setChild(LanguageMappingWidget child) {
|
||||
fChild = child;
|
||||
}
|
||||
|
||||
protected void createHeader(Composite parent, String description) {
|
||||
Link link = new Link(fContents, SWT.NONE);
|
||||
link.setText(description);
|
||||
|
||||
|
@ -172,72 +105,7 @@ public class LanguageMappingWidget {
|
|||
gridData.horizontalSpan = 2;
|
||||
link.setLayoutData(gridData);
|
||||
}
|
||||
|
||||
public IAdaptable getElement() {
|
||||
return fElement;
|
||||
}
|
||||
|
||||
public void setElement(IAdaptable element) {
|
||||
fElement = element;
|
||||
}
|
||||
|
||||
public void refreshMappings() {
|
||||
if (fTable == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
fTable.removeAll();
|
||||
Iterator mappings = fContentTypeMappings.entrySet().iterator();
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
|
||||
while (mappings.hasNext()) {
|
||||
Entry entry = (Entry) mappings.next();
|
||||
|
||||
TableItem item = new TableItem(fTable, SWT.NONE);
|
||||
|
||||
String contentType = (String) entry.getKey();
|
||||
String contentTypeName = contentTypeManager.getContentType(contentType).getName();
|
||||
String languageName = LanguageManager.getInstance().getLanguage((String) entry.getValue()).getName();
|
||||
|
||||
if (fOverriddenContentTypes.contains(contentType)) {
|
||||
item.setText(0, Messages.format(PreferencesMessages.ProjectLanguagesPropertyPage_overriddenContentType, contentTypeName));
|
||||
item.setFont(fOverriddenFont);
|
||||
} else {
|
||||
item.setText(0, contentTypeName);
|
||||
}
|
||||
item.setText(1, languageName);
|
||||
}
|
||||
|
||||
if (fChild != null) {
|
||||
Set overrides = new HashSet(fContentTypeMappings.keySet());
|
||||
overrides.addAll(fOverriddenContentTypes);
|
||||
fChild.setOverriddenContentTypes(overrides);
|
||||
fChild.refreshMappings();
|
||||
}
|
||||
}
|
||||
|
||||
public void setOverriddenContentTypes(Set contentTypes) {
|
||||
fOverriddenContentTypes = contentTypes;
|
||||
}
|
||||
|
||||
public void setMappings(Map mappings) {
|
||||
fContentTypeMappings = new TreeMap(mappings);
|
||||
}
|
||||
|
||||
public IContentType[] getAffectedContentTypes() {
|
||||
return (IContentType[]) fAffectedContentTypes.toArray(new IContentType[fAffectedContentTypes.size()]);
|
||||
}
|
||||
|
||||
public Map getContentTypeMappings() {
|
||||
return Collections.unmodifiableMap(fContentTypeMappings);
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean isReadOnly) {
|
||||
fIsReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
public void setChild(LanguageMappingWidget child) {
|
||||
fChild = child;
|
||||
}
|
||||
public abstract Composite createContents(Composite parent, String description);
|
||||
public abstract void refreshMappings();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.language;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
|
||||
public class ProjectContentTypeMappingDialog extends ContentTypeMappingDialog {
|
||||
|
||||
private Combo fConfiguration;
|
||||
private ICConfigurationDescription[] fConfigurations;
|
||||
private String[] fContentTypesIDs;
|
||||
private Set fFilteredContentTypes;
|
||||
|
||||
public ProjectContentTypeMappingDialog(Shell parentShell, ICConfigurationDescription[] configurations) {
|
||||
super(parentShell);
|
||||
fConfigurations = configurations;
|
||||
|
||||
fContentTypesIDs = LanguageManager.getInstance().getRegisteredContentTypeIds();
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
|
||||
for (int i = 0; i < fContentTypesIDs.length; i++) {
|
||||
String name = contentTypeManager.getContentType(fContentTypesIDs[i]).getName();
|
||||
|
||||
// keep track of what ID this name corresponds to so that when
|
||||
// we setup the mapping
|
||||
// later based upon user selection, we'll know what ID to use
|
||||
fContentTypeNamesToIDsMap.put(name, fContentTypesIDs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void configureConfigurations(Combo combo) {
|
||||
combo.add(PreferencesMessages.ContentTypeMappingsDialog_allConfigurations);
|
||||
for (int i = 0; i < fConfigurations.length; i++) {
|
||||
combo.add(fConfigurations[i].getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite area = new Composite(parent, SWT.NONE);
|
||||
area.setLayout(new GridLayout(2, false));
|
||||
|
||||
Label configurationLabel = new Label(area, SWT.TRAIL);
|
||||
configurationLabel.setText(PreferencesMessages.ContentTypeMappingsDialog_configuration);
|
||||
fConfiguration = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fConfiguration.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
configureConfigurations(fConfiguration);
|
||||
fConfiguration.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
int index = fConfiguration.getSelectionIndex();
|
||||
if (index <= 0) {
|
||||
fSelectedConfigurationName = null;
|
||||
fSelectedConfigurationID = null;
|
||||
configureContentTypes(fContentType, null);
|
||||
getButton(IDialogConstants.OK_ID).setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift index by one because of "All configurations" entry.
|
||||
int configurationIndex = index - 1;
|
||||
ICConfigurationDescription configuration = fConfigurations[configurationIndex];
|
||||
|
||||
fSelectedConfigurationName = configuration.getName();
|
||||
fSelectedConfigurationID = configuration.getId();
|
||||
configureContentTypes(fContentType, configuration);
|
||||
|
||||
getButton(IDialogConstants.OK_ID).setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
fConfiguration.select(0);
|
||||
|
||||
Label contentTypeLabel = new Label(area, SWT.TRAIL);
|
||||
contentTypeLabel.setText(PreferencesMessages.ContentTypeMappingsDialog_contentType);
|
||||
|
||||
fContentType = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fContentType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
fContentType.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fSelectedContentTypeName = fContentType.getText();
|
||||
fSelectedContentTypeID = (String) fContentTypeNamesToIDsMap.get(fSelectedContentTypeName);
|
||||
getButton(IDialogConstants.OK_ID).setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
configureContentTypes(fContentType, null);
|
||||
|
||||
Label languageLabel = new Label(area, SWT.TRAIL);
|
||||
languageLabel.setText(PreferencesMessages.ContentTypeMappingsDialog_language);
|
||||
|
||||
fLanguage = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fLanguage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
fLanguage.setItems(getLanguages());
|
||||
fLanguage.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fSelectedLanguageName = fLanguage.getText();
|
||||
fSelectedLanguageID = (String) fLanguageNamesToIDsMap.get(fSelectedLanguageName);
|
||||
getButton(IDialogConstants.OK_ID).setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private void configureContentTypes(Combo combo, ICConfigurationDescription configuration) {
|
||||
combo.removeAll();
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
for (int i = 0; i < fContentTypesIDs.length; i++) {
|
||||
String contentTypeId = fContentTypesIDs[i];
|
||||
String name = contentTypeManager.getContentType(contentTypeId).getName();
|
||||
if (configuration != null) {
|
||||
String key = ProjectLanguageMappingWidget.createFilterKey(configuration.getId(), contentTypeId);
|
||||
if (!fFilteredContentTypes.contains(key)) {
|
||||
combo.add(name);
|
||||
}
|
||||
} else {
|
||||
combo.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isValidSelection() {
|
||||
return fContentType.getSelectionIndex() != -1 && fLanguage.getSelectionIndex() != -1 && fConfiguration.getSelectionIndex() != -1;
|
||||
}
|
||||
|
||||
public void setContentTypeFilter(Set contentTypeFilter) {
|
||||
fFilteredContentTypes = contentTypeFilter;
|
||||
}
|
||||
|
||||
public String getConfigurationID() {
|
||||
return fSelectedConfigurationID;
|
||||
}
|
||||
}
|
|
@ -34,16 +34,16 @@ import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
|||
|
||||
public class ProjectLanguageMappingPropertyPage extends PropertyPage {
|
||||
|
||||
private LanguageMappingWidget fMappingWidget;
|
||||
private LanguageMappingWidget fInheritedMappingWidget;
|
||||
private ProjectLanguageMappingWidget fMappingWidget;
|
||||
private WorkspaceLanguageMappingWidget fInheritedMappingWidget;
|
||||
private ProjectLanguageConfiguration fMappings;
|
||||
private ILanguageMappingChangeListener fInheritedMappingsChangeListener;
|
||||
|
||||
public ProjectLanguageMappingPropertyPage() {
|
||||
super();
|
||||
fMappingWidget = new LanguageMappingWidget();
|
||||
fMappingWidget = new ProjectLanguageMappingWidget();
|
||||
|
||||
fInheritedMappingWidget = new LanguageMappingWidget();
|
||||
fInheritedMappingWidget = new WorkspaceLanguageMappingWidget();
|
||||
fInheritedMappingWidget.setReadOnly(true);
|
||||
|
||||
fMappingWidget.setChild(fInheritedMappingWidget);
|
||||
|
|
|
@ -0,0 +1,262 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.language;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.eclipse.jface.layout.TableColumnLayout;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||
|
||||
public class ProjectLanguageMappingWidget extends LanguageMappingWidget {
|
||||
|
||||
static final String CONTENT_TYPE_KEY_DELIMITER = "::"; //$NON-NLS-1$
|
||||
|
||||
private static final String ALL_CONFIGURATIONS = ""; //$NON-NLS-1$
|
||||
|
||||
private static final int CONFIGURATION_COLUMN = 0;
|
||||
|
||||
private static final int CONTENT_TYPE_COLUMN = 1;
|
||||
|
||||
private static final int LANGUAGE_COLUMN = 2;
|
||||
|
||||
private Map fConfigurationContentTypeMappings;
|
||||
|
||||
public void setMappings(Map contentTypeMappings) {
|
||||
fConfigurationContentTypeMappings = contentTypeMappings;
|
||||
}
|
||||
|
||||
public Map getContentTypeMappings() {
|
||||
return fConfigurationContentTypeMappings;
|
||||
}
|
||||
|
||||
public Composite createContents(Composite parent, String description) {
|
||||
fContents = new Composite(parent, SWT.NONE);
|
||||
fContents.setLayout(new GridLayout(2, false));
|
||||
|
||||
if (description != null) {
|
||||
createHeader(parent, description);
|
||||
}
|
||||
|
||||
Composite tableParent = new Composite(fContents, SWT.NONE);
|
||||
tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
fTable = new Table(tableParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
||||
fTable.setHeaderVisible(true);
|
||||
fTable.setLinesVisible(true);
|
||||
|
||||
TableColumn configurationColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
configurationColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_configurationColumn);
|
||||
|
||||
TableColumn contentTypeColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
contentTypeColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_contentTypeColumn);
|
||||
|
||||
TableColumn languageColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
languageColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_languageColumn);
|
||||
|
||||
TableColumnLayout layout = new TableColumnLayout();
|
||||
layout.setColumnData(configurationColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
layout.setColumnData(contentTypeColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
layout.setColumnData(languageColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
tableParent.setLayout(layout);
|
||||
|
||||
Composite buttons = new Composite(fContents, SWT.NONE);
|
||||
buttons.setLayout(new GridLayout());
|
||||
buttons.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
|
||||
|
||||
Button addButton = new Button(buttons, SWT.PUSH);
|
||||
addButton.setText(PreferencesMessages.ProjectLanguagesPropertyPage_addMappingButton);
|
||||
addButton.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
IProject project = (IProject) getElement().getAdapter(IProject.class);
|
||||
ICProjectDescription description = CoreModel.getDefault().getProjectDescription(project, false);
|
||||
ICConfigurationDescription[] configurations = description.getConfigurations();
|
||||
ProjectContentTypeMappingDialog dialog = new ProjectContentTypeMappingDialog(fContents.getShell(), configurations);
|
||||
|
||||
dialog.setContentTypeFilter(createContentTypeFilter(fConfigurationContentTypeMappings));
|
||||
dialog.setBlockOnOpen(true);
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
String contentType = dialog.getContentTypeID();
|
||||
String language = dialog.getLanguageID();
|
||||
String configuration = dialog.getConfigurationID();
|
||||
if (configuration == null) {
|
||||
configuration = ALL_CONFIGURATIONS;
|
||||
}
|
||||
Map contentTypeMappings = (Map) fConfigurationContentTypeMappings.get(configuration);
|
||||
if (contentTypeMappings == null) {
|
||||
contentTypeMappings = new TreeMap();
|
||||
fConfigurationContentTypeMappings.put(configuration, contentTypeMappings);
|
||||
}
|
||||
contentTypeMappings.put(contentType, language);
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
fAffectedContentTypes.add(contentTypeManager.getContentType(contentType));
|
||||
refreshMappings();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button removeButton = new Button(buttons, SWT.PUSH);
|
||||
removeButton.setText(PreferencesMessages.ProjectLanguagesPropertyPage_removeMappingButton);
|
||||
removeButton.addListener(SWT.Selection, new Listener() {
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
TableItem[] selection = fTable.getSelection();
|
||||
|
||||
for (int i = 0; i < selection.length; i++) {
|
||||
LanguageTableData data = (LanguageTableData) selection[i].getData();
|
||||
String contentType = data.contentTypeId;
|
||||
|
||||
String configurationId;
|
||||
if (data.configuration == null) {
|
||||
configurationId = ALL_CONFIGURATIONS;
|
||||
} else {
|
||||
configurationId = data.configuration.getId();
|
||||
}
|
||||
|
||||
Map contentTypeMappings = (Map) fConfigurationContentTypeMappings.get(configurationId);
|
||||
if (contentTypeMappings != null) {
|
||||
contentTypeMappings.remove(contentType);
|
||||
}
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
fAffectedContentTypes.add(contentTypeManager.getContentType(contentType));
|
||||
}
|
||||
|
||||
refreshMappings();
|
||||
}
|
||||
});
|
||||
|
||||
refreshMappings();
|
||||
return fContents;
|
||||
}
|
||||
|
||||
private Set createContentTypeFilter(Map mappings) {
|
||||
Set filter = new HashSet();
|
||||
Iterator configurationContentTypeMappings = mappings.entrySet().iterator();
|
||||
while (configurationContentTypeMappings.hasNext()) {
|
||||
Entry entry = (Entry) configurationContentTypeMappings.next();
|
||||
String configuration = (String) entry.getKey();
|
||||
Iterator contentTypeMappings = ((Map) entry.getValue()).entrySet().iterator();
|
||||
while (contentTypeMappings.hasNext()) {
|
||||
Entry contentTypeEntry = (Entry) contentTypeMappings.next();
|
||||
String contentType = (String) contentTypeEntry.getKey();
|
||||
filter.add(createFilterKey(configuration, contentType));
|
||||
}
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void refreshMappings() {
|
||||
if (fTable == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
fTable.removeAll();
|
||||
Iterator mappings = fConfigurationContentTypeMappings.entrySet().iterator();
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
|
||||
IProject project = (IProject) getElement().getAdapter(IProject.class);
|
||||
ICProjectDescription description = CoreModel.getDefault().getProjectDescription(project, false);
|
||||
|
||||
while (mappings.hasNext()) {
|
||||
Entry configurationEntry = (Entry) mappings.next();
|
||||
String configurationId = (String) configurationEntry.getKey();
|
||||
Iterator contentTypeMappings = ((Map) configurationEntry.getValue()).entrySet().iterator();
|
||||
while (contentTypeMappings.hasNext()) {
|
||||
Entry entry = (Entry) contentTypeMappings.next();
|
||||
TableItem item = new TableItem(fTable, SWT.NONE);
|
||||
|
||||
String contentType = (String) entry.getKey();
|
||||
String contentTypeName = contentTypeManager.getContentType(contentType).getName();
|
||||
String languageId = (String) entry.getValue();
|
||||
String languageName = LanguageManager.getInstance().getLanguage(languageId).getName();
|
||||
|
||||
ICConfigurationDescription configuration = description.getConfigurationById(configurationId);
|
||||
|
||||
item.setData(new LanguageTableData(configuration, contentType, languageId));
|
||||
|
||||
if (configuration == null) {
|
||||
item.setText(CONFIGURATION_COLUMN, PreferencesMessages.ContentTypeMappingsDialog_allConfigurations);
|
||||
} else {
|
||||
item.setText(CONFIGURATION_COLUMN, configuration.getName());
|
||||
}
|
||||
|
||||
if (fOverriddenContentTypes.contains(contentType)) {
|
||||
item.setText(CONTENT_TYPE_COLUMN, Messages.format(PreferencesMessages.ProjectLanguagesPropertyPage_overriddenContentType, contentTypeName));
|
||||
item.setFont(fOverriddenFont);
|
||||
} else {
|
||||
item.setText(CONTENT_TYPE_COLUMN, contentTypeName);
|
||||
}
|
||||
item.setText(LANGUAGE_COLUMN, languageName);
|
||||
}
|
||||
}
|
||||
|
||||
if (fChild != null) {
|
||||
Set overrides = new HashSet(createWorkspaceContentTypeFilter(fConfigurationContentTypeMappings));
|
||||
fChild.setOverriddenContentTypes(overrides);
|
||||
fChild.refreshMappings();
|
||||
}
|
||||
}
|
||||
|
||||
private Set createWorkspaceContentTypeFilter(Map configurationContentTypeMappings) {
|
||||
Map contentTypeMappings = (Map) configurationContentTypeMappings.get(ALL_CONFIGURATIONS);
|
||||
if (contentTypeMappings == null) {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
return contentTypeMappings.keySet();
|
||||
}
|
||||
|
||||
static String createFilterKey(String configurationId, String contentTypeId) {
|
||||
return configurationId + CONTENT_TYPE_KEY_DELIMITER + contentTypeId;
|
||||
}
|
||||
|
||||
private static class LanguageTableData {
|
||||
ICConfigurationDescription configuration;
|
||||
String contentTypeId;
|
||||
String languageId;
|
||||
|
||||
LanguageTableData(ICConfigurationDescription configuration, String contentTypeId, String languageId) {
|
||||
this.configuration = configuration;
|
||||
this.contentTypeId = contentTypeId;
|
||||
this.languageId = languageId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.language;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
|
||||
public class WorkspaceContentTypeMappingDialog extends ContentTypeMappingDialog {
|
||||
private Set fFilteredContentTypes;
|
||||
|
||||
public WorkspaceContentTypeMappingDialog(Shell parentShell) {
|
||||
super(parentShell);
|
||||
fFilteredContentTypes = Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite area = new Composite(parent, SWT.NONE);
|
||||
area.setLayout(new GridLayout(2, false));
|
||||
|
||||
Label contentTypeLabel = new Label(area, SWT.TRAIL);
|
||||
contentTypeLabel.setText(PreferencesMessages.ContentTypeMappingsDialog_contentType);
|
||||
|
||||
fContentType = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fContentType.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
configureContentTypes(fContentType);
|
||||
fContentType.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fSelectedContentTypeName = fContentType.getText();
|
||||
fSelectedContentTypeID = (String) fContentTypeNamesToIDsMap.get(fSelectedContentTypeName);
|
||||
getButton(IDialogConstants.OK_ID).setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
|
||||
Label languageLabel = new Label(area, SWT.TRAIL);
|
||||
languageLabel.setText(PreferencesMessages.ContentTypeMappingsDialog_language);
|
||||
|
||||
fLanguage = new Combo(area, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
fLanguage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
fLanguage.setItems(getLanguages());
|
||||
fLanguage.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fSelectedLanguageName = fLanguage.getText();
|
||||
fSelectedLanguageID = (String) fLanguageNamesToIDsMap.get(fSelectedLanguageName);
|
||||
getButton(IDialogConstants.OK_ID).setEnabled(isValidSelection());
|
||||
}
|
||||
});
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private void configureContentTypes(Combo combo) {
|
||||
combo.removeAll();
|
||||
String[] contentTypesIDs = LanguageManager.getInstance()
|
||||
.getRegisteredContentTypeIds();
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform
|
||||
.getContentTypeManager();
|
||||
|
||||
for (int i = 0; i < contentTypesIDs.length; i++) {
|
||||
if (!fFilteredContentTypes.contains(contentTypesIDs[i])) {
|
||||
|
||||
String name = contentTypeManager.getContentType(
|
||||
contentTypesIDs[i]).getName();
|
||||
|
||||
combo.add(name);
|
||||
|
||||
// keep track of what ID this name corresponds to so that when
|
||||
// we setup the mapping
|
||||
// later based upon user selection, we'll know what ID to use
|
||||
fContentTypeNamesToIDsMap.put(name, contentTypesIDs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setContentTypeFilter(Set contentTypes) {
|
||||
fFilteredContentTypes = contentTypes;
|
||||
}
|
||||
|
||||
protected boolean isValidSelection() {
|
||||
return fContentType.getSelectionIndex() != -1 && fLanguage.getSelectionIndex() != -1;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,10 +27,10 @@ import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
|||
public class WorkspaceLanguageMappingPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
|
||||
|
||||
WorkspaceLanguageConfiguration fMappings;
|
||||
LanguageMappingWidget fMappingWidget;
|
||||
WorkspaceLanguageMappingWidget fMappingWidget;
|
||||
|
||||
public WorkspaceLanguageMappingPreferencePage() {
|
||||
fMappingWidget = new LanguageMappingWidget();
|
||||
fMappingWidget = new WorkspaceLanguageMappingWidget();
|
||||
}
|
||||
|
||||
protected Control createContents(Composite parent) {
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.language;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.eclipse.jface.layout.TableColumnLayout;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.PreferencesMessages;
|
||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||
|
||||
public class WorkspaceLanguageMappingWidget extends LanguageMappingWidget {
|
||||
private Map fContentTypeMappings;
|
||||
|
||||
public WorkspaceLanguageMappingWidget() {
|
||||
super();
|
||||
fContentTypeMappings = new TreeMap();
|
||||
}
|
||||
|
||||
public Composite createContents(Composite parent, String description) {
|
||||
fContents = new Composite(parent, SWT.NONE);
|
||||
fContents.setLayout(new GridLayout(2, false));
|
||||
|
||||
if (description != null) {
|
||||
createHeader(parent, description);
|
||||
}
|
||||
|
||||
Composite tableParent = new Composite(fContents, SWT.NONE);
|
||||
tableParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
fTable = new Table(tableParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
||||
fTable.setHeaderVisible(true);
|
||||
fTable.setLinesVisible(true);
|
||||
|
||||
TableColumn contentTypeColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
contentTypeColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_contentTypeColumn);
|
||||
|
||||
TableColumn languageColumn = new TableColumn(fTable, SWT.LEAD);
|
||||
languageColumn.setText(PreferencesMessages.ProjectLanguagesPropertyPage_languageColumn);
|
||||
|
||||
TableColumnLayout layout = new TableColumnLayout();
|
||||
layout.setColumnData(contentTypeColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
layout.setColumnData(languageColumn, new ColumnWeightData(1, MINIMUM_COLUMN_WIDTH, true));
|
||||
tableParent.setLayout(layout);
|
||||
|
||||
if (!fIsReadOnly) {
|
||||
Composite buttons = new Composite(fContents, SWT.NONE);
|
||||
buttons.setLayout(new GridLayout());
|
||||
buttons.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
|
||||
|
||||
Button addButton = new Button(buttons, SWT.PUSH);
|
||||
addButton.setText(PreferencesMessages.ProjectLanguagesPropertyPage_addMappingButton);
|
||||
addButton.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
WorkspaceContentTypeMappingDialog dialog = new WorkspaceContentTypeMappingDialog(fContents.getShell());
|
||||
dialog.setContentTypeFilter(fContentTypeMappings.keySet());
|
||||
dialog.setBlockOnOpen(true);
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
String contentType = dialog.getContentTypeID();
|
||||
String language = dialog.getLanguageID();
|
||||
fContentTypeMappings.put(contentType, language);
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
fAffectedContentTypes.add(contentTypeManager.getContentType(contentType));
|
||||
refreshMappings();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button removeButton = new Button(buttons, SWT.PUSH);
|
||||
removeButton.setText(PreferencesMessages.ProjectLanguagesPropertyPage_removeMappingButton);
|
||||
removeButton.addListener(SWT.Selection, new Listener() {
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
TableItem[] selection = fTable.getSelection();
|
||||
|
||||
for (int i = 0; i < selection.length; i++) {
|
||||
String contentType = (String) fContentTypeNamesToIDsMap.get(selection[i].getText(0));
|
||||
|
||||
fContentTypeMappings.remove(contentType);
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
fAffectedContentTypes.add(contentTypeManager.getContentType(contentType));
|
||||
}
|
||||
|
||||
refreshMappings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
refreshMappings();
|
||||
return fContents;
|
||||
}
|
||||
|
||||
public void refreshMappings() {
|
||||
if (fTable == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
fTable.removeAll();
|
||||
Iterator mappings = fContentTypeMappings.entrySet().iterator();
|
||||
|
||||
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
|
||||
|
||||
while (mappings.hasNext()) {
|
||||
Entry entry = (Entry) mappings.next();
|
||||
|
||||
TableItem item = new TableItem(fTable, SWT.NONE);
|
||||
|
||||
String contentType = (String) entry.getKey();
|
||||
String contentTypeName = contentTypeManager.getContentType(contentType).getName();
|
||||
String languageName = LanguageManager.getInstance().getLanguage((String) entry.getValue()).getName();
|
||||
|
||||
if (fOverriddenContentTypes.contains(contentType)) {
|
||||
item.setText(0, Messages.format(PreferencesMessages.ProjectLanguagesPropertyPage_overriddenContentType, contentTypeName));
|
||||
item.setFont(fOverriddenFont);
|
||||
} else {
|
||||
item.setText(0, contentTypeName);
|
||||
}
|
||||
item.setText(1, languageName);
|
||||
}
|
||||
|
||||
if (fChild != null) {
|
||||
Set overrides = new HashSet(fContentTypeMappings.keySet());
|
||||
overrides.addAll(fOverriddenContentTypes);
|
||||
fChild.setOverriddenContentTypes(overrides);
|
||||
fChild.refreshMappings();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMappings(Map mappings) {
|
||||
fContentTypeMappings = new TreeMap(mappings);
|
||||
}
|
||||
|
||||
public Map getContentTypeMappings() {
|
||||
return Collections.unmodifiableMap(fContentTypeMappings);
|
||||
}
|
||||
}
|
|
@ -196,6 +196,7 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String WorkspaceLanguagesPreferencePage_description;
|
||||
|
||||
public static String ProjectLanguagesPropertyPage_description;
|
||||
public static String ProjectLanguagesPropertyPage_configurationColumn;
|
||||
public static String ProjectLanguagesPropertyPage_contentTypeColumn;
|
||||
public static String ProjectLanguagesPropertyPage_languageColumn;
|
||||
public static String ProjectLanguagesPropertyPage_addMappingButton;
|
||||
|
@ -204,8 +205,10 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String ProjectLanguagesPropertyPage_overriddenContentType;
|
||||
|
||||
public static String ContentTypeMappingsDialog_title;
|
||||
public static String ContentTypeMappingsDialog_configuration;
|
||||
public static String ContentTypeMappingsDialog_contentType;
|
||||
public static String ContentTypeMappingsDialog_language;
|
||||
public static String ContentTypeMappingsDialog_allConfigurations;
|
||||
|
||||
public static String FileLanguagesPropertyPage_languageLabel;
|
||||
public static String FileLanguagesPropertyPage_inheritedProjectMappingsGroup;
|
||||
|
@ -213,7 +216,10 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String FileLanguagesPropertyPage_inheritedFromSystem;
|
||||
public static String FileLanguagesPropertyPage_inheritedFromProject;
|
||||
public static String FileLanguagesPropertyPage_inheritedFromWorkspace;
|
||||
public static String FileLanguagesPropertyPage_inheritedFromFile;
|
||||
public static String FileLanguagesPropertyPage_description;
|
||||
public static String FileLanguagesPropertyPage_configurationColumn;
|
||||
public static String FileLanguagesPropertyPage_defaultMapping;
|
||||
|
||||
public static String CPluginPreferencePage_linkToEditor_label;
|
||||
public static String CPluginPreferencePage_structuralParseMode_label;
|
||||
|
|
|
@ -230,6 +230,7 @@ PathEntryVariablesBlock_removeVariableButton = &Remove
|
|||
WorkspaceLanguagesPreferencePage_description = These settings are global to the entire workspace. They are overridden by project-specific language mappings.
|
||||
|
||||
ProjectLanguagesPropertyPage_description = These settings are project-specific. The mappings listed here override <a href="workspace">workspace-wide</a> language mappings.
|
||||
ProjectLanguagesPropertyPage_configurationColumn = Configuration
|
||||
ProjectLanguagesPropertyPage_contentTypeColumn = Content Type
|
||||
ProjectLanguagesPropertyPage_languageColumn = Language
|
||||
ProjectLanguagesPropertyPage_addMappingButton = &Add...
|
||||
|
@ -238,8 +239,10 @@ ProjectLanguagesPropertyPage_inheritedWorkspaceMappingsGroup = Language settings
|
|||
ProjectLanguagesPropertyPage_overriddenContentType = (Overridden) {0}
|
||||
|
||||
ContentTypeMappingsDialog_title = Add Mapping
|
||||
ContentTypeMappingsDialog_configuration = Configuration
|
||||
ContentTypeMappingsDialog_contentType = Content type
|
||||
ContentTypeMappingsDialog_language = Language
|
||||
ContentTypeMappingsDialog_allConfigurations = (All)
|
||||
|
||||
FileLanguagesPropertyPage_description = This language assignment overrides all <a href="project">project-wide</a> and <a href="workspace">workspace-wide</a> language mappings.
|
||||
FileLanguagesPropertyPage_contentTypeLabel = Content Type:
|
||||
|
@ -248,6 +251,9 @@ FileLanguagesPropertyPage_inheritedProjectMappingsGroup = Language settings inhe
|
|||
FileLanguagesPropertyPage_inheritedFromSystem = Inherited from the system ({0})
|
||||
FileLanguagesPropertyPage_inheritedFromProject = Inherited from the project ({0})
|
||||
FileLanguagesPropertyPage_inheritedFromWorkspace = Inherited from the workspace ({0})
|
||||
FileLanguagesPropertyPage_inheritedFromFile = Inherited from (Default) ({0})
|
||||
FileLanguagesPropertyPage_configurationColumn = Configuration
|
||||
FileLanguagesPropertyPage_defaultMapping = (Default)
|
||||
|
||||
# Others
|
||||
ProposalFilterPreferencesUtil_defaultFilterName=<Default Filter>
|
||||
|
|
Loading…
Add table
Reference in a new issue