【发布时间】:2023-03-29 14:12:01
【问题描述】:
在单选状态菜单项的命令处理程序中,我会提示用户是否要继续。如果他们选择否,我需要将选定的菜单项重置为之前的值。
我正在使用HandlerUtil.updateRadioState(event.getCommand(), oldScope),但菜单仍保留新值。
有什么建议吗?
命令处理程序
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (HandlerUtil.matchesRadioState(event))
return null;
String scope = event.getParameter(RadioState.PARAMETER_ID);
if (MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm restart",
"Switching source of Motors requires a restart. Continue?")) {
int connection = MotorDbPreferencesPage.DATABASE_ACCESS_LOCAL;
if ("Cloud".compareToIgnoreCase(scope) == 0) {
connection = MotorDbPreferencesPage.DATABASE_ACCESS_CLOUD;
}
Activator.getDefault().getPreferenceStore().setValue(MotorDbPreferencesPage.DATABASE_ACCESS, connection);
PlatformUI.getWorkbench().restart();
} else {
String oldScope = "Local";
// switch it back to the way it was before the user selected it
if ("Local".compareToIgnoreCase(scope) == 0) {
oldScope = "Cloud";
}
HandlerUtil.updateRadioState(event.getCommand(), oldScope);
}
return null;
}
plugin.xml 中的命令定义
<command
id="com.client.eclipse.connection"
name="Connection">
<commandParameter
id="org.eclipse.ui.commands.radioStateParameter"
name="State"
optional="false">
</commandParameter>
<state
class="org.eclipse.ui.handlers.RadioState:Cloud"
id="org.eclipse.ui.commands.radioState">
</state>
</command>
还有来自 plugin.xml 的菜单定义
<menu
label="Connection">
<command
commandId="com.client.eclipse.connection"
label="Local"
style="radio">
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="Local">
</parameter>
</command>
<command
commandId="com.client.eclipse.connection"
label="Cloud"
style="radio">
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="Cloud">
</parameter>
</command>
</menu>
【问题讨论】:
标签: eclipse eclipse-plugin eclipse-rcp