mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 08:15:48 +02:00
Fix NPE on initializing the external executables state service provider
This commit is contained in:
parent
b093d30afe
commit
6b26ac987b
2 changed files with 11 additions and 5 deletions
|
@ -10,10 +10,8 @@
|
|||
package org.eclipse.tm.terminal.view.ui.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.tm.terminal.view.ui.local.showin.ExternalExecutablesManager;
|
||||
import org.eclipse.ui.AbstractSourceProvider;
|
||||
import org.eclipse.ui.ISources;
|
||||
|
||||
|
@ -22,11 +20,13 @@ import org.eclipse.ui.ISources;
|
|||
*/
|
||||
public class ExternalExecutablesState extends AbstractSourceProvider {
|
||||
public final static String CONFIGURED_STATE = "org.eclipse.tm.terminal.external.executable.configured"; //$NON-NLS-1$
|
||||
private boolean enabled;
|
||||
private boolean enabled = false;
|
||||
|
||||
public ExternalExecutablesState() {
|
||||
List<Map<String, String>> externals = ExternalExecutablesManager.load();
|
||||
this.enabled = (externals != null && !externals.isEmpty());
|
||||
// Cannot initialize the state here by calling ExternalExecutablesManager.load(),
|
||||
// because it will trigger a ExternalExectuablesManger.save() which tries to call
|
||||
// the enable() or disable() method here. Better initialize the state from the
|
||||
// load method itself.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,6 +46,7 @@ public class ExternalExecutablesManager {
|
|||
*
|
||||
* @return The list of all saved external executables or <code>null</code>.
|
||||
*/
|
||||
@SuppressWarnings("cast")
|
||||
public static List<Map<String, String>> load() {
|
||||
List<Map<String, String>> l = new ArrayList<Map<String, String>>();
|
||||
|
||||
|
@ -165,6 +166,11 @@ public class ExternalExecutablesManager {
|
|||
gitBashSearchDone = true;
|
||||
}
|
||||
|
||||
// Make sure the source provider is initialized properly
|
||||
ISourceProviderService sourceProviderService = (ISourceProviderService) PlatformUI.getWorkbench().getService(ISourceProviderService.class);
|
||||
ExternalExecutablesState stateService = (ExternalExecutablesState) sourceProviderService.getSourceProvider(ExternalExecutablesState.CONFIGURED_STATE);
|
||||
if (l.isEmpty()) stateService.disable(); else stateService.enable();
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue