eclipse插件开发手记之编辑器上下文菜单

阅读更多

 研究eclipse插件已经第四天了,由于文档的缺乏,对eclipse各个接口和类的继承关系没有清晰地认识。今天要给插件加上一个和编辑器交互的action,目的是将选择的文本替换为插入的代码。

第一步:加上菜单,这个比较容易,plugin.xml(此action挂在已有的菜单下)

 
         
          

 第二步:编写action类,该类实现IEditorActionDelegate接口

 

package com.h2isea.ices.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.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;

/**
 * Our sample action implements workbench action delegate.
 * The action proxy will be created by the workbench and
 * shown in the UI. When the user tries to use the action,
 * this delegate will be created and execution will be 
 * delegated to it.
 * @see IWorkbenchWindowActionDelegate
 */
public class GenerateCodeAction implements IEditorActionDelegate {
	private ISelection selection = null;
	private Shell shell;
	/**
	 * 调试弹出框
	 * 
	 * @param content
	 */
	public void alert(Object content) {
		MessageDialog.openInformation(shell, "ices 提示", content + "");
	}
	

	
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
		shell = targetEditor.getSite().getShell();
		
	}

	public void run(IAction action) {
                                   alert("run");
	}

	public void selectionChanged(IAction action, ISelection selection) {
		this.selection=selection;
	}
}

 接下来就要写run方法了,这个就比较麻烦了

你可能感兴趣的:(Eclipse,UI,Flash,XML)