1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
9 package net.sourceforge.phpeclipse.wiki.editor;
11 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
12 import net.sourceforge.phpeclipse.wiki.editor.action.WeblogWikiAction;
13 import net.sourceforge.phpeclipse.wiki.preferences.Util;
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.Separator;
18 import org.eclipse.ui.IActionBars;
19 import org.eclipse.ui.IEditorInput;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IFileEditorInput;
22 import org.eclipse.ui.IViewPart;
23 import org.eclipse.ui.IWorkbenchPage;
24 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
25 import org.eclipse.ui.texteditor.ITextEditor;
26 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
27 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
29 public class WikiEditorContributor extends BasicTextEditorActionContributor {
31 private static final String CONTENTASSIST_ACTION = "net.sourceforge.phpeclipse.wiki.editor.ContentAssist";
33 private RetargetTextEditorAction fContentAssist;
34 public WikiEditorContributor() {
36 fContentAssist = new RetargetTextEditorAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal.");
37 fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
40 public void setActiveEditor(IEditorPart part) {
41 super.setActiveEditor(part);
42 ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
43 fContentAssist.setAction(getAction(editor, CONTENTASSIST_ACTION));
45 setBrowserPreview(editor);
48 public void setBrowserPreview(ITextEditor editor) {
49 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
51 IViewPart part = page.findView(BrowserView.ID_BROWSER);
53 part = page.showView(BrowserView.ID_BROWSER);
55 // if (bringToTopPreview) {
56 // page.bringToTop(part);
59 IEditorInput editorInput = null;
61 editorInput = editor.getEditorInput();
63 if (editorInput instanceof IFileEditorInput) {
64 IFile file = ((IFileEditorInput) editorInput).getFile();
65 String srcBasePath = Util.getWikiTextsPath(file);
66 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
67 String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
69 ((BrowserView) part).setUrl(htmlName);
72 } catch (Exception e) {
76 public void contributeToMenu(IMenuManager menu) {
78 super.contributeToMenu(menu);
82 public void init(IActionBars bars, IWorkbenchPage page) {
83 super.init(bars, page);
84 bars.setGlobalActionHandler(CONTENTASSIST_ACTION, fContentAssist);
88 public void dispose() {
89 setActiveEditor(null);