1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Fix toggle/source in case of mixed C/C++ projects

This commit is contained in:
Anton Leherbauer 2007-04-24 09:38:45 +00:00
parent f8d8620ddc
commit 640b94f6a3

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.ui.editor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.ResourceBundle;
@ -253,12 +254,15 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
// search partnerfile based on filename/extension
IPath sourceFileLocation= tUnit.getLocation();
IPath partnerBasePath= sourceFileLocation.removeFileExtension();
IContentType contentType= getPartnerContentType(tUnit.getContentTypeId());
if (contentType != null) {
IContentType[] contentTypes= getPartnerContentTypes(tUnit.getContentTypeId());
HashSet extensionsTried= new HashSet();
for (int j = 0; j < contentTypes.length; j++) {
IContentType contentType= contentTypes[j];
String[] partnerExtensions;
partnerExtensions= contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
for (int i= 0; i < partnerExtensions.length; i++) {
String ext= partnerExtensions[i];
if (extensionsTried.add(ext)) {
String partnerFileBasename= partnerBasePath.addFileExtension(ext).lastSegment();
IFile partnerFile= null;
@ -284,6 +288,7 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
}
}
}
}
return null;
}
@ -318,20 +323,32 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
return result[0];
}
private IContentType getPartnerContentType(String contentTypeId) {
private IContentType[] getPartnerContentTypes(String contentTypeId) {
IContentTypeManager mgr= Platform.getContentTypeManager();
if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CHEADER)) {
return mgr.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE);
return new IContentType[] {
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE),
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE)
};
}
if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CSOURCE)) {
return mgr.getContentType(CCorePlugin.CONTENT_TYPE_CHEADER);
return new IContentType[] {
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CHEADER),
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CXXHEADER)
};
}
if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER)) {
return mgr.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
return new IContentType[] {
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE),
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE)
};
}
if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CXXSOURCE)) {
return mgr.getContentType(CCorePlugin.CONTENT_TYPE_CXXHEADER);
return new IContentType[] {
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CXXHEADER),
mgr.getContentType(CCorePlugin.CONTENT_TYPE_CHEADER)
};
}
return null;
return new IContentType[0];
}
}