diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index d3d5a04fdbf..aa900f58ed1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -18,8 +18,10 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.IDecoration; @@ -114,21 +116,19 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { return overlayKeys; } - if (currentLanguageId != null) { - IResource rc = getResource(); - List entries = getSettingEntries(provider); - if (entries == null && !(rc instanceof IProject)) { - List entriesParent = getSettingEntriesUpResourceTree(provider); - if (entriesParent != null) { - overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; - } - } else if (provider instanceof ILanguageSettingsBroadcastingProvider && (page.isForFile() || page.isForFolder())) { - // Assuming that the default entries for a resource are always null. - // Using that for performance reasons. See note in performDefaults(). - List entriesParent = provider.getSettingEntries(null, null, currentLanguageId); - if (entries != null && !entries.equals(entriesParent)) { - overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; - } + IResource rc = getResource(); + List entries = getSettingEntries(provider); + if (entries == null && !(rc instanceof IProject)) { + List entriesParent = getSettingEntriesUpResourceTree(provider); + if (entriesParent != null) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; + } + } else if (provider instanceof ILanguageSettingsBroadcastingProvider && (page.isForFile() || page.isForFolder())) { + // Assuming that the default entries for a resource are always null. + // Using that for performance reasons. See note in performDefaults(). + List entriesParent = provider.getSettingEntries(null, null, currentLanguageId); + if (entries != null && !entries.equals(entriesParent)) { + overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; } } @@ -291,9 +291,6 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { * @return list of setting entries for the current context. */ private List getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider) { - if (currentLanguageId == null) - return null; - ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); List entries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, currentLanguageId); @@ -305,9 +302,6 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { * @return list of setting entries for the current context. */ private List getSettingEntries(ILanguageSettingsProvider provider) { - if (currentLanguageId==null) - return null; - ICConfigurationDescription cfgDescription = getConfigurationDescription(); IResource rc = getResource(); return provider.getSettingEntries(cfgDescription, rc, currentLanguageId); @@ -906,22 +900,20 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { */ private List getProviders(String languageSettingId) { List itemsList = new LinkedList(); - if (currentLanguageId != null) { - IResource rc = getResource(); - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (rc != null && cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - List cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); - for (ILanguageSettingsProvider cfgProvider : cfgProviders) { - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider); - if (rawProvider instanceof LanguageSettingsBaseProvider) { - // filter out providers incapable of providing entries for this language - List languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope(); - if (languageIds != null && !languageIds.contains(currentLanguageId)) { - continue; - } + IResource rc = getResource(); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + if (rc != null && cfgDescription instanceof ILanguageSettingsProvidersKeeper) { + List cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + for (ILanguageSettingsProvider cfgProvider : cfgProviders) { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider); + if (rawProvider instanceof LanguageSettingsBaseProvider) { + // filter out providers incapable of providing entries for this language + List languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope(); + if (languageIds != null && !languageIds.contains(currentLanguageId)) { + continue; } - itemsList.add(cfgProvider); } + itemsList.add(cfgProvider); } } return itemsList; @@ -945,15 +937,18 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { currentLanguageId = null; List languageIds = LanguageSettingsManager.getLanguages(rcDes); - // Not sure what to do with null language ID, ignoring for now - languageIds.remove(null); - Collections.sort(languageIds); + if (languageIds.size() > 1) { + // remove null language when some real ones are defined + languageIds.remove(null); + Collections.sort(languageIds); + } else if (languageIds.isEmpty()) { + // if no languages are defined keep null language as "Unspecified language" + languageIds.add(null); + } for (String langId : languageIds) { ILanguage language = LanguageManager.getInstance().getLanguage(langId); - if (language == null) - continue; - String langName = language.getName(); + String langName = language != null ? language.getName() : Messages.LanguageSettingsEntriesTab_UnspecifiedLanguage; if (langName == null || langName.length() == 0) continue; @@ -980,7 +975,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { currentLanguageIdGlobal = currentLanguageId; for (TreeItem t : treeLanguages.getItems()) { - if (t.getData().equals(langId)) { + if ((t.getData() == null && langId == null) || t.getData().equals(langId)) { treeLanguages.setSelection(t); break; } @@ -1040,18 +1035,16 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (provider instanceof ILanguageSettingsEditableProvider) { for (TreeItem langItems : treeLanguages.getItems()) { String langId = (String)langItems.getData(); - if (langId != null) { - if (provider.getSettingEntries(cfgDescription, rc, langId) != null) { + if (provider.getSettingEntries(cfgDescription, rc, langId) != null) { + if (providerCopy == null) { + // copy providers to be able to "Cancel" in UI + providerCopy = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); if (providerCopy == null) { - // copy providers to be able to "Cancel" in UI - providerCopy = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); - if (providerCopy == null) { - continue providers; - } + continue providers; } - providerCopy.setSettingEntries(cfgDescription, rc, langId, null); - changed = true; } + providerCopy.setSettingEntries(cfgDescription, rc, langId, null); + changed = true; } } } @@ -1101,11 +1094,26 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // filter out files not associated with any languages such as *.o if (page.isForFile()) { List languageIds = LanguageSettingsManager.getLanguages(getResDesc()); - for (String langId : languageIds) { - if (langId != null) { - ILanguage language = LanguageManager.getInstance().getLanguage(langId); - if (language != null) { - return true; + if (languageIds.isEmpty() || (languageIds.size() == 1 && languageIds.get(0) == null)) { + // for legacy projects check if the file is associated with any CDT language + IResource rc = getResource(); + if (rc instanceof IFile) { + try { + ILanguage language = LanguageManager.getInstance().getLanguageForFile((IFile)rc, null); + return language != null; + } catch (CoreException e) { + // who cares, not even logging + } + } + return false; + } else { + // for regular MBS project verify language against toolchain language + for (String langId : languageIds) { + if (langId != null) { + ILanguage language = LanguageManager.getInstance().getLanguage(langId); + if (language != null) { + return true; + } } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java index 8b6b5fc7190..cba8dc59d7b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java @@ -213,6 +213,7 @@ public class Messages extends NLS { public static String LanguageSettingEntryDialog_WorkspacePath; public static String LanguageSettingsEntriesTab_Cannot_Determine_Languages; public static String LanguageSettingsEntriesTab_Entries_Not_Editable; + public static String LanguageSettingsEntriesTab_UnspecifiedLanguage; public static String LanguageSettingsImages_FileDoesNotExist; public static String LanguageSettingsImages_FolderDoesNotExist; public static String LanguageSettingsImages_UsingRelativePathsNotRecommended; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties index f3223679b8a..85aa7101518 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties @@ -189,6 +189,7 @@ LanguageSettingEntryDialog_Value=Value: LanguageSettingEntryDialog_WorkspacePath=Workspace Path LanguageSettingsEntriesTab_Cannot_Determine_Languages=Cannot determine toolchain languages. LanguageSettingsEntriesTab_Entries_Not_Editable=Setting entries for this provider are supplied by the system and are not editable. +LanguageSettingsEntriesTab_UnspecifiedLanguage=[ Unspecified ] LanguageSettingsImages_FileDoesNotExist=The selected file does not exist or not accessible. LanguageSettingsImages_FolderDoesNotExist=The selected folder does not exist or not accessible. LanguageSettingsImages_UsingRelativePathsNotRecommended=Using relative paths is ambiguous and not recommended. It can cause unexpected effects.