mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 04:45:38 +02:00
bug 401961: Adjusted LSP property page UI to function for legacy projects where no languages defined in the toolchain
This commit is contained in:
parent
807f937284
commit
856760644c
3 changed files with 66 additions and 56 deletions
|
@ -18,8 +18,10 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.viewers.IDecoration;
|
import org.eclipse.jface.viewers.IDecoration;
|
||||||
|
@ -114,21 +116,19 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
return overlayKeys;
|
return overlayKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentLanguageId != null) {
|
IResource rc = getResource();
|
||||||
IResource rc = getResource();
|
List<ICLanguageSettingEntry> entries = getSettingEntries(provider);
|
||||||
List<ICLanguageSettingEntry> entries = getSettingEntries(provider);
|
if (entries == null && !(rc instanceof IProject)) {
|
||||||
if (entries == null && !(rc instanceof IProject)) {
|
List<ICLanguageSettingEntry> entriesParent = getSettingEntriesUpResourceTree(provider);
|
||||||
List<ICLanguageSettingEntry> entriesParent = getSettingEntriesUpResourceTree(provider);
|
if (entriesParent != null) {
|
||||||
if (entriesParent != null) {
|
overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT;
|
||||||
overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT;
|
}
|
||||||
}
|
} else if (provider instanceof ILanguageSettingsBroadcastingProvider && (page.isForFile() || page.isForFolder())) {
|
||||||
} else if (provider instanceof ILanguageSettingsBroadcastingProvider && (page.isForFile() || page.isForFolder())) {
|
// Assuming that the default entries for a resource are always null.
|
||||||
// Assuming that the default entries for a resource are always null.
|
// Using that for performance reasons. See note in performDefaults().
|
||||||
// Using that for performance reasons. See note in performDefaults().
|
List<ICLanguageSettingEntry> entriesParent = provider.getSettingEntries(null, null, currentLanguageId);
|
||||||
List<ICLanguageSettingEntry> entriesParent = provider.getSettingEntries(null, null, currentLanguageId);
|
if (entries != null && !entries.equals(entriesParent)) {
|
||||||
if (entries != null && !entries.equals(entriesParent)) {
|
overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING;
|
||||||
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.
|
* @return list of setting entries for the current context.
|
||||||
*/
|
*/
|
||||||
private List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider) {
|
private List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider) {
|
||||||
if (currentLanguageId == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||||
IResource rc = getResource();
|
IResource rc = getResource();
|
||||||
List<ICLanguageSettingEntry> entries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, currentLanguageId);
|
List<ICLanguageSettingEntry> 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.
|
* @return list of setting entries for the current context.
|
||||||
*/
|
*/
|
||||||
private List<ICLanguageSettingEntry> getSettingEntries(ILanguageSettingsProvider provider) {
|
private List<ICLanguageSettingEntry> getSettingEntries(ILanguageSettingsProvider provider) {
|
||||||
if (currentLanguageId==null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||||
IResource rc = getResource();
|
IResource rc = getResource();
|
||||||
return provider.getSettingEntries(cfgDescription, rc, currentLanguageId);
|
return provider.getSettingEntries(cfgDescription, rc, currentLanguageId);
|
||||||
|
@ -906,22 +900,20 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
*/
|
*/
|
||||||
private List<ILanguageSettingsProvider> getProviders(String languageSettingId) {
|
private List<ILanguageSettingsProvider> getProviders(String languageSettingId) {
|
||||||
List<ILanguageSettingsProvider> itemsList = new LinkedList<ILanguageSettingsProvider>();
|
List<ILanguageSettingsProvider> itemsList = new LinkedList<ILanguageSettingsProvider>();
|
||||||
if (currentLanguageId != null) {
|
IResource rc = getResource();
|
||||||
IResource rc = getResource();
|
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
if (rc != null && cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
|
||||||
if (rc != null && cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
|
List<ILanguageSettingsProvider> cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
||||||
List<ILanguageSettingsProvider> cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
|
for (ILanguageSettingsProvider cfgProvider : cfgProviders) {
|
||||||
for (ILanguageSettingsProvider cfgProvider : cfgProviders) {
|
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider);
|
||||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(cfgProvider);
|
if (rawProvider instanceof LanguageSettingsBaseProvider) {
|
||||||
if (rawProvider instanceof LanguageSettingsBaseProvider) {
|
// filter out providers incapable of providing entries for this language
|
||||||
// filter out providers incapable of providing entries for this language
|
List<String> languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope();
|
||||||
List<String> languageIds = ((LanguageSettingsBaseProvider)rawProvider).getLanguageScope();
|
if (languageIds != null && !languageIds.contains(currentLanguageId)) {
|
||||||
if (languageIds != null && !languageIds.contains(currentLanguageId)) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
itemsList.add(cfgProvider);
|
|
||||||
}
|
}
|
||||||
|
itemsList.add(cfgProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return itemsList;
|
return itemsList;
|
||||||
|
@ -945,15 +937,18 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
currentLanguageId = null;
|
currentLanguageId = null;
|
||||||
|
|
||||||
List<String> languageIds = LanguageSettingsManager.getLanguages(rcDes);
|
List<String> languageIds = LanguageSettingsManager.getLanguages(rcDes);
|
||||||
// Not sure what to do with null language ID, ignoring for now
|
if (languageIds.size() > 1) {
|
||||||
languageIds.remove(null);
|
// remove null language when some real ones are defined
|
||||||
Collections.sort(languageIds);
|
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) {
|
for (String langId : languageIds) {
|
||||||
ILanguage language = LanguageManager.getInstance().getLanguage(langId);
|
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)
|
if (langName == null || langName.length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -980,7 +975,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
currentLanguageIdGlobal = currentLanguageId;
|
currentLanguageIdGlobal = currentLanguageId;
|
||||||
|
|
||||||
for (TreeItem t : treeLanguages.getItems()) {
|
for (TreeItem t : treeLanguages.getItems()) {
|
||||||
if (t.getData().equals(langId)) {
|
if ((t.getData() == null && langId == null) || t.getData().equals(langId)) {
|
||||||
treeLanguages.setSelection(t);
|
treeLanguages.setSelection(t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1040,18 +1035,16 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
if (provider instanceof ILanguageSettingsEditableProvider) {
|
if (provider instanceof ILanguageSettingsEditableProvider) {
|
||||||
for (TreeItem langItems : treeLanguages.getItems()) {
|
for (TreeItem langItems : treeLanguages.getItems()) {
|
||||||
String langId = (String)langItems.getData();
|
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) {
|
if (providerCopy == null) {
|
||||||
// copy providers to be able to "Cancel" in UI
|
continue providers;
|
||||||
providerCopy = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true);
|
|
||||||
if (providerCopy == null) {
|
|
||||||
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
|
// filter out files not associated with any languages such as *.o
|
||||||
if (page.isForFile()) {
|
if (page.isForFile()) {
|
||||||
List<String> languageIds = LanguageSettingsManager.getLanguages(getResDesc());
|
List<String> languageIds = LanguageSettingsManager.getLanguages(getResDesc());
|
||||||
for (String langId : languageIds) {
|
if (languageIds.isEmpty() || (languageIds.size() == 1 && languageIds.get(0) == null)) {
|
||||||
if (langId != null) {
|
// for legacy projects check if the file is associated with any CDT language
|
||||||
ILanguage language = LanguageManager.getInstance().getLanguage(langId);
|
IResource rc = getResource();
|
||||||
if (language != null) {
|
if (rc instanceof IFile) {
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,7 @@ public class Messages extends NLS {
|
||||||
public static String LanguageSettingEntryDialog_WorkspacePath;
|
public static String LanguageSettingEntryDialog_WorkspacePath;
|
||||||
public static String LanguageSettingsEntriesTab_Cannot_Determine_Languages;
|
public static String LanguageSettingsEntriesTab_Cannot_Determine_Languages;
|
||||||
public static String LanguageSettingsEntriesTab_Entries_Not_Editable;
|
public static String LanguageSettingsEntriesTab_Entries_Not_Editable;
|
||||||
|
public static String LanguageSettingsEntriesTab_UnspecifiedLanguage;
|
||||||
public static String LanguageSettingsImages_FileDoesNotExist;
|
public static String LanguageSettingsImages_FileDoesNotExist;
|
||||||
public static String LanguageSettingsImages_FolderDoesNotExist;
|
public static String LanguageSettingsImages_FolderDoesNotExist;
|
||||||
public static String LanguageSettingsImages_UsingRelativePathsNotRecommended;
|
public static String LanguageSettingsImages_UsingRelativePathsNotRecommended;
|
||||||
|
|
|
@ -189,6 +189,7 @@ LanguageSettingEntryDialog_Value=Value:
|
||||||
LanguageSettingEntryDialog_WorkspacePath=Workspace Path
|
LanguageSettingEntryDialog_WorkspacePath=Workspace Path
|
||||||
LanguageSettingsEntriesTab_Cannot_Determine_Languages=Cannot determine toolchain languages.
|
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_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_FileDoesNotExist=The selected file does not exist or not accessible.
|
||||||
LanguageSettingsImages_FolderDoesNotExist=The selected folder 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.
|
LanguageSettingsImages_UsingRelativePathsNotRecommended=Using relative paths is ambiguous and not recommended. It can cause unexpected effects.
|
||||||
|
|
Loading…
Add table
Reference in a new issue