1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14 import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.help.IHelp;
18 import org.eclipse.help.IHelpResource;
19 import org.eclipse.jface.action.MenuManager;
20 import org.eclipse.jface.dialogs.MessageDialog;
21 import org.eclipse.jface.text.BadLocationException;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.ITextSelection;
24 import org.eclipse.jface.text.source.ISourceViewer;
25 import org.eclipse.swt.graphics.Point;
26 import org.eclipse.ui.IEditorInput;
27 import org.eclipse.ui.editors.text.TextEditor;
28 import org.eclipse.ui.help.WorkbenchHelp;
29 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
30 import org.eclipse.ui.texteditor.TextOperationAction;
31 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
32 import org.eclipse.jface.action.IAction;
34 * Java specific text editor.
36 public class PHPEditor extends TextEditor {
38 /** The outline page */
39 private PHPContentOutlinePage fOutlinePage;
42 * Default constructor.
48 /** The <code>JavaEditor</code> implementation of this
49 * <code>AbstractTextEditor</code> method extend the
50 * actions to add those specific to the receiver
52 protected void createActions() {
53 super.createActions();
55 "ContentAssistProposal",
56 new TextOperationAction(
57 PHPEditorMessages.getResourceBundle(),
58 "ContentAssistProposal.",
60 ISourceViewer.CONTENTASSIST_PROPOSALS));
63 new TextOperationAction(
64 PHPEditorMessages.getResourceBundle(),
67 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
70 /** The <code>JavaEditor</code> implementation of this
71 * <code>AbstractTextEditor</code> method performs any extra
72 * disposal actions required by the java editor.
74 public void dispose() {
75 PHPEditorEnvironment.disconnect(this);
76 if (fOutlinePage != null)
77 fOutlinePage.setInput(null);
81 /** The <code>JavaEditor</code> implementation of this
82 * <code>AbstractTextEditor</code> method performs any extra
83 * revert behavior required by the java editor.
85 public void doRevertToSaved() {
86 super.doRevertToSaved();
87 if (fOutlinePage != null)
88 fOutlinePage.update();
91 /** The <code>JavaEditor</code> implementation of this
92 * <code>AbstractTextEditor</code> method performs any extra
93 * save behavior required by the java editor.
95 public void doSave(IProgressMonitor monitor) {
96 super.doSave(monitor);
97 // compile or not, according to the user preferences
98 IAction a = PHPParserAction.getInstance();
101 if (fOutlinePage != null)
102 fOutlinePage.update();
105 /** The <code>JavaEditor</code> implementation of this
106 * <code>AbstractTextEditor</code> method performs any extra
107 * save as behavior required by the java editor.
109 public void doSaveAs() {
111 if (fOutlinePage != null)
112 fOutlinePage.update();
115 /** The <code>JavaEditor</code> implementation of this
116 * <code>AbstractTextEditor</code> method performs sets the
117 * input of the outline page after AbstractTextEditor has set input.
119 public void doSetInput(IEditorInput input) throws CoreException {
120 super.doSetInput(input);
121 if (fOutlinePage != null)
122 fOutlinePage.setInput(input);
125 /** The <code>JavaEditor</code> implementation of this
126 * <code>AbstractTextEditor</code> method adds any
127 * JavaEditor specific entries.
129 public void editorContextMenuAboutToShow(MenuManager menu) {
130 super.editorContextMenuAboutToShow(menu);
131 addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
132 addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
135 /** The <code>JavaEditor</code> implementation of this
136 * <code>AbstractTextEditor</code> method performs gets
137 * the java content outline page if request is for a an
140 public Object getAdapter(Class required) {
141 if (IContentOutlinePage.class.equals(required)) {
142 if (fOutlinePage == null) {
143 fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
144 if (getEditorInput() != null)
145 fOutlinePage.setInput(getEditorInput());
149 return super.getAdapter(required);
152 public void openContextHelp() {
153 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
154 ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
155 int pos = selection.getOffset();
156 String word = getFunctionName(doc, pos);
157 openContextHelp(word);
160 private void openContextHelp(String word) {
164 public static void open(String word) {
165 IHelp help = WorkbenchHelp.getHelpSupport();
167 IHelpResource helpResource = new PHPFunctionHelpResource(word);
168 WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
170 // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
174 private String getFunctionName(IDocument doc, int pos) {
175 Point word = PHPWordExtractor.findWord(doc, pos);
178 return doc.get(word.x, word.y).replace('_', '-');
179 } catch (BadLocationException e) {
186 * Method declared on AbstractTextEditor
188 protected void initializeEditor() {
190 PHPEditorEnvironment.connect(this);
192 setSourceViewerConfiguration(new PHPSourceViewerConfiguration());
193 setRangeIndicator(new DefaultRangeIndicator());
194 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
195 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$