1) Fixed the 'Save Failed' issue by uncommenting the incriminating code from showPrev...
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / editor / BrowserUtil.java
index ef3b7a1..f905c83 100644 (file)
@@ -5,11 +5,16 @@ import java.net.URL;
 
 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
 import net.sourceforge.phpeclipse.ui.WebUI;
+import net.sourceforge.phpeclipse.ui.internal.WebUIMessages;
 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
 import net.sourceforge.phpeclipse.webbrowser.views.ShowInContextBrowser;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IViewReference;
 import org.eclipse.ui.IWorkbenchPage;
@@ -27,11 +32,11 @@ public class BrowserUtil {
 
        public static ShowInContextBrowser getShowInContext(IFile previewFile,
                        boolean forceDBGPreview, String postFix) {
-               String extension = previewFile.getFileExtension().toLowerCase();
+               //String extension = previewFile.getFileExtension().toLowerCase();
                // boolean showHTMLFilesLocal = false;
                // boolean showXMLFilesLocal = false;
-               boolean isHTMLFileName = false;
-               boolean isXMLFileName = false;
+//             boolean isHTMLFileName = false;
+//             boolean isXMLFileName = false;
                String localhostURL;
                if (!forceDBGPreview) {
                        // showHTMLFilesLocal =
@@ -40,10 +45,10 @@ public class BrowserUtil {
                        // 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);
+//                     isHTMLFileName = "html".equals(extension)
+//                                     || "htm".equals(extension) || "xhtml".equals(extension);
+//                     isXMLFileName = "xml".equals(extension) || "xsd".equals(extension)
+//                                     || "dtd".equals(extension);
                }
                // if (showHTMLFilesLocal && isHTMLFileName) {
                // localhostURL = previewFile.getLocation().toString();
@@ -122,44 +127,52 @@ public class BrowserUtil {
                                // return;
                                // }
                                // localhostURL += postFix;
-                               ShowInContext context = getShowInContext(previewFile,
-                                               forceDBGPreview, postFix);
+                               ShowInContext context = getShowInContext (previewFile, forceDBGPreview, postFix);
                                IWorkbenchPart sourcePart = page.getActivePart();
+                               
                                if (sourcePart == null && context != null) {
                                        return;
                                }
 
                                // try {
-                               Perspective persp = ((WorkbenchPage) page)
-                                               .getActivePerspective();
+/* Don't know what this is for, but I removed it by now because of some compile errors!                        
+                               Perspective persp = ((WorkbenchPage) page).getActivePerspective();
                                if (persp != null) {
-
                                        // If this view is already visible just return.
-                                       IViewReference ref = persp.findView(BrowserView.ID_BROWSER,
-                                                       null);
+                                       IViewReference ref = persp.findView (BrowserView.ID_BROWSER, null);
                                        IViewPart view = null;
+                                       
                                        if (ref != null) {
                                                view = ref.getView(true);
                                        }
+                                       
                                        if (view == null && forceDBGPreview) {
                                                try {
-                                                       view = persp.showView(BrowserView.ID_BROWSER, null);
-                                                       persp.bringToTop(persp.findView(
-                                                                       BrowserView.ID_BROWSER, null));
+                                                       view = persp.showView (BrowserView.ID_BROWSER, null);
+                                                       persp.bringToTop (persp.findView (BrowserView.ID_BROWSER, null));
                                                } catch (PartInitException e) {
                                                        WebUI.log(e);
                                                }
                                        }
+                                       
                                        if (view != null) {
                                                IShowInTarget target = getShowInTarget(view);
-                                               if (target != null && target.show(context)) {
-                                                       // success
+                                               boolean stickyBrowserURL = ProjectPrefUtil.getPreviewBooleanValue(
+                                                               previewFile,
+                                                               IPreferenceConstants.PHP_STICKY_BROWSER_URL_DEFAULT);
+                                               if (target != null) {
+                                                       if (stickyBrowserURL
+                                                                       && ((BrowserView) target).getUrl() != null
+                                                                       && ((BrowserView) target).getUrl().length() > 0) {
+                                                               ((BrowserView) target).refresh();
+                                                       } else {
+                                                               target.show(context);
+                                                       }
                                                }
-                                               ((WorkbenchPage) page)
-                                                               .performedShowIn(BrowserView.ID_BROWSER);
+                                               ((WorkbenchPage) page).performedShowIn (BrowserView.ID_BROWSER);
                                        }
                                }
-
+*/
                                // IViewPart view = page.showView(BrowserView.ID_BROWSER);
                                // IShowInTarget target = getShowInTarget(view);
                                // if (target != null && target.show(new
@@ -227,6 +240,18 @@ public class BrowserUtil {
        public static void showBrowser(int style, IFile file, String queryString) {
                ShowInContextBrowser context = getShowInContext(file, true, queryString);
                String url = context.getLocalhostUrl();
+               if (url == null) {
+                       String dialogTitle = WebUIMessages
+                                       .getString("BrowserUtil.error.dialog.title");
+                       String message = WebUIMessages
+                                       .getString("BrowserUtil.null.url.message");
+                       String reason = WebUIMessages
+                                       .getString("BrowserUtil.null.url.reason");
+                       IStatus status = new Status(IStatus.ERROR, WebUI.PLUGIN_ID, 0,
+                                       reason, null);
+                       ErrorDialog.openError(new Shell(), dialogTitle, message, status);
+                       return;
+               }
                String id = BROWSER_ID;
                switch (style) {
                case IWorkbenchBrowserSupport.AS_EXTERNAL: