[英]Add Button to Eclipse view toolbar without using viewer
I am trying to create an Eclipse PDE plugin that has a view with a button in the view's tool bar.我正在尝试创建一个 Eclipse PDE 插件,该插件在视图的工具栏中有一个带有按钮的视图。 The view is intended to display text, which will change format when the toolbar button is clicked.
该视图旨在显示文本,单击工具栏按钮时将更改格式。 I have been trying to work around using a viewer, because none of the viewers match fit my needs.
我一直在尝试使用查看器来解决问题,因为没有一个查看器符合我的需求。 I followed this SO post for reference but have not been able to get the function to work.
我关注了这篇SO 帖子以供参考,但未能让 function 工作。 Is there something wrong with my plugin.xml file?
我的 plugin.xml 文件有问题吗? I added the ID of the view as the location URI for the menu contribution, but the plugin is not showing the button in the toolbar as intended.
我将视图的 ID 添加为菜单贡献的位置 URI,但插件未按预期在工具栏中显示按钮。
I have added my plugin.xml and ViewPart class below for your reference:我在下面添加了我的 plugin.xml 和 ViewPart class 供您参考:
Plugin.xml:插件.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="Sample Category"
id="asher">
</category>
<view
id="asher.views.id.SampleView"
name="Sample View"
icon="icons/daffodil.png"
class="asher.views.SampleView"
category="asher"
inject="true">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective">
<view
id="asher.views.id.SampleView"
relative="org.eclipse.ui.views.ProblemView"
relationship="right"
ratio="0.5">
</view>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
id="asher.commands.unparse.category"
name="Unparse Category">
</category>
<command
categoryId="asher.commands.unparse.category"
name="UnParse"
id="asher.commands.unparseCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="asher.handlers.UnparseHandler"
commandId="asher.commands.unparseCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="asher.commands.unparseCommand"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+7">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<menu
id="asher.menus.unparseMenu"
label="Unparse"
mnemonic="M">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menu>
</menuContribution>
</extension>
</plugin>
ViewPart Class:查看零件 Class:
public class SampleView extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "asher.views.id.SampleView";
@Inject IWorkbench workbench;
@Override
public void createPartControl(Composite parent) {
Text text = new Text(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
File file = new File("/Users/user/Desktop/install.json");
Scanner sc;
try {
sc = new Scanner(file);
while (sc.hasNextLine())
text.setText(text.getText()+"\n"+sc.nextLine());
sc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void setFocus() {
}
}
I found a solution to my answer.我找到了答案的解决方案。 The change I made was to remove the tag from the for the toolbar.
我所做的更改是从工具栏中删除标签。
Here is the fixed plugin.xml section:这是固定的plugin.xml部分:
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menuContribution>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.