From 59aab6d09a2974f0a0fbcc91479309125944ae7c Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 28 Apr 2005 17:10:58 +0000 Subject: [PATCH] Avoid NPE when deleting a project --- .../ui/editor/ShowExternalPreviewAction.java | 37 +++++++++++--------- 1 files changed, 20 insertions(+), 17 deletions(-) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java index bef108a..7b6dd8e 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java @@ -52,7 +52,7 @@ public class ShowExternalPreviewAction extends TextEditorAction { IFile previewFile = getFile(); BrowserUtil.showPreview(previewFile, false, ""); } - + public void refresh(int type) { IFile fileToParse = getFile(); if (fileToParse == null) { @@ -99,22 +99,25 @@ public class ShowExternalPreviewAction extends TextEditorAction { } public static String getLocalhostURL(IPreferenceStore store, IFile file) { - if (store == null) { - store = WebUI.getDefault().getPreferenceStore(); - } - // IPath path = file.getFullPath(); - String localhostURL = file.getLocation().toString(); - String lowerCaseFileName = localhostURL.toLowerCase(); - // String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); - IPath documentRootPath = ProjectPrefUtil.getDocumentRoot(file.getProject()); - String documentRoot = documentRootPath.toString().toLowerCase(); - if (lowerCaseFileName.startsWith(documentRoot)) { - localhostURL = localhostURL.substring(documentRoot.length()); - } else { - return null; + if (file != null) { + if (store == null) { + store = WebUI.getDefault().getPreferenceStore(); + } + // IPath path = file.getFullPath(); + String localhostURL = file.getLocation().toString(); + String lowerCaseFileName = localhostURL.toLowerCase(); + // String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); + IPath documentRootPath = ProjectPrefUtil.getDocumentRoot(file.getProject()); + String documentRoot = documentRootPath.toString().toLowerCase(); + if (lowerCaseFileName.startsWith(documentRoot)) { + localhostURL = localhostURL.substring(documentRoot.length()); + } else { + return null; + } + // return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL; + return ProjectPrefUtil.getMiscProjectsPreferenceValue(file.getProject(), IPreferenceConstants.PHP_LOCALHOST_PREF) + + localhostURL; } - // return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL; - return ProjectPrefUtil.getMiscProjectsPreferenceValue(file.getProject(), IPreferenceConstants.PHP_LOCALHOST_PREF) - + localhostURL; + return "http://localhost"; } } \ No newline at end of file -- 1.7.1