1) Added missing strings for italic, underline and strike through.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / editor / BrowserUtil.java
1 package net.sourceforge.phpeclipse.wiki.editor;
2
3 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
4 import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
5 import net.sourceforge.phpeclipse.wiki.preferences.Util;
6
7 import org.eclipse.core.resources.IFile;
8 import org.eclipse.ui.IEditorInput;
9 import org.eclipse.ui.IFileEditorInput;
10 import org.eclipse.ui.IViewPart;
11 import org.eclipse.ui.IWorkbenchPage;
12 import org.eclipse.ui.texteditor.ITextEditor;
13
14 /**
15  * Set browser preview URL and refresh URL Utilities
16  */
17 public class BrowserUtil {
18
19   public static void setBrowserPreview(ITextEditor editor) {
20     
21     IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
22     try {
23       IViewPart part = page.findView(BrowserView.ID_BROWSER);
24       if (part == null) {
25         part = page.showView(BrowserView.ID_BROWSER);
26       } else {
27         //                if (bringToTopPreview) {
28         //                  page.bringToTop(part);
29         //                }
30       }
31       IEditorInput editorInput = null;
32       if (editor != null) {
33         editorInput = editor.getEditorInput();
34       }
35       if (editorInput instanceof IFileEditorInput) {
36         IFile file = ((IFileEditorInput) editorInput).getFile();
37         String srcBasePath = Util.getWikiTextsPath(file);
38         String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
39         String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
40
41         if (htmlName != null) {
42           java.io.File htmlFile = new java.io.File(htmlName);
43           if (htmlFile.exists()) {
44             ((BrowserView) part).setUrl(htmlName);
45           }
46         }
47       }
48     } catch (Exception e) {
49     }
50   }
51
52   /**
53    *  
54    */
55   public static void refreshBrowserPreview(WikiEditor editor) {
56
57     IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
58     try {
59       IViewPart part = page.findView(BrowserView.ID_BROWSER);
60       if (part == null) {
61         part = page.showView(BrowserView.ID_BROWSER);
62       } else {
63         IEditorInput editorInput = null;
64         editorInput = editor.getEditorInput();
65         if (editorInput instanceof IFileEditorInput) {
66           IFile file = ((IFileEditorInput) editorInput).getFile();
67           CreatePageAction.createPage(file);
68
69           String srcBasePath = Util.getWikiTextsPath(file);
70           String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
71           String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
72           if (htmlName != null) {
73             java.io.File htmlFile = new java.io.File(htmlName);
74             if (htmlFile.exists()) {
75               ((BrowserView) part).refresh(htmlName);
76             }
77           }
78         }
79       }
80
81     } catch (Exception e) {
82     }
83   }
84
85 }