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.PHPWordDetector;
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;
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 if (fOutlinePage != null)
98 fOutlinePage.update();
101 /** The <code>JavaEditor</code> implementation of this
102 * <code>AbstractTextEditor</code> method performs any extra
103 * save as behavior required by the java editor.
105 public void doSaveAs() {
107 if (fOutlinePage != null)
108 fOutlinePage.update();
111 /** The <code>JavaEditor</code> implementation of this
112 * <code>AbstractTextEditor</code> method performs sets the
113 * input of the outline page after AbstractTextEditor has set input.
115 public void doSetInput(IEditorInput input) throws CoreException {
116 super.doSetInput(input);
117 if (fOutlinePage != null)
118 fOutlinePage.setInput(input);
121 /** The <code>JavaEditor</code> implementation of this
122 * <code>AbstractTextEditor</code> method adds any
123 * JavaEditor specific entries.
125 public void editorContextMenuAboutToShow(MenuManager menu) {
126 super.editorContextMenuAboutToShow(menu);
127 addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
128 addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
131 /** The <code>JavaEditor</code> implementation of this
132 * <code>AbstractTextEditor</code> method performs gets
133 * the java content outline page if request is for a an
136 public Object getAdapter(Class required) {
137 if (IContentOutlinePage.class.equals(required)) {
138 if (fOutlinePage == null) {
139 fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
140 if (getEditorInput() != null)
141 fOutlinePage.setInput(getEditorInput());
145 return super.getAdapter(required);
148 public void openContextHelp() {
149 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
150 ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
151 int pos = selection.getOffset();
152 String word = getFunctionName(doc, pos);
153 openContextHelp(word);
156 private void openContextHelp(String word) {
160 public static void open(String word) {
161 IHelp help = WorkbenchHelp.getHelpSupport();
163 IHelpResource helpResource = new PHPFunctionHelpResource(word);
164 WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
166 // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
170 private String getFunctionName(IDocument doc, int pos) {
171 Point word = PHPWordDetector.findWord(doc, pos);
174 return doc.get(word.x, word.y).replace('_', '-');
175 } catch (BadLocationException e) {
182 * Method declared on AbstractTextEditor
184 protected void initializeEditor() {
186 PHPEditorEnvironment.connect(this);
188 setSourceViewerConfiguration(new PHPSourceViewerConfiguration());
189 setRangeIndicator(new DefaultRangeIndicator());
190 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
191 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$