persist watched keywords and regexes

This commit is contained in:
Zlatin Balevsky
2019-07-09 20:11:29 +01:00
parent 39a81a3376
commit 57d593a68a
4 changed files with 30 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.annotation.Nonnull
import com.muwire.core.Core
import com.muwire.core.EventBus
import com.muwire.core.content.ContentControlEvent
@@ -16,12 +17,19 @@ class ContentPanelController {
@MVCMember @Nonnull
ContentPanelView view
EventBus eventBus
Core core
@ControllerAction
void addRule() {
def term = view.ruleTextField.text
eventBus.publish(new ContentControlEvent(term : term, regex : model.regex, add:true))
if (model.regex)
core.muOptions.watchedRegexes.add(term)
else
core.muOptions.watchedKeywords.add(term)
saveMuWireSettings()
core.eventBus.publish(new ContentControlEvent(term : term, regex : model.regex, add:true))
}
@ControllerAction
@@ -38,4 +46,11 @@ class ContentPanelController {
void regex() {
model.regex = true
}
void saveMuWireSettings() {
File f = new File(core.home, "MuWire.properties")
f.withOutputStream {
core.muOptions.write(it)
}
}
}

View File

@@ -2,6 +2,7 @@ package com.muwire.gui
import javax.annotation.Nonnull
import com.muwire.core.Core
import com.muwire.core.EventBus
import com.muwire.core.content.ContentControlEvent
import com.muwire.core.content.ContentManager
@@ -17,7 +18,7 @@ class ContentPanelModel {
@MVCMember @Nonnull
ContentPanelView view
EventBus eventBus
Core core
private ContentManager contentManager
@@ -29,11 +30,11 @@ class ContentPanelModel {
void mvcGroupInit(Map<String,String> args) {
contentManager = application.context.get("core").contentManager
rules.addAll(contentManager.matchers)
eventBus.register(ContentControlEvent.class, this)
core.eventBus.register(ContentControlEvent.class, this)
}
void mvcGroupDestroy() {
eventBus.unregister(ContentControlEvent.class, this)
core.eventBus.unregister(ContentControlEvent.class, this)
}
void refresh() {

View File

@@ -17,6 +17,7 @@ import com.muwire.core.RouterDisconnectedEvent
import com.muwire.core.connection.ConnectionAttemptStatus
import com.muwire.core.connection.ConnectionEvent
import com.muwire.core.connection.DisconnectionEvent
import com.muwire.core.content.ContentControlEvent
import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.download.Downloader
import com.muwire.core.files.AllFilesLoadedEvent
@@ -164,6 +165,13 @@ class MainFrameModel {
core.eventBus.register(UpdateDownloadedEvent.class, this)
core.eventBus.register(TrustSubscriptionUpdatedEvent.class, this)
core.muOptions.watchedKeywords.each {
core.eventBus.publish(new ContentControlEvent(term : it, regex: false, add: true))
}
core.muOptions.watchedRegexes.each {
core.eventBus.publish(new ContentControlEvent(term : it, regex: true, add: true))
}
timer.schedule({
if (core.shutdown.get())
return

View File

@@ -74,7 +74,7 @@ class MainFrameView {
menuItem("Configuration", actionPerformed : {mvcGroup.createMVCGroup("Options")})
menuItem("Content Control", actionPerformed : {
def env = [:]
env["eventBus"] = model.core.eventBus
env["core"] = model.core
mvcGroup.createMVCGroup("content-panel", env)
})
}