id="net.sourceforge.phpeclipse.actions.showAction">
</action>
</objectContribution>
- <!-- <viewerContribution
+ <viewerContribution
targetID="#PHPEditorContext"
id="net.sourceforge.phpeclipse.actions.popup.editor">
<action
menubarPath="additions"
id="net.sourceforge.phpeclipse.actions.editor.contexthelp">
</action>
- </viewerContribution> -->
+ </viewerContribution>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.help.IHelp;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
-
import org.eclipse.ui.help.WorkbenchHelp;
-import org.eclipse.help.IHelp;
//import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil;
// import org.eclipse.help.ui.browser.LaunchURL;
// single file:
IFile file = (IFile) resource;
IPath path = file.getFullPath();
- // if (j2h==null) {
- // shell = new Shell();
- // j2h = new Java2HTML(shell);
- // }
- String fileName = file.getLocation().toString();
- String lowerCaseFileName = fileName.toLowerCase();
+ String localhostURL = file.getLocation().toString();
+ String lowerCaseFileName = localhostURL.toLowerCase();
// fileName = "http://localhost"+fileName.replaceAll("c:", "");
String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
documentRoot = documentRoot.replace('\\', '/');
documentRoot = documentRoot.toLowerCase();
- MessageDialog.openInformation(shell, "lowerCaseFileName", "lowerCaseFileName: " + lowerCaseFileName);
-
+
if (lowerCaseFileName.startsWith(documentRoot)) {
- fileName = fileName.substring(documentRoot.length());
+ localhostURL = localhostURL.substring(documentRoot.length());
} else {
MessageDialog.openInformation(shell, "Wrong DocumentRoot", "Adjust DocumentRoot: " + documentRoot);
return;
}
- fileName = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + fileName.replaceAll(documentRoot, "");
+ localhostURL = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL.replaceAll(documentRoot, "");
try {
if (store.getBoolean(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF)) {
- String[] arguments = { fileName };
+ String[] arguments = { localhostURL };
MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF));
Runtime runtime = Runtime.getRuntime();
// runtime.exec(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF) + " " + fileName);
// runtime.exec("command.com /c start iexplore " + fileName);
} else {
- open(new URL(fileName), shell, fileName);
+ // MessageDialog.openInformation(shell, "localhostURL", "localhostURL: " + localhostURL);
+ // this doesn't work under win98 ?
+ // Program.launch(localhostURL);
+ open(new URL(localhostURL), shell, localhostURL);
}
} catch (MalformedURLException e) {
MessageDialog.openInformation(shell, "MalformedURLException: ", e.toString());
} catch (IOException e) {
- MessageDialog.openInformation(shell, "IOException", "Cannot show: " + fileName);
+ MessageDialog.openInformation(shell, "IOException", "Cannot show: " + localhostURL);
}
-
- // MessageDialog.openInformation(shell, "PHPEclipse", "FileName - " + fileName);
- //
- // Runtime runtime = Runtime.getRuntime();
- // try {
- // runtime.exec("command.com /c start iexplore "+fileName);
-
- // MessageDialog.openInformation(shell, "J2h Plug-in", "FileName - " + fileName);
- // j2h.convert( fileName );
}
}
}
**********************************************************************/
package net.sourceforge.phpeclipse.actions;
+import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionDelegate;
-import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.internal.EditorPluginAction;
-import org.eclipse.ui.part.FileEditorInput;
public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate {
- private TextEditor editor;
- /**
- * @see ActionDelegate#run(IAction)
- */
+ private IWorkbenchWindow window;
+ private PHPEditor editor;
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (!selection.isEmpty()) {
+ if (selection instanceof TextSelection) {
+ action.setEnabled(true);
+ } else if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
+ //
+ }
+ }
+ }
+
public void run(IAction action) {
- EditorPluginAction editorPluginAction = (EditorPluginAction) action;
- FileEditorInput input = (FileEditorInput) editor.getEditorInput();
- // Add your code here to perform the action
- MessageDialog.openInformation(editor.getSite().getShell(), "Context Help: ", input.toString());
+ if (editor == null) {
+ IEditorPart targetEditor = window.getActivePage().getActiveEditor();
+ if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+ editor = (PHPEditor) targetEditor;
+ }
+ }
+ if (editor != null) {
+ editor.openContextHelp();
+ }
}
- /**
- * @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
- */
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
- this.editor = (TextEditor) targetEditor;
+ if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+ editor = (PHPEditor) targetEditor;
+ }
}
}
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
*/
import org.eclipse.jface.text.Region;
/**
- * Example implementation for an <code>ITextHover</code> which hovers over Java code.
+ * Example implementation for an <code>ITextHover</code>
+ * which hovers over PHP code.
*/
public class PHPTextHover implements ITextHover {
++position;
}
+ start++;
end = position;
if (end > start)