/*********************************************************************************************************************************** * Copyright (c) 2000, 2004 IBM Corporation 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 API and implementation **********************************************************************************************************************************/ package net.sourceforge.phpeclipse.wiki.editor; import net.sourceforge.phpeclipse.webbrowser.views.BrowserView; import net.sourceforge.phpeclipse.wiki.editor.action.WeblogWikiAction; import net.sourceforge.phpeclipse.wiki.preferences.Util; import org.eclipse.core.resources.IFile; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.Separator; 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; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.RetargetTextEditorAction; public class WikiEditorContributor extends BasicTextEditorActionContributor { private static final String CONTENTASSIST_ACTION = "net.sourceforge.phpeclipse.wiki.editor.ContentAssist"; private RetargetTextEditorAction fContentAssist; public WikiEditorContributor() { super(); fContentAssist = new RetargetTextEditorAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal."); fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); } public void setActiveEditor(IEditorPart part) { 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) { } } public void contributeToMenu(IMenuManager menu) { super.contributeToMenu(menu); } public void init(IActionBars bars, IWorkbenchPage page) { super.init(bars, page); bars.setGlobalActionHandler(CONTENTASSIST_ACTION, fContentAssist); } public void dispose() { setActiveEditor(null); super.dispose(); } }