[英]How to add button to eclipse toolbar and connecting him to function xml extension Point
您好,我正在尝试为我的插件在elipse中的主要工具栏添加按钮。
我已成功将按钮添加到工具栏,但未能将此按钮连接到将打开属性页的功能。
这是我在xml中的代码:
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="Sample Category"
id="FirstTextHoverTry.commands.category">
</category>
<command
name="Sample Command"
categoryId="FirstTextHoverTry.commands.category"
id="FirstTextHoverTry.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="FirstTextHoverTry.commands.sampleCommand"
class="FirstTextHoverTry.SettingPage">
</handler>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="opr.toolbars.sampleToolbar">
<command
commandId="FirstTextHoverTry.Settings.SettingPage.execute"
icon="icons/sample.gif"
tooltip="Say hello world"
id="FirstTextHoverTry.Settings.execute">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
问题可能出在commandId和id中。
我有一个“包”调用设置,其中包括一个类调用SettingPage,这是我在此类中的代码。
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;
public class SettingPage extends AbstractHandler {
public SettingPage() {
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"hi",
"Need Somthing else probably");
return null;
}
}
你org.eclipse.ui.handlers
扩展点说,你的处理程序类是FirstTextHoverTry.SettingPage
-这样一类被称为SettingPage
在FirstTextHoverTry
包,而不是Settings
包。 因此,请确定软件包名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.