【问题标题】:plugin development in eclipseeclipse中的插件开发
【发布时间】:2010-12-21 17:32:20
【问题描述】:

这些天我的项目遇到了这个问题。我正在eclipse中开发一个插件, 当我点击一个按钮时,我需要在活动窗口(编码区域)上写一个文本。

我在 button.java 类中使用以下代码

public class Button implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
/**
 * The constructor.
 */
public Button() {
}

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI.
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    MessageDialog.openInformation(
        window.getShell(),
        "Button",
        "Code of the Button goes here");
}

如何在 run 方法中做到这一点?在这里我显示一条消息,而不是显示一条消息,我想在文本编辑器窗格中显示一些文本。请帮助我实现这一目标。

如果你们能给我一些链接来了解eclipse插件的开发吗?任何易于理解的博客文章会更好吗?

【问题讨论】:

    标签: java eclipse eclipse-plugin


    【解决方案1】:

    你应该这样做。它完全未经测试,您将需要添加大量空检查和 try-catch 块,但下面的代码获取当前活动的编辑器并用作为参数传入的任何内容替换当前选择:

    void method (String text) {
        IEditorPart part = Workbench.getInstance().getWorkbenchWindows()[0].getActivePage().getActiveEditor();
        IEditorInput editorInput = part.getEditorInput();
        if (part instanceof ITextEditor) {
            ITextEditor textEditor = (ITextEditor) part;
            IDocument doc = textEditor.getDocumentProvider().getDocument(editorInput);
            ITextSelection sel = textEditor.getSelectionProvider().getSelection();
            doc.replace(sel.getOffset(), sel.getLength(), text);
        }
    }
    

    它是杂乱而复杂的,但这就是适合你的 Eclipse 框架。

    这可能是您了解 Eclipse 插件开发的好地方: http://www.ibm.com/developerworks/views/opensource/libraryview.jsp?search_by=Create+commercial-quality+eclipse+ide

    Developer Works 总的来说有很多关于 Eclipse 的好内容,所以如果这个系列不是您真正需要的,您可以探索 Developer Works 的其他内容。

    【讨论】:

    • 我测试了上面的代码,这正是我想要的。谢谢安德鲁。
    【解决方案2】:

    我推荐this one。这是一个很好的入门教程

    【讨论】:

    • 谢谢你,我已经完成了这个......但是thanx分享它......我真正需要的是完成我上面提到的任务......??跨度>
    猜你喜欢
    • 2011-01-07
    • 2013-07-20
    • 2012-10-31
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多