From: scorphus Date: Mon, 3 Dec 2007 18:53:51 +0000 (+0000) Subject: Fixing some bugs and making the plug-in compatible with Java 1.4 X-Git-Url: http://secure.phpeclipse.com Fixing some bugs and making the plug-in compatible with Java 1.4 --- diff --git a/net.sourceforge.phpeclipse.phpmanual/.classpath b/net.sourceforge.phpeclipse.phpmanual/.classpath index 751c8f2..ce73933 100644 --- a/net.sourceforge.phpeclipse.phpmanual/.classpath +++ b/net.sourceforge.phpeclipse.phpmanual/.classpath @@ -1,7 +1,7 @@ - + diff --git a/net.sourceforge.phpeclipse.phpmanual/.settings/org.eclipse.jdt.core.prefs b/net.sourceforge.phpeclipse.phpmanual/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b6b84f5 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Sat Dec 01 16:45:06 BRST 2007 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 diff --git a/net.sourceforge.phpeclipse.phpmanual/.settings/org.eclipse.ltk.core.refactoring.prefs b/net.sourceforge.phpeclipse.phpmanual/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 0000000..a742315 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpmanual/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,3 @@ +#Sat Dec 01 16:29:29 BRST 2007 +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF index e8aa1da..8c995f0 100644 --- a/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF +++ b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF @@ -3,6 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: net.sourceforge.phpeclipse.phpmanual; singleton:=true Bundle-Version: 0.0.0 +Bundle-ClassPath: phpmanual.jar Bundle-Activator: net.sourceforge.phpeclipse.phpmanual.PHPManualUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin @@ -15,3 +16,4 @@ Require-Bundle: org.eclipse.core.runtime, net.sourceforge.phpeclipse.phphelp, net.sourceforge.phpeclipse.phpmanual.htmlparser Eclipse-LazyStart: true +Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/net.sourceforge.phpeclipse.phpmanual/build.properties b/net.sourceforge.phpeclipse.phpmanual/build.properties index 0d3d3a7..e856e13 100644 --- a/net.sourceforge.phpeclipse.phpmanual/build.properties +++ b/net.sourceforge.phpeclipse.phpmanual/build.properties @@ -1,6 +1,6 @@ -source.. = src/ -output.. = bin/ bin.includes = plugin.xml,\ META-INF/,\ - .,\ - icons/ + icons/,\ + phpmanual.jar +source.phpmanual.jar = src/ +output.phpmanual.jar = bin/ 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 index 09233d3..4089f0e 100644 --- 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 @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.regex.Matcher; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -29,6 +30,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.browser.Browser; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.INullSelectionListener; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart; @@ -57,7 +59,7 @@ import org.osgi.framework.Bundle; *

* @author scorphus */ -public class PHPManualView extends ViewPart implements ISelectionListener, ISelectionListenerWithAST { +public class PHPManualView extends ViewPart implements INullSelectionListener, ISelectionListenerWithAST { /** * The ViewPart's browser @@ -71,6 +73,11 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele private PHPEditor lastEditor; /** + * String that stores the last selected word + */ + private String lastOccurrence = null; + + /** * The path to the doc.zip file containing the PHP Manual * in HTML format */ @@ -95,7 +102,7 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele SelectionListenerWithASTManager.getDefault().addListener(lastEditor, this); } getSite().getWorkbenchWindow().getSelectionService() - .addSelectionListener(PHPeclipsePlugin.EDITOR_ID, this); + .addPostSelectionListener(PHPeclipsePlugin.EDITOR_ID, this); } /** @@ -103,7 +110,7 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele */ public void dispose() { getSite().getWorkbenchWindow().getSelectionService() - .removeSelectionListener(PHPeclipsePlugin.EDITOR_ID, this); + .removePostSelectionListener(PHPeclipsePlugin.EDITOR_ID, this); } /** @@ -120,12 +127,17 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele IDocument document = ((PHPEditor)part).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) { - e.printStackTrace(); + if (document != null && iRegion != null) { + try { + final String wordStr = document.get(iRegion.getOffset(), + iRegion.getLength()); + if (!wordStr.equalsIgnoreCase(lastOccurrence)) { + showReference(wordStr); + lastOccurrence = wordStr; + } + } catch (Exception e) { + e.printStackTrace(); + } } } @@ -134,9 +146,11 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele * instance of PHPEditor it gets a listener attached */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if (!((PHPEditor)part).equals(lastEditor)) { + if (part != null && !((PHPEditor)part).equals(lastEditor)) { SelectionListenerWithASTManager.getDefault().addListener((PHPEditor)part, this); lastEditor = (PHPEditor)part; + } else { + System.out.println(part); } } @@ -169,7 +183,7 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele try { Parser parser = new Parser(source); String [] tagsToBeFound = {"DIV"}; - ArrayList classList = new ArrayList(6); + ArrayList classList = new ArrayList(8); classList.add("refnamediv"); classList.add("refsect1 description"); classList.add("refsect1 parameters"); @@ -180,14 +194,14 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele TagFindingVisitor visitor = new TagFindingVisitor(tagsToBeFound); parser.visitAllNodesWith(visitor); Node [] allPTags = visitor.getTags(0); - StringBuilder output = new StringBuilder(); + StringBuffer output = new StringBuffer(); 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("—", "-"); + return output.toString().replaceAll("—", "-"); //.replace("

Description

", " "); } catch (ParserException e) { e.printStackTrace(); @@ -233,10 +247,38 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele } /** - * Looks for the function's reference page inside the doc.zip file - * and returns a filtered HTML source of it embedded in the template - * - * @param funcName Function name + * Replaces each substring of source string that matches the + * given pattern string with the given replace string + * + * @param source The source string + * @param pattern The pattern string + * @param replace The replace string + * @return The resulting String + */ + public static String replace(String source, String pattern, String replace) { + if (source != null) { + final int len = pattern.length(); + StringBuffer sb = new StringBuffer(); + int found = -1; + int start = 0; + while ((found = source.indexOf(pattern, start)) != -1) { + sb.append(source.substring(start, found)); + sb.append(replace); + start = found + len; + } + sb.append(source.substring(start)); + return sb.toString(); + } else { + return ""; + } + } + + /** + * Looks for the function's reference page inside the doc.zip file and + * returns a filtered HTML source of it embedded in the template + * + * @param funcName + * Function name * @return HTML source of reference page */ public String getHtmlSource(String funcName) { @@ -250,15 +292,17 @@ public class PHPManualView extends ViewPart implements ISelectionListener, ISele InputStream ref = docFile.getInputStream(entry); b = new byte[(int)entry.getSize()]; ref.read(b, 0, (int)entry.getSize()); + if (b != null) { + String reference = filterHtmlSource(new String(b)); + String refPageTpl = getRefPageTemplate(); + refPageTpl = refPageTpl.replaceAll("%title%", funcName); + refPageTpl = replace(refPageTpl, "%reference%", reference); + return refPageTpl; + } } 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; + } catch (Exception e) { + return null; } return ""; } diff --git a/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html b/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html index 67bf007..a59e66d 100644 --- a/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html +++ b/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html @@ -1,7 +1,7 @@ -{title} +%title% -{reference} +%reference% \ No newline at end of file