Start the debugger through setting the url with "?DBGSESSID=1@clienthost:10001" in...
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / editor / BrowserUtil.java
diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/BrowserUtil.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/BrowserUtil.java
new file mode 100644 (file)
index 0000000..a2b5786
--- /dev/null
@@ -0,0 +1,66 @@
+package net.sourceforge.phpeclipse.ui.editor;
+
+import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
+import net.sourceforge.phpeclipse.ui.WebUI;
+import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
+import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+
+public class BrowserUtil {
+
+  public static void showPreview(IFile previewFile, boolean forceDBGPreview, String postFix) {
+    if (previewFile == null) {
+      // should never happen
+      return;
+    }
+    String extension = previewFile.getFileExtension().toLowerCase();
+    boolean autoPreview = forceDBGPreview;
+    boolean bringToTopPreview = true;
+    boolean showHTMLFilesLocal = false;
+    boolean showXMLFilesLocal = false;
+    boolean isHTMLFileName = false;
+    boolean isXMLFileName = false;
+    if (!forceDBGPreview) {
+      autoPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
+  
+      bringToTopPreview = ProjectPrefUtil
+          .getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
+      showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
+      showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
+      isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
+      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 = ShowExternalPreviewAction.getLocalhostURL(null, previewFile)) == null) {
+        return;
+      }
+      localhostURL += postFix;
+      
+      try {
+        IWorkbenchPage page = WebUI.getActivePage();
+        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);
+      }
+    }
+  }
+
+}