[英]Add Button to Eclipse view toolbar without using viewer
我正在嘗試創建一個 Eclipse PDE 插件,該插件在視圖的工具欄中有一個帶有按鈕的視圖。 該視圖旨在顯示文本,單擊工具欄按鈕時將更改格式。 我一直在嘗試使用查看器來解決問題,因為沒有一個查看器符合我的需求。 我關注了這篇SO 帖子以供參考,但未能讓 function 工作。 我的 plugin.xml 文件有問題嗎? 我將視圖的 ID 添加為菜單貢獻的位置 URI,但插件未按預期在工具欄中顯示按鈕。
我在下面添加了我的 plugin.xml 和 ViewPart class 供您參考:
插件.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>
查看零件 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() {
}
}
我找到了答案的解決方案。 我所做的更改是從工具欄中刪除標簽。
這是固定的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.