X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java index a3669ed..359084e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java @@ -1,22 +1,18 @@ package net.sourceforge.phpeclipse.phpeditor; - -/********************************************************************** -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 -**********************************************************************/ - +/******************************************************************************* + * 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.IPreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction; - +import net.sourceforge.phpeclipse.views.browser.BrowserView; import org.eclipse.core.resources.IFile; -import org.eclipse.swt.SWT; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IViewPart; @@ -24,18 +20,14 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; +import net.sourceforge.phpeclipse.overlaypages.Util; //import org.eclipse.update.internal.ui.UpdatePerspective; //import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser; - /** * ClassDeclaration that defines the action for parsing the current PHP file */ public class ShowExternalPreviewAction extends TextEditorAction { - private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction(); - - protected IFile fileToParse; - /** * Constructs and updates the action. */ @@ -43,57 +35,85 @@ public class ShowExternalPreviewAction extends TextEditorAction { super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$ update(); } - public static ShowExternalPreviewAction getInstance() { return instance; } - /** * Code called when the action is fired. */ public void run() { - fileToParse = getFile(); + IFile fileToParse = getFile(); if (fileToParse == null) { // should never happen return; } - -// if (SWT.getPlatform().equals("win32")) { -// String localhostURL; -// if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) { -// return; -// } -// IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); -// try { -// IViewPart part = page.findView(UpdatePerspective.ID_BROWSER); -// if (part == null) { -// part = page.showView(UpdatePerspective.ID_BROWSER); -// } else -// page.bringToTop(part); -// ((IEmbeddedWebBrowser) part).openTo(localhostURL); -// } catch (PartInitException e) { -// PHPeclipsePlugin.log(e); -// } -// } - + boolean autoPreview = Util.getPreviewBooleanValue(fileToParse, + IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT); + boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse, + IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT); + if (autoPreview) { + String localhostURL; + if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, + fileToParse)) == 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; + } + 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); + } + } } - /** * Finds the file that's currently opened in the PHP Text Editor */ protected IFile getFile() { ITextEditor editor = getTextEditor(); - IEditorInput editorInput = null; if (editor != null) { editorInput = editor.getEditorInput(); } - if (editorInput instanceof IFileEditorInput) return ((IFileEditorInput) editorInput).getFile(); - // if nothing was found, which should never happen return null; } - } \ No newline at end of file