f3d93c978810576a09be457c98353284ebb410b2
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / editor / WikiEditorContributor.java
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
5  * 
6  * Contributors: IBM Corporation - initial API and implementation
7  **********************************************************************************************************************************/
8
9 package net.sourceforge.phpeclipse.wiki.editor;
10
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;
14
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;
28
29 public class WikiEditorContributor extends BasicTextEditorActionContributor {
30
31   private static final String CONTENTASSIST_ACTION = "net.sourceforge.phpeclipse.wiki.editor.ContentAssist";
32
33   private RetargetTextEditorAction fContentAssist;
34   public WikiEditorContributor() {
35     super();
36     fContentAssist = new RetargetTextEditorAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal.");
37     fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
38   }
39
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));
44     // jsurfer
45     setBrowserPreview(editor);
46   }
47
48   public void setBrowserPreview(ITextEditor editor) {
49     IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
50     try {
51       IViewPart part = page.findView(BrowserView.ID_BROWSER);
52       if (part == null) {
53         part = page.showView(BrowserView.ID_BROWSER);
54       } else {
55         //                if (bringToTopPreview) {
56         //                  page.bringToTop(part);
57         //                }
58       }
59       IEditorInput editorInput = null;
60       if (editor != null) {
61         editorInput = editor.getEditorInput();
62       }
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);
68         if (htmlName!=null) {
69           ((BrowserView) part).setUrl(htmlName);
70         }
71       }
72     } catch (Exception e) {
73     }
74   }
75
76   public void contributeToMenu(IMenuManager menu) {
77         
78         super.contributeToMenu(menu);
79         
80 }
81   
82   public void init(IActionBars bars, IWorkbenchPage page) {
83     super.init(bars, page);
84     bars.setGlobalActionHandler(CONTENTASSIST_ACTION, fContentAssist);
85     
86   }
87         
88   public void dispose() {
89     setActiveEditor(null);
90     super.dispose();
91   }
92 }