Search in sources :

Example 1 with PydevFileEditorInput

use of org.python.pydev.shared_ui.editor_input.PydevFileEditorInput 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)

Aggregations

URI (java.net.URI)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IEditorInput (org.eclipse.ui.IEditorInput)1 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)1 PydevFileEditorInput (org.python.pydev.shared_ui.editor_input.PydevFileEditorInput)1 PydevZipFileEditorInput (org.python.pydev.shared_ui.editor_input.PydevZipFileEditorInput)1 PydevZipFileStorage (org.python.pydev.shared_ui.editor_input.PydevZipFileStorage)1