Optimized Scanner
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / editor / ShowExternalPreviewAction.java
index 5cfaeb7..8ba89aa 100644 (file)
@@ -50,43 +50,7 @@ public class ShowExternalPreviewAction extends TextEditorAction {
 
   public void doRun(int type) {
     IFile previewFile = getFile();
-    if (previewFile == null) {
-      // should never happen
-      return;
-    }
-    String extension = previewFile.getFileExtension().toLowerCase();
-    boolean autoPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
-    boolean bringToTopPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
-    boolean showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
-    boolean showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
-    boolean isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
-    boolean isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension);
-
-    if (autoPreview) {
-      String localhostURL;
-      if (showHTMLFilesLocal && isHTMLFileName) {
-        localhostURL = previewFile.getLocation().toString();
-      } else if (showXMLFilesLocal && isXMLFileName) {
-        localhostURL = previewFile.getLocation().toString();
-      } else if ((localhostURL = getLocalhostURL(null, previewFile)) == null) {
-        return;
-      }
-      IWorkbenchPage page = WebUI.getActivePage();
-      try {
-        IViewPart part = page.findView(BrowserView.ID_BROWSER);
-        if (part == null) {
-          part = page.showView(BrowserView.ID_BROWSER);
-        } else {
-          if (bringToTopPreview) {
-            page.bringToTop(part);
-          }
-        }
-        ((BrowserView) part).setUrl(localhostURL);
-
-      } catch (Exception e) {
-        //PHPeclipsePlugin.log(e);
-      }
-    }
+    BrowserUtil.showPreview(previewFile, false, "");
   }
 
   public void refresh(int type) {
@@ -96,7 +60,8 @@ public class ShowExternalPreviewAction extends TextEditorAction {
       return;
     }
     boolean autoPreview = ProjectPrefUtil.getPreviewBooleanValue(fileToParse, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
-    boolean bringToTopPreview = ProjectPrefUtil.getPreviewBooleanValue(fileToParse, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
+    boolean bringToTopPreview = ProjectPrefUtil.getPreviewBooleanValue(fileToParse,
+        IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
 
     if (autoPreview) {
       IWorkbenchPage page = WebUI.getActivePage();
@@ -134,21 +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