From 2a3047e389e3dcdea563969f6fc16c4d9811f518 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 6 Nov 2007 21:29:12 +0000 Subject: [PATCH] Bug 208944 - start of Flexible File System. --- core/org.eclipse.cdt.core/plugin.xml | 9 ++ .../cdt/internal/core/ffs/FFSFileSystem.java | 88 +++++++++++++++++++ core/org.eclipse.cdt.ui/plugin.xml | 8 ++ .../ui/ffs/FFSFileSystemContributor.java | 48 ++++++++++ 4 files changed, 153 insertions(+) create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ffs/FFSFileSystem.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ffs/FFSFileSystemContributor.java diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index e9af4273600..214bbefa1cc 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -704,5 +704,14 @@ + + + + + + diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ffs/FFSFileSystem.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ffs/FFSFileSystem.java new file mode 100644 index 00000000000..b2943312a80 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/ffs/FFSFileSystem.java @@ -0,0 +1,88 @@ +/********************************************************************** + * Copyright (c) 2007 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + **********************************************************************/ + +package org.eclipse.cdt.internal.core.ffs; + +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.filesystem.IFileTree; +import org.eclipse.core.filesystem.provider.FileSystem; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Doug Schaefer + * + * This is the virtual file system. It maps URIs to files in underlying file systems. + * In doing so, it allows the hierarchical structure of URIs to be different. + * In particular, you can add files from one location to another and excludes files + * and directories from the tree. + */ +public class FFSFileSystem extends FileSystem { + + public FFSFileSystem() { + } + + public IFileStore getStore(URI uri) { + try { + URI realURI = new URI(getScheme(), uri.getSchemeSpecificPart(), uri.getFragment()); + return EFS.getStore(realURI); + } catch (URISyntaxException e) { + CCorePlugin.log(e); + } catch (CoreException e) { + CCorePlugin.log(e); + } + + return EFS.getNullFileSystem().getStore(uri); + } + + public int attributes() { + // TODO what attributes should we support? + return 0; + } + + public boolean canDelete() { + return true; + } + + public boolean canWrite() { + return true; + } + + public IFileTree fetchFileTree(IFileStore root, IProgressMonitor monitor) { + try { + // TODO obviously + return EFS.getNullFileSystem().fetchFileTree(root, monitor); + } catch (CoreException e) { + CCorePlugin.log(e); + return null; + } + } + + public IFileStore fromLocalFile(File file) { + return EFS.getLocalFileSystem().fromLocalFile(file); + } + + public IFileStore getStore(IPath path) { + return EFS.getLocalFileSystem().getStore(path); + } + + public boolean isCaseSensitive() { + return EFS.getLocalFileSystem().isCaseSensitive(); + } + +} diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index bd8b187f166..789e656497c 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -2274,5 +2274,13 @@ id="org.eclipse.cdt.ui.provider1"> + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ffs/FFSFileSystemContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ffs/FFSFileSystemContributor.java new file mode 100644 index 00000000000..0cdb898b767 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ffs/FFSFileSystemContributor.java @@ -0,0 +1,48 @@ +/********************************************************************** + * Copyright (c) 2007 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + **********************************************************************/ + +package org.eclipse.cdt.internal.ui.ffs; + +import java.io.File; +import java.net.URI; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.runtime.Path; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.ide.fileSystem.FileSystemContributor; + +/** + * @author Doug Schaefer + * + */ +public class FFSFileSystemContributor extends FileSystemContributor { + + public URI browseFileSystem(String initialPath, Shell shell) { + DirectoryDialog dialog = new DirectoryDialog(shell); + dialog.setMessage("Select Project Location"); + + if (!initialPath.equals("")) { //$NON-NLS-1$ + IFileInfo info = EFS.getLocalFileSystem().getStore(new Path(initialPath)).fetchInfo(); + if (info != null && info.exists()) { + dialog.setFilterPath(initialPath); + } + } + + String selectedDirectory = dialog.open(); + if (selectedDirectory == null) { + return null; + } + return new File(selectedDirectory).toURI(); + } + +}