Merge pull request #10103 from dekvall/loottracker-confirm-reset

loottracker: add confirm dialog to reset all
This commit is contained in:
Adam
2019-10-22 15:43:05 -04:00
committed by GitHub

View File

@@ -40,6 +40,7 @@ import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.border.EmptyBorder;
@@ -74,6 +75,10 @@ class LootTrackerPanel extends PluginPanel
private static final String HTML_LABEL_TEMPLATE =
"<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>";
private static final String SYNC_RESET_ALL_WARNING_TEXT =
"This will permanently delete the current loot from both the client and the RuneLite website.";
private static final String NO_SYNC_RESET_ALL_WARNING_TEXT =
"This will permanently delete the current loot from the client.";
// When there is no loot, display this
private final PluginErrorPanel errorPanel = new PluginErrorPanel();
@@ -312,6 +317,18 @@ class LootTrackerPanel extends PluginPanel
final JMenuItem reset = new JMenuItem("Reset All");
reset.addActionListener(e ->
{
final LootTrackerClient client = plugin.getLootTrackerClient();
final boolean syncLoot = client != null && config.syncPanel();
final int result = JOptionPane.showOptionDialog(overallPanel,
syncLoot ? SYNC_RESET_ALL_WARNING_TEXT : NO_SYNC_RESET_ALL_WARNING_TEXT,
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
null, new String[]{"Yes", "No"}, "No");
if (result != JOptionPane.YES_OPTION)
{
return;
}
// If not in detailed view, remove all, otherwise only remove for the currently detailed title
records.removeIf(r -> r.matches(currentView));
boxes.removeIf(b -> b.matches(currentView));
@@ -320,8 +337,7 @@ class LootTrackerPanel extends PluginPanel
logsContainer.repaint();
// Delete all loot, or loot matching the current view
LootTrackerClient client = plugin.getLootTrackerClient();
if (client != null && config.syncPanel())
if (syncLoot)
{
client.delete(currentView);
}