~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2013-10-03 20:30:16 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20131003203016-d4ug6l0xgosasumq
Tags: 8.2.1-1
* New upstream release.
* Updated autotools documentation sources.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 *
8
8
 * Contributors:
9
9
 *     Andrew Gvozdev - Initial API and implementation
 
10
 *     Tom Hochstein (Freescale) - Bug 412601 - Preprocessor Entries properties tab should list languages
10
11
 *******************************************************************************/
11
12
package org.eclipse.cdt.internal.ui.language.settings.providers;
12
13
 
17
18
import java.util.LinkedList;
18
19
import java.util.List;
19
20
import java.util.Map;
 
21
import java.util.TreeMap;
20
22
 
 
23
import org.eclipse.core.resources.IContainer;
21
24
import org.eclipse.core.resources.IFile;
22
25
import org.eclipse.core.resources.IProject;
23
26
import org.eclipse.core.resources.IResource;
695
698
                        ICConfigurationDescription cfgDescription = getConfigurationDescription();
696
699
                        IResource rc = getResource();
697
700
                        if (entries != null && rc != null) {
698
 
                                List<ICLanguageSettingEntry> parentEntries = null;
699
 
                                if (rc instanceof IProject) {
700
 
                                        parentEntries = new ArrayList<ICLanguageSettingEntry>();
701
 
                                } else {
702
 
                                        parentEntries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc.getParent(), currentLanguageId);
703
 
                                }
 
701
                                IContainer parent = rc instanceof IProject ? null : rc.getParent();
 
702
                                List<ICLanguageSettingEntry> parentEntries = LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, cfgDescription, parent, currentLanguageId);
704
703
                                if (entries.equals(parentEntries)) {
705
704
                                        // to use parent entries instead
706
705
                                        entries = null;
940
939
                if (languageIds.size() > 1) {
941
940
                        // remove null language when some real ones are defined
942
941
                        languageIds.remove(null);
943
 
                        Collections.sort(languageIds);
944
942
                } else if (languageIds.isEmpty()) {
945
943
                        // if no languages are defined keep null language as "Unspecified language"
946
944
                        languageIds.add(null);
947
945
                }
 
946
                
 
947
                // Use a TreeMap to sort the languages by name.
 
948
                // For each name we keep a list of ids in case of name overlap.
 
949
                Map<String, List<String>> map = new TreeMap<String, List<String>>();
948
950
                for (String langId : languageIds) {
949
951
                        ILanguage language = LanguageManager.getInstance().getLanguage(langId);
950
952
 
951
953
                        String langName = language != null ? language.getName() : Messages.LanguageSettingsEntriesTab_UnspecifiedLanguage;
952
954
                        if (langName == null || langName.length() == 0)
953
955
                                continue;
954
 
 
955
 
                        TreeItem t = new TreeItem(treeLanguages, SWT.NONE);
956
 
                        t.setText(0, langName);
957
 
                        t.setData(langId);
958
 
                        if (currentLanguageIdGlobal != null && currentLanguageIdGlobal.equals(langId)) {
959
 
                                currentLanguageId = currentLanguageIdGlobal;
960
 
                                treeLanguages.setSelection(t);
961
 
                        } else if (currentLanguageId == null) {
962
 
                                // this selects first language on first round
963
 
                                // do not select the tree item and global language selection here, only on actual click
964
 
                                currentLanguageId = langId;
965
 
                        }
966
 
                }
967
 
 
 
956
                        List<String> langIds = map.get(langName);
 
957
                        if (langIds == null) {
 
958
                                langIds = new ArrayList<String>();
 
959
                                map.put(langName, langIds);
 
960
                        }
 
961
                        langIds.add(langId);
 
962
                }
 
963
                
 
964
                for (String langName : map.keySet()) {
 
965
                        List<String> langIds = map.get(langName);
 
966
                        for (String langId : langIds) {
 
967
                                TreeItem t = new TreeItem(treeLanguages, SWT.NONE);
 
968
                                if (langIds.size() == 1) {
 
969
                                        t.setText(0, langName);
 
970
                                } else {
 
971
                                        StringBuilder uniqueLangName = new StringBuilder();
 
972
                                        uniqueLangName.append(langName).append(" [id=") //$NON-NLS-1$
 
973
                                                        .append(langId).append("]"); //$NON-NLS-1$
 
974
                                        t.setText(0, uniqueLangName.toString());
 
975
                                }
 
976
                                t.setData(langId);
 
977
                                if (currentLanguageIdGlobal != null && currentLanguageIdGlobal.equals(langId)) {
 
978
                                        currentLanguageId = currentLanguageIdGlobal;
 
979
                                        treeLanguages.setSelection(t);
 
980
                                } else if (currentLanguageId == null) {
 
981
                                        // this selects first language on first round
 
982
                                        // do not select the tree item and global language selection here, only on actual click
 
983
                                        currentLanguageId = langId;
 
984
                                }
 
985
                        }
 
986
                }
968
987
        }
969
988
 
970
989
        /**