From: <va...@us...> - 2007-09-23 20:46:23
|
Revision: 10729 http://jedit.svn.sourceforge.net/jedit/?rev=10729&view=rev Author: vanza Date: 2007-09-23 13:46:21 -0700 (Sun, 23 Sep 2007) Log Message: ----------- First round of changes to switch to jEdit's VFS: - get rid of PV's old VFSFile code - switch the project model to jEdit's VFSFile internally - comment out code that relies on java.io.File PV is pretty much broken for regular use until the importer code is also changed to use jEdit's VFS. Also, this adds a lot of API breakage. Modified Paths: -------------- plugins/ProjectViewer/trunk/projectviewer/action/NodeRenamerAction.java plugins/ProjectViewer/trunk/projectviewer/action/SearchAction.java plugins/ProjectViewer/trunk/projectviewer/importer/FileImporter.java plugins/ProjectViewer/trunk/projectviewer/importer/Importer.java plugins/ProjectViewer/trunk/projectviewer/importer/NewFileImporter.java plugins/ProjectViewer/trunk/projectviewer/importer/ReImporter.java plugins/ProjectViewer/trunk/projectviewer/persist/FileNodeHandler.java plugins/ProjectViewer/trunk/projectviewer/persist/OldConfigLoader.java plugins/ProjectViewer/trunk/projectviewer/persist/ProjectPersistenceManager.java plugins/ProjectViewer/trunk/projectviewer/vpt/IconComposer.java plugins/ProjectViewer/trunk/projectviewer/vpt/VPTContextMenu.java plugins/ProjectViewer/trunk/projectviewer/vpt/VPTFile.java Removed Paths: ------------- plugins/ProjectViewer/trunk/projectviewer/action/VFSFileImportAction.java plugins/ProjectViewer/trunk/projectviewer/importer/VFSFileImporter.java plugins/ProjectViewer/trunk/projectviewer/persist/VFSFileNodeHandler.java plugins/ProjectViewer/trunk/projectviewer/vpt/VFSFile.java Modified: plugins/ProjectViewer/trunk/projectviewer/action/NodeRenamerAction.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/action/NodeRenamerAction.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/action/NodeRenamerAction.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -44,7 +44,6 @@ import projectviewer.ProjectManager; import projectviewer.vpt.VPTNode; import projectviewer.vpt.VPTFile; -import projectviewer.vpt.VFSFile; import projectviewer.vpt.VPTProject; import projectviewer.vpt.VPTDirectory; //}}} @@ -124,6 +123,7 @@ reinsert(node, project); return; } else if (node.isFile()) { + /* XXX: need to fix now that we're working with VFS. VPTFile f = (VPTFile) node; String oldPath = node.getNodePath(); // updates all files from the old directory to point to the new one @@ -137,6 +137,7 @@ } project.unregisterNodePath(oldPath); reinsert(f, project); + */ } else if (node.isDirectory() ) { VPTDirectory dir = (VPTDirectory) node; if (dir.getFile().exists()) { @@ -189,13 +190,13 @@ dirty = b.isDirty(); } cmItem.setVisible(!dirty && node != null && - (node.isFile() || node.isDirectory() || node.isProject() || - node.getClass() == VFSFile.class)); + (node.isFile() || node.isDirectory() || node.isProject())); } //}}} //{{{ -renameFile(VPTFile, File) : boolean /** Renames a file and tries not to mess up jEdit's current buffer. */ private boolean renameFile(VPTFile f, File newFile, boolean rename) { + /* XXX: need to fix this for VFS. Buffer b = jEdit.getActiveView().getBuffer(); if (b.getPath().equals(f.getNodePath())) { b = null; @@ -214,7 +215,9 @@ if (b != null) { jEdit.getActiveView().setBuffer(b); } + } + */ return true; } //}}} Modified: plugins/ProjectViewer/trunk/projectviewer/action/SearchAction.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/action/SearchAction.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/action/SearchAction.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -187,7 +187,7 @@ continue; } - if (!((VPTFile)n).getFile().exists()) { + if (!((VPTFile)n).getFile().isReadable()) { continue; } Deleted: plugins/ProjectViewer/trunk/projectviewer/action/VFSFileImportAction.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/action/VFSFileImportAction.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/action/VFSFileImportAction.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -1,58 +0,0 @@ -/* - * :tabSize=4:indentSize=4:noTabs=false: - * :folding=explicit:collapseFolds=1: - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package projectviewer.action; - -//{{{ Imports -import java.awt.event.ActionEvent; - -import org.gjt.sp.jedit.jEdit; - -import projectviewer.vpt.VPTNode; -import projectviewer.importer.VFSFileImporter; -//}}} - -/** - * Action that when executed imports files from jEdit's VFS into a node. - * - * @author Marcelo Vanzin - * @version $Id$ - */ -public class VFSFileImportAction extends Action { - - //{{{ +getText() : String - /** Returns the text to be shown on the button and/or menu item. */ - public String getText() { - return jEdit.getProperty("projectviewer.action.vfs_import"); - } //}}} - - //{{{ +actionPerformed(ActionEvent) : void - /** Creates a new project. */ - public void actionPerformed(ActionEvent e) { - new VFSFileImporter(viewer.getSelectedNode(), viewer).doImport(); - } //}}} - - //{{{ +prepareForNode(VPTNode) : void - /** Enable action only for projects and directories. */ - public void prepareForNode(VPTNode node) { - cmItem.setVisible( (node != null) && - (node.isProject() || node.isDirectory()) ); - } //}}} - -} - Modified: plugins/ProjectViewer/trunk/projectviewer/importer/FileImporter.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/importer/FileImporter.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/importer/FileImporter.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -113,7 +113,7 @@ addTree(chosen[i], node, fnf, id.getFlattenFilePaths()); } } else if (findDirectory(chosen[i], root, false) == null) { - node = new VPTFile(chosen[i]); + node = new VPTFile(chosen[i].getAbsolutePath()); registerFile((VPTFile) node); fileCount++; } @@ -165,7 +165,7 @@ child = (flatten) ? where : findDirectory(children[i], where, true); addTree(children[i], child, filter, flatten); } else { - child = new VPTFile(children[i]); + child = new VPTFile(children[i].getAbsolutePath()); if (where.getIndex(child) != -1) { continue; } Modified: plugins/ProjectViewer/trunk/projectviewer/importer/Importer.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/importer/Importer.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/importer/Importer.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -197,14 +197,7 @@ if (n.getNodePath().equals(dir.getAbsolutePath())) { return n; } else if (n.isFile()) { - try { - if (((VPTFile)n).getFile().getCanonicalPath().equals(dir.getAbsolutePath())) { - return n; - } - } catch (java.io.IOException ioe) { - // shouldn't happen - Log.log(Log.WARNING, this, ioe); - } + return n; } } return (create) ? new VPTDirectory(dir) : null; Modified: plugins/ProjectViewer/trunk/projectviewer/importer/NewFileImporter.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/importer/NewFileImporter.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/importer/NewFileImporter.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -68,7 +68,7 @@ ArrayList added = new ArrayList(); VPTNode where = makePathTo(f.getParent(), added); - VPTFile vf = new VPTFile(f); + VPTFile vf = new VPTFile(f.getAbsolutePath()); if (where == project) { added.add(vf); } else if (added.size() != 0) { Modified: plugins/ProjectViewer/trunk/projectviewer/importer/ReImporter.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/importer/ReImporter.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/importer/ReImporter.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -76,7 +76,7 @@ // check whether the node is under the root (new or old) if (!path.startsWith(project.getRootPath())) { if (node.isFile()) { - if (!((VPTFile)node).getFile().exists()) { + if (!((VPTFile)node).getFile().isReadable()) { unregisterFile((VPTFile)node); project.remove(i--); } @@ -121,7 +121,7 @@ for (int i = 0; i < dir.getChildCount(); i++) { VPTNode node = (VPTNode) dir.getChildAt(i); if (node.isFile()) { - if (!((VPTFile)node).getFile().exists()) { + if (!((VPTFile)node).getFile().isReadable()) { unregisterFile((VPTFile)node); dir.remove(i--); } Deleted: plugins/ProjectViewer/trunk/projectviewer/importer/VFSFileImporter.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/importer/VFSFileImporter.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/importer/VFSFileImporter.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -1,129 +0,0 @@ -/* - * :tabSize=4:indentSize=4:noTabs=false: - * :folding=explicit:collapseFolds=1: - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package projectviewer.importer; - -//{{{ Imports -import java.io.File; - -import java.util.ArrayList; -import java.util.Collection; - -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.GUIUtilities; -import org.gjt.sp.jedit.MiscUtilities; - -import org.gjt.sp.jedit.io.VFSManager; -import org.gjt.sp.jedit.browser.VFSBrowser; - -import projectviewer.ProjectViewer; -import projectviewer.vpt.VPTNode; -import projectviewer.vpt.VPTFile; -import projectviewer.vpt.VFSFile; -import projectviewer.vpt.VPTDirectory; -//}}} - -/** - * Imports files from a VFS into a project. If any selected file is actually - * from the "File" VFS, a normal file is added instead of using the VFS - * facilities. - * - * @author Marcelo Vanzin - * @version $Id$ - */ -public class VFSFileImporter extends Importer { - - //{{{ Protected Members - protected int fileCount; - //}}} - - //{{{ +VFSFileImporter(VPTNode, ProjectViewer) : <init> - - public VFSFileImporter(VPTNode node, ProjectViewer viewer) { - super(node, viewer, true); - } - - //}}} - - //{{{ #internalDoImport() : Collection - /** - * Queries the user for files to be added by showing a jEdit file chooser - * dialog. - * - * @return A collection of VPTNode instances. - */ - protected Collection internalDoImport() { - fileCount = 0; - - String[] chosen = null; - if (selected.isDirectory() && ((VPTDirectory)selected).getFile().exists()) { - chosen = GUIUtilities.showVFSFileDialog(viewer.getView(), selected.getNodePath() + "/", - VFSBrowser.OPEN_DIALOG, true); - } else { - chosen = GUIUtilities.showVFSFileDialog(viewer.getView(), project.getRootPath() + "/", - VFSBrowser.OPEN_DIALOG, true); - } - - if (chosen == null || chosen.length == 0) { - return null; - } - - ArrayList lst = new ArrayList(); - - boolean asked = false, recurse = false; - for (int i = 0; i < chosen.length; i++) { - VPTNode node = null; - - if (VFSManager.getVFSForPath(chosen[i]) == VFSManager.getFileVFS()) { - File f; - if (MiscUtilities.isURL(chosen[i])) { - String proto = MiscUtilities.getProtocolOfURL(chosen[i]); - f = new File(chosen[i].substring(proto.length())); - } else { - f = new File(chosen[i]); - } - // it's a normal file - node = findDirectory(f, selected, false); - if (node == null) { - VPTFile file = new VPTFile(f); - registerFile(file); - lst.add(file); - fileCount++; - } - } else { - node = new VFSFile(chosen[i]); - lst.add(node); - fileCount++; - } - - } - - showFileCount(); - return lst; - } //}}} - - //{{{ #showFileCount() : void - /** Shows a message in the status bar indicating how many files were imported. */ - protected void showFileCount() { - viewer.setStatus( - jEdit.getProperty("projectviewer.import.msg_result", - new Object[] { new Integer(fileCount) })); - } //}}} - -} - Modified: plugins/ProjectViewer/trunk/projectviewer/persist/FileNodeHandler.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/persist/FileNodeHandler.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/persist/FileNodeHandler.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -80,12 +80,8 @@ * list. */ public VPTNode createNode(Attributes attrs, VPTProject project) { - File f = new File(attrs.getValue(PATH_ATTR)); - if (ProjectViewerConfig.getInstance().getDeleteNotFoundFiles() && - !f.exists()) { - return null; - } - VPTFile vf = new VPTFile(f); + String url = attrs.getValue(PATH_ATTR); + VPTFile vf = new VPTFile(url); if (attrs.getValue(NAME_ATTR) != null) { vf.setName(attrs.getValue(NAME_ATTR)); } @@ -102,7 +98,7 @@ if (!file.getName().equals(file.getFile().getName())) { writeAttr(NAME_ATTR, file.getName(), out); } - writeAttr(PATH_ATTR, translatePath(file.getFile().getAbsolutePath()), out); + writeAttr(PATH_ATTR, translatePath(file.getURL()), out); } } Modified: plugins/ProjectViewer/trunk/projectviewer/persist/OldConfigLoader.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/persist/OldConfigLoader.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/persist/OldConfigLoader.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -144,7 +144,7 @@ if (key.startsWith("file")) { File f = new File(props.getProperty(key)); VPTNode parent = ensureDirAdded(p, f.getParent(), paths); - VPTFile vf = new VPTFile(f); + VPTFile vf = new VPTFile(f.getAbsolutePath()); p.registerNodePath(vf); parent.add(vf); } else if (key.startsWith("open_files")) { @@ -173,7 +173,7 @@ while (fileName != null) { File f = new File(fileName); VPTNode parent = ensureDirAdded(p, f.getParent(), paths); - VPTFile vf = new VPTFile(f); + VPTFile vf = new VPTFile(f.getAbsolutePath()); p.registerNodePath(vf); parent.add(vf); fileName = props.getProperty(prefix + (++counter) + suffix); Modified: plugins/ProjectViewer/trunk/projectviewer/persist/ProjectPersistenceManager.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/persist/ProjectPersistenceManager.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/persist/ProjectPersistenceManager.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -303,7 +303,15 @@ registerHandler(new DirectoryNodeHandler()); registerHandler(new PropertyNodeHandler()); registerHandler(new OpenFileNodeHandler()); - registerHandler(new VFSFileNodeHandler()); + + /* + * To maintain compatibility with config files that have + * old VFSFile entries, we add this to the name map, but + * not to the class map, since they'll be translated to + * plain file entries when saving the project data. + */ + handlerNames.put("vfsfile", handlerNames.get("file")); + if (l != null && l.size() > 0) { for (Object o : l) { registerHandler((NodeHandler)o); Deleted: plugins/ProjectViewer/trunk/projectviewer/persist/VFSFileNodeHandler.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/persist/VFSFileNodeHandler.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/persist/VFSFileNodeHandler.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -1,107 +0,0 @@ -/* - * :tabSize=4:indentSize=4:noTabs=false: - * :folding=explicit:collapseFolds=1: - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package projectviewer.persist; - -//{{{ Imports -import java.util.Map; - -import java.io.Writer; -import java.io.IOException; - -import org.xml.sax.Attributes; - -import org.gjt.sp.jedit.io.VFSManager; - -import projectviewer.vpt.VFSFile; -import projectviewer.vpt.VPTNode; -import projectviewer.vpt.VPTProject; -//}}} - -/** - * Handler for file nodes. - * - * @author Marcelo Vanzin - * @version $Id$ - */ -public class VFSFileNodeHandler extends NodeHandler { - - private static final String NODE_NAME = "vfsfile"; - private static final String PATH_ATTR = "path"; - private static final String NAME_ATTR = "name"; - - //{{{ +getNodeName() : String - /** - * Returns the name of the nodes that should be delegated to this handler - * when loading configuration data. - */ - public String getNodeName() { - return NODE_NAME; - } //}}} - - //{{{ +getNodeClass() : Class - /** - * Returns the class of the nodes that should be delegated to this handler - * when saving node data to the config file. - */ - public Class getNodeClass() { - return VFSFile.class; - } //}}} - - //{{{ +isChild() : boolean - /** - * Returns whether the node is a child of nome other node or not. - */ - public boolean isChild() { - return true; - } //}}} - - //{{{ +hasChildren() : boolean - /** - * Returns whether the node(s) handled by this handler are expected to - * have children or not. - */ - public boolean hasChildren() { - return false; - } //}}} - - //{{{ +createNode(Attributes, VPTProject) : VPTNode - /** Loads a VFSFile from the cofiguration. */ - public VPTNode createNode(Attributes attrs, VPTProject project) { - String path = attrs.getValue(PATH_ATTR); - VFSFile vf = new VFSFile(path); - if (attrs.getValue(NAME_ATTR) != null) { - vf.setName(attrs.getValue(NAME_ATTR)); - } - return vf; - } //}}} - - //{{{ +saveNode(VPTNode, Writer) : void - /** Saves a VFS file node to the config file. */ - public void saveNode(VPTNode node, Writer out) throws IOException { - startElement(out); - VFSFile file = (VFSFile) node; - String name = VFSManager.getVFSForPath(file.getNodePath()).getFileName(file.getNodePath()); - if (!file.getName().equals(name)) { - writeAttr(NAME_ATTR, file.getName(), out); - } - writeAttr(PATH_ATTR, translatePath(file.getNodePath()), out); - } //}}} - -} - Modified: plugins/ProjectViewer/trunk/projectviewer/vpt/IconComposer.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/vpt/IconComposer.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/vpt/IconComposer.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -19,7 +19,6 @@ package projectviewer.vpt; //{{{ Imports -import java.io.File; import java.util.HashMap; import java.awt.Graphics; @@ -35,6 +34,7 @@ import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.util.Log; import errorlist.ErrorSource; @@ -93,8 +93,8 @@ vcProvider = vc; } //}}} - //{{{ +_composeIcon(File, String, Icon)_ : Icon - public static Icon composeIcon(File f, String path, Icon baseIcon) { + //{{{ +_composeIcon(VFSFile, String, Icon)_ : Icon + public static Icon composeIcon(VFSFile f, String path, Icon baseIcon) { Icon[][][][] cache = getIconCache(baseIcon); int msg_state = MSG_STATE_NONE; @@ -275,9 +275,9 @@ return cache; } //}}} - //{{{ -_getFileState(File, String)_ : int - private static int getFileState(File f, String path) { - if (f != null && !f.exists()) + //{{{ -_getFileState(VFSFile, String)_ : int + private static int getFileState(VFSFile f, String path) { + if (f != null && !f.isReadable()) return FILE_STATE_NOT_FOUND; Buffer buffer = jEdit.getBuffer(path); int file_state = IconComposer.FILE_STATE_NORMAL; @@ -287,7 +287,7 @@ } else if (!buffer.isEditable()) { return FILE_STATE_READONLY; } - } else if (!f.canWrite()) { + } else if (!f.isWriteable()) { return FILE_STATE_READONLY; } return FILE_STATE_NORMAL; @@ -348,7 +348,7 @@ * @param path The path to the file (absolute path if local, VFS * URL otherwise). */ - public int getFileState(File f, String path); //}}} + public int getFileState(VFSFile f, String path); //}}} //{{{ +*getIcon(int)* : Icon /** Deleted: plugins/ProjectViewer/trunk/projectviewer/vpt/VFSFile.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/vpt/VFSFile.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/vpt/VFSFile.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -1,202 +0,0 @@ -/* - * :tabSize=4:indentSize=4:noTabs=false: - * :folding=explicit:collapseFolds=1: - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package projectviewer.vpt; - -//{{{ Imports -import java.io.File; -import java.io.IOException; - -import java.awt.Color; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.filechooser.FileSystemView; - -import org.gjt.sp.util.Log; -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.Buffer; -import org.gjt.sp.jedit.GUIUtilities; - -import org.gjt.sp.jedit.io.VFS; -import org.gjt.sp.jedit.io.VFSManager; - -import projectviewer.ProjectViewer; -import projectviewer.config.ProjectViewerConfig; -//}}} - -/** - * Models a file accessed using jEdit's VFS. - * - * @author Marcelo Vanzin - * @version $Id$ - */ -public class VFSFile extends VPTNode { - - //{{{ Constants - - private final static Icon fileClosedIcon = - new ImageIcon(VFSFile.class.getResource("/projectviewer/images/remote_file.png"));; - private final static Icon fileOpenedIcon = (ImageIcon) GUIUtilities.loadIcon("OpenFile.png"); - - private final static ProjectViewerConfig config = ProjectViewerConfig.getInstance(); - private static FileSystemView fsView; - - //}}} - - //{{{ Attributes - private String path; - private Color fileTypeColor; - private Icon fileIcon; - private boolean loadedIcon; - //}}} - - //{{{ +VFSFile(String) : <init> - public VFSFile(String path) { - super(VFSManager.getVFSForPath(path).getFileName(path), false); - this.path = path; - this.fileTypeColor = VFS.getDefaultColorFor(getName()); - this.loadedIcon = false; - } //}}} - - //{{{ +canWrite() : boolean - /** - * Returns true. Since we can't check (easily) if we can or cannot write - * to a file using the VFS api, let the VFS manager decide it, and show - * an error in case it can't write... - */ - public boolean canWrite() { - return true; - } //}}} - - //{{{ +delete() : boolean - /** - * Deletes the file from disk. Before deleting, try to close the file. - */ - public boolean delete() { - VFS vfs = VFSManager.getVFSForPath(path); - if ((vfs.getCapabilities() & VFS.DELETE_CAP) != 0) { - close(); - ProjectViewer v = ProjectViewer.getViewer(jEdit.getActiveView()); - Object s = vfs.createVFSSession(path, v); - try { - vfs._delete(s, path, v); - } catch (IOException ioe) { - open(); - Log.log(Log.DEBUG, this, ioe); - return false; - } - } - return true; - } //}}} - - //{{{ +isOpened() : boolean - /** Returns "true" if the node is a file and is currently opened in jEdit. */ - public boolean isOpened() { - return (org.gjt.sp.jedit.jEdit.getBuffer(path) != null); - } //}}} - - //{{{ +getIcon(boolean) : Icon - /** - * Returns the icon to be shown on the tree next to the node name. - * - * @param expanded If the node is currently expanded or not. - */ - public Icon getIcon(boolean expanded) { - Icon baseIcon; - if (isOpened()) { - baseIcon = fileOpenedIcon; - } else { - if (config.getUseSystemIcons()) { - if (!loadedIcon) { - if (fsView == null) fsView = FileSystemView.getFileSystemView(); - File f = new File(getName()); - fileIcon = fsView.getSystemIcon(f); - loadedIcon = true; - } - baseIcon = (fileIcon != null) ? fileIcon : fileClosedIcon; - } else { - baseIcon = fileClosedIcon; - } - } - return IconComposer.composeIcon(null, path, baseIcon); - } //}}} - - //{{{ +getForegroundColor(boolean) : Color - /** - * Returns the node's foreground color. - * - * @param sel If the node is currently selected. - */ - public Color getForegroundColor(boolean sel) { - if (sel) return super.getForegroundColor(sel); - if (fileTypeColor == null) { - return super.getForegroundColor(sel); - } else { - return fileTypeColor; - } - } //}}} - - //{{{ +toString() : String - /** Returns a string representation of the current node. */ - public String toString() { - return "VFSFile [" + path + "]"; - } //}}} - - //{{{ +canOpen() : boolean - /** File nodes can be opened, so return true. */ - public boolean canOpen() { - return true; - } //}}} - - //{{{ +open() : void - /** - * Opens a new buffer in jEdit with the file pointed by this node. The - * buffer is loaded in the currently active view. - */ - public void open() { - jEdit.openFile(jEdit.getActiveView(), getNodePath()); - jEdit.getActiveView().getTextArea().requestFocus(); - } //}}} - - //{{{ +close() : void - /** "Closes" the jEdit buffer that contains the file. */ - public void close() { - Buffer b = jEdit.getBuffer(path); - if (b != null) { - jEdit.closeBuffer(jEdit.getActiveView(), b); - } - } //}}} - - //{{{ +getNodePath() : String - /** Returns the path to the file represented by this node. */ - public String getNodePath() { - return path; - } //}}} - - //{{{ +compareToNode(VPTNode) : int - /** Compares a VFSFile node to another VPTNode. */ - public int compareToNode(VPTNode node) { - if (node.getAllowsChildren()) { - return 1; - } else { - return compareName(node); - } - } //}}} - -} - Modified: plugins/ProjectViewer/trunk/projectviewer/vpt/VPTContextMenu.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/vpt/VPTContextMenu.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/vpt/VPTContextMenu.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -48,7 +48,6 @@ import projectviewer.action.NodeRenamerAction; import projectviewer.action.OpenWithAppAction; import projectviewer.action.LaunchBrowserAction; -import projectviewer.action.VFSFileImportAction; import projectviewer.action.OpenWithEncodingAction; import projectviewer.config.ExtensionManager; @@ -88,7 +87,6 @@ addAction(new EditGroupAction(true), false); addAction(new EditGroupAction(false), true); addAction(new FileImportAction(), false); - addAction(new VFSFileImportAction(), false); addAction(new ReimportAction(), false); addAction(new NodeRemoverAction(false), false); addAction(new NodeRemoverAction(true), false); Modified: plugins/ProjectViewer/trunk/projectviewer/vpt/VPTFile.java =================================================================== --- plugins/ProjectViewer/trunk/projectviewer/vpt/VPTFile.java 2007-09-23 20:35:03 UTC (rev 10728) +++ plugins/ProjectViewer/trunk/projectviewer/vpt/VPTFile.java 2007-09-23 20:46:21 UTC (rev 10729) @@ -19,17 +19,22 @@ package projectviewer.vpt; //{{{ Imports -import java.io.File; +import java.io.IOException; +import java.lang.ref.WeakReference; import java.awt.Color; import javax.swing.Icon; import javax.swing.filechooser.FileSystemView; import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.io.VFS; import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.GUIUtilities; +import org.gjt.sp.util.Log; +import org.gjt.sp.jedit.io.VFS; +import org.gjt.sp.jedit.io.VFSFile; +import org.gjt.sp.jedit.io.VFSManager; + import projectviewer.PVActions; import projectviewer.config.AppLauncher; import projectviewer.config.ProjectViewerConfig; @@ -41,7 +46,8 @@ * @author Marcelo Vanzin * @version $Id$ */ -public class VPTFile extends VPTNode { +public class VPTFile extends VPTNode +{ //{{{ Constants @@ -56,79 +62,98 @@ //{{{ Attributes - private File file; + private String url; private Color fileTypeColor; private Icon fileIcon; private boolean loadedIcon; + + private WeakReference<Object> vfsSession; //}}} - //{{{ +VPTFile(String) : <init> - public VPTFile(String path) { - this(new File(path)); - } //}}} - - //{{{ +VPTFile(File) : <init> - public VPTFile(File file) { - super(file.getName(), false); - this.file = file; - this.fileTypeColor = VFS.getDefaultColorFor(file.getName()); + public VPTFile(String url) + { + super(VFSManager.getVFSForPath(url).getFileName(url), false); + this.url = url; + this.fileTypeColor = VFS.getDefaultColorFor(getName()); this.fileIcon = null; this.loadedIcon = false; - } //}}} + } - //{{{ +canWrite() : boolean + /** Returns is the underlying file is writable. */ - public boolean canWrite() { - return file.canWrite(); - } //}}} + public boolean canWrite() + { + return getFile().isWriteable(); + } - //{{{ +delete() : boolean + /** - * Deletes the file from disk. Before deleting, try to close the file. + * Deletes the file from the VFS. Before deleting, try to close + * the file. */ - public boolean delete() { + public boolean delete() + { close(); - if (!file.delete()) { - open(); - return false; - } + /* XXX: TODO */ return true; - } //}}} + } - //{{{ +getFile() : File - /** Return the file associated with this node. */ - public File getFile() { - return file; - } //}}} - //{{{ +setFile(File) : void - /** Sets the file associated with this node. */ - public void setFile(File f) { - this.file = f; - fileTypeColor = VFS.getDefaultColorFor(file.getName()); - setName(f.getName()); - } //}}} + /** Return the VFS file associated with this node. */ + public VFSFile getFile() + { + try { + VFS vfs = VFSManager.getVFSForPath(url); + Object session = getVFSSession(vfs); + return vfs._getFile(session, url, null); + } catch (IOException ioe) { + Log.log(Log.ERROR, this, ioe); + return null; + } + } - //{{{ +isOpened() : boolean + /** - * Returns "true" if the node is a file and is currently opened in jEdit. + * Returns "true" if the node is a file and is currently opened + * in jEdit. */ - public boolean isOpened() { - return (org.gjt.sp.jedit.jEdit.getBuffer(getFile().getAbsolutePath()) != null); - } //}}} + public boolean isOpened() + { + return (jEdit.getBuffer(url) != null); + } - //{{{ +getIcon(boolean) : Icon + /** + * Returns the VFS URL for this file. + */ + public String getURL() + { + return url; + } + + + /** + * Changes this file's URL. + */ + public void setURL(String url) + { + this.url = url; + } + + + /** * Returns the icon to be shown on the tree next to the node name. * * @param expanded If the node is currently expanded or not. */ - public Icon getIcon(boolean expanded) { + public Icon getIcon(boolean expanded) + { Icon baseIcon = fileClosedIcon; if (isOpened()) { baseIcon = fileOpenedIcon; } else { + /* XXX: Need to fix this now that we don't have file anymore. if (ProjectViewerConfig.getInstance().getUseSystemIcons()) { if (!loadedIcon) { if (file.exists()) { @@ -143,11 +168,14 @@ baseIcon = (fileIcon != null) ? fileIcon : fileClosedIcon; } } + */ + baseIcon = fileClosedIcon; } - return IconComposer.composeIcon(file, file.getAbsolutePath(), baseIcon); - } //}}} + return IconComposer.composeIcon(getFile(), url, baseIcon); + } - //{{{ +getForegroundColor(boolean) : Color + + /** * Returns the node's foreground color. * @@ -160,59 +188,78 @@ } else { return fileTypeColor; } - } //}}} + } - //{{{ +toString() : String + + /** Returns a string representation of the current node. */ - public String toString() { - return "File [" + getFile().getAbsolutePath() + "]"; - } //}}} + public String toString() + { + return "File [" + url + "]"; + } - //{{{ +canOpen() : boolean + /** File nodes can be opened, so return true. */ - public boolean canOpen() { + public boolean canOpen() + { return true; - } //}}} + } - //{{{ +open() : void + /** * Opens a new buffer in jEdit with the file pointed by this node. The * buffer is loaded in the currently active view. */ public void open() { if (ProjectViewerConfig.getInstance().getUseExternalApps() - && appList.getAppName(getFile().getAbsolutePath()) != null) { - appList.launchApp(getFile().getAbsolutePath(), jEdit.getActiveView()); + && appList.getAppName(url) != null) { + appList.launchApp(url, jEdit.getActiveView()); } else { jEdit.openFile(jEdit.getActiveView(), getNodePath()); PVActions.requestFocus(jEdit.getActiveView().getTextArea()); } - } //}}} + } - //{{{ +close() : void + /** "Closes" the jEdit buffer that contains the file. */ - public void close() { - Buffer b = jEdit.getBuffer(getFile().getAbsolutePath()); + public void close() + { + Buffer b = jEdit.getBuffer(url); if (b != null) { jEdit.closeBuffer(jEdit.getActiveView(), b); } - } //}}} + } - //{{{ +getNodePath() : String + /** Returns the path to the file represented by this node. */ - public String getNodePath() { - return getFile().getAbsolutePath(); - } //}}} + public String getNodePath() + { + return url; + } - //{{{ +compareToNode(VPTNode) : int + /** Files are at the same level of every leaf node. */ - public int compareToNode(VPTNode node) { + public int compareToNode(VPTNode node) + { if (!node.getAllowsChildren()) { return compareName(node); } else { return 1; } - } //}}} + } + + private Object getVFSSession(VFS vfs) + { + if (vfsSession == null || vfsSession.get() == null) { + if (vfs == null) { + vfs = VFSManager.getVFSForPath(url); + } + vfsSession = new WeakReference<Object>( + vfs.createVFSSession(url, null)); + } + return vfsSession.get(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |