Search in sources :

Example 1 with PyBreakpoint

use of org.python.pydev.debug.model.PyBreakpoint in project Pydev by fabioz.

the class PyBreakpointRulerAction method addBreakpointMarker.

public static void addBreakpointMarker(IDocument document, int lineNumber, ITextEditor textEditor, final String type) {
    try {
        if (lineNumber < 0) {
            return;
        }
        // just to validate it
        try {
            document.getLineInformation(lineNumber - 1);
        } catch (Exception e) {
            // ignore
            return;
        }
        final IResource resource = PyMarkerUIUtils.getResourceForTextEditor(textEditor);
        // The map containing the marker attributes
        final Map<String, Object> map = new HashMap<String, Object>();
        // if not null, we're dealing with an external file.
        final IEditorInput externalFileEditorInput = getExternalFileEditorInput(textEditor);
        // TODO: that happens when we're trying to set a breakpoint in a file that's within a zip file.
        if (externalFileEditorInput == null && resource instanceof IWorkspaceRoot) {
            return;
        }
        map.put(IMarker.MESSAGE, PYDEV_BREAKPOINT);
        map.put(IMarker.LINE_NUMBER, lineNumber);
        map.put(IBreakpoint.ENABLED, true);
        map.put(IBreakpoint.ID, PyDebugModelPresentation.PY_DEBUG_MODEL_ID);
        map.put(PyBreakpoint.PY_BREAK_TYPE, type);
        if (externalFileEditorInput != null) {
            File file = EditorInputUtils.getFile(externalFileEditorInput);
            if (file != null) {
                map.put(PyBreakpoint.PY_BREAK_EXTERNAL_PATH_ID, FileUtils.getFileAbsolutePath(file));
            }
        }
        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                IMarker marker;
                if (type.equals(PyBreakpoint.PY_BREAK_TYPE_DJANGO)) {
                    marker = resource.createMarker(PyBreakpoint.DJANGO_BREAK_MARKER);
                } else {
                    if (!type.equals(PyBreakpoint.PY_BREAK_TYPE_PYTHON)) {
                        Log.log("Error. Expected :" + PyBreakpoint.PY_BREAK_TYPE_PYTHON + " or " + PyBreakpoint.PY_BREAK_TYPE_DJANGO + ". Found: " + type + " (considered as python break type).");
                    }
                    marker = resource.createMarker(PyBreakpoint.PY_BREAK_MARKER);
                }
                marker.setAttributes(map);
                PyBreakpoint br = new PyBreakpoint();
                br.setMarker(marker);
                IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
                breakpointManager.addBreakpoint(br);
            }
        };
        resource.getWorkspace().run(runnable, null);
    } catch (Exception e) {
        Log.log(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) PyBreakpoint(org.python.pydev.debug.model.PyBreakpoint) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IMarker(org.eclipse.core.resources.IMarker) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with PyBreakpoint

use of org.python.pydev.debug.model.PyBreakpoint in project Pydev by fabioz.

the class PythonBreakpointPage method createLabels.

/**
 * Creates the labels displayed for the breakpoint.
 * @param parent
 */
protected void createLabels(Composite parent) {
    PyBreakpoint breakpoint = (PyBreakpoint) getElement();
    Composite labelComposite = createComposite(parent, 2);
    String typeName = breakpoint.getFile();
    if (typeName != null) {
        // $NON-NLS-1$
        createLabel(labelComposite, "File");
        createLabel(labelComposite, typeName);
    }
    createTypeSpecificLabels(labelComposite);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) PyBreakpoint(org.python.pydev.debug.model.PyBreakpoint)

Example 3 with PyBreakpoint

use of org.python.pydev.debug.model.PyBreakpoint in project Pydev by fabioz.

the class PythonBreakpointPage method doStore.

/**
 * Stores the values configured in this page. This method
 * should be called from within a workspace runnable to
 * reduce the number of resource deltas.
 */
protected void doStore() throws CoreException {
    PyBreakpoint breakpoint = getBreakpoint();
    storeEnabled(breakpoint);
    if (fConditionEditor != null) {
        boolean enableCondition = fEnableConditionButton.getSelection();
        String condition = fConditionEditor.getCondition();
        if (breakpoint.isConditionEnabled() != enableCondition) {
            breakpoint.setConditionEnabled(enableCondition);
        }
        if (!condition.equals(breakpoint.getCondition())) {
            breakpoint.setCondition(condition);
        }
    }
}
Also used : PyBreakpoint(org.python.pydev.debug.model.PyBreakpoint)

Example 4 with PyBreakpoint

use of org.python.pydev.debug.model.PyBreakpoint in project Pydev by fabioz.

the class PythonBreakpointPage method createConditionEditor.

/**
 * Creates the controls that allow the user to specify the breakpoint's
 * condition
 * @param parent the composite in which the condition editor should be created
 * @throws CoreException if an exception occurs accessing the breakpoint
 */
private void createConditionEditor(Composite parent) throws CoreException {
    PyBreakpoint breakpoint = getBreakpoint();
    String label = null;
    ICommandManager commandManager = PlatformUI.getWorkbench().getCommandSupport().getCommandManager();
    // $NON-NLS-1$
    ICommand command = commandManager.getCommand("org.eclipse.ui.edit.text.contentAssist.proposals");
    if (command != null) {
        List keyBindings = command.getKeySequenceBindings();
        if (keyBindings != null && keyBindings.size() > 0) {
            IKeySequenceBinding binding = (IKeySequenceBinding) keyBindings.get(0);
            // $NON-NLS-1$
            label = StringUtils.format("E&nable Condition %s", binding.getKeySequence().format());
        }
    }
    if (label == null) {
        // $NON-NLS-1$
        label = "E&nable Condition (code assist not available)";
    }
    Composite conditionComposite = new Group(parent, SWT.NONE);
    conditionComposite.setFont(parent.getFont());
    conditionComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    conditionComposite.setLayout(new GridLayout());
    fEnableConditionButton = createCheckButton(conditionComposite, label);
    fEnableConditionButton.setSelection(breakpoint.isConditionEnabled());
    fEnableConditionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setConditionEnabled(fEnableConditionButton.getSelection());
        }
    });
    fConditionEditor = new BreakpointConditionEditor(conditionComposite, this);
    // fSuspendWhenLabel= createLabel(conditionComposite, "Suspend when:");
    // fConditionIsTrue= createRadioButton(conditionComposite, "condition is \'tr&ue\'");
    // fConditionIsTrue= createLabel(conditionComposite, "condition is \'tr&ue\'");
    // fConditionHasChanged= createRadioButton(conditionComposite, "value of condition ch&anges");
    // if (breakpoint.isConditionSuspendOnTrue()) {
    // fConditionIsTrue.setSelection(true);
    // } else {
    // fConditionHasChanged.setSelection(true);
    // }
    setConditionEnabled(fEnableConditionButton.getSelection());
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ICommandManager(org.eclipse.ui.commands.ICommandManager) GridLayout(org.eclipse.swt.layout.GridLayout) PyBreakpoint(org.python.pydev.debug.model.PyBreakpoint) ICommand(org.eclipse.ui.commands.ICommand) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) IKeySequenceBinding(org.eclipse.ui.commands.IKeySequenceBinding)

Example 5 with PyBreakpoint

use of org.python.pydev.debug.model.PyBreakpoint in project Pydev by fabioz.

the class PythonBreakpointPage method createTypeSpecificLabels.

/**
 * Allows subclasses to add type specific labels to the common Java
 * breakpoint page.
 * @param parent
 */
protected void createTypeSpecificLabels(Composite parent) {
    // Line number
    PyBreakpoint breakpoint = getBreakpoint();
    StringBuffer lineNumber = new StringBuffer(4);
    try {
        int lNumber = breakpoint.getLineNumber();
        if (lNumber > 0) {
            lineNumber.append(lNumber);
        }
    } catch (CoreException ce) {
        PydevDebugPlugin.log(IStatus.ERROR, ce.getLocalizedMessage(), ce);
    }
    if (lineNumber.length() > 0) {
        createLabel(parent, "&Line Number:");
        createLabel(parent, lineNumber.toString());
    }
// Member
/*
        try {
            IMember member = BreakpointUtils.getMember(breakpoint);
            if (member == null) {
                return;
            }
            String label = PropertyPageMessages.JavaLineBreakpointPage_3; //$NON-NLS-1$
            String memberName = fJavaLabelProvider.getText(member);
            if (breakpoint instanceof IJavaMethodBreakpoint) {
                label = PropertyPageMessages.JavaLineBreakpointPage_4; //$NON-NLS-1$
            } else if (breakpoint instanceof IJavaWatchpoint) {
                label = PropertyPageMessages.JavaLineBreakpointPage_5; //$NON-NLS-1$
            }
            createLabel(parent, label);
            createLabel(parent, memberName);
        } catch (CoreException exception) {
            PydevDebugPlugin.log(IStatus.ERROR,e.getLocalizedMessage(),exception);
        }*/
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PyBreakpoint(org.python.pydev.debug.model.PyBreakpoint) PyBreakpoint(org.python.pydev.debug.model.PyBreakpoint)

Aggregations

PyBreakpoint (org.python.pydev.debug.model.PyBreakpoint)7 CoreException (org.eclipse.core.runtime.CoreException)3 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Composite (org.eclipse.swt.widgets.Composite)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)1 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Group (org.eclipse.swt.widgets.Group)1 IEditorInput (org.eclipse.ui.IEditorInput)1