Search in sources :

Example 6 with PyOpenAction

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

the class PyEdit method openWithPathAndInnerStructure.

/**
 * This function will open an editor given the passed parameters
 *
 * @param projectName
 * @param path
 * @param innerStructure
 * @throws MisconfigurationException
 */
public static void openWithPathAndInnerStructure(String projectName, IPath path, List<String> innerStructure) throws MisconfigurationException {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    if (project != null) {
        IFile file = project.getFile(path);
        if (file != null) {
            IEditorPart editor = PyOpenEditor.doOpenEditor(file);
            if (editor instanceof PyEdit) {
                PyEdit pyEdit = (PyEdit) editor;
                IPythonNature nature = pyEdit.getPythonNature();
                AbstractModule mod = AbstractModule.createModuleFromDoc(nature.resolveModule(file), file.getLocation().toFile(), pyEdit.getDocument(), nature, false);
                StringBuffer tok = new StringBuffer(80);
                for (String s : innerStructure) {
                    if (tok.length() > 0) {
                        tok.append('.');
                    }
                    tok.append(s);
                }
                try {
                    IDefinition[] definitions = mod.findDefinition(CompletionStateFactory.getEmptyCompletionState(tok.toString(), nature, new CompletionCache()), -1, -1, nature);
                    List<ItemPointer> pointers = new ArrayList<ItemPointer>();
                    PyRefactoringFindDefinition.getAsPointers(pointers, definitions);
                    if (pointers.size() > 0) {
                        new PyOpenAction().run(pointers.get(0));
                    }
                } catch (Exception e) {
                    Log.log(e);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IPythonNature(org.python.pydev.core.IPythonNature) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IDefinition(org.python.pydev.core.IDefinition) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SyntaxErrorException(org.python.pydev.core.docutils.SyntaxErrorException) BadLocationException(org.eclipse.jface.text.BadLocationException) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.python.pydev.parser.jython.ParseException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractModule(org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule) CompletionCache(org.python.pydev.ast.codecompletion.revisited.CompletionCache) IWorkspace(org.eclipse.core.resources.IWorkspace) IPyEdit(org.python.pydev.core.IPyEdit) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 7 with PyOpenAction

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

the class PyOpenPythonFileAction method openFiles.

/**
 * Opens the given files with the Pydev editor.
 *
 * @param filesSelected the files to be opened with the pydev editor.
 */
protected void openFiles(List<IFile> filesSelected) {
    for (IFile f : filesSelected) {
        // If a file is opened here, set it as having the Pydev editor as the default editor.
        IDE.setDefaultEditor(f, PyEdit.EDITOR_ID);
        new PyOpenAction().run(new ItemPointer(f));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 8 with PyOpenAction

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

the class PyOpenResourceAction method openFiles.

@Override
protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) {
    for (PythonpathTreeNode n : pythonPathFilesSelected) {
        try {
            if (PythonPathHelper.isValidSourceFile(n.file.getName())) {
                new PyOpenAction().run(new ItemPointer(n.file));
            } else {
                final IFileStore fileStore = EFS.getLocalFileSystem().getStore(n.file.toURI());
                IDE.openEditorOnFileStore(page, fileStore);
            }
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
Also used : PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 9 with PyOpenAction

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

the class PyOpenResourceAction method openFiles.

@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
    for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
        try {
            if (PythonPathHelper.isValidSourceFile(n.zipPath)) {
                new PyOpenAction().run(new ItemPointer(n.zipStructure.file, new Location(), new Location(), null, n.zipPath));
            } else {
                IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
                IEditorDescriptor defaultEditor = editorReg.getDefaultEditor(n.zipPath);
                PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
                PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);
                if (defaultEditor != null) {
                    IDE.openEditor(page, input, defaultEditor.getId());
                } else {
                    IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
                }
            }
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
Also used : PythonpathZipChildTreeNode(org.python.pydev.navigator.PythonpathZipChildTreeNode) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) PydevZipFileEditorInput(org.python.pydev.shared_ui.editor_input.PydevZipFileEditorInput) PartInitException(org.eclipse.ui.PartInitException) IEditorRegistry(org.eclipse.ui.IEditorRegistry) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer) Location(org.python.pydev.shared_core.structure.Location)

Example 10 with PyOpenAction

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

the class PyOutlineSelectionDialog method open.

/* (non-Javadoc)
     * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#open()
     */
@Override
public int open() {
    int ret = super.open();
    if (ret == OK) {
        Object[] result = getResult();
        if (result != null && result.length > 0) {
            @SuppressWarnings("unchecked") DataAndImageTreeNode<Object> n = (DataAndImageTreeNode<Object>) result[0];
            OutlineEntry outlineEntry = (OutlineEntry) n.data;
            if (outlineEntry.model == null) {
                Location location = new Location(NodeUtils.getNameLineDefinition(outlineEntry.node) - 1, NodeUtils.getNameColDefinition(outlineEntry.node) - 1);
                EditorUtils.showInEditor(pyEdit, location, location);
            } else {
                PyOpenAction pyOpenAction = new PyOpenAction();
                IModule m = outlineEntry.model.module;
                if (m instanceof SourceModule) {
                    SourceModule sourceModule = (SourceModule) m;
                    File file = sourceModule.getFile();
                    if (file != null) {
                        ItemPointer p = new ItemPointer(file, outlineEntry.node);
                        pyOpenAction.run(p);
                    }
                }
            }
        }
    }
    return ret;
}
Also used : SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) IModule(org.python.pydev.core.IModule) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) File(java.io.File) Location(org.python.pydev.shared_core.structure.Location) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Aggregations

PyOpenAction (org.python.pydev.editor.actions.PyOpenAction)13 ItemPointer (org.python.pydev.ast.item_pointer.ItemPointer)11 IFile (org.eclipse.core.resources.IFile)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3 PartInitException (org.eclipse.ui.PartInitException)3 CoreException (org.eclipse.core.runtime.CoreException)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Point (org.eclipse.swt.graphics.Point)2 IModule (org.python.pydev.core.IModule)2 IPythonNature (org.python.pydev.core.IPythonNature)2 PyEdit (org.python.pydev.editor.PyEdit)2 AdditionalInfoAndIInfo (com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo)1 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)1 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1