mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Make it so Advanced Search filter automatically prompts to select a filter if no filters defined already
Prevent crash when clearing a filter
This commit is contained in:
@@ -2,6 +2,8 @@ package forge.itemmanager.filters;
|
|||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
import forge.UiCommand;
|
import forge.UiCommand;
|
||||||
@@ -26,6 +28,7 @@ import org.apache.commons.lang3.ArrayUtils;
|
|||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
|
||||||
public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T> {
|
public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T> {
|
||||||
@@ -171,6 +174,15 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
|||||||
|
|
||||||
private boolean show() {
|
private boolean show() {
|
||||||
optionPane = new FOptionPane(null, "Advanced Search", null, scroller, ImmutableList.of("OK", "Cancel"), 0);
|
optionPane = new FOptionPane(null, "Advanced Search", null, scroller, ImmutableList.of("OK", "Cancel"), 0);
|
||||||
|
optionPane.addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentShown(ComponentEvent e) {
|
||||||
|
//automatically edit first filter if search is empty
|
||||||
|
if (model.isEmpty()) {
|
||||||
|
model.editFilterControl(Iterables.getFirst(model.getControls(), null), onFilterChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
scroller.revalidate();
|
scroller.revalidate();
|
||||||
scroller.repaint();
|
scroller.repaint();
|
||||||
optionPane.setVisible(true);
|
optionPane.setVisible(true);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package forge.itemmanager.filters;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.assets.FSkinImage;
|
import forge.assets.FSkinImage;
|
||||||
@@ -181,6 +182,16 @@ public class AdvancedSearchFilter<T extends InventoryItem> extends ItemFilter<T>
|
|||||||
scroller.add(filter);
|
scroller.add(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivate() {
|
||||||
|
super.onActivate();
|
||||||
|
|
||||||
|
//automatically edit first filter if search is empty
|
||||||
|
if (model.isEmpty()) {
|
||||||
|
model.editFilterControl(Iterables.getFirst(model.getControls(), null), onFilterChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose(Callback<Boolean> canCloseCallback) {
|
public void onClose(Callback<Boolean> canCloseCallback) {
|
||||||
onFilterChange.run();
|
onFilterChange.run();
|
||||||
|
|||||||
@@ -1063,17 +1063,18 @@ public class AdvancedSearch {
|
|||||||
control.setFilter(filter);
|
control.setFilter(filter);
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
control.getBtnFilter().setText(GuiBase.getInterface().encodeSymbols(filter.toString(), false));
|
control.getBtnFilter().setText(GuiBase.getInterface().encodeSymbols(filter.toString(), false));
|
||||||
|
|
||||||
|
if (filter.getOption() == FilterOption.CARD_KEYWORDS) {
|
||||||
|
//the first time the user selects keywords, preload keywords for all cards
|
||||||
|
Runnable preloadTask = Keyword.getPreloadTask();
|
||||||
|
if (preloadTask != null) {
|
||||||
|
GuiBase.getInterface().runBackgroundTask("Loading keywords...", preloadTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
control.getBtnFilter().setText(EMPTY_FILTER_TEXT);
|
control.getBtnFilter().setText(EMPTY_FILTER_TEXT);
|
||||||
}
|
}
|
||||||
if (filter.getOption() == FilterOption.CARD_KEYWORDS) {
|
|
||||||
//the first time the user selects keywords, preload keywords for all cards
|
|
||||||
Runnable preloadTask = Keyword.getPreloadTask();
|
|
||||||
if (preloadTask != null) {
|
|
||||||
GuiBase.getInterface().runBackgroundTask("Loading keywords...", preloadTask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (onChange != null) {
|
if (onChange != null) {
|
||||||
onChange.run();
|
onChange.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user