add option to close warning dialog to exit app. Add config option for exit behavior in the options

This commit is contained in:
Zlatin Balevsky
2019-10-28 13:28:03 +00:00
parent 5eb8d75bba
commit 7d652fabcb
8 changed files with 70 additions and 16 deletions

View File

@@ -23,17 +23,38 @@ class CloseWarningController {
@ControllerAction
void close() {
boolean showWarning = !view.checkbox.model.isSelected()
model.closeWarning = showWarning
settings.closeWarning = showWarning
File props = new File(home, "gui.properties")
props.withOutputStream {
settings.write(it)
boolean rememberDecision = view.checkbox.model.isSelected()
if (rememberDecision) {
settings.exitOnClose = false
settings.closeWarning = false
saveMuSettings()
}
view.dialog.setVisible(false)
view.mainFrame.setVisible(false)
mvcGroup.destroy()
}
@ControllerAction
void exit() {
boolean rememberDecision = view.checkbox.model.isSelected()
if (rememberDecision) {
settings.exitOnClose = true
settings.closeWarning = false
saveMuSettings()
}
view.dialog.setVisible(false)
view.mainFrame.setVisible(false)
def parentView = mvcGroup.parentGroup.view
mvcGroup.destroy()
parentView.closeApplication()
}
private void saveMuSettings() {
File props = new File(home, "gui.properties")
props.withOutputStream {
settings.write(it)
}
}
}

View File

@@ -161,6 +161,10 @@ class OptionsController {
boolean clearUploads = view.clearUploadsCheckbox.model.isSelected()
model.clearUploads = clearUploads
uiSettings.clearUploads = clearUploads
uiSettings.exitOnClose = model.exitOnClose
if (model.closeDecisionMade)
uiSettings.closeWarning = false
File uiSettingsFile = new File(core.home, "gui.properties")
uiSettingsFile.withOutputStream {
@@ -199,13 +203,25 @@ class OptionsController {
}
@ControllerAction
void automaticFontAction() {
void automaticFont() {
model.automaticFontSize = true
model.customFontSize = 12
}
@ControllerAction
void customFontAction() {
void customFont() {
model.automaticFontSize = false
}
@ControllerAction
void exitOnClose() {
model.exitOnClose = true
model.closeDecisionMade = true
}
@ControllerAction
void minimizeOnClose() {
model.exitOnClose = false
model.closeDecisionMade = true
}
}

View File

@@ -7,9 +7,12 @@ import griffon.core.artifact.GriffonModel
import griffon.core.controller.ControllerAction
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import griffon.transform.Observable
import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonModel)
class CloseWarningModel {
@griffon.transform.Observable boolean closeWarning
@Observable boolean closeWarning
@Observable boolean exitOnClose
}

View File

@@ -39,6 +39,8 @@ class OptionsModel {
@Observable boolean excludeLocalResult
@Observable boolean showSearchHashes
@Observable boolean clearUploads
@Observable boolean exitOnClose
@Observable boolean closeDecisionMade
// bw options
@Observable String inBw
@@ -83,6 +85,7 @@ class OptionsModel {
excludeLocalResult = uiSettings.excludeLocalResult
showSearchHashes = uiSettings.showSearchHashes
clearUploads = uiSettings.clearUploads
exitOnClose = uiSettings.exitOnClose
if (core.router != null) {
inBw = String.valueOf(settings.inBw)

View File

@@ -28,15 +28,16 @@ class CloseWarningView {
void initUI() {
mainFrame = application.windowManager.findWindow("main-frame")
dialog = new JDialog(mainFrame, "MuWire will continue running", true)
dialog = new JDialog(mainFrame, "Close MuWire?", true)
panel = builder.panel {
gridBagLayout()
label(text : "MuWire will continue running. You can close it from the system tray", constraints : gbc(gridx: 0, gridy: 0, gridwidth : 2))
label(text : "Would you like to minimize to system tray or exit immediately?", constraints : gbc(gridx: 0, gridy: 0, gridwidth : 2))
label(text : "\n", constraints : gbc(gridx : 0, gridy : 1)) // TODO: real padding
label(text : "Do not show this warning again", constraints : gbc(gridx: 0, gridy : 2, weightx: 100, anchor : GridBagConstraints.LINE_END))
label(text : "Remember my decision", constraints : gbc(gridx: 0, gridy : 2, weightx: 100, anchor : GridBagConstraints.LINE_END))
checkbox = checkBox(selected : bind {model.closeWarning}, constraints : gbc(gridx: 1, gridy :2))
panel (constraints : gbc(gridx: 0, gridy : 3, gridwidth : 2)) {
button(text : "Ok", closeAction)
button(text : "Minimize To Tray", closeAction)
button(text : "Exit MuWire", exitAction)
}
}
dialog.getContentPane().add(panel)

View File

@@ -463,7 +463,8 @@ class MainFrameView {
args2.put("home", model.core.home)
mvcGroup.createMVCGroup("close-warning", "Close Warning", args2)
}
}
} else if (settings.exitOnClose)
closeApplication()
} else {
closeApplication()
}

View File

@@ -194,13 +194,19 @@ class OptionsView {
constraints : gbc(gridx : 1, gridy:1, anchor : GridBagConstraints.LINE_END))
label(text : "Smooth download speed over (seconds)", constraints : gbc(gridx: 0, gridy : 2, anchor : GridBagConstraints.LINE_START, weightx: 100))
speedSmoothSecondsField = textField(text : bind {model.speedSmoothSeconds},
constraints : gbc(gridx:1, gridy: 2, anchor : GridBagConstraints.LINE_START))
constraints : gbc(gridx:1, gridy: 2, anchor : GridBagConstraints.LINE_END))
label(text : "Exclude local files from results", constraints: gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100))
excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult},
constraints : gbc(gridx: 1, gridy : 3, anchor : GridBagConstraints.LINE_END))
label(text : "Automatically Clear finished uploads", constraints:gbc(gridx:0, gridy:4, anchor: GridBagConstraints.LINE_START, weightx : 100))
clearUploadsCheckbox = checkBox(selected : bind {model.clearUploads},
constraints : gbc(gridx:1, gridy: 4, anchor:GridBagConstraints.LINE_END))
label(text : "When closing MuWire", constraints : gbc(gridx: 0, gridy : 5, anchor : GridBagConstraints.LINE_START, weightx: 100))
panel (constraints : gbc(gridx:1, gridy: 5, anchor : GridBagConstraints.LINE_END)) {
buttonGroup(id : "closeBehaviorGroup")
radioButton(text : "Minimize to tray", selected : bind {!model.exitOnClose}, buttonGroup: closeBehaviorGroup, minimizeOnCloseAction)
radioButton(text : "Exit", selected : bind {model.exitOnClose}, buttonGroup : closeBehaviorGroup, exitOnCloseAction)
}
}
panel (constraints : gbc(gridx: 0, gridy: 2, weighty: 100))
}