a3669ed12d86a6ff0a2eaafe2b9202362b8818df
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / ShowExternalPreviewAction.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14
15 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
16 import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.ui.IEditorInput;
21 import org.eclipse.ui.IFileEditorInput;
22 import org.eclipse.ui.IViewPart;
23 import org.eclipse.ui.IWorkbenchPage;
24 import org.eclipse.ui.PartInitException;
25 import org.eclipse.ui.texteditor.ITextEditor;
26 import org.eclipse.ui.texteditor.TextEditorAction;
27 //import org.eclipse.update.internal.ui.UpdatePerspective;
28 //import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
29
30 /**
31  * ClassDeclaration that defines the action for parsing the current PHP file
32  */
33 public class ShowExternalPreviewAction extends TextEditorAction {
34
35   private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
36
37   protected IFile fileToParse;
38
39   /**
40    * Constructs and updates the action.
41    */
42   private ShowExternalPreviewAction() {
43     super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
44     update();
45   }
46
47   public static ShowExternalPreviewAction getInstance() {
48     return instance;
49   }
50
51   /**
52    * Code called when the action is fired.
53    */
54   public void run() {
55     fileToParse = getFile();
56     if (fileToParse == null) {
57       // should never happen
58       return;
59     }
60
61 //    if (SWT.getPlatform().equals("win32")) {
62 //      String localhostURL;
63 //      if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) {
64 //        return;
65 //      }
66 //      IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
67 //      try {
68 //        IViewPart part = page.findView(UpdatePerspective.ID_BROWSER);
69 //        if (part == null) {
70 //          part = page.showView(UpdatePerspective.ID_BROWSER);
71 //        } else
72 //          page.bringToTop(part);
73 //        ((IEmbeddedWebBrowser) part).openTo(localhostURL);
74 //      } catch (PartInitException e) {
75 //        PHPeclipsePlugin.log(e);
76 //      }
77 //    }
78
79   }
80
81   /**
82    * Finds the file that's currently opened in the PHP Text Editor
83    */
84   protected IFile getFile() {
85     ITextEditor editor = getTextEditor();
86
87     IEditorInput editorInput = null;
88     if (editor != null) {
89       editorInput = editor.getEditorInput();
90     }
91
92     if (editorInput instanceof IFileEditorInput)
93       return ((IFileEditorInput) editorInput).getFile();
94
95     // if nothing was found, which should never happen
96     return null;
97   }
98
99 }