Configurable max note pages
This commit is contained in:
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.notes;
|
|||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
import net.runelite.client.config.Range;
|
||||||
|
|
||||||
@ConfigGroup("notes")
|
@ConfigGroup("notes")
|
||||||
public interface NotesConfig extends Config
|
public interface NotesConfig extends Config
|
||||||
@@ -34,8 +35,6 @@ public interface NotesConfig extends Config
|
|||||||
String CONFIG_GROUP = "notes";
|
String CONFIG_GROUP = "notes";
|
||||||
String NOTES = "notes";
|
String NOTES = "notes";
|
||||||
|
|
||||||
int MAX_NOTES = 5;
|
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "notesData",
|
keyName = "notesData",
|
||||||
name = "",
|
name = "",
|
||||||
@@ -53,4 +52,18 @@ public interface NotesConfig extends Config
|
|||||||
description = ""
|
description = ""
|
||||||
)
|
)
|
||||||
void notesData(String str);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ public class NotesManager
|
|||||||
{
|
{
|
||||||
log.info("Adding tab for legacy note data");
|
log.info("Adding tab for legacy note data");
|
||||||
notes.add(0, config.notesData());
|
notes.add(0, config.notesData());
|
||||||
|
|
||||||
|
if (notes.size() == 2 && notes.get(1).equals(""))
|
||||||
|
{
|
||||||
|
// remove the default empty note page
|
||||||
|
notes.remove(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import javax.swing.JPopupMenu;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.client.eventbus.EventBus;
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.plugins.notes.events.PageAdded;
|
import net.runelite.client.plugins.notes.events.PageAdded;
|
||||||
import net.runelite.client.plugins.notes.events.PageDeleted;
|
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 final ImageIcon addIcon = new ImageIcon(ImageUtil.getResourceStreamFromClass(getClass(), "add_icon.png"));
|
||||||
private MaterialTab addTab;
|
private MaterialTab addTab;
|
||||||
private List<MaterialTab> tabs = new ArrayList<>();
|
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(PageAdded.class, this, this::onPageAdded);
|
||||||
eventBus.subscribe(PageDeleted.class, this, this::onPageDeleted);
|
eventBus.subscribe(PageDeleted.class, this, this::onPageDeleted);
|
||||||
|
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
|
||||||
|
|
||||||
// this may or may not qualify as a hack
|
// this may or may not qualify as a hack
|
||||||
// but this lets the editor pane expand to fill the whole parent panel
|
// but this lets the editor pane expand to fill the whole parent panel
|
||||||
@@ -114,7 +119,7 @@ class NotesPanel extends PluginPanel
|
|||||||
tabGroup.addTab(tab);
|
tabGroup.addTab(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalNotes < NotesConfig.MAX_NOTES)
|
if (totalNotes < config.maxNotes())
|
||||||
{
|
{
|
||||||
tabGroup.addTab(addTab);
|
tabGroup.addTab(addTab);
|
||||||
}
|
}
|
||||||
@@ -129,6 +134,14 @@ class NotesPanel extends PluginPanel
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onConfigChanged(ConfigChanged e){
|
||||||
|
if(!e.getGroup().equals(NotesConfig.CONFIG_GROUP)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
private void onPageAdded(PageAdded e)
|
private void onPageAdded(PageAdded e)
|
||||||
{
|
{
|
||||||
MaterialTab tab = buildTab(e.getIndex());
|
MaterialTab tab = buildTab(e.getIndex());
|
||||||
@@ -137,7 +150,7 @@ class NotesPanel extends PluginPanel
|
|||||||
|
|
||||||
// re-add add button to make it last
|
// re-add add button to make it last
|
||||||
tabGroup.removeTab(addTab);
|
tabGroup.removeTab(addTab);
|
||||||
if (notesManager.getNotes().size() < NotesConfig.MAX_NOTES)
|
if (notesManager.getNotes().size() < config.maxNotes())
|
||||||
{
|
{
|
||||||
tabGroup.addTab(addTab);
|
tabGroup.addTab(addTab);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user