package net.sourceforge.phpeclipse.ui.editor;
-/*******************************************************************************
- * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Common Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
- * www.eclipseproject.de
- ******************************************************************************/
import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
import net.sourceforge.phpeclipse.ui.WebUI;
-import net.sourceforge.phpeclipse.ui.overlaypages.Util;
+import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
public void doRun(int type) {
IFile previewFile = getFile();
- if (previewFile == null) {
- // should never happen
- return;
- }
- String extension = previewFile.getFileExtension().toLowerCase();
- 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 showXMLFilesLocal = Util.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) {
// should never happen
return;
}
- boolean autoPreview = Util.getPreviewBooleanValue(fileToParse, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
- boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
+ boolean autoPreview = ProjectPrefUtil.getPreviewBooleanValue(fileToParse, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
+ boolean bringToTopPreview = ProjectPrefUtil.getPreviewBooleanValue(fileToParse,
+ IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
if (autoPreview) {
- IWorkbenchPage page = WebUI.getActivePage();
+ IWorkbenchPage page = WebUI.getDefault().getActivePage();
try {
IViewPart part = page.findView(BrowserView.ID_BROWSER);
if (part == null) {
}
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);
- String documentRoot = Util.getMiscProjectsPreferenceValue(file.getProject(), IPreferenceConstants.PHP_DOCUMENTROOT_PREF);
-
- documentRoot = documentRoot.replace('\\', '/');
- documentRoot = documentRoot.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 Util.getMiscProjectsPreferenceValue(file.getProject(), IPreferenceConstants.PHP_LOCALHOST_PREF) + localhostURL;
+ return "http://localhost";
}
}
\ No newline at end of file