config: Expand panels on search and restore state when search query i… (#2206)
* config: Expand panels on search and restore state when search query is empty * Update PluginListItem.java Co-authored-by: Kyle <48519776+xKylee@users.noreply.github.com>
This commit is contained in:
@@ -40,7 +40,6 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.plugins.PluginType;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
@@ -48,7 +47,6 @@ import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
import org.apache.commons.text.similarity.JaroWinklerDistance;
|
||||
|
||||
@Slf4j
|
||||
public class PluginListItem extends JPanel
|
||||
{
|
||||
private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance();
|
||||
@@ -195,7 +193,6 @@ public class PluginListItem extends JPanel
|
||||
}
|
||||
|
||||
this.color = color;
|
||||
log.info("{}, updated to {}", nameLabel.getText(), color);
|
||||
this.nameLabel.setForeground(color);
|
||||
}
|
||||
|
||||
@@ -254,4 +251,4 @@ public class PluginListItem extends JPanel
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@@ -337,8 +338,22 @@ public class PluginListPanel extends PluginPanel
|
||||
}
|
||||
|
||||
sections.get(sectionName).add(pluginListItem);
|
||||
|
||||
}
|
||||
|
||||
sections.forEach((key, value) ->
|
||||
{
|
||||
Container parent = value.getParent();
|
||||
JToggleButton collapseButton = (JToggleButton) ((JPanel) parent.getComponent(0)).getComponent(0);
|
||||
|
||||
if (searchBar.getText().equals(""))
|
||||
{
|
||||
resetSection(key, collapseButton, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
forceExpandSection(collapseButton, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMatchingPlugins(boolean pinned, String text)
|
||||
@@ -527,10 +542,10 @@ public class PluginListPanel extends PluginPanel
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
toggleSection("pluginlist", name, collapse, sectionContents);
|
||||
toggleSection(name, collapse, sectionContents);
|
||||
}
|
||||
};
|
||||
collapse.addActionListener(e -> toggleSection("pluginlist", name, collapse, sectionContents));
|
||||
collapse.addActionListener(e -> toggleSection(name, collapse, sectionContents));
|
||||
headerLabel.addMouseListener(adapter);
|
||||
|
||||
// Allow for sub-sections
|
||||
@@ -540,13 +555,45 @@ public class PluginListPanel extends PluginPanel
|
||||
return sectionContents;
|
||||
}
|
||||
|
||||
private void toggleSection(String group, String key, JToggleButton button, JPanel contents)
|
||||
private void toggleSection(String key, JToggleButton button, JPanel contents)
|
||||
{
|
||||
if (!button.isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newState = !contents.isVisible();
|
||||
button.setSelected(newState);
|
||||
contents.setVisible(newState);
|
||||
configManager.setConfiguration(group, key, newState);
|
||||
button.setToolTipText(newState ? "Retract" : "Expand");
|
||||
contents.setVisible(newState);
|
||||
configManager.setConfiguration("pluginlist", key, newState);
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
contents.revalidate();
|
||||
contents.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
private void forceExpandSection(JToggleButton button, JPanel contents)
|
||||
{
|
||||
button.setSelected(true);
|
||||
button.setToolTipText(null);
|
||||
button.setEnabled(false);
|
||||
contents.setVisible(true);
|
||||
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
contents.revalidate();
|
||||
contents.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
private void resetSection(String key, JToggleButton button, JPanel contents)
|
||||
{
|
||||
boolean newState = Boolean.parseBoolean(configManager.getConfiguration("pluginlist", key));
|
||||
button.setSelected(newState);
|
||||
button.setToolTipText(newState ? "Retract" : "Expand");
|
||||
contents.setVisible(newState);
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
contents.revalidate();
|
||||
|
||||
Reference in New Issue
Block a user