use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class StepIntoEditorSelectionHandler method execute.
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof PyEdit) {
PyEdit pyEdit = (PyEdit) editor;
StepIntoSelectionHyperlinkDetector stepIntoSelectionHyperlinkDetector = new StepIntoSelectionHyperlinkDetector();
ISelection selection = editor.getEditorSite().getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
stepIntoSelectionHyperlinkDetector.setContext(pyEdit);
ITextSelection iTextSelection = (ITextSelection) selection;
IHyperlink[] detectHyperlinks = stepIntoSelectionHyperlinkDetector.detectHyperlinks(pyEdit.getISourceViewer(), new Region(iTextSelection.getOffset(), iTextSelection.getLength()), false);
if (detectHyperlinks != null && detectHyperlinks.length > 0) {
detectHyperlinks[0].open();
}
}
}
return null;
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PyRunToLineTarget method runToLine.
@Override
public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException {
// System.out.println("Run to line:"+target);
PyStackFrame stack = null;
if (target instanceof PyStackFrame) {
stack = (PyStackFrame) target;
target = stack.getThread();
}
if (!(part instanceof PyEdit)) {
return;
}
PyEdit pyEdit = (PyEdit) part;
SimpleNode ast = pyEdit.getAST();
if (ast == null) {
IDocument doc = pyEdit.getDocument();
SourceModule sourceModule;
IPythonNature nature = null;
try {
nature = pyEdit.getPythonNature();
} catch (MisconfigurationException e) {
// Let's try to find a suitable nature
File editorFile = pyEdit.getEditorFile();
if (editorFile == null || !editorFile.exists()) {
Log.log(e);
return;
}
nature = InterpreterManagersAPI.getInfoForFile(editorFile).o1;
}
if (nature == null) {
Log.log("Unable to determine nature!");
return;
}
try {
sourceModule = AbstractModule.createModuleFromDoc("", pyEdit.getEditorFile(), doc, nature, true);
} catch (MisconfigurationException e) {
Log.log(e);
return;
}
ast = sourceModule.getAst();
}
if (ast == null) {
Log.log("Cannot determine context to run to.");
return;
}
if (target instanceof PyThread && selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
PyThread pyThread = (PyThread) target;
if (!pyThread.isPydevThread()) {
int line = textSelection.getStartLine();
String functionName = NodeUtils.getContextName(line, ast);
if (functionName == null) {
// global context
functionName = "";
} else {
functionName = FullRepIterable.getLastPart(functionName).trim();
}
pyThread.runToLine(line + 1, functionName);
return;
}
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class EvaluateActionSetter method onCreateActions.
/**
* This method associates Ctrl+new line with the evaluation of commands in the console.
*/
@Override
public void onCreateActions(ListResourceBundle resources, final BaseEditor baseEditor, IProgressMonitor monitor) {
final PyEdit edit = (PyEdit) baseEditor;
final EvaluateAction evaluateAction = new EvaluateAction(edit);
evaluateAction.setActionDefinitionId(IInteractiveConsoleConstants.EVALUATE_ACTION_ID);
evaluateAction.setId(IInteractiveConsoleConstants.EVALUATE_ACTION_ID);
Runnable runnable = new Runnable() {
@Override
public void run() {
if (!edit.isDisposed()) {
edit.setAction(IInteractiveConsoleConstants.EVALUATE_ACTION_ID, evaluateAction);
}
}
};
Display.getDefault().syncExec(runnable);
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class DjangoActionCreatorPyEditListener method onCreateActions.
@Override
public void onCreateActions(ListResourceBundle resources, BaseEditor baseEditor, IProgressMonitor monitor) {
PyEdit edit = (PyEdit) baseEditor;
edit.addOfflineActionListener("dj", new PyDjangoOfflineAction(edit), "Execute django action", true);
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PydevIProcessFactory method createInteractiveLaunch.
/**
* Creates a launch (and its associated IProcess) for the xml-rpc server to be used in the interactive console.
*
* It'll ask the user how to create it:
* - editor
* - python interpreter
* - jython interpreter
*
* @return the Launch, the Process created and the port that'll be used for the server to call back into
* this client for requesting input.
*
* @throws UserCanceledException
* @throws Exception
*/
public PydevConsoleLaunchInfo createInteractiveLaunch() throws UserCanceledException, Exception {
IWorkbenchWindow workbenchWindow = EditorUtils.getActiveWorkbenchWindow();
IEditorPart activeEditor = EditorUtils.getActiveEditor();
PyEdit edit = null;
if (activeEditor instanceof PyEdit) {
edit = (PyEdit) activeEditor;
}
ChooseProcessTypeDialog dialog = new ChooseProcessTypeDialog(getShell(), edit);
String rep = InteractiveConsolePrefs.getDefaultInteractiveConsole();
boolean hasPrefs = false;
if (!rep.isEmpty()) {
dialog.create();
hasPrefs = dialog.setInteractiveConsoleInterpreterPref(rep);
if (hasPrefs) {
dialog.okPressed();
}
}
if (hasPrefs || dialog.open() == ChooseProcessTypeDialog.OK) {
PyStackFrame selectedFrame = dialog.getSelectedFrame();
if (selectedFrame != null) {
// Interpreter not required for Debug Console
String encoding = getEncodingFromFrame(selectedFrame);
return new PydevConsoleLaunchInfo(null, null, 0, null, selectedFrame, new String[] { "Debug connection (no command line)" }, null, encoding);
}
IInterpreterManager interpreterManager = dialog.getInterpreterManager();
if (interpreterManager == null) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreter manager for creating console", "No interpreter manager was available for creating a console.");
}
IInterpreterInfo[] interpreters = interpreterManager.getInterpreterInfos();
if (interpreters == null || interpreters.length == 0) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreters for creating console", "No interpreter available for creating a console.");
return null;
}
IInterpreterInfo interpreter = null;
if (interpreters.length == 1) {
// We just have one, so, no point in asking about which one should be there.
interpreter = interpreters[0];
}
if (interpreter == null) {
if (PydevConsoleConstants.ACTIVE_EDITOR_INTERPRETER_REPRESENTATION.equals(dialog.getSelectedInteractiveConsoleInterpreterRep())) {
if (edit != null) {
PythonNature pythonNature = PythonNature.getPythonNature(edit.getProject());
if (pythonNature != null) {
interpreter = pythonNature.getProjectInterpreter();
}
}
}
if (interpreter == null) {
SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(workbenchWindow, interpreters, "Select interpreter to be used.", false);
int open = listDialog.open();
if (open != ListDialog.OK || listDialog.getResult().length > 1) {
return null;
}
Object[] result = listDialog.getResult();
if (result == null || result.length == 0) {
interpreter = interpreters[0];
} else {
interpreter = ((IInterpreterInfo) result[0]);
}
}
}
if (interpreter == null) {
return null;
}
Tuple<Collection<String>, IPythonNature> pythonpathAndNature = dialog.getPythonpathAndNature(interpreter);
if (pythonpathAndNature == null) {
return null;
}
return createLaunch(interpreterManager, interpreter, pythonpathAndNature.o1, pythonpathAndNature.o2, dialog.getNatures());
}
return null;
}
Aggregations