Skip to content

Commit

Permalink
v0.8.4b4, fix error on Completion
Browse files Browse the repository at this point in the history
  • Loading branch information
tduva committed Sep 3, 2016
1 parent 0bda41b commit 484763f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/chatty/Chatty.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Chatty {
* by points. May contain a single "b" for beta versions, anything following
* it will be ignored for version checking.
*/
public static final String VERSION = "0.8.4b3";
public static final String VERSION = "0.8.4b4";

/**
* Enable Version Checker (if you compile and distribute this yourself, you
Expand Down
9 changes: 5 additions & 4 deletions src/chatty/gui/components/AutoCompletion.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ else if (items.size() > 1 && prevCompletion == null && showPopup
textField.setCaretPosition(newEnd);

if (showPopup) {
// Will only do something if more than one item was found
// Will only do something if more than one item was found or item
// info has to be displayed
showCompletionInfo(index, prevCompletion == null,
results, commonPrefix);
}
Expand Down Expand Up @@ -409,7 +410,7 @@ private void showCompletionInfo(final int index,
final List<String> items = results.items;
final int size = items.size();
// Don't show info popup if there is only one entry and no info for it
if (size == 1 && !results.info.containsKey(items.get(0))) {
if (size == 1 && !results.hasInfo(items.get(0))) {
return;
}
/**
Expand Down Expand Up @@ -510,8 +511,8 @@ private int addNames(StringBuilder b, int index, int maxShown,
b.append(item);
}
}
if (results.info != null && results.info.containsKey(item)) {
b.append(" <span style='color:#555555'>(").append(results.info.get(item)).append(")</span>");
if (results.hasInfo(item)) {
b.append(" <span style='color:#555555'>(").append(results.getInfo(item)).append(")</span>");
}
b.append("</span><br />");
}
Expand Down
33 changes: 33 additions & 0 deletions src/chatty/gui/components/AutoCompletionServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public CompletionItems getCompletionItems(String type, String prefix,
public static class CompletionItems {

public final List<String> items;

/**
* Can store info on certain items. The key is an item that may or may
* not be in the list of matched items. The key is the value that can be
* used for display.
*
* This may be null. The methods {@link hasInfo(String) hasInfo()} and
* {@link getInfo(String) getInfo()} can be used for more convenience.
*/
public final Map<String, String> info;
public final String prefixToRemove;

Expand All @@ -59,6 +68,7 @@ public static class CompletionItems {
* actually matter. It must not be longer than the actual prefix was.
*
* @param items
* @param info
* @param prefixToRemove
*/
public CompletionItems(List<String> items, Map<String, String> info, String prefixToRemove) {
Expand All @@ -79,6 +89,29 @@ public CompletionItems() {
this.prefixToRemove = "";
this.info = null;
}

/**
* Checks if there is an info String for the given item.
*
* @param item The item, usually a match result
* @return true if there is an info for the given item, false otherwise
*/
public boolean hasInfo(String item) {
return info != null && info.containsKey(item);
}

/**
* Returns the info for the given item.
*
* @param item The item, usually a match result
* @return The info, or null if no info is set
*/
public String getInfo(String item) {
if (info == null) {
return null;
}
return info.get(item);
}
}
}

2 changes: 1 addition & 1 deletion src/chatty/gui/components/help/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1><a name="top">Chatty (Version: 0.8.4b3)</a></h1>
<h1><a name="top">Chatty (Version: 0.8.4b4)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down

0 comments on commit 484763f

Please sign in to comment.