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.preferences.Util;
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.jface.action.IMenuManager;
16 import org.eclipse.ui.IActionBars;
17 import org.eclipse.ui.IEditorInput;
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.IFileEditorInput;
20 import org.eclipse.ui.IViewPart;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
23 import org.eclipse.ui.texteditor.ITextEditor;
24 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
25 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
27 public class WikiEditorContributor extends BasicTextEditorActionContributor {
29 private static final String CONTENTASSIST_ACTION = "net.sourceforge.phpeclipse.wiki.editor.ContentAssist";
31 private RetargetTextEditorAction fContentAssist;
32 public WikiEditorContributor() {
34 fContentAssist = new RetargetTextEditorAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal.");
35 fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
38 public void setActiveEditor(IEditorPart part) {
39 super.setActiveEditor(part);
40 ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
41 fContentAssist.setAction(getAction(editor, CONTENTASSIST_ACTION));
43 setBrowserPreview(editor);
46 public void setBrowserPreview(ITextEditor editor) {
47 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
49 IViewPart part = page.findView(BrowserView.ID_BROWSER);
51 part = page.showView(BrowserView.ID_BROWSER);
53 // if (bringToTopPreview) {
54 // page.bringToTop(part);
57 IEditorInput editorInput = null;
59 editorInput = editor.getEditorInput();
61 if (editorInput instanceof IFileEditorInput) {
62 IFile file = ((IFileEditorInput) editorInput).getFile();
63 String srcBasePath = Util.getWikiTextsPath(file);
64 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
65 String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
67 ((BrowserView) part).setUrl(htmlName);
70 } catch (Exception e) {
74 public void contributeToMenu(IMenuManager menu) {
76 super.contributeToMenu(menu);
80 public void init(IActionBars bars, IWorkbenchPage page) {
81 super.init(bars, page);
82 bars.setGlobalActionHandler(CONTENTASSIST_ACTION, fContentAssist);
86 public void dispose() {
87 setActiveEditor(null);