From: axelcl Date: Thu, 6 Jan 2005 18:39:50 +0000 (+0000) Subject: Better event handling for browser preview refreshs X-Git-Url: http://secure.phpeclipse.com Better event handling for browser preview refreshs --- diff --git a/archive/net.sourceforge.phpeclipse.wiki/plugin.xml b/archive/net.sourceforge.phpeclipse.wiki/plugin.xml index a08e763..beafde2 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.wiki/plugin.xml @@ -15,7 +15,6 @@ - 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 index 0000000..a066abf --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/BrowserUtil.java @@ -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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditor.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditor.java index 5cd82f8..8339692 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditor.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditor.java @@ -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); } diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorContributor.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorContributor.java index 29edcb1..b10a7fb 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorContributor.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorContributor.java @@ -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) { diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java index 88dff81..5dce1b6 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java @@ -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 { + "" + "" + "" - + "" + + "" + "" + ""; @@ -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