我考虑重新调整org.eclipse.jface.bindings.Scheme
以在每个用户群上存储密钥绑定:
String userName = "Bob";
BindingManager bindingManager = ((BindingService) PlatformUI.getWorkbench().getService(IBindingService.class)).getBindingManager();
Scheme scheme = bindingManager.getScheme(userName);
scheme.define(userName, "Scheme for user " + userName, DEFAULT_SCHEME);
bindingManager.setActiveScheme(scheme);
适用于某些时刻,但无论何时从首选项加载方案(例如,通过CommandPersistence#reRead
),只会读取 plugin.xml 中定义的方案以及其他所有方案被丢弃了。
特别是类BindingService
的这种方法是一个问题:
public final void savePreferences(final Scheme activeScheme,
final Binding[] bindings) throws IOException {
// store everything in preferences, then read everything
// -> custom schemes get removed
BindingPersistence.write(activeScheme, bindings);
// now the removed (undefined) scheme gets set
bindingManager.setActiveScheme(activeScheme);
bindingManager.setBindings(bindings);
}
由于我无法通过 plugin.xml 真正注册所有用户,如何以编程方式注册方案?
答案 0 :(得分:0)
作为"解决方案",我只是为我们的用例重新实现了该方案:
String userName = "Bob";
String keyBindings = MyPlugin.getDefault().getPreferenceStore().getString("keyBindings." + userName);
PlatformUI.getPreferenceStore().setValue(PlatformUI.PLUGIN_ID + ".commands", keyBindings);
这也会触发CommandPersistence#reRead
,但由于此次我没有自定义方案,因此不会失败。现在,我们对不同方案的管理是我们的问题,但至少这种方式有效。