add options for search history
This commit is contained in:
@@ -10,6 +10,7 @@ import java.util.logging.Level
|
|||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import javax.swing.JFileChooser
|
import javax.swing.JFileChooser
|
||||||
|
import javax.swing.JOptionPane
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
import com.muwire.core.MuWireSettings
|
import com.muwire.core.MuWireSettings
|
||||||
@@ -21,11 +22,13 @@ class OptionsController {
|
|||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
OptionsView view
|
OptionsView view
|
||||||
|
|
||||||
|
Core core
|
||||||
|
MuWireSettings settings
|
||||||
|
UISettings uiSettings
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void save() {
|
void save() {
|
||||||
String text
|
String text
|
||||||
Core core = application.context.get("core")
|
|
||||||
MuWireSettings settings = application.context.get("muwire-settings")
|
|
||||||
|
|
||||||
def i2pProps = core.i2pOptions
|
def i2pProps = core.i2pOptions
|
||||||
|
|
||||||
@@ -141,7 +144,6 @@ class OptionsController {
|
|||||||
|
|
||||||
// UI Setttings
|
// UI Setttings
|
||||||
|
|
||||||
UISettings uiSettings = application.context.get("ui-settings")
|
|
||||||
text = view.lnfField.text
|
text = view.lnfField.text
|
||||||
model.lnf = text
|
model.lnf = text
|
||||||
uiSettings.lnf = text
|
uiSettings.lnf = text
|
||||||
@@ -169,16 +171,24 @@ class OptionsController {
|
|||||||
model.clearUploads = clearUploads
|
model.clearUploads = clearUploads
|
||||||
uiSettings.clearUploads = clearUploads
|
uiSettings.clearUploads = clearUploads
|
||||||
|
|
||||||
|
boolean storeSearchHistory = view.storeSearchHistoryCheckbox.model.isSelected()
|
||||||
|
model.storeSearchHistory = storeSearchHistory
|
||||||
|
uiSettings.storeSearchHistory = storeSearchHistory
|
||||||
|
|
||||||
uiSettings.exitOnClose = model.exitOnClose
|
uiSettings.exitOnClose = model.exitOnClose
|
||||||
if (model.closeDecisionMade)
|
if (model.closeDecisionMade)
|
||||||
uiSettings.closeWarning = false
|
uiSettings.closeWarning = false
|
||||||
|
|
||||||
|
saveUISettings()
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveUISettings() {
|
||||||
File uiSettingsFile = new File(core.home, "gui.properties")
|
File uiSettingsFile = new File(core.home, "gui.properties")
|
||||||
uiSettingsFile.withOutputStream {
|
uiSettingsFile.withOutputStream {
|
||||||
uiSettings.write(it)
|
uiSettings.write(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
@@ -231,4 +241,11 @@ class OptionsController {
|
|||||||
model.exitOnClose = false
|
model.exitOnClose = false
|
||||||
model.closeDecisionMade = true
|
model.closeDecisionMade = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void clearHistory() {
|
||||||
|
uiSettings.searchHistory.clear()
|
||||||
|
saveUISettings()
|
||||||
|
JOptionPane.showMessageDialog(null, "Search history has been cleared")
|
||||||
|
}
|
||||||
}
|
}
|
@@ -21,6 +21,7 @@ class OptionsModel {
|
|||||||
@Observable int speedSmoothSeconds
|
@Observable int speedSmoothSeconds
|
||||||
@Observable int totalUploadSlots
|
@Observable int totalUploadSlots
|
||||||
@Observable int uploadSlotsPerUser
|
@Observable int uploadSlotsPerUser
|
||||||
|
@Observable boolean storeSearchHistory
|
||||||
|
|
||||||
// i2p options
|
// i2p options
|
||||||
@Observable String inboundLength
|
@Observable String inboundLength
|
||||||
@@ -90,6 +91,7 @@ class OptionsModel {
|
|||||||
showSearchHashes = uiSettings.showSearchHashes
|
showSearchHashes = uiSettings.showSearchHashes
|
||||||
clearUploads = uiSettings.clearUploads
|
clearUploads = uiSettings.clearUploads
|
||||||
exitOnClose = uiSettings.exitOnClose
|
exitOnClose = uiSettings.exitOnClose
|
||||||
|
storeSearchHistory = uiSettings.storeSearchHistory
|
||||||
|
|
||||||
if (core.router != null) {
|
if (core.router != null) {
|
||||||
inBw = String.valueOf(settings.inBw)
|
inBw = String.valueOf(settings.inBw)
|
||||||
|
@@ -96,7 +96,13 @@ class MainFrameView {
|
|||||||
menuItem("Exit", actionPerformed : {closeApplication()})
|
menuItem("Exit", actionPerformed : {closeApplication()})
|
||||||
}
|
}
|
||||||
menu (text : "Options") {
|
menu (text : "Options") {
|
||||||
menuItem("Configuration", actionPerformed : {mvcGroup.createMVCGroup("Options")})
|
menuItem("Configuration", actionPerformed : {
|
||||||
|
def params = [:]
|
||||||
|
params['core'] = application.context.get("core")
|
||||||
|
params['settings'] = params['core'].muOptions
|
||||||
|
params['uiSettings'] = settings
|
||||||
|
mvcGroup.createMVCGroup("Options", params)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
menu (text : "Status") {
|
menu (text : "Status") {
|
||||||
menuItem("MuWire", actionPerformed : {mvcGroup.createMVCGroup("mu-wire-status")})
|
menuItem("MuWire", actionPerformed : {mvcGroup.createMVCGroup("mu-wire-status")})
|
||||||
|
@@ -61,6 +61,7 @@ class OptionsView {
|
|||||||
def excludeLocalResultCheckbox
|
def excludeLocalResultCheckbox
|
||||||
def showSearchHashesCheckbox
|
def showSearchHashesCheckbox
|
||||||
def clearUploadsCheckbox
|
def clearUploadsCheckbox
|
||||||
|
def storeSearchHistoryCheckbox
|
||||||
|
|
||||||
def inBwField
|
def inBwField
|
||||||
def outBwField
|
def outBwField
|
||||||
@@ -196,8 +197,17 @@ class OptionsView {
|
|||||||
constraints : gbc(gridx : 3, gridy : 2, anchor : GridBagConstraints.LINE_END))
|
constraints : gbc(gridx : 3, gridy : 2, anchor : GridBagConstraints.LINE_END))
|
||||||
|
|
||||||
}
|
}
|
||||||
panel (border : titledBorder(title : "Other Settings", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
panel (border : titledBorder(title : "Search Settings", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
||||||
constraints : gbc(gridx : 0, gridy : 1, fill : GridBagConstraints.HORIZONTAL, weightx : 100)) {
|
constraints : gbc(gridx : 0, gridy : 1, fill : GridBagConstraints.HORIZONTAL, weightx : 100)) {
|
||||||
|
gridBagLayout()
|
||||||
|
label(text : "Remember search history", constraints: gbc(gridx: 0, gridy:0, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
||||||
|
storeSearchHistoryCheckbox = checkBox(selected : bind {model.storeSearchHistory},
|
||||||
|
constraints : gbc(gridx : 1, gridy:0, anchor : GridBagConstraints.LINE_END))
|
||||||
|
button(text : "Clear history", constraints : gbc(gridx : 1, gridy : 1, anchor : GridBagConstraints.LINE_END), clearHistoryAction)
|
||||||
|
|
||||||
|
}
|
||||||
|
panel (border : titledBorder(title : "Other Settings", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
||||||
|
constraints : gbc(gridx : 0, gridy : 2, fill : GridBagConstraints.HORIZONTAL, weightx : 100)) {
|
||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
label(text : "Automatically clear cancelled downloads", constraints: gbc(gridx: 0, gridy:0, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
label(text : "Automatically clear cancelled downloads", constraints: gbc(gridx: 0, gridy:0, anchor : GridBagConstraints.LINE_START, weightx: 100))
|
||||||
clearCancelledDownloadsCheckbox = checkBox(selected : bind {model.clearCancelledDownloads},
|
clearCancelledDownloadsCheckbox = checkBox(selected : bind {model.clearCancelledDownloads},
|
||||||
@@ -221,7 +231,7 @@ class OptionsView {
|
|||||||
radioButton(text : "Exit", selected : bind {model.exitOnClose}, buttonGroup : closeBehaviorGroup, exitOnCloseAction)
|
radioButton(text : "Exit", selected : bind {model.exitOnClose}, buttonGroup : closeBehaviorGroup, exitOnCloseAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel (constraints : gbc(gridx: 0, gridy: 2, weighty: 100))
|
panel (constraints : gbc(gridx: 0, gridy: 3, weighty: 100))
|
||||||
}
|
}
|
||||||
bandwidth = builder.panel {
|
bandwidth = builder.panel {
|
||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
|
@@ -18,9 +18,11 @@ class SearchFieldModel extends AbstractListModel implements MutableComboBoxModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addElement(Object string) {
|
public void addElement(Object string) {
|
||||||
if (!uiSettings.searchHistory.add(string))
|
if (uiSettings.storeSearchHistory) {
|
||||||
return
|
if (!uiSettings.searchHistory.add(string))
|
||||||
settingsFile.withOutputStream { uiSettings.write(it) }
|
return
|
||||||
|
settingsFile.withOutputStream { uiSettings.write(it) }
|
||||||
|
}
|
||||||
objects.add(string);
|
objects.add(string);
|
||||||
fireIntervalAdded(this,objects.size()-1, objects.size()-1);
|
fireIntervalAdded(this,objects.size()-1, objects.size()-1);
|
||||||
if ( objects.size() == 1 && selectedObject == null && string != null ) {
|
if ( objects.size() == 1 && selectedObject == null && string != null ) {
|
||||||
|
@@ -16,6 +16,7 @@ class UISettings {
|
|||||||
boolean closeWarning
|
boolean closeWarning
|
||||||
boolean exitOnClose
|
boolean exitOnClose
|
||||||
boolean clearUploads
|
boolean clearUploads
|
||||||
|
boolean storeSearchHistory
|
||||||
Set<String> searchHistory
|
Set<String> searchHistory
|
||||||
|
|
||||||
UISettings(Properties props) {
|
UISettings(Properties props) {
|
||||||
@@ -31,6 +32,7 @@ class UISettings {
|
|||||||
closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true"))
|
closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true"))
|
||||||
exitOnClose = Boolean.parseBoolean(props.getProperty("exitOnClose","false"))
|
exitOnClose = Boolean.parseBoolean(props.getProperty("exitOnClose","false"))
|
||||||
clearUploads = Boolean.parseBoolean(props.getProperty("clearUploads","false"))
|
clearUploads = Boolean.parseBoolean(props.getProperty("clearUploads","false"))
|
||||||
|
storeSearchHistory = Boolean.parseBoolean(props.getProperty("storeSearchHistory","true"))
|
||||||
|
|
||||||
searchHistory = DataUtil.readEncodedSet(props, "searchHistory")
|
searchHistory = DataUtil.readEncodedSet(props, "searchHistory")
|
||||||
}
|
}
|
||||||
@@ -48,6 +50,7 @@ class UISettings {
|
|||||||
props.setProperty("closeWarning", String.valueOf(closeWarning))
|
props.setProperty("closeWarning", String.valueOf(closeWarning))
|
||||||
props.setProperty("exitOnClose", String.valueOf(exitOnClose))
|
props.setProperty("exitOnClose", String.valueOf(exitOnClose))
|
||||||
props.setProperty("clearUploads", String.valueOf(clearUploads))
|
props.setProperty("clearUploads", String.valueOf(clearUploads))
|
||||||
|
props.setProperty("storeSearchHistory", String.valueOf(storeSearchHistory))
|
||||||
if (font != null)
|
if (font != null)
|
||||||
props.setProperty("font", font)
|
props.setProperty("font", font)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user