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