X-Git-Url: http://git.phpeclipse.com 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 c471f50..2679fb4 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 @@ -7,11 +7,16 @@ import net.sourceforge.phpeclipse.webbrowser.views.BrowserView; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.progress.WorkbenchJob; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; @@ -64,24 +69,57 @@ public class ShowExternalPreviewAction extends TextEditorAction { boolean bringToTopPreview = ProjectPrefUtil.getPreviewBooleanValue( previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT); + boolean stickyBrowserURL = ProjectPrefUtil.getPreviewBooleanValue( + previewFile, + IPreferenceConstants.PHP_STICKY_BROWSER_URL_DEFAULT); if (autoPreview) { IWorkbenchPage page = WebUI.getActivePage(); + if (page == null) { + // startup stage + return; + } try { - IViewPart part = page.findView(BrowserView.ID_BROWSER); - if (part == null) { - part = page.showView(BrowserView.ID_BROWSER); - } else { + // IViewPart part = page.findView(BrowserView.ID_BROWSER); + // if (part == null) { + // part = page.showView(BrowserView.ID_BROWSER); + // } + IViewPart part = page.showView(BrowserView.ID_BROWSER, null, + IWorkbenchPage.VIEW_CREATE); + if (part != null) { if (bringToTopPreview) { - page.bringToTop(part); + // page.bringToTop(part); + new WorkbenchJob(getClass().getName()) { + public IStatus runInUIThread( + IProgressMonitor monitor) { + IWorkbenchPage page = WebUI.getActivePage(); + if (page != null) { + IViewPart part = page + .findView(BrowserView.ID_BROWSER); + if (part != null) { + page.bringToTop(part); + } + } + return Status.OK_STATUS; + } + }.schedule(); } - } - if (part != null) { // ((BrowserView) part).refresh(); - String localhostURL = getLocalhostURL(null, previewFile); - ((BrowserView) part).refresh(localhostURL); + if (stickyBrowserURL + && ((BrowserView) part).getUrl() != null + && ((BrowserView) part).getUrl().length() > 0) { + ((BrowserView) part).refresh(); + } else { + String localhostURL = getLocalhostURL(null, previewFile); + ((BrowserView) part).refresh(localhostURL); + } } - } catch (Exception e) { + } catch (PartInitException e) { + // ad hoc + WebUI.getDefault().getLog().log( + new Status(IStatus.ERROR, + "net.sourceforge.phpeclipse.ui", IStatus.OK, + "Failed to show Browser View", e)); // PHPeclipsePlugin.log(e); } } @@ -108,12 +146,14 @@ public class ShowExternalPreviewAction extends TextEditorAction { store = WebUI.getDefault().getPreferenceStore(); } // IPath path = file.getFullPath(); - String localhostURL = file.getLocation().toString(); + String localhostURL = file.getFullPath().toString(); String lowerCaseFileName = localhostURL.toLowerCase(); + //removed by ed_mann for RSE fixes testing // String documentRoot = // store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); - IPath documentRootPath = ProjectPrefUtil.getDocumentRoot(file - .getProject()); + //IPath documentRootPath = ProjectPrefUtil.getDocumentRoot(file + // .getProject()); + IPath documentRootPath = file.getProject().getFullPath(); String documentRoot = documentRootPath.toString().toLowerCase(); if (lowerCaseFileName.startsWith(documentRoot)) { localhostURL = localhostURL.substring(documentRoot.length()); @@ -122,9 +162,12 @@ public class ShowExternalPreviewAction extends TextEditorAction { } // return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + // localhostURL; - return ProjectPrefUtil.getMiscProjectsPreferenceValue(file - .getProject(), IPreferenceConstants.PHP_LOCALHOST_PREF) - + localhostURL; + String projectPath = ProjectPrefUtil.getMiscProjectsPreferenceValue(file + .getProject(), IPreferenceConstants.PHP_LOCALHOST_PREF); + if(projectPath.endsWith("/") && localhostURL.startsWith("/")) { + localhostURL = localhostURL.substring(1); + } + return projectPath + localhostURL; } return "http://localhost"; }