|
1 | 1 | package it.baeyens.arduino.tools;
|
2 | 2 |
|
| 3 | +import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; |
3 | 4 | import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper;
|
| 5 | +import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; |
| 6 | +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; |
4 | 7 | import org.eclipse.cdt.core.model.CoreModel;
|
5 | 8 | import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
6 | 9 | import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
7 | 10 | import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
8 | 11 | import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
9 | 12 | import org.eclipse.cdt.managedbuilder.core.IBuilder;
|
| 13 | +import org.eclipse.cdt.managedbuilder.core.IConfiguration; |
10 | 14 | import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
11 | 15 | import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
12 | 16 | import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
|
|
20 | 24 | import it.baeyens.arduino.ui.BuildConfigurationsPage.ConfigurationDescriptor;
|
21 | 25 |
|
22 | 26 | import java.util.ArrayList;
|
| 27 | +import java.util.List; |
23 | 28 |
|
24 | 29 | @SuppressWarnings("restriction")
|
25 | 30 | // TOFIX Get this code in CDT so I should not have to do this
|
26 | 31 | public class ShouldHaveBeenInCDT {
|
27 | 32 | /*
|
28 | 33 | * Copied from wizard STDWizardHandler package package org.eclipse.cdt.managedbuilder.ui.wizards;; This method creates the .cProject file in your
|
29 | 34 | * project.
|
30 |
| - * |
| 35 | + * |
31 | 36 | * BK: modified this and made it work for multiple configs.
|
32 | 37 | */
|
33 | 38 | /**
|
34 | 39 | * This method creates the .cProject file in your project. it is intended to be used with newly created projects. Using this method with project
|
35 | 40 | * that have existed for some time is unknown
|
36 |
| - * |
37 |
| - * |
| 41 | + * |
| 42 | + * |
38 | 43 | * @param project
|
39 | 44 | * The newly created project that needs a .cproject file.
|
40 | 45 | * @param alCfgs
|
@@ -101,16 +106,52 @@ public static void setCProjectDescription(IProject project,
|
101 | 106 | }
|
102 | 107 | CConfigurationData data = cfg.getConfigurationData();
|
103 | 108 | ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
|
104 |
| - |
105 |
| - if (cfgDes instanceof ILanguageSettingsProvidersKeeper) { |
106 |
| - ILanguageSettingsProvidersKeeper lspk = (ILanguageSettingsProvidersKeeper)cfgDes; |
107 |
| - lspk.setDefaultLanguageSettingsProvidersIds(new String[] {alCfgs.get(i).ToolchainID}); |
108 |
| - } |
109 |
| -// ConfigurationDataProvider.setDefaultLanguageSettingsProviders(project, cfg, cfgDes); |
| 109 | + |
| 110 | + setDefaultLanguageSettingsProviders(project, alCfgs.get(i), cfg, cfgDes); |
110 | 111 | }
|
111 | 112 | monitor.worked(50);
|
112 | 113 | mngr.setProjectDescription(project, des);
|
113 | 114 |
|
114 | 115 | }
|
115 | 116 |
|
| 117 | + private static void setDefaultLanguageSettingsProviders(IProject project, ConfigurationDescriptor cfgDes, IConfiguration cfg, ICConfigurationDescription cfgDescription) { |
| 118 | + // propagate the preference to project properties |
| 119 | + boolean isPreferenceEnabled = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(null); |
| 120 | + ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isPreferenceEnabled); |
| 121 | + |
| 122 | + if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { |
| 123 | + ILanguageSettingsProvidersKeeper lspk = (ILanguageSettingsProvidersKeeper)cfgDescription; |
| 124 | + |
| 125 | + lspk.setDefaultLanguageSettingsProvidersIds(new String[] {cfgDes.ToolchainID}); |
| 126 | + |
| 127 | + List<ILanguageSettingsProvider> providers = getDefaultLanguageSettingsProviders(cfg, cfgDescription); |
| 128 | + lspk.setLanguageSettingProviders(providers); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + private static List<ILanguageSettingsProvider> getDefaultLanguageSettingsProviders(IConfiguration cfg, ICConfigurationDescription cfgDescription) { |
| 133 | + List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(); |
| 134 | + String[] ids = cfg != null ? cfg.getDefaultLanguageSettingsProviderIds() : null; |
| 135 | + |
| 136 | + if (ids == null) { |
| 137 | + // Try with legacy providers |
| 138 | + ids = ScannerDiscoveryLegacySupport.getDefaultProviderIdsLegacy(cfgDescription); |
| 139 | + } |
| 140 | + |
| 141 | + if (ids != null) { |
| 142 | + for (String id : ids) { |
| 143 | + ILanguageSettingsProvider provider = null; |
| 144 | + if (!LanguageSettingsManager.isPreferShared(id)) { |
| 145 | + provider = LanguageSettingsManager.getExtensionProviderCopy(id, false); |
| 146 | + } |
| 147 | + if (provider == null) { |
| 148 | + provider = LanguageSettingsManager.getWorkspaceProvider(id); |
| 149 | + } |
| 150 | + providers.add(provider); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + return providers; |
| 155 | + } |
| 156 | + |
116 | 157 | }
|
0 commit comments