Merge pull request #11183 from DSerp/quest-filter-fix

quest list: stop chat input from closing when pressing enter
This commit is contained in:
Abex
2020-04-27 15:52:47 -06:00
committed by GitHub
6 changed files with 26 additions and 7 deletions

View File

@@ -106,7 +106,7 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
private Runnable onClose = null;
@Getter
private Consumer<String> onDone = null;
private Predicate<String> onDone = null;
@Getter
private Consumer<String> onChanged = null;
@@ -235,6 +235,20 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
}
public ChatboxTextInput onDone(Consumer<String> onDone)
{
this.onDone = (s) ->
{
onDone.accept(s);
return true;
};
return this;
}
/**
* Called when the user attempts to close the input by pressing enter
* Return false to cancel the close
*/
public ChatboxTextInput onDone(Predicate<String> onDone)
{
this.onDone = onDone;
return this;
@@ -753,9 +767,9 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
break;
case KeyEvent.VK_ENTER:
ev.consume();
if (onDone != null)
if (onDone != null && !onDone.test(getValue()))
{
onDone.accept(getValue());
return;
}
chatboxPanelManager.close();
return;

View File

@@ -37,6 +37,7 @@ import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.inject.Inject;
@@ -407,7 +408,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
chatboxPanelManager.openTextInput(name + " tags:<br>(append " + VAR_TAG_SUFFIX + " for variation tag)")
.addCharValidator(FILTERED_CHARS)
.value(initialValue)
.onDone((newValue) ->
.onDone((Consumer<String>) (newValue) ->
clientThread.invoke(() ->
{
// Split inputted tags to vartags (ending with *) and regular tags

View File

@@ -45,6 +45,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;
import javax.inject.Inject;
@@ -268,7 +269,7 @@ public class TabInterface
chatboxPanelManager.openTextInput((inventory ? "Inventory " : "Equipment ") + " tags:")
.addCharValidator(FILTERED_CHARS)
.onDone((newTags) ->
.onDone((Consumer<String>) (newTags) ->
clientThread.invoke(() ->
{
final List<String> tags = Text.fromCSV(newTags.toLowerCase());
@@ -290,7 +291,7 @@ public class TabInterface
case NewTab.NEW_TAB:
chatboxPanelManager.openTextInput("Tag name")
.addCharValidator(FILTERED_CHARS)
.onDone((tagName) -> clientThread.invoke(() ->
.onDone((Consumer<String>) (tagName) -> clientThread.invoke(() ->
{
if (!Strings.isNullOrEmpty(tagName))
{
@@ -908,7 +909,7 @@ public class TabInterface
{
chatboxPanelManager.openTextInput("Enter new tag name for tag \"" + oldTag + "\":")
.addCharValidator(FILTERED_CHARS)
.onDone((newTag) -> clientThread.invoke(() ->
.onDone((Consumer<String>) (newTag) -> clientThread.invoke(() ->
{
if (!Strings.isNullOrEmpty(newTag) && !newTag.equalsIgnoreCase(oldTag))
{

View File

@@ -196,6 +196,7 @@ public class FairyRingPlugin extends Plugin
searchBtn.setOnOpListener((JavaScriptCallback) this::menuClose);
searchInput = chatboxPanelManager.openTextInput("Filter fairy rings")
.onChanged(s -> clientThread.invokeLater(() -> updateFilter(s)))
.onDone(s -> false)
.onClose(() ->
{
clientThread.invokeLater(() -> updateFilter(""));

View File

@@ -321,6 +321,7 @@ public class MusicPlugin extends Plugin
musicSearchButton.setOnOpListener((JavaScriptCallback) e -> closeSearch());
searchInput = chatboxPanelManager.openTextInput("Search music list")
.onChanged(s -> clientThread.invokeLater(() -> updateFilter(s.trim())))
.onDone(s -> false)
.onClose(() ->
{
clientThread.invokeLater(() -> updateFilter(""));

View File

@@ -233,6 +233,7 @@ public class QuestListPlugin extends Plugin
questSearchButton.setOnOpListener((JavaScriptCallback) e -> closeSearch());
searchInput = chatboxPanelManager.openTextInput("Search quest list")
.onChanged(s -> clientThread.invokeLater(() -> updateFilter(s)))
.onDone(s -> false)
.onClose(() ->
{
clientThread.invokeLater(() -> updateFilter(""));