mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 234777: Potential NPE in content assist advanced preference page
This commit is contained in:
parent
ca244d15bc
commit
8e3a44eafe
1 changed files with 41 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -20,12 +20,15 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.commands.Command;
|
||||
import org.eclipse.core.commands.CommandManager;
|
||||
import org.eclipse.core.commands.IParameter;
|
||||
import org.eclipse.core.commands.Parameterization;
|
||||
import org.eclipse.core.commands.ParameterizedCommand;
|
||||
import org.eclipse.core.commands.common.NotDefinedException;
|
||||
import org.eclipse.core.commands.contexts.ContextManager;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.jface.bindings.Binding;
|
||||
import org.eclipse.jface.bindings.BindingManager;
|
||||
import org.eclipse.jface.bindings.Scheme;
|
||||
import org.eclipse.jface.bindings.TriggerSequence;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
|
@ -58,6 +61,7 @@ import org.eclipse.ui.keys.IBindingService;
|
|||
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
|
||||
|
@ -347,6 +351,8 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
|
|||
Composite composite= new Composite(scrolled, SWT.NONE);
|
||||
int columns= 2;
|
||||
GridLayout layout= new GridLayout(columns, false);
|
||||
layout.marginWidth= 0;
|
||||
layout.marginHeight= 0;
|
||||
composite.setLayout(layout);
|
||||
|
||||
|
||||
|
@ -411,7 +417,7 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
|
|||
nameColumn.setResizable(false);
|
||||
TableColumn keyColumn= new TableColumn(table, SWT.NONE);
|
||||
keyColumn.setText(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_default_table_keybinding_column_title);
|
||||
keyColumn.setResizable(false);
|
||||
keyColumn.setResizable(true);
|
||||
|
||||
fDefaultViewer.addCheckStateListener(new ICheckStateListener() {
|
||||
public void checkStateChanged(CheckStateChangedEvent event) {
|
||||
|
@ -670,15 +676,40 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
|
|||
}
|
||||
}
|
||||
|
||||
private static String getKeyboardShortcut(ParameterizedCommand command) {
|
||||
final IBindingService bindingSvc= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
|
||||
final Binding[] bindings= bindingSvc.getBindings();
|
||||
for (Binding binding : bindings) {
|
||||
if (command.equals(binding.getParameterizedCommand())) {
|
||||
TriggerSequence triggers= bindingSvc.getBestActiveBindingFor(command.getId());
|
||||
return triggers.format();
|
||||
private static BindingManager fgLocalBindingManager;
|
||||
static {
|
||||
fgLocalBindingManager= new BindingManager(new ContextManager(), new CommandManager());
|
||||
final IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getService(IBindingService.class);
|
||||
final Scheme[] definedSchemes= bindingService.getDefinedSchemes();
|
||||
if (definedSchemes != null) {
|
||||
try {
|
||||
for (int i = 0; i < definedSchemes.length; i++) {
|
||||
final Scheme scheme= definedSchemes[i];
|
||||
final Scheme copy= fgLocalBindingManager.getScheme(scheme.getId());
|
||||
copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
|
||||
}
|
||||
} catch (final NotDefinedException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
fgLocalBindingManager.setLocale(bindingService.getLocale());
|
||||
fgLocalBindingManager.setPlatform(bindingService.getPlatform());
|
||||
}
|
||||
|
||||
private static String getKeyboardShortcut(ParameterizedCommand command) {
|
||||
IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
|
||||
fgLocalBindingManager.setBindings(bindingService.getBindings());
|
||||
try {
|
||||
Scheme activeScheme= bindingService.getActiveScheme();
|
||||
if (activeScheme != null)
|
||||
fgLocalBindingManager.setActiveScheme(activeScheme);
|
||||
} catch (NotDefinedException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
|
||||
TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
|
||||
if (bindings.length > 0)
|
||||
return bindings[0].format();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue