📄 watchexpressionaction.java
字号:
package org.python.pydev.debug.ui.actions;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IWatchExpression;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.python.pydev.debug.core.PydevDebugPlugin;
public class WatchExpressionAction implements IEditorActionDelegate {
private ITextSelection fSelection;
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
}
public void run(IAction action) {
if (fSelection == null) {
return;
}
String text = fSelection.getText();
createExpression(text);
}
public void selectionChanged(IAction action, ISelection selection) {
fSelection = null;
if (selection instanceof ITextSelection ) {
fSelection = (ITextSelection) selection;
}
}
private void showExpressionsView() {
IWorkbenchPage page = PydevDebugPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart part = page.findView(IDebugUIConstants.ID_EXPRESSION_VIEW);
if (part == null) {
try {
page.showView(IDebugUIConstants.ID_EXPRESSION_VIEW);
} catch (PartInitException e) {
}
} else {
page.bringToTop(part);
}
}
private void createExpression(String variable) {
IWatchExpression expression = DebugPlugin.getDefault().getExpressionManager().newWatchExpression(variable);
DebugPlugin.getDefault().getExpressionManager().addExpression(expression);
IAdaptable object = DebugUITools.getDebugContext();
IDebugElement context = null;
if (object instanceof IDebugElement) {
context = (IDebugElement) object;
} else if (object instanceof ILaunch) {
context = ((ILaunch) object).getDebugTarget();
}
expression.setExpressionContext(context);
showExpressionsView();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -