IBM Corporation - Initial implementation
Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
+import net.sourceforge.phpeclipse.phpeditor.php.PHPWordDetector;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.help.IHelp;
+import org.eclipse.help.IHelpResource;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
* Java specific text editor.
*/
public class PHPEditor extends TextEditor {
-
+
/** The outline page */
private PHPContentOutlinePage fOutlinePage;
return super.getAdapter(required);
}
+ public void openContextHelp() {
+ IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
+ ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
+ int pos = selection.getOffset();
+ String word = getFunctionName(doc, pos);
+ openContextHelp(word);
+ }
+
+ private void openContextHelp(String word) {
+ open(word);
+ }
+
+ public static void open(String word) {
+ IHelp help = WorkbenchHelp.getHelpSupport();
+ if (help != null) {
+ IHelpResource helpResource = new PHPFunctionHelpResource(word);
+ WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
+ } else {
+ // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+ }
+ }
+
+ private String getFunctionName(IDocument doc, int pos) {
+ Point word = PHPWordDetector.findWord(doc, pos);
+ if (word != null) {
+ try {
+ return doc.get(word.x, word.y).replace('_', '-');
+ } catch (BadLocationException e) {
+ }
+ }
+ return "";
+ }
+
/* (non-Javadoc)
* Method declared on AbstractTextEditor
*/