Add ability to import/export tag tabs with clipboard
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -28,6 +28,8 @@ package net.runelite.client.plugins.banktags;
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
@@ -104,6 +106,15 @@ public class TagManager
|
||||
return getTags(itemId).stream().anyMatch(tag -> tag.contains(Text.standardize(search)));
|
||||
}
|
||||
|
||||
public List<Integer> getItemsForTag(String tag)
|
||||
{
|
||||
final String prefix = CONFIG_GROUP + "." + ITEM_KEY_PREFIX;
|
||||
return configManager.getConfigurationKeys(prefix).stream()
|
||||
.map(item -> Integer.parseInt(item.replace(prefix, "")))
|
||||
.filter(item -> getTags(item).contains(tag))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void removeTag(String tag)
|
||||
{
|
||||
final String prefix = CONFIG_GROUP + "." + ITEM_KEY_PREFIX;
|
||||
|
||||
@@ -28,11 +28,19 @@ package net.runelite.client.plugins.banktags.tabs;
|
||||
import com.google.common.base.Strings;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
@@ -59,6 +67,7 @@ import net.runelite.api.vars.InputType;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetConfig;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ChatboxInputManager;
|
||||
@@ -81,6 +90,8 @@ public class TabInterface
|
||||
private static final String SCROLL_DOWN = "Scroll down";
|
||||
private static final String NEW_TAB = "New tag tab";
|
||||
private static final String REMOVE_TAB = "Delete tag tab";
|
||||
private static final String EXPORT_TAB = "Export tag tab";
|
||||
private static final String IMPORT_TAB = "Import tag tab";
|
||||
private static final String VIEW_TAB = "View tag tab";
|
||||
private static final String CHANGE_ICON = "Change icon";
|
||||
private static final String REMOVE_TAG = "Remove-tag";
|
||||
@@ -114,6 +125,7 @@ public class TabInterface
|
||||
private final TabManager tabManager;
|
||||
private final ChatboxInputManager chatboxInputManager;
|
||||
private final BankTagsConfig config;
|
||||
private final Notifier notifier;
|
||||
private final Rectangle bounds = new Rectangle();
|
||||
private final Rectangle canvasBounds = new Rectangle();
|
||||
|
||||
@@ -145,7 +157,8 @@ public class TabInterface
|
||||
final TagManager tagManager,
|
||||
final TabManager tabManager,
|
||||
final ChatboxInputManager chatboxInputManager,
|
||||
final BankTagsConfig config)
|
||||
final BankTagsConfig config,
|
||||
final Notifier notifier)
|
||||
{
|
||||
this.client = client;
|
||||
this.clientThread = clientThread;
|
||||
@@ -155,6 +168,7 @@ public class TabInterface
|
||||
this.tabManager = tabManager;
|
||||
this.chatboxInputManager = chatboxInputManager;
|
||||
this.config = config;
|
||||
this.notifier = notifier;
|
||||
}
|
||||
|
||||
public boolean isActive()
|
||||
@@ -191,6 +205,7 @@ public class TabInterface
|
||||
|
||||
newTab = createGraphic("", TabSprites.NEW_TAB.getSpriteId(), -1, TAB_WIDTH, 39, bounds.x, 0, true);
|
||||
newTab.setAction(1, NEW_TAB);
|
||||
newTab.setAction(2, IMPORT_TAB);
|
||||
|
||||
tabManager.clear();
|
||||
tabManager.getAllTabs().forEach(this::loadTab);
|
||||
@@ -525,6 +540,59 @@ public class TabInterface
|
||||
}
|
||||
});
|
||||
break;
|
||||
case EXPORT_TAB:
|
||||
event.consume();
|
||||
final List<String> data = new ArrayList<>();
|
||||
final TagTab tagTab = tabManager.find(Text.removeTags(event.getMenuTarget()));
|
||||
data.add(tagTab.getTag());
|
||||
data.add(String.valueOf(tagTab.getIconItemId()));
|
||||
|
||||
for (Integer item : tagManager.getItemsForTag(tagTab.getTag()))
|
||||
{
|
||||
data.add(String.valueOf(item));
|
||||
}
|
||||
|
||||
final StringSelection stringSelection = new StringSelection(BankTagsPlugin.JOINER.join(data));
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
|
||||
notifier.notify("Tag tab " + tagTab.getTag() + " has been copied to your clipboard!");
|
||||
break;
|
||||
case IMPORT_TAB:
|
||||
event.consume();
|
||||
|
||||
try
|
||||
{
|
||||
final String dataString = Toolkit
|
||||
.getDefaultToolkit()
|
||||
.getSystemClipboard()
|
||||
.getData(DataFlavor.stringFlavor)
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
final Iterator<String> dataIter = BankTagsPlugin.SPLITTER.split(dataString).iterator();
|
||||
final String name = dataIter.next();
|
||||
final String icon = dataIter.next();
|
||||
configManager.setConfiguration(CONFIG_GROUP, ICON_SEARCH + name, icon);
|
||||
|
||||
while (dataIter.hasNext())
|
||||
{
|
||||
tagManager.addTag(Integer.valueOf(dataIter.next()), name);
|
||||
}
|
||||
|
||||
loadTab(name);
|
||||
tabManager.save();
|
||||
scrollTab(0);
|
||||
|
||||
if (activeTab != null && name.equals(activeTab.getTag()))
|
||||
{
|
||||
openTag(TAG_SEARCH + activeTab.getTag());
|
||||
}
|
||||
|
||||
notifier.notify("Tag tab " + name + " has been imported from your clipboard!");
|
||||
}
|
||||
catch (UnsupportedFlavorException | NoSuchElementException | IOException | NumberFormatException ex)
|
||||
{
|
||||
notifier.notify("Failed to import tag tab from clipboard, invalid format.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -615,6 +683,7 @@ public class TabInterface
|
||||
btn.setAction(1, VIEW_TAB);
|
||||
btn.setAction(2, CHANGE_ICON);
|
||||
btn.setAction(3, REMOVE_TAB);
|
||||
btn.setAction(4, EXPORT_TAB);
|
||||
tagTab.setBackground(btn);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user