IBM Corporation - Initial implementation
Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
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.IAction;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+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.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+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.
*/
super.dispose();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs any extra
- * revert behavior required by the java editor.
+ * revert behavior required by the php editor.
*/
public void doRevertToSaved() {
super.doRevertToSaved();
fOutlinePage.update();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs any extra
- * save behavior required by the java editor.
+ * save behavior required by the php editor.
*/
public void doSave(IProgressMonitor monitor) {
super.doSave(monitor);
+ // compile or not, according to the user preferences
+ IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
+ IAction a = PHPParserAction.getInstance();
+ if (a != null)
+ a.run();
+ }
if (fOutlinePage != null)
fOutlinePage.update();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs any extra
- * save as behavior required by the java editor.
+ * save as behavior required by the php editor.
*/
public void doSaveAs() {
super.doSaveAs();
fOutlinePage.update();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs sets the
* input of the outline page after AbstractTextEditor has set input.
*/
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 = PHPWordExtractor.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
*/
setRangeIndicator(new DefaultRangeIndicator());
setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
+ // setDocumentProvider(PHPeclipsePlugin.getCompilationUnitDocumentProvider());
+
+ PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ PHPCodeScanner scanner = PHPEditorEnvironment.getPHPCodeScanner();
+ if (scanner != null) {
+ scanner.updateToken(PHPEditorEnvironment.getPHPColorProvider());
+ }
+ if (getSourceViewer() != null) {
+ getSourceViewer().invalidateTextPresentation();
+ }
+ }
+ });
}
}