Configurable max note pages

This commit is contained in:
Manatsawin Hanmongkolchai
2019-10-03 22:38:01 +07:00
parent e938aab624
commit d552f94de7
3 changed files with 37 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.notes;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
@ConfigGroup("notes")
public interface NotesConfig extends Config
@@ -34,8 +35,6 @@ public interface NotesConfig extends Config
String CONFIG_GROUP = "notes";
String NOTES = "notes";
int MAX_NOTES = 5;
@ConfigItem(
keyName = "notesData",
name = "",
@@ -53,4 +52,18 @@ public interface NotesConfig extends Config
description = ""
)
void notesData(String str);
@Range(
min = 1,
max = 5
)
@ConfigItem(
keyName = "maxNotes",
name = "Max Notes",
description = "Desired maximum amount of notes"
)
default int maxNotes()
{
return 5;
}
}

View File

@@ -78,6 +78,12 @@ public class NotesManager
{
log.info("Adding tab for legacy note data");
notes.add(0, config.notesData());
if (notes.size() == 2 && notes.get(1).equals(""))
{
// remove the default empty note page
notes.remove(1);
}
}
}

View File

@@ -45,6 +45,7 @@ import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.ConfigChanged;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.plugins.notes.events.PageAdded;
import net.runelite.client.plugins.notes.events.PageDeleted;
@@ -69,11 +70,15 @@ class NotesPanel extends PluginPanel
private final ImageIcon addIcon = new ImageIcon(ImageUtil.getResourceStreamFromClass(getClass(), "add_icon.png"));
private MaterialTab addTab;
private List<MaterialTab> tabs = new ArrayList<>();
private NotesConfig config;
void init(final NotesConfig config)
void init(final NotesConfig mConfig)
{
config = mConfig;
eventBus.subscribe(PageAdded.class, this, this::onPageAdded);
eventBus.subscribe(PageDeleted.class, this, this::onPageDeleted);
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
// this may or may not qualify as a hack
// but this lets the editor pane expand to fill the whole parent panel
@@ -114,7 +119,7 @@ class NotesPanel extends PluginPanel
tabGroup.addTab(tab);
}
if (totalNotes < NotesConfig.MAX_NOTES)
if (totalNotes < config.maxNotes())
{
tabGroup.addTab(addTab);
}
@@ -129,6 +134,14 @@ class NotesPanel extends PluginPanel
repaint();
}
private void onConfigChanged(ConfigChanged e){
if(!e.getGroup().equals(NotesConfig.CONFIG_GROUP)){
return;
}
rebuild();
}
private void onPageAdded(PageAdded e)
{
MaterialTab tab = buildTab(e.getIndex());
@@ -137,7 +150,7 @@ class NotesPanel extends PluginPanel
// re-add add button to make it last
tabGroup.removeTab(addTab);
if (notesManager.getNotes().size() < NotesConfig.MAX_NOTES)
if (notesManager.getNotes().size() < config.maxNotes())
{
tabGroup.addTab(addTab);
}