Search in sources :

Example 51 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class PyCopyQualifiedName method run.

@Override
public void run(IAction action) {
    FastStringBuffer buf = new FastStringBuffer();
    try {
        PyEdit pyEdit = getPyEdit();
        PySelection pySelection = PySelectionFromEditor.createPySelectionFromEditor(pyEdit);
        IPythonNature nature = pyEdit.getPythonNature();
        File editorFile = pyEdit.getEditorFile();
        if (editorFile != null) {
            if (nature != null) {
                String mod = nature.resolveModule(editorFile);
                if (mod != null) {
                    buf.append(mod);
                } else {
                    // Support for external files (not in PYTHONPATH).
                    buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
                }
            } else {
                buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
            }
        }
        List<stmtType> path = FastParser.parseToKnowGloballyAccessiblePath(pySelection.getDoc(), pySelection.getStartLineIndex());
        for (stmtType stmtType : path) {
            if (buf.length() > 0) {
                buf.append('.');
            }
            buf.append(NodeUtils.getRepresentationString(stmtType));
        }
    } catch (MisconfigurationException e1) {
        Log.log(e1);
        return;
    }
    Transfer[] dataTypes = new Transfer[] { TextTransfer.getInstance() };
    Object[] data = new Object[] { buf.toString() };
    Clipboard clipboard = new Clipboard(EditorUtils.getShell().getDisplay());
    try {
        clipboard.setContents(data, dataTypes);
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
            throw e;
        }
        MessageDialog.openError(EditorUtils.getShell(), "Error copying to clipboard.", e.getMessage());
    } finally {
        clipboard.dispose();
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) org.python.pydev.parser.jython.ast.stmtType(org.python.pydev.parser.jython.ast.stmtType) MisconfigurationException(org.python.pydev.core.MisconfigurationException) IPythonNature(org.python.pydev.core.IPythonNature) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) PySelection(org.python.pydev.core.docutils.PySelection) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File) PyEdit(org.python.pydev.editor.PyEdit)

Example 52 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class PyRemoveBlockComment method run.

/**
 * Grabs the selection information and performs the action.
 */
@Override
public void run(IAction action) {
    try {
        if (!canModifyEditor()) {
            return;
        }
        // Select from text editor
        PyEdit pyEdit = getPyEdit();
        PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(getTextEditor());
        // Perform the action
        Tuple<Integer, Integer> repRegion = perform(ps);
        if (repRegion == null) {
            return;
        }
        // Put cursor at the first area of the selection
        pyEdit.selectAndReveal(repRegion.o1, repRegion.o2);
    } catch (Exception e) {
        beep(e);
    }
}
Also used : PySelection(org.python.pydev.core.docutils.PySelection) PyEdit(org.python.pydev.editor.PyEdit)

Example 53 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class PyScopeSelection method run.

@Override
public void run(IAction action) {
    try {
        PyEdit editor = getPyEdit();
        IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
        ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
        new ScopeSelectionAction().perform(doc, new CoreTextSelection(doc, selection.getOffset(), selection.getLength()), editor);
    } catch (Exception e) {
        Log.log(e);
    }
}
Also used : ScopeSelectionAction(org.python.pydev.shared_ui.actions.ScopeSelectionAction) CoreTextSelection(org.python.pydev.shared_core.string.CoreTextSelection) PyEdit(org.python.pydev.editor.PyEdit) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 54 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class PySelectWord method run.

@Override
public void run(IAction action) {
    PyEdit pyEdit = getPyEdit();
    PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(pyEdit);
    try {
        Tuple<String, Integer> currToken = ps.getCurrToken();
        if (currToken.o1 != null) {
            int len = currToken.o1.length();
            if (len > 0) {
                pyEdit.selectAndReveal(currToken.o2, len);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
}
Also used : PySelection(org.python.pydev.core.docutils.PySelection) PyEdit(org.python.pydev.editor.PyEdit)

Example 55 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class PyToggleForceTabs method updateActionState.

private void updateActionState(IIndentPrefs indentPrefs) {
    // This doesn't work! (setChecked and setImageDescriptor don't seem to update the action in the pop up menu).
    // setChecked(forceTabs);
    // setImageDescriptor(desc);
    PyEdit pyEdit = getPyEdit();
    pyEdit.updateForceTabsMessage();
}
Also used : PyEdit(org.python.pydev.editor.PyEdit)

Aggregations

PyEdit (org.python.pydev.editor.PyEdit)64 PySelection (org.python.pydev.core.docutils.PySelection)22 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)14 BadLocationException (org.eclipse.jface.text.BadLocationException)13 Path (org.eclipse.core.runtime.Path)12 IDocument (org.eclipse.jface.text.IDocument)12 MisconfigurationException (org.python.pydev.core.MisconfigurationException)9 ICompletionProposalHandle (org.python.pydev.shared_core.code_completion.ICompletionProposalHandle)9 IPythonNature (org.python.pydev.core.IPythonNature)8 File (java.io.File)7 ICallbackListener (org.python.pydev.shared_core.callbacks.ICallbackListener)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IRegion (org.eclipse.jface.text.IRegion)5 ITextSelection (org.eclipse.jface.text.ITextSelection)5 IEditorInput (org.eclipse.ui.IEditorInput)5 SimpleNode (org.python.pydev.parser.jython.SimpleNode)5 CoreException (org.eclipse.core.runtime.CoreException)4 RefactoringRequest (org.python.pydev.ast.refactoring.RefactoringRequest)4 IInterpreterManager (org.python.pydev.core.IInterpreterManager)4