Search in sources :

Example 1 with PydevZipFileStorage

use of org.python.pydev.shared_ui.editor_input.PydevZipFileStorage in project Pydev by fabioz.

the class PyOpenExternalAction method openFiles.

@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
    for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
        try {
            PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
            PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);
            IDE.openEditor(page, input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
Also used : PythonpathZipChildTreeNode(org.python.pydev.navigator.PythonpathZipChildTreeNode) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) PydevZipFileEditorInput(org.python.pydev.shared_ui.editor_input.PydevZipFileEditorInput) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with PydevZipFileStorage

use of org.python.pydev.shared_ui.editor_input.PydevZipFileStorage 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 3 with PydevZipFileStorage

use of org.python.pydev.shared_ui.editor_input.PydevZipFileStorage in project Pydev by fabioz.

the class EditorInputFactory method create.

/**
 * Creates an editor input for the passed file.
 *
 * If forceExternalFile is True, it won't even try to create a FileEditorInput, otherwise,
 * it will try to create it with the most suitable type it can
 * (i.e.: FileEditorInput, FileStoreEditorInput, PydevFileEditorInput, ...)
 */
public static IEditorInput create(File file, boolean forceExternalFile) {
    IPath path = Path.fromOSString(FileUtils.getFileAbsolutePath(file));
    if (!forceExternalFile) {
        // May call again to this method (but with forceExternalFile = true)
        IEditorInput input = new PySourceLocatorBase().createEditorInput(path, false, null, null);
        if (input != null) {
            return input;
        }
    }
    IPath zipPath = new Path("");
    while (path.segmentCount() > 0) {
        if (path.toFile().exists()) {
            break;
        }
        zipPath = new Path(path.lastSegment()).append(zipPath);
        path = path.uptoSegment(path.segmentCount() - 1);
    }
    if (zipPath.segmentCount() > 0 && path.segmentCount() > 0) {
        return new PydevZipFileEditorInput(new PydevZipFileStorage(path.toFile(), zipPath.toPortableString()));
    }
    try {
        URI uri = file.toURI();
        return new FileStoreEditorInput(EFS.getStore(uri));
    } catch (Throwable e) {
        // not always available! (only added in eclipse 3.3)
        return new PydevFileEditorInput(file);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) PydevZipFileEditorInput(org.python.pydev.shared_ui.editor_input.PydevZipFileEditorInput) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) PydevFileEditorInput(org.python.pydev.shared_ui.editor_input.PydevFileEditorInput) URI(java.net.URI) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 4 with PydevZipFileStorage

use of org.python.pydev.shared_ui.editor_input.PydevZipFileStorage in project Pydev by fabioz.

the class PydevPackageExplorer method getElementOfInput.

/**
 * Returns the element contained in the EditorInput
 */
Object getElementOfInput(IEditorInput input) {
    if (input instanceof IFileEditorInput) {
        return ((IFileEditorInput) input).getFile();
    }
    if (input instanceof IURIEditorInput) {
        IURIEditorInput iuriEditorInput = (IURIEditorInput) input;
        URI uri = iuriEditorInput.getURI();
        return new File(uri);
    }
    if (input instanceof PydevZipFileEditorInput) {
        PydevZipFileEditorInput pydevZipFileEditorInput = (PydevZipFileEditorInput) input;
        try {
            IStorage storage = pydevZipFileEditorInput.getStorage();
            if (storage instanceof PydevZipFileStorage) {
                PydevZipFileStorage pydevZipFileStorage = (PydevZipFileStorage) storage;
                return pydevZipFileStorage;
            }
        } catch (CoreException e) {
            Log.log(e);
        }
    }
    return null;
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) CoreException(org.eclipse.core.runtime.CoreException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) PydevZipFileEditorInput(org.python.pydev.shared_ui.editor_input.PydevZipFileEditorInput) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) IStorage(org.eclipse.core.resources.IStorage) URI(java.net.URI) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 5 with PydevZipFileStorage

use of org.python.pydev.shared_ui.editor_input.PydevZipFileStorage in project Pydev by fabioz.

the class PydevPackageExplorer method tryToReveal.

/**
 * This is the method that actually tries to reveal some item in the tree.
 *
 * It will go through the pipeline to see if the actual object to reveal has been replaced in the replace pipeline.
 */
public boolean tryToReveal(Object element) {
    element = getPythonModelElement(element);
    if (element instanceof PydevZipFileStorage) {
        pythonLinkHelper.setCommonViewer(this.getCommonViewer());
        PydevZipFileStorage pydevZipFileStorage = (PydevZipFileStorage) element;
        IStructuredSelection externalFileSelectionInTree = pythonLinkHelper.findExternalFileSelection(pydevZipFileStorage.zipFile);
        if (externalFileSelectionInTree != null && !externalFileSelectionInTree.isEmpty()) {
            Object firstElement = externalFileSelectionInTree.getFirstElement();
            if (firstElement instanceof TreeNode) {
                TreeNode treeNode = (TreeNode) firstElement;
                // Ok, got to the zip file, let's try to find the path below it...
                String zipPath = pydevZipFileStorage.zipPath;
                List<String> split = StringUtils.split(zipPath, '/');
                for (String string : split) {
                    List<TreeNode> children = treeNode.getChildren();
                    for (TreeNode<LabelAndImage> child : children) {
                        if (string.equals(child.getData().label)) {
                            treeNode = child;
                            // Goes on to the next substring...
                            break;
                        }
                    }
                }
                if (revealAndVerify(new StructuredSelection(treeNode))) {
                    return true;
                }
            } else {
                Log.log("Expected a TreeNode. Found: " + firstElement);
                // Just go on to show the zip, not the internal contents...
                if (revealAndVerify(externalFileSelectionInTree)) {
                    return true;
                }
            }
        }
    } else if (element instanceof File) {
        pythonLinkHelper.setCommonViewer(this.getCommonViewer());
        IStructuredSelection externalFileSelectionInTree = pythonLinkHelper.findExternalFileSelection((File) element);
        if (externalFileSelectionInTree != null && !externalFileSelectionInTree.isEmpty()) {
            if (revealAndVerify(externalFileSelectionInTree)) {
                return true;
            }
        }
    }
    // null is checked in the revealAndVerify function
    if (revealAndVerify(element)) {
        return true;
    }
    // if it is a wrapped resource that we couldn't show, try to reveal as a resource...
    if (element instanceof IAdaptable && !(element instanceof IResource)) {
        IAdaptable adaptable = (IAdaptable) element;
        IResource resource = adaptable.getAdapter(IResource.class);
        if (resource != null) {
            if (revealAndVerify(resource)) {
                return true;
            }
        }
    }
    return false;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) LabelAndImage(org.python.pydev.navigator.LabelAndImage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeNode(org.python.pydev.shared_core.structure.TreeNode) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

PydevZipFileStorage (org.python.pydev.shared_ui.editor_input.PydevZipFileStorage)5 PydevZipFileEditorInput (org.python.pydev.shared_ui.editor_input.PydevZipFileEditorInput)4 File (java.io.File)2 URI (java.net.URI)2 IFile (org.eclipse.core.resources.IFile)2 PartInitException (org.eclipse.ui.PartInitException)2 PythonpathZipChildTreeNode (org.python.pydev.navigator.PythonpathZipChildTreeNode)2 IResource (org.eclipse.core.resources.IResource)1 IStorage (org.eclipse.core.resources.IStorage)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorRegistry (org.eclipse.ui.IEditorRegistry)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 IURIEditorInput (org.eclipse.ui.IURIEditorInput)1