Package org.python.pydev.editor

Examples of org.python.pydev.editor.PyEdit$MyResources


            int e = end == null ? s : end.toOffset(doc);
            TextSelection sel = new TextSelection(s, e - s);
            textEdit.getSelectionProvider().setSelection(sel);
        } catch (BadLocationException e1) {
            if (textEdit instanceof PyEdit) {
                PyEdit p = (PyEdit) textEdit;
                Log.log(IStatus.ERROR, ("Error setting selection:" + start + " - " + end + " - " + p.getEditorFile()),
                        e1);

            } else {
                Log.log(IStatus.ERROR, ("Error setting selection:" + start + " - " + end), e1);
            }
View Full Code Here


        pyAutoIndentStrategy.setBlockSelection(blockSelection);
        super.customizeDocumentCommand(command);
    }

    public Object getAdapter(Class adapter) {
        PyEdit pyEdit = projection.get();
        if (pyEdit != null) {
            return pyEdit.getAdapter(adapter);
        }
        return null;
    }
View Full Code Here

        try {
            if (!canModifyEditor()) {
                return;
            }

            PyEdit pyEdit = getPyEdit();
            PySelection ps = new PySelection(pyEdit);

            try {
                int[] regionsToFormat = null;
                if (ps.getSelLength() > 0) {
                    int startLineIndex = ps.getStartLineIndex();
                    int endLineIndex = ps.getEndLineIndex();
                    regionsToFormat = new int[endLineIndex - startLineIndex + 1];
                    for (int i = startLineIndex, j = 0; i <= endLineIndex; i++, j++) {
                        regionsToFormat[j] = i;
                    }
                } else {
                    //For full-formatting, we cannot have a syntax error.
                    if (pyEdit.hasSyntaxError(ps.getDoc())) {
                        return;
                    }
                }

                applyFormatAction(pyEdit, ps, regionsToFormat, true);
            } catch (SyntaxErrorException e) {
                pyEdit.getStatusLineManager().setErrorMessage(e.getMessage());
            }

        } catch (Exception e) {
            beep(e);
        }
View Full Code Here

    private void getDocstringHover(IRegion hoverRegion, PySourceViewer s, PySelection ps) {
        //Now, aside from the marker, let's check if there's some definition we should show the user about.
        CompletionCache completionCache = new CompletionCache();
        ArrayList<IDefinition> selected = new ArrayList<IDefinition>();

        PyEdit edit = s.getEdit();
        RefactoringRequest request;
        IPythonNature nature = null;
        try {
            nature = edit.getPythonNature();
            request = new RefactoringRequest(edit.getEditorFile(), ps, new NullProgressMonitor(), nature, edit);
        } catch (MisconfigurationException e) {
            return;
        }
        String[] tokenAndQual = null;
        try {
            tokenAndQual = PyRefactoringFindDefinition.findActualDefinition(request, completionCache, selected);
        } catch (CompletionRecursionException e1) {
            Log.log(e1);
            buf.append("Unable to compute hover. Details: " + e1.getMessage());
            return;
        }

        FastStringBuffer temp = new FastStringBuffer();

        if (tokenAndQual != null && selected.size() > 0) {
            for (IDefinition d : selected) {
                Definition def = (Definition) d;

                SimpleNode astToPrint = null;
                if (def.ast != null) {
                    astToPrint = def.ast;
                    if ((astToPrint instanceof Name || astToPrint instanceof NameTok) && def.scope != null) {
                        //There's no real point in just printing the name, let's see if we're able to actually find
                        //the scope where it's in and print that scope.
                        FastStack<SimpleNode> scopeStack = def.scope.getScopeStack();
                        if (scopeStack != null && scopeStack.size() > 0) {
                            SimpleNode peek = scopeStack.peek();
                            if (peek != null) {
                                stmtType stmt = NodeUtils.findStmtForNode(peek, astToPrint);
                                if (stmt != null) {
                                    astToPrint = stmt;
                                }
                            }
                        }
                    }
                    try {
                        astToPrint = astToPrint.createCopy();
                        MakeAstValidForPrettyPrintingVisitor.makeValid(astToPrint);
                    } catch (Exception e) {
                        Log.log(e);
                    }
                }

                temp = temp.clear();
                if (def.value != null) {
                    if (astToPrint instanceof FunctionDef) {
                        temp.append("def ");

                    } else if (astToPrint instanceof ClassDef) {
                        temp.append("class ");

                    }
                    temp.append("<pydev_hint_bold>");
                    temp.append(def.value);
                    temp.append("</pydev_hint_bold>");
                    temp.append(' ');
                }

                if (def.module != null) {
                    temp.append("Found at: ");
                    temp.append("<pydev_hint_bold>");
                    temp.append(def.module.getName());
                    temp.append("</pydev_hint_bold>");
                    temp.append(PyInformationPresenter.LINE_DELIM);
                }

                if (def.module != null && def.value != null) {
                    ItemPointer pointer = PyRefactoringFindDefinition.createItemPointer(def);
                    String asPortableString = pointer.asPortableString();
                    if (asPortableString != null) {
                        //may happen if file is not in the pythonpath
                        temp.replaceAll(
                                "<pydev_hint_bold>",
                                com.aptana.shared_core.string.StringUtils.format("<pydev_link pointer=\"%s\">",
                                        StringEscapeUtils.escapeXml(asPortableString)));
                        temp.replaceAll("</pydev_hint_bold>", "</pydev_link>");
                    }
                }

                String str = printAst(edit, astToPrint);

                if (str != null && str.trim().length() > 0) {
                    temp.append(PyInformationPresenter.LINE_DELIM);
                    temp.append(str);

                } else {
                    String docstring = d.getDocstring(nature, completionCache);
                    if (docstring != null && docstring.trim().length() > 0) {
                        IIndentPrefs indentPrefs = edit.getIndentPrefs();
                        temp.append(StringUtils.fixWhitespaceColumnsToLeftFromDocstring(docstring,
                                indentPrefs.getIndentationString()));
                    }
                }
View Full Code Here

*/
public class PyScopeDeselection extends PyAction {

    public void run(IAction action) {
        try {
            PyEdit pyEdit = getPyEdit();
            FastStack<IRegion> stack = PyScopeSelection.getCache(pyEdit);

            ITextSelection selection = (ITextSelection) pyEdit.getSelectionProvider().getSelection();
            Region region = new Region(selection.getOffset(), selection.getLength());
            Iterator<IRegion> it = stack.topDownIterator();
            while (it.hasNext()) {
                IRegion iRegion = it.next();
                stack.pop(); //After getting the latest, pop it.

                if (iRegion.equals(region)) {
                    if (stack.size() > 0) {
                        IRegion peek = stack.peek();
                        pyEdit.setSelection(peek.getOffset(), peek.getLength());
                    }
                    break;
                }
            }

View Full Code Here

        try {
            if (!canModifyEditor()) {
                return;
            }

            PyEdit pyEdit = getPyEdit();
            Collection<ActionInfo> offlineActionDescriptions = pyEdit.getOfflineActionDescriptions();
            for (ActionInfo actionInfo : offlineActionDescriptions) {
                if ("wrap paragraph".equals(actionInfo.description.trim().toLowerCase())) {
                    actionInfo.action.run();
                    return;
                }
View Full Code Here

    /**
     * This method will search for the next/previous function (depending on the abstract methods)
     * and will go to the position in the document that corresponds to the name of the class/function definition.
     */
    public void run(IAction action) {
        PyEdit pyEdit = getPyEdit();
        IDocument doc = pyEdit.getDocument();
        ITextSelection selection = (ITextSelection) pyEdit.getSelectionProvider().getSelection();

        boolean searchForward = getSearchForward();

        int startLine = selection.getStartLine();

        //we want to start searching in the line before/after the line we're in.
        if (searchForward) {
            startLine += 1;
        } else {
            startLine -= 1;
        }
        stmtType goHere = FastParser.firstClassOrFunction(doc, startLine, searchForward, pyEdit.isCythonFile());

        NameTok node = getNameNode(goHere);
        if (node != null) {
            //ok, somewhere to go
            pyEdit.revealModelNode(node);

        } else {
            //no place specified until now... let's try to see if we should go to the start or end of the file
            if (searchForward) {
                pyEdit.selectAndReveal(doc.getLength(), 0);

            } else {
                pyEdit.selectAndReveal(0, 0);
            }
        }
    }
View Full Code Here

        try {
            if (!canModifyEditor()) {
                return;
            }

            PyEdit pyEdit = getPyEdit();

            PySelection ps = new PySelection(pyEdit);
            String endLineDelim = ps.getEndLineDelim();
            final IDocument doc = ps.getDoc();
            DocumentRewriteSession session = null;

            try {
                if (ps.getStartLineIndex() == ps.getEndLineIndex()) {
                    //let's see if someone wants to make a better implementation in another plugin...
                    List<IOrganizeImports> participants = ExtensionHelper
                            .getParticipants(ExtensionHelper.PYDEV_ORGANIZE_IMPORTS);

                    for (IOrganizeImports organizeImports : participants) {
                        if (!organizeImports.beforePerformArrangeImports(ps, pyEdit)) {
                            return;
                        }
                    }

                    session = startWrite(doc);

                    performArrangeImports(doc, endLineDelim, pyEdit.getIndentPrefs().getIndentationString());

                    for (IOrganizeImports organizeImports : participants) {
                        organizeImports.afterPerformArrangeImports(ps, pyEdit);
                    }
                } else {
View Full Code Here

                            }

                        } else {
                            IIndentPrefs indentPrefs;
                            if (targetEditor instanceof PyEdit) {
                                PyEdit pyEdit = (PyEdit) targetEditor;
                                indentPrefs = pyEdit.getIndentPrefs();
                            } else {
                                indentPrefs = DefaultIndentPrefs.get();
                            }

                            String indentationString = indentPrefs.getIndentationString();
View Full Code Here

     * @throws MisconfigurationException
     */
    public RefactoringRequest getRefactoringRequest(IProgressMonitor monitor) throws MisconfigurationException {
        if (request == null) {
            //testing first with whole lines.
            PyEdit pyEdit = getPyEdit(); //may not be available in tests, that's why it is important to be able to operate without it
            request = createRefactoringRequest(monitor, pyEdit, ps);
        }
        request.pushMonitor(monitor);
        return request;
    }
View Full Code Here

TOP

Related Classes of org.python.pydev.editor.PyEdit$MyResources

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.