如何替换默认处理程序
How To Replace Default Handler
我们使用的 JFace PreferenceDialog
有一个错误,IPersistentPreferenceStore#save()
抛出的异常没有得到处理,对话框就关闭了,用户没有意识到出了什么问题。
所以我创建了自己的 class 实现来解决这个问题,并且 "just" 需要以某种方式替换由命令 org.eclipse.ui.window.preferences
定义的默认处理程序。
通常我会这样做:
<extension point="org.eclipse.ui.activities">
<activity id="org.acme.preference.oldPreferenceDialog" name="Remove Preference Dialog">
<enabledWhen>
<with variable="selection">
<count value="-1" />
</with>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="org.acme.preference.oldPreferenceDialog"
isEqualityPattern="true"
pattern="org.eclipse.ui/org.eclipse.ui.window.preferences" />
</activityPatternBinding>
</extension>
除上述命令外,它在某种程度上对每个命令都非常有效。但即使它确实有效,它也不会做我想做的事——我仍然想要命令,我只想禁用处理程序,但处理程序没有 ID(更不用说 [=25 中定义的那些了) =] 命令的属性。
我可以做些什么来替换命令的首选项对话框/默认处理程序吗?
自定义 context 可用于覆盖处理程序。
如果您像这样指定处理程序的 activeWhen
子句
<activeWhen>
<with variable="activeContexts">
<iterate operator="or">
<equals value="myContext" /equals>
</iterate>
</with>
</activeWhen>
每当 myContext
处于活动状态时,自定义处理程序将优先。
如果 - 就像您的情况一样 - 自定义处理程序应始终优先,我建议在 plug-in 的 Activator 中激活上下文。
我们使用的 JFace PreferenceDialog
有一个错误,IPersistentPreferenceStore#save()
抛出的异常没有得到处理,对话框就关闭了,用户没有意识到出了什么问题。
所以我创建了自己的 class 实现来解决这个问题,并且 "just" 需要以某种方式替换由命令 org.eclipse.ui.window.preferences
定义的默认处理程序。
通常我会这样做:
<extension point="org.eclipse.ui.activities">
<activity id="org.acme.preference.oldPreferenceDialog" name="Remove Preference Dialog">
<enabledWhen>
<with variable="selection">
<count value="-1" />
</with>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="org.acme.preference.oldPreferenceDialog"
isEqualityPattern="true"
pattern="org.eclipse.ui/org.eclipse.ui.window.preferences" />
</activityPatternBinding>
</extension>
除上述命令外,它在某种程度上对每个命令都非常有效。但即使它确实有效,它也不会做我想做的事——我仍然想要命令,我只想禁用处理程序,但处理程序没有 ID(更不用说 [=25 中定义的那些了) =] 命令的属性。
我可以做些什么来替换命令的首选项对话框/默认处理程序吗?
自定义 context 可用于覆盖处理程序。
如果您像这样指定处理程序的 activeWhen
子句
<activeWhen>
<with variable="activeContexts">
<iterate operator="or">
<equals value="myContext" /equals>
</iterate>
</with>
</activeWhen>
每当 myContext
处于活动状态时,自定义处理程序将优先。
如果 - 就像您的情况一样 - 自定义处理程序应始终优先,我建议在 plug-in 的 Activator 中激活上下文。