[autocomplete] 30/143: AutoComplete's description window now updates itself in response to a selection change after a small delay (120ms) instead of immediately, to help performance for language supports with slower descriptions (e.g. file IO). Provide a small hook into CompletionXMLPerser to allow use of custom Completion types. Hide completion popup window if it is visible and an invalid completion char is typed (such as space). Make "dumb complete word action" (shift+space) insert a space if caret isn't just after a string of letters.

Benjamin Mesing ben at alioth.debian.org
Sat Oct 19 12:53:12 UTC 2013


This is an automated email from the git hooks/post-receive script.

ben pushed a commit to branch master
in repository autocomplete.

commit d699b88ef551309812d9cdee781c9513bc560716
Author: bobbylight <robert at fifesoft.com>
Date:   Thu Apr 8 03:43:38 2010 +0000

    AutoComplete's description window now updates itself in response to a selection change after a small delay (120ms) instead of immediately, to help performance for language supports with slower descriptions (e.g. file IO).
    Provide a small hook into CompletionXMLPerser to allow use of custom Completion types.
    Hide completion popup window if it is visible and an invalid completion char is typed (such as space).
    Make "dumb complete word action" (shift+space) insert a space if caret isn't just after a string of letters.
---
 .../ui/autocomplete/AutoCompleteDescWindow.java    |   61 +++++++++++++++++++-
 src/org/fife/ui/autocomplete/AutoCompletion.java   |   18 +++++-
 .../fife/ui/autocomplete/CompletionXMLParser.java  |   51 +++++++++++++++-
 .../ui/autocomplete/DefaultCompletionProvider.java |    8 ++-
 4 files changed, 130 insertions(+), 8 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
index 1049b33..cd43e9e 100644
--- a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
@@ -47,6 +47,7 @@ import javax.swing.JScrollPane;
 import javax.swing.JToolBar;
 import javax.swing.JWindow;
 import javax.swing.SwingUtilities;
+import javax.swing.Timer;
 import javax.swing.UIManager;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
@@ -107,11 +108,32 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 	private int historyPos;
 
 	/**
+	 * Provides a slight delay between asking to set a description and actually
+	 * displaying it, so that if the user is scrolling quickly through
+	 * completions, those with slow-to-calculate summaries won't bog down the
+	 * scrolling.
+	 */
+	private Timer timer;
+
+	/**
+	 * The action that listens for the timer to fire.
+	 */
+	private TimerAction timerAction;
+
+	/**
 	 * The resource bundle for this window.
 	 */
 	private ResourceBundle bundle;
 
 	/**
+	 * The amount of time to wait after the user changes the selected
+	 * completion to refresh the description.  This delay is in place to help
+	 * performance for {@link Completion}s that may be slow to compute their
+	 * summary text.
+	 */
+	private static final int INITIAL_TIMER_DELAY			= 120;
+
+	/**
 	 * The resource bundle name.
 	 */
 	private static final String MSG =
@@ -162,6 +184,10 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 		history = new ArrayList(1); // Usually small
 		historyPos = -1;
 
+		timerAction = new TimerAction();
+		timer = new Timer(INITIAL_TIMER_DELAY, timerAction);
+		timer.setRepeats(false);
+
 	}
 
 
@@ -308,18 +334,27 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 	 *        (as opposed to clearing it and starting anew).
 	 */
 	protected void setDescriptionFor(Completion item, boolean addToHistory) {
-		String desc = item==null ? null : item.getSummary();
+		timer.stop();
+		timerAction.setCompletion(item, addToHistory);
+		timer.start();
+	}
+
+
+	private void setDisplayedDesc(String desc, boolean addToHistory) {
+
 		if (desc==null) {
 			desc = "<html><em>" + getString("NoDescAvailable") + "</em>";
 		}
 		descArea.setText(desc);
 		descArea.setCaretPosition(0); // In case of scrolling
+
 		if (!addToHistory) {
 			// Remove everything first if this is going to be the only
 			// thing in history.
 			clearHistory();
 		}
 		addToHistory(desc);
+
 	}
 
 
@@ -346,6 +381,30 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 
 
 	/**
+	 * Action that actually updates the summary text displayed.
+	 */
+	private class TimerAction extends AbstractAction {
+
+		private Completion completion;
+		private boolean addToHistory;
+
+		/**
+		 * Called when the timer is fired.
+		 */
+		public void actionPerformed(ActionEvent e) {
+			String desc = completion==null ? null : completion.getSummary();
+			setDisplayedDesc(desc, addToHistory);
+		}
+
+		public void setCompletion(Completion c, boolean addToHistory) {
+			this.completion = c;
+			this.addToHistory = addToHistory;
+		}
+
+	}
+
+
+	/**
 	 * Action that moves to the previous description displayed.
 	 */
 	class ToolBarBackAction extends AbstractAction {
diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java b/src/org/fife/ui/autocomplete/AutoCompletion.java
index 9aff77d..5a3663c 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -43,9 +43,9 @@ import javax.swing.text.*;
  *        (as seen in Eclipse and NetBeans).</li>
  *    <li>Parameter assistance.  If this is enabled, if the user enters a
  *        "parameterized" completion, such as a method or a function, then
- *        they will receive a tooltip describing the arguments they have to
+ *        they will receive a tool tip describing the arguments they have to
  *        enter to the completion.  Also, the arguments can be navigated via
- *        tab and shift+tab (ala Eclipse and NetBeans).</li>
+ *        tab and shift+tab (a la Eclipse and NetBeans).</li>
  * </ul>
  *
  * @author Robert Futrell
@@ -90,7 +90,7 @@ public class AutoCompletion implements HierarchyListener {
 	private Dimension preferredDescWindowSize;
 
 	/**
-	 * A "tooltip" describing a function just entered.
+	 * A "tool tip" describing a function just entered.
 	 */
 	private ParameterizedCompletionDescriptionToolTip descToolTip;
 
@@ -624,6 +624,18 @@ try {
 	 */
 	protected int refreshPopupWindow() {
 
+		// If the popup is currently visible, and they type a space (or any
+		// character that resets the completion list to "all completions"),
+		// the popup window should be hidden instead of being reset to show
+		// everything.
+		String text = provider.getAlreadyEnteredText(textComponent);
+		if (text==null || text.length()==0) {
+			if (isPopupVisible()) {
+				hidePopupWindow();
+				return getLineOfCaret();
+			}
+		}
+
 		final List completions = provider.getCompletions(textComponent);
 		int count = completions.size();
 
diff --git a/src/org/fife/ui/autocomplete/CompletionXMLParser.java b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
index c4631ad..abca3f0 100644
--- a/src/org/fife/ui/autocomplete/CompletionXMLParser.java
+++ b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
@@ -23,6 +23,7 @@
  */
 package org.fife.ui.autocomplete;
 
+import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.List;
 import org.xml.sax.Attributes;
@@ -30,7 +31,10 @@ import org.xml.sax.helpers.DefaultHandler;
 
 
 /**
- * Parser for an XML file describing a procedural language such as C.
+ * Parser for an XML file describing a procedural language such as C.<p>
+ *
+ * Error checking is minimal to non-existent; that will be handled via a
+ * schema in the future.
  *
  * @author Robert Futrell
  * @version 1.0
@@ -64,10 +68,18 @@ public class CompletionXMLParser extends DefaultHandler {
 	private boolean gettingParams;
 	private boolean inParam;
 	private boolean gettingParamDesc;
+	private boolean inCompletionTypes;
 	private char paramStartChar;
 	private char paramEndChar;
 	private String paramSeparator;
 
+	/**
+	 * If specified in the XML, this class will be used instead of
+	 * {@link FunctionCompletion} when appropriate.  This class should extend
+	 * <tt>FunctionCompletion</tt>, or stuff will break.
+	 */
+	private String funcCompletionType;
+
 
 	/**
 	 * Constructor.
@@ -104,8 +116,27 @@ public class CompletionXMLParser extends DefaultHandler {
 
 
 	private FunctionCompletion createFunctionCompletion() {
-		FunctionCompletion fc = new FunctionCompletion(provider,
-				name, returnType);
+
+		FunctionCompletion fc = null;
+		if (funcCompletionType!=null) {
+			try {
+				Class clazz = Class.forName(funcCompletionType);
+				Class[] paramTypes = { CompletionProvider.class,
+										String.class, String.class };
+				Constructor c = clazz.getDeclaredConstructor(paramTypes);
+				fc = (FunctionCompletion)c.newInstance(
+					new Object[] { provider, name, returnType });
+			} catch (RuntimeException re) { // FindBugs
+				throw re;
+			} catch (Exception e) {
+				throw new RuntimeException(
+					"Problem with custom FunctionCompletion: " + e.toString());
+			}
+		}
+		else {
+			fc = new FunctionCompletion(provider, name, returnType);
+		}
+
 		if (desc.length()>0) {
 			fc.setShortDescription(desc.toString());
 			desc.setLength(0);
@@ -205,6 +236,12 @@ public class CompletionXMLParser extends DefaultHandler {
 
 		}
 
+		else if (inCompletionTypes) {
+			if ("completionTypes".equals(qName)) {
+				inCompletionTypes = false;
+			}
+		}
+
 	}
 
 
@@ -310,6 +347,14 @@ public class CompletionXMLParser extends DefaultHandler {
 			paramSeparator = attrs.getValue("paramSeparator");
 			//paramTerminal = attrs.getValua("terminal");
 		}
+		else if ("completionTypes".equals(qName)) {
+			inCompletionTypes = true;
+		}
+		else if (inCompletionTypes) {
+			if ("functionCompletionType".equals(qName)) {
+				funcCompletionType = attrs.getValue("type");
+			}
+		}
 	}
 
 
diff --git a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
index 3f6e5e7..eaf6891 100644
--- a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
+++ b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
@@ -350,7 +350,13 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
 		ClassLoader cl = getClass().getClassLoader();
 		InputStream in = cl.getResourceAsStream(resource);
 		if (in==null) {
-			throw new IOException("No such resource: " + resource);
+			File file = new File(resource);
+			if (file.isFile()) {
+				in = new FileInputStream(file);
+			}
+			else {
+				throw new IOException("No such resource: " + resource);
+			}
 		}
 		BufferedInputStream bin = new BufferedInputStream(in);
 		try {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/autocomplete.git



More information about the pkg-java-commits mailing list