Better event handling for browser preview refreshs
authoraxelcl <axelcl>
Thu, 6 Jan 2005 18:39:50 +0000 (18:39 +0000)
committeraxelcl <axelcl>
Thu, 6 Jan 2005 18:39:50 +0000 (18:39 +0000)
archive/net.sourceforge.phpeclipse.wiki/plugin.xml
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/BrowserUtil.java [new file with mode: 0644]
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditor.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorContributor.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java

index a08e763..beafde2 100644 (file)
@@ -15,7 +15,6 @@
       <library name="lib/radeox.jar"/>
       <library name="lib/commons-logging.jar"/>
       <library name="lib/commons-httpclient-2.0.2.jar"/>
-      <library name="lib/java2html_4.1.jar"/>
       <library name="lib/plog4u.jar"/>
       <library name="lib/velocity-dep-1.4.jar"/>
       <library name="lib/mysql-connector.jar"/>
diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/BrowserUtil.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/BrowserUtil.java
new file mode 100644 (file)
index 0000000..a066abf
--- /dev/null
@@ -0,0 +1,84 @@
+package net.sourceforge.phpeclipse.wiki.editor;
+
+import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
+import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
+import net.sourceforge.phpeclipse.wiki.preferences.Util;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Set browser preview URL and refresh URL Utilities
+ */
+public class BrowserUtil {
+
+  public static void setBrowserPreview(ITextEditor editor) {
+    IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
+    try {
+      IViewPart part = page.findView(BrowserView.ID_BROWSER);
+      if (part == null) {
+        part = page.showView(BrowserView.ID_BROWSER);
+      } else {
+        //               if (bringToTopPreview) {
+        //                 page.bringToTop(part);
+        //               }
+      }
+      IEditorInput editorInput = null;
+      if (editor != null) {
+        editorInput = editor.getEditorInput();
+      }
+      if (editorInput instanceof IFileEditorInput) {
+        IFile file = ((IFileEditorInput) editorInput).getFile();
+        String srcBasePath = Util.getWikiTextsPath(file);
+        String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
+        String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
+
+        if (htmlName != null) {
+          java.io.File htmlFile = new java.io.File(htmlName);
+          if (htmlFile.exists()) {
+            ((BrowserView) part).setUrl(htmlName);
+          }
+        }
+      }
+    } catch (Exception e) {
+    }
+  }
+
+  /**
+   *  
+   */
+  public static void refreshBrowserPreview(WikiEditor editor) {
+
+    IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
+    try {
+      IViewPart part = page.findView(BrowserView.ID_BROWSER);
+      if (part == null) {
+        part = page.showView(BrowserView.ID_BROWSER);
+      } else {
+        IEditorInput editorInput = null;
+        editorInput = editor.getEditorInput();
+        if (editorInput instanceof IFileEditorInput) {
+          IFile file = ((IFileEditorInput) editorInput).getFile();
+          CreatePageAction.createPage(file);
+
+          String srcBasePath = Util.getWikiTextsPath(file);
+          String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
+          String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
+          if (htmlName != null) {
+            java.io.File htmlFile = new java.io.File(htmlName);
+            if (htmlFile.exists()) {
+              ((BrowserView) part).refresh(htmlName);
+            }
+          }
+        }
+      }
+
+    } catch (Exception e) {
+    }
+  }
+
+}
\ No newline at end of file
index 5cd82f8..8339692 100644 (file)
@@ -7,8 +7,6 @@
  **********************************************************************************************************************************/
 package net.sourceforge.phpeclipse.wiki.editor;
 
-import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
-import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaSection;
 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaText;
 import net.sourceforge.phpeclipse.wiki.preferences.Util;
@@ -20,10 +18,6 @@ import org.eclipse.jface.text.source.IVerticalRuler;
 import org.eclipse.jface.text.source.projection.ProjectionSupport;
 import org.eclipse.jface.text.source.projection.ProjectionViewer;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 import org.eclipse.ui.texteditor.TextOperationAction;
@@ -139,25 +133,7 @@ public class WikiEditor extends AbstractDecoratedTextEditor {
    */
   protected void editorSaved() {
     super.editorSaved();
-    // doesn't work here, wikibuilder has to be finished with generating html page
-    IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
-    try {
-      IViewPart part = page.findView(BrowserView.ID_BROWSER);
-      if (part == null) {
-        part = page.showView(BrowserView.ID_BROWSER);
-      } else {
-        //               if (bringToTopPreview) {
-        //                 page.bringToTop(part);
-        //               }
-      }
-      IEditorInput editorInput = null;
-      editorInput = this.getEditorInput();
-      if (editorInput instanceof IFileEditorInput) {
-        CreatePageAction.createPage(((IFileEditorInput) editorInput).getFile());
-        ((BrowserView) part).refresh();
-      }
-    } catch (Exception e) {
-    }
+    BrowserUtil.refreshBrowserPreview(this);
   }
   
   
index 29edcb1..b10a7fb 100644 (file)
@@ -8,16 +8,10 @@
 
 package net.sourceforge.phpeclipse.wiki.editor;
 
-import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
-import net.sourceforge.phpeclipse.wiki.preferences.Util;
 
-import org.eclipse.core.resources.IFile;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
 import org.eclipse.ui.texteditor.ITextEditor;
@@ -39,36 +33,8 @@ public class WikiEditorContributor extends BasicTextEditorActionContributor {
     super.setActiveEditor(part);
     ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
     fContentAssist.setAction(getAction(editor, CONTENTASSIST_ACTION));
-    // jsurfer
-    setBrowserPreview(editor);
-  }
-
-  public void setBrowserPreview(ITextEditor editor) {
-    IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
-    try {
-      IViewPart part = page.findView(BrowserView.ID_BROWSER);
-      if (part == null) {
-        part = page.showView(BrowserView.ID_BROWSER);
-      } else {
-        //               if (bringToTopPreview) {
-        //                 page.bringToTop(part);
-        //               }
-      }
-      IEditorInput editorInput = null;
-      if (editor != null) {
-        editorInput = editor.getEditorInput();
-      }
-      if (editorInput instanceof IFileEditorInput) {
-        IFile file = ((IFileEditorInput) editorInput).getFile();
-        String srcBasePath = Util.getWikiTextsPath(file);
-        String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
-        String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
-        if (htmlName!=null) {
-          ((BrowserView) part).setUrl(htmlName);
-        }
-      }
-    } catch (Exception e) {
-    }
+    BrowserUtil.setBrowserPreview(editor);
   }
 
   public void contributeToMenu(IMenuManager menu) {
index 88dff81..5dce1b6 100644 (file)
@@ -10,8 +10,8 @@ import java.util.List;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
-import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy;
 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
+import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy;
 import net.sourceforge.phpeclipse.wiki.sql.WikipediaDB;
 
 import org.eclipse.core.runtime.CoreException;
@@ -76,7 +76,7 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
       + "<config name=\"Koders.com Search\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>"
       + "<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
       + "<config name=\"Wikipedia-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&amp;action=edit\"/>"
-      + "<config name=\"Wikibooks-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikibooks.org/w/wiki.phtml?title=$text.wikiname&amp;action=edit\"/>"
+      + "<config name=\"Wikibooks-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikibooks.org/w/index.php?title=$text.wikiname&amp;action=edit\"/>"
       + "<config name=\"Wikipedia-SQL\" type-id=\"Wikipedia SQL access\" user=\"root\" url=\"jdbc:mysql://localhost/wikidb\"/>"
       + "</configurations>";
 
@@ -392,4 +392,18 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
     }
     super.shutdown();
   }
+  
+  public static void log(int severity, String message) {
+    Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
+    log(status);
+  }
+
+  public static void log(IStatus status) {
+    getDefault().getLog().log(status);
+  }
+
+  public static void log(Throwable e) {
+    log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
+  }
+
 }
\ No newline at end of file