From cd2b9c5457a204321573e8d71b7adbc45adff4c8 Mon Sep 17 00:00:00 2001 From: scorphus Date: Tue, 20 Nov 2007 01:53:37 +0000 Subject: [PATCH] Initial import of the phpmanual plugin --- net.sourceforge.phpeclipse.phpmanual/.classpath | 7 + net.sourceforge.phpeclipse.phpmanual/.project | 28 ++ .../META-INF/MANIFEST.MF | 17 + .../build.properties | 6 + .../icons/phpmanual.png | Bin 0 -> 754 bytes .../plugin.properties | 7 + net.sourceforge.phpeclipse.phpmanual/plugin.xml | 32 ++ .../phpeclipse/phpmanual/PHPManualUIPlugin.java | 61 ++++ .../phpeclipse/phpmanual/views/PHPManualView.java | 319 ++++++++++++++++++++ .../templates/refpage.html | 24 ++ 10 files changed, 501 insertions(+), 0 deletions(-) create mode 100644 net.sourceforge.phpeclipse.phpmanual/.classpath create mode 100644 net.sourceforge.phpeclipse.phpmanual/.project create mode 100644 net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF create mode 100644 net.sourceforge.phpeclipse.phpmanual/build.properties create mode 100644 net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png create mode 100644 net.sourceforge.phpeclipse.phpmanual/plugin.properties create mode 100644 net.sourceforge.phpeclipse.phpmanual/plugin.xml create mode 100644 net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java create mode 100644 net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java create mode 100644 net.sourceforge.phpeclipse.phpmanual/templates/refpage.html diff --git a/net.sourceforge.phpeclipse.phpmanual/.classpath b/net.sourceforge.phpeclipse.phpmanual/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/net.sourceforge.phpeclipse.phpmanual/.project b/net.sourceforge.phpeclipse.phpmanual/.project new file mode 100644 index 0000000..6c598df --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/.project @@ -0,0 +1,28 @@ + + + net.sourceforge.phpeclipse.phpmanual + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e8aa1da --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: net.sourceforge.phpeclipse.phpmanual; singleton:=true +Bundle-Version: 0.0.0 +Bundle-Activator: net.sourceforge.phpeclipse.phpmanual.PHPManualUIPlugin +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.jface.text, + org.eclipse.ui, + org.eclipse.ui.editors, + org.eclipse.ui.workbench.texteditor, + net.sourceforge.phpeclipse, + net.sourceforge.phpeclipse.phphelp, + net.sourceforge.phpeclipse.phpmanual.htmlparser +Eclipse-LazyStart: true diff --git a/net.sourceforge.phpeclipse.phpmanual/build.properties b/net.sourceforge.phpeclipse.phpmanual/build.properties new file mode 100644 index 0000000..0d3d3a7 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/ diff --git a/net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png b/net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png new file mode 100644 index 0000000000000000000000000000000000000000..9159c3db7c79df4300cd97f15d61c98000624bf6 GIT binary patch literal 754 zcmV)9@v&9Ez&3uPh{qe-9!mOcijbE1QK+WgiPI77hQ#6 zH{neL1wqnb(#g8$Ky=};lc(^I8}rbdI`iB1&94h}E|KUD54^|U^XGZrM_^kvAP126 zx8{IpV14ICsj8}>SS%LTG)>1nwq^S!0DyX?1iEtM}2VdH>#=u zpeQmKW`*1wBm3>?l$90|4F004tLtWCW8)2ATB@!&KLK1+6w~3Aa0HXlz|||YeEc*; zB%%>sjS`q$Wn?T!U%!uRi~tT2w=@K6JKAa=k+K9Lw@S(j!<4^N0#MEF>`MkIoav7-+ISlXpNI63K{zB=ke1o z94N@daWISf5Bm7}EkH?$4S<(DBZWiJw&4#hE$p3 zl?9ZR*y!#1xp7Mn5&+p|H8VN2$l#El=P!n_SWL{#hcOvbF&Jcui*gwl^6~1;C{G@B z0&vK&54Zcn24MWh!esxTuOJXu0bnH@0U#WX&_Cc~cw~-=$sq6F-a}Dj?%ru9E6a$- z;{j+8$Ho^Net)Pg6bd}FSn$xUI&gcZ1AP;=O-_0;K@f1e-N|P=<)q1aJRV<@BuUw7l-;yxUw1m4F(96t k&A!>r;y=pKu*0qA4_vG-sA#D%?f?J)07*qoM6N<$f{oEn0RR91 literal 0 HcmV?d00001 diff --git a/net.sourceforge.phpeclipse.phpmanual/plugin.properties b/net.sourceforge.phpeclipse.phpmanual/plugin.properties new file mode 100644 index 0000000..84f29a9 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/plugin.properties @@ -0,0 +1,7 @@ +######################################### +# +######################################### +pluginName=PHP Manual +providerName=PHPEclipse project team +viewCategoryName=PHPeclipse Web Development +phpManualViewName=PHP Manual diff --git a/net.sourceforge.phpeclipse.phpmanual/plugin.xml b/net.sourceforge.phpeclipse.phpmanual/plugin.xml new file mode 100644 index 0000000..526f24f --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java b/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java new file mode 100644 index 0000000..81e4e8b --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java @@ -0,0 +1,61 @@ +package net.sourceforge.phpeclipse.phpmanual; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class PHPManualUIPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phpmanual"; + + // The shared instance + private static PHPManualUIPlugin plugin; + + /** + * The constructor + */ + public PHPManualUIPlugin() { + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static PHPManualUIPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java b/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java new file mode 100644 index 0000000..fe2cace --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java @@ -0,0 +1,319 @@ +package net.sourceforge.phpeclipse.phpmanual.views; + + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import net.sourceforge.phpdt.internal.ui.text.JavaWordFinder; +import net.sourceforge.phpdt.internal.ui.viewsupport.ISelectionListenerWithAST; +import net.sourceforge.phpdt.internal.ui.viewsupport.SelectionListenerWithASTManager; +import net.sourceforge.phpdt.phphelp.PHPHelpPlugin; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.PHPEditor; +import net.sourceforge.phpeclipse.phpmanual.PHPManualUIPlugin; + +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; +import org.htmlparser.Node; +import org.htmlparser.Parser; +import org.htmlparser.tags.Div; +import org.htmlparser.util.ParserException; +import org.htmlparser.visitors.TagFindingVisitor; +import org.osgi.framework.Bundle; + +/** + * This sample class demonstrates how to plug-in a new + * workbench view. The view shows data obtained from the + * model. The sample creates a dummy model on the fly, + * but a real implementation would connect to the model + * available either in this or another plug-in (e.g. the workspace). + * The view is connected to the model using a content provider. + *

+ * The view uses a label provider to define how model + * objects should be presented in the view. Each + * view can present the same model objects using + * different labels and icons, if needed. Alternatively, + * a single label provider can be shared between views + * in order to ensure that objects of the same type are + * presented in the same way everywhere. + *

+ */ + +public class PHPManualView extends ViewPart implements ISelectionListenerWithAST { + private Browser browser; + private Action action1; + private Action action2; + private PHPEditor phpEditor; + private final Path docPath = new Path("doc.zip"); + + /** + * The constructor. + */ + public PHPManualView() { + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + browser = new Browser(parent, SWT.NONE); + parent.pack(); + phpEditor = getJavaEditor(); + makeActions(); + hookContextMenu(); + SelectionListenerWithASTManager.getDefault().addListener(phpEditor, this); + if (phpEditor.getSelectionProvider() != null) { + ISelection its = phpEditor.getSelectionProvider().getSelection(); + SelectionListenerWithASTManager.getDefault().forceSelectionChange( + phpEditor, (ITextSelection) its); + } + } + + /* (non-Javadoc) + * @see net.sourceforge.phpdt.internal.ui.viewsupport.ISelectionListenerWithAST#selectionChanged() + */ + public void selectionChanged(IEditorPart part, ITextSelection selection) { + if (getJavaEditor() != null) { + phpEditor = getJavaEditor(); + } + IDocument document = phpEditor.getViewer().getDocument(); + int offset = selection.getOffset(); + IRegion iRegion = JavaWordFinder.findWord(document, offset); + try { + final String wordStr = document.get(iRegion.getOffset(), + iRegion.getLength()); + showReference(wordStr); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void showReference(final String occurrence) { + System.out.println("Show reference for " + occurrence); + new Thread(new Runnable() { + public void run() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + String html = getHtmlSource(occurrence); + browser.setText(html); + } + }); + } + }).start(); + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + PHPManualView.this.fillContextMenu(manager); + } + }); +// Menu menu = menuMgr.createContextMenu(viewer.getControl()); +// viewer.getControl().setMenu(menu); +// getSite().registerContextMenu(menuMgr, viewer); + } + + private void fillContextMenu(IMenuManager manager) { + manager.add(action1); + manager.add(action2); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void makeActions() { + action1 = new Action() { + public void run() { + showMessage("Action 1 executed"); + } + }; + action1.setText("Action 1"); + action1.setToolTipText("Action 1 tooltip"); + action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + + action2 = new Action() { + public void run() { + showMessage("Action 2 executed"); + } + }; + action2.setText("Action 2"); + action2.setToolTipText("Action 2 tooltip"); + action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + } + + private void showMessage(String message) { +// MessageDialog.openInformation( +// viewer.getControl().getShell(), +// "%phpManualView", +// message); + } + + /** + * Looks for the function's reference page inside the doc.zip file and + * returns a filtered HTML source of it + * @param funcName Function name + * @return HTML source of reference page + */ + private String filterHtmlSource(String source) { + try { + Parser parser = new Parser(source); + String [] tagsToBeFound = {"DIV"}; + ArrayList classList = new ArrayList(6); + classList.add("refnamediv"); + classList.add("refsect1 description"); + classList.add("refsect1 parameters"); + classList.add("refsect1 returnvalues"); + classList.add("refsect1 examples"); + classList.add("refsect1 seealso"); + classList.add("refsect1 u"); + TagFindingVisitor visitor = new TagFindingVisitor(tagsToBeFound); + parser.visitAllNodesWith(visitor); + Node [] allPTags = visitor.getTags(0); + StringBuilder output = new StringBuilder(); + for (int i = 0; i < allPTags.length; i++) { + String tagClass = ((Div)allPTags[i]).getAttribute("class"); + if (classList.contains(tagClass)) { + output.append(allPTags[i].toHtml()); + } + } + return output.toString().replace("—", "-"); + //.replace("

Description

", " "); + } catch (ParserException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ""; + } + + /** + * Looks for the function's reference page inside the doc.zip file and + * returns a filtered HTML source of it + * @param funcName Function name + * @return HTML source of reference page + */ + public String getRefPageTemplate() { + Bundle bundle = Platform.getBundle(PHPManualUIPlugin.PLUGIN_ID); + URL fileURL = Platform.find(bundle, new Path("templates")); + StringBuffer contents = new StringBuffer(); + BufferedReader input = null; + try { + URL resolve = Platform.resolve(fileURL); + input = new BufferedReader(new FileReader(resolve.getPath()+"/refpage.html")); + String line = null; + while ((line = input.readLine()) != null){ + contents.append(line); + } + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + finally { + try { + if (input!= null) { + input.close(); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + return contents.toString(); + } + + /** + * Looks for the function's reference page inside the doc.zip file and + * returns a filtered HTML source of it + * @param funcName Function name + * @return HTML source of reference page + */ + public String getHtmlSource(String funcName) { + Bundle bundle = Platform.getBundle(PHPHelpPlugin.PLUGIN_ID); + URL fileURL = Platform.find(bundle, docPath); + byte[] b = null; + try { + URL resolve = Platform.resolve(fileURL); + ZipFile docFile = new ZipFile(resolve.getPath()); + ZipEntry entry = docFile.getEntry("doc/function."+funcName.replace('_', '-')+".html"); + InputStream ref = docFile.getInputStream(entry); + b = new byte[(int)entry.getSize()]; + ref.read(b, 0, (int)entry.getSize()); + } catch (IOException e) { + return ""; + } + if (b != null) { + String reference = filterHtmlSource(new String(b)); + String refPageTpl = getRefPageTemplate(); + refPageTpl = refPageTpl.replace("{title}", funcName); + refPageTpl = refPageTpl.replace("{reference}", reference); + return refPageTpl; + } + return ""; + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { +// viewer.getControl().setFocus(); + } + + /** + * Returns the currently active java editor, or null if it + * cannot be determined. + * + * @return the currently active java editor, or null + */ + private PHPEditor getJavaEditor() { + try { + IEditorPart part = PHPeclipsePlugin.getActivePage().getActiveEditor(); + if (part instanceof PHPEditor) + return (PHPEditor) part; + else + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html b/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html new file mode 100644 index 0000000..67bf007 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html @@ -0,0 +1,24 @@ + + + +{title} + + + + +{reference} + + \ No newline at end of file -- 1.7.1