【问题标题】:Eclipse plugin, where in the editor did the popup menu happen?Eclipse 插件,弹出菜单在编辑器的哪个位置出现?
【发布时间】:2014-05-19 19:06:06
【问题描述】:

我正在为特定领域的语言编写一个 Eclipse 插件。我已经对编辑器进行了子类化,并且一切正常。

我想添加一个弹出菜单,以便我可以进行自己的重构。我用org.eclipse.ui.popupmenus添加了popupmenu,当你在编辑器上右击时,确实提供了菜单,可以点击,点击执行如下方法:

  public void run(IAction action) {
    MessageDialog.openInformation(shell, "SyntaxColoringCSharp", "refactorA was executed.");
  }

我的问题是我不知道点击发生在编辑器的哪个位置 - 所以我很难获得文件的正确位来执行重构。光标不会移动到单击发生的位置。

如何在编辑器中找到弹出菜单点击的位置? (即 Java 重构如何获取这些信息?)

这是我正在使用的基本类:

package arteditor.popup.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.editors.text.TextEditor;

import editoractions.EditorActions;

public class refactorA implements IObjectActionDelegate {

  private Shell shell;

  /**
   * Constructor for Action1.
   */
  public refactorA() {
    super();
  }

  /**
   * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
   */
  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
    shell = targetPart.getSite().getShell();
  }

  /**
   * @see IActionDelegate#run(IAction)
   */
  public void run(IAction action) {
    MessageDialog.openInformation(shell, "SyntaxColoringCSharp", "refactorA was executed.");
  }

  /**
   * @see IActionDelegate#selectionChanged(IAction, ISelection)
   */
  public void selectionChanged(IAction action, ISelection selection) {

   }
}

【问题讨论】:

  • 在右键单击操作中使用光标(插入符号)位置是正常的 - 这就是 Java 重构在 Java 编辑器上下文菜单中所做的。
  • 枪的儿子,就是这样!

标签: java eclipse eclipse-plugin


【解决方案1】:

在右键单击操作中使用光标(插入符号)位置是正常的 - 这就是 Java 重构在 Java 编辑器上下文菜单中所做的。

StyledText 小部件具有多种返回插入符号位置的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多