我正在尝试在选中条目时在编辑器中打开一个文件的复制版本,在编辑器中打开修改版本。
我在 Fedora 15 笔记本电脑上使用 Eclipse Indigo。
这是一个非常具体的问题,它可能足够集中,并且可能为我解决我遇到的一般问题提供帮助。
Eclipse 提供了一个名为 org.eclipse.ui.examples.readmetool 的示例插件,可以从 Help->Welcome 页面进行设置。
这个插件定义了一个名为 ReadmeEditor.java 的编辑器。它还在 plugin.xml 中定义了一个扩展点“org.eclipse.ui.popupMenus”。当您从 eclipse Project Explorer View 对带有后缀“.readme”的文件使用此操作时,您只会看到一个小弹出窗口。
如何更改 readmetool 插件,以便当您在 foo.readme 文件上选择上面定义的 Project Explorer 菜单项时,您会在 eclipse 中获得一个新的 ReadmeEditor,其中包含 foo.readme?
我正在努力解决的更具体的项目需求如下:
我有上面的一些部分;我扩充了 MultiPageEditor 示例,以便它执行运行外部程序、创建临时文件以及在文本编辑器中打开临时文件的工作。
但是,我目前可以访问该功能的唯一方法是在项目资源管理器中文件的弹出上下文窗口中选择“打开方式”选项,然后转到该窗口中的“其他”并选择我的新编辑器选项.
所以,我目前遇到的问题是如何向 plugin.xml 添加正确的魔法,以便我在 Project Manager 弹出上下文窗口中获得一个新选项,并将其与新的 TextEditor 窗口连接。
这看起来很像普通的“打开”选项会做的事情,看起来这应该是 eclipse 中非常基本的事情。任何示例和/或指导将不胜感激。
格雷格
最佳答案
这是设置和使用项目的简洁但完整的示例。 (在网上搜索,有很多关于 eclipse 的建议,但它往往相当零碎和零碎,当我努力解决我的问题时,拥有一个完整的、独立的 HOWTO 会很有帮助。所以,这是那..)
本秘籍假设您将 Eclipse Indigo 或 Juno 与:
要从 eclipse 中确认上述内容,请参阅
Help -> About Eclipse -> Installation Details -> Installed Software
you, before starting eclipse:
move or delete ~/eclipse.d/popup_workspace.d
mkdir -p ~/eclipse.d/popup_workspace.d
start eclipse: eclipse
eclipse: "Select a workspace"
you: "Browse", navigate to above-created popup_workspace.d; "OK" "OK"
eclipse: "Welcome to Eclipse IDE for Java Developers"
you: select "Workbench"
you: File -> New -> Project
eclipse: "Select a wizard:
you: Plug-in Development -> Plug-in Project; Next>
eclipse: "Plug-in Project"
you: Project name: org.mypopup.popup_editor Next>
eclipse: "Content"
you: Next>
eclipse: "Templates"
you: Plug-in with a popup menu Finish
eclipse: "This kind of project is associated with the
Plug-in Development perspective..."
you: Yes
org.mypopup.popup_editor
-> src
-> org.mypopup.popup_editor.popup.actions
-> NewAction.java
delete entire contents and replace with:
package org.mypopup.popup_editor.popup.actions;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
public class NewAction implements IObjectActionDelegate {
public NewAction() {
super();
}
public void run(IAction action) {
try {
IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ISelection selection = window.getSelectionService()
.getSelection("org.eclipse.ui.navigator.ProjectExplorer");
TreePath[] paths = ((TreeSelection) selection).getPaths();
TreePath p = paths[0];
Object last = p.getLastSegment();
if (last instanceof IFile) {
IPath ipath = ((IFile) last).getLocation();
IWorkbenchPage page = window.getActivePage();
IDE.openEditorOnFileStore(page,
EFS.getLocalFileSystem().getStore(ipath));
}
} catch (Exception blah) {
}
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) { }
public void selectionChanged(IAction action, ISelection selection) { }
}
in Package Explorer, navigate to and open META-INF -> MANIFEST.MF
Select "Dependencies" tab along the bottom of the resulting
"org.mypopup.plugin_editor" window
"Add..."; "Select a Plug-in:" enter org.eclipse.core.filesystem; "OK"
"Add..."; "Select a Plug-in:" enter org.eclipse.ui.ide; "OK"
File -> Save my.popup.popup_editor
outside of eclipse, browse to the directory containing popup_workspace.d,
in this case ~/eclipse.d, and if a folder "runtime-EclipseApplication"
exists, move it or delete it.
right-click META-INF -> MANIFEST.MF, select Run As -> Eclipse Application
in new eclipse window:
eclipse: "Welcome to Eclipse"
you: select "Workbench"
you: File -> New -> Project
eclipse: "Select a wizard"
you: General -> Project Next>
eclipse: "Project"
you: project name popup_test Finish
you: in Project Explorer, right-click popup_test, select New -> File
eclipse: "File"
you: File name: test_file1 Finish
you: enter a little text in test_file1, File -> Save; File -> Close
in Project Explorer, right-click popup_test -> test_file1
select New Submenu -> New Action
关于eclipse - 如何向 eclipse Package Explorer 上下文菜单添加条目以启动 TextEditor?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11287715/