diff --git a/ide/utilities/src/org/netbeans/modules/openfile/RecentFileAction.java b/ide/utilities/src/org/netbeans/modules/openfile/RecentFileAction.java index 2138d1aa6c67..5ff977d16206 100644 --- a/ide/utilities/src/org/netbeans/modules/openfile/RecentFileAction.java +++ b/ide/utilities/src/org/netbeans/modules/openfile/RecentFileAction.java @@ -27,14 +27,16 @@ import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.modules.openfile.RecentFiles.HistoryItem; import org.openide.awt.*; -import org.openide.filesystems.FileUtil; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.URLMapper; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.actions.Presenter; @@ -224,8 +226,15 @@ public void actionPerformed(ActionEvent evt) { msg = OFMSG_NO_RECENT_FILE; } } - if( null == msg ) - msg = openFile(path); + + try { + URL url = new URL(path); + if( null == msg ) msg = openFile(url); + } catch (MalformedURLException ex) { + msg = ""; //NOI18N + } + + if (msg != null) { StatusDisplayer.getDefault().setStatusText(msg); Toolkit.getDefaultToolkit().beep(); @@ -235,19 +244,15 @@ public void actionPerformed(ActionEvent evt) { /** * Open a file. - * @param path the path to the file or {@code null}. + * @param url the path to the file. * @return error message or {@code null} on success. */ - private String openFile(String path) { - if(path == null || path.length() == 0) { - return OFMSG_PATH_IS_NOT_DEFINED; - } - File f = new File(path); - if (!f.exists()) { + private String openFile(URL url) { + FileObject fo = URLMapper.findFileObject(url); + if (fo == null || !fo.isValid()) { return OFMSG_FILE_NOT_EXISTS; } - File nf = FileUtil.normalizeFile(f); - return OpenFile.open(FileUtil.toFileObject(nf), -1); + return OpenFile.open(fo, -1); } /** Menu that checks its enabled state just before is populated */ diff --git a/ide/utilities/src/org/netbeans/modules/openfile/RecentFiles.java b/ide/utilities/src/org/netbeans/modules/openfile/RecentFiles.java index 16fddcb2d369..28b8c491dd0b 100644 --- a/ide/utilities/src/org/netbeans/modules/openfile/RecentFiles.java +++ b/ide/utilities/src/org/netbeans/modules/openfile/RecentFiles.java @@ -30,6 +30,8 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -42,7 +44,7 @@ import javax.swing.ImageIcon; import org.netbeans.modules.openfile.RecentFiles.HistoryItem; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; +import org.openide.filesystems.URLMapper; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.modules.OnStop; @@ -162,8 +164,7 @@ static List load() { String value = _prefs.get(curKey, null); if (value != null) { try { - int id = new Integer( - curKey.substring(PROP_URL_PREFIX.length())).intValue(); + int id = Integer.parseInt(curKey.substring(PROP_URL_PREFIX.length())); HistoryItem hItem = new HistoryItem(id, value, _prefs.getByteArray(PROP_ICON_PREFIX + id, null)); int ind = result.indexOf(hItem); @@ -313,7 +314,7 @@ private static Icon findIconForPath(String path) { } private static String obtainPath(TopComponent tc) { - Object file = tc.getClientProperty( RECENT_FILE_KEY ); + Object file = tc.getClientProperty( RECENT_FILE_KEY ); //TODO: possible dead code. RECENT_FILE_KEY not found in entire codebase if( file instanceof File ) return ((File)file).getPath(); if( tc instanceof CloneableTopComponent ) { @@ -338,14 +339,14 @@ private static HistoryItem findHistoryItem(String path) { } static String convertFile2Path(FileObject fo) { - File f = FileUtil.toFile(fo); - return f == null ? null : f.getPath(); + return fo.toURL().toExternalForm(); } static FileObject convertPath2File(String path) { - File f = new File(path); - f = FileUtil.normalizeFile(f); - return f == null ? null : FileUtil.toFileObject(f); + try { + return URLMapper.findFileObject(new URL(path)); + } catch (MalformedURLException ex) {} + return null; } /** Checks recent files history and removes non-valid entries */ @@ -411,8 +412,14 @@ static void pruneHistory() { Iterator it = history.iterator(); while (it.hasNext()) { HistoryItem historyItem = it.next(); - File f = new File(historyItem.getPath()); - if (!f.exists()) { + boolean prune = false; + try { + FileObject fo = URLMapper.findFileObject(new URL(historyItem.getPath())); + if (fo == null || !fo.isValid()) prune = true; + } catch (MalformedURLException ex) { + prune = true; + } + if (prune) { it.remove(); } }