some unused Plug-in Depnedencies removed
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / ShowExternalPreviewAction.java
index 941829e..e2e76d2 100644 (file)
@@ -8,8 +8,11 @@ package net.sourceforge.phpeclipse.phpeditor;
  * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
  * www.eclipseproject.de
  ******************************************************************************/
+import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
+import net.sourceforge.phpeclipse.IPreferenceConstants;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction;
+import net.sourceforge.phpeclipse.overlaypages.Util;
 import net.sourceforge.phpeclipse.views.browser.BrowserView;
 
 import org.eclipse.core.resources.IFile;
@@ -27,7 +30,6 @@ import org.eclipse.ui.texteditor.TextEditorAction;
  */
 public class ShowExternalPreviewAction extends TextEditorAction {
   private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
-  protected IFile fileToParse;
   /**
    * Constructs and updates the action.
    */
@@ -35,33 +37,79 @@ public class ShowExternalPreviewAction extends TextEditorAction {
     super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
     update();
   }
-  public static ShowExternalPreviewAction getInstance() {
+  
+public static ShowExternalPreviewAction getInstance() {
     return instance;
   }
   /**
    * Code called when the action is fired.
    */
   public void run() {
-    fileToParse = getFile();
-    if (fileToParse == null) {
+    IFile previewFile = getFile();
+    if (previewFile == null) {
       // should never happen
       return;
     }
-    String localhostURL;
-    if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) {
+    boolean autoPreview = Util.getPreviewBooleanValue(previewFile,
+        IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
+    boolean bringToTopPreview = Util.getPreviewBooleanValue(previewFile,
+        IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
+    boolean showHTMLFilesLocal = Util.getPreviewBooleanValue(previewFile,
+        IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
+    boolean isPHPFileName = PHPFileUtil.isPHPFileName(previewFile.getLocation().toString());
+    
+    if (autoPreview) { 
+      String localhostURL;
+      if (showHTMLFilesLocal && (!isPHPFileName)) {  
+        localhostURL = previewFile.getLocation().toString();
+      } else if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null,
+          previewFile)) == null) {
+        return;
+      }
+      IWorkbenchPage page = PHPeclipsePlugin.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 (PartInitException e) {
+        PHPeclipsePlugin.log(e);
+      }
+    }
+  }
+  
+  public void refresh() {
+    IFile fileToParse = getFile();
+    if (fileToParse == null) {
+      // should never happen
       return;
     }
-    IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
-    try {
-      IViewPart part = page.findView(BrowserView.ID_BROWSER);
-      if (part == null) {
-        part = page.showView(BrowserView.ID_BROWSER);
-      } else {
-        page.bringToTop(part);
+    boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
+        IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
+    boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
+        IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
+    if (autoPreview) {
+      IWorkbenchPage page = PHPeclipsePlugin.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).refresh();
+        
+      } catch (PartInitException e) {
+        PHPeclipsePlugin.log(e);
       }
-      ((BrowserView) part).setUrl(localhostURL);
-    } catch (PartInitException e) {
-      PHPeclipsePlugin.log(e);
     }
   }
   /**