mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
resource tree to present nice looking hierarchical view to the user
This commit is contained in:
parent
e1e1bc2e19
commit
f8a545a2fb
2 changed files with 48 additions and 43 deletions
|
@ -61,7 +61,12 @@ public class LanguageSettingsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
||||||
|
*
|
||||||
|
* @param provider - language settings provider to build the tree for.
|
||||||
|
* @param cfgDescription - configuration description.
|
||||||
|
* @param languageId - language ID.
|
||||||
|
* @param project - the project which is considered the root of the resource tree.
|
||||||
*/
|
*/
|
||||||
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) {
|
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) {
|
||||||
LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project);
|
LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project);
|
||||||
|
|
|
@ -393,7 +393,14 @@ public class LanguageSettingsExtensionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
||||||
|
* Note that it is not advisable to "compact" the tree because of potential loss of information
|
||||||
|
* which is especially important during partial or incremental builds.
|
||||||
|
*
|
||||||
|
* @param provider - language settings provider to build the tree for.
|
||||||
|
* @param cfgDescription - configuration description.
|
||||||
|
* @param languageId - language ID.
|
||||||
|
* @param folder - container where the tree roots.
|
||||||
*/
|
*/
|
||||||
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) {
|
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) {
|
||||||
IResource[] members = null;
|
IResource[] members = null;
|
||||||
|
@ -420,61 +427,39 @@ public class LanguageSettingsExtensionManager {
|
||||||
List<ICLanguageSettingEntry> candidate = null;
|
List<ICLanguageSettingEntry> candidate = null;
|
||||||
int candidateCount = 0;
|
int candidateCount = 0;
|
||||||
for (IResource rc : members) {
|
for (IResource rc : members) {
|
||||||
if (rc instanceof IFile) {
|
if (!isLanguageInScope(rc, cfgDescription, languageId)) {
|
||||||
IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(rc.getName());
|
rcNumber--;
|
||||||
if (contentType==null) {
|
} else {
|
||||||
|
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||||
|
if (entries==null && rc instanceof IContainer) {
|
||||||
rcNumber--;
|
rcNumber--;
|
||||||
if (candidateCount > rcNumber/2) {
|
} else {
|
||||||
majorityEntries = candidate;
|
Integer count = listMap.get(entries);
|
||||||
break;
|
if (count==null) {
|
||||||
|
count = 0;
|
||||||
}
|
}
|
||||||
continue;
|
count++;
|
||||||
}
|
|
||||||
|
if (count>candidateCount) {
|
||||||
ILanguage lang = LanguageManager.getInstance().getLanguage(contentType);
|
candidateCount = count;
|
||||||
List<String> languageScope = provider.getLanguageScope();
|
candidate = entries;
|
||||||
if (lang==null || (languageScope!=null && !languageScope.contains(lang.getId()))) {
|
|
||||||
rcNumber--;
|
|
||||||
if (candidateCount > rcNumber/2) {
|
|
||||||
majorityEntries = candidate;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
|
listMap.put(entries, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
if (candidateCount > rcNumber/2) {
|
||||||
if (entries==null && rc instanceof IContainer) {
|
majorityEntries = candidate;
|
||||||
rcNumber--;
|
|
||||||
if (candidateCount > rcNumber/2) {
|
|
||||||
majorityEntries = candidate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer count = listMap.get(entries);
|
|
||||||
if (count==null) {
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
if (count > rcNumber/2) {
|
|
||||||
majorityEntries = entries;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (count>candidateCount) {
|
|
||||||
candidateCount = count;
|
|
||||||
candidate = entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
listMap.put(entries, count);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (majorityEntries!=null) {
|
if (majorityEntries!=null) {
|
||||||
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// second pass - assign the entries to the folders
|
||||||
for (IResource rc : members) {
|
for (IResource rc : members) {
|
||||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||||
if (entries!=null && entries==majorityEntries) {
|
if (entries!=null && entries==majorityEntries) {
|
||||||
|
@ -484,6 +469,21 @@ public class LanguageSettingsExtensionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) {
|
||||||
|
if (rc instanceof IFile) {
|
||||||
|
ILanguage lang = null;
|
||||||
|
try {
|
||||||
|
lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
if (lang==null || (languageId!=null && languageId.equals(lang.getId()))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean checkBit(int flags, int bit) {
|
private static boolean checkBit(int flags, int bit) {
|
||||||
return (flags & bit) == bit;
|
return (flags & bit) == bit;
|
||||||
|
|
Loading…
Add table
Reference in a new issue