override config file only if components positions changed

This commit is contained in:
sqshq 2019-06-04 23:37:28 -04:00
parent 2596f6b0cd
commit 2343f8e970
3 changed files with 12 additions and 2 deletions

View File

@ -21,6 +21,7 @@ type Layout struct {
ChangeModeEvents chan Mode
mode Mode
selection int
positionsChanged bool
}
type Mode rune
@ -70,6 +71,9 @@ func (l *Layout) RunIntro() {
}
func (l *Layout) changeMode(m Mode) {
if m == ModeComponentResize || m == ModeComponentMove {
l.positionsChanged = true
}
l.mode = m
l.ChangeModeEvents <- m
}
@ -367,3 +371,7 @@ func (l *Layout) resetAlerts() {
c.AlertChannel <- nil
}
}
func (l *Layout) WerePositionsChanged() bool {
return l.positionsChanged
}

View File

@ -48,7 +48,9 @@ func (h *Handler) HandleEvents() {
payload := e.Payload.(ui.Mouse)
h.layout.HandleMouseClick(payload.X, payload.Y)
case console.KeyQuit, console.KeyExit:
h.handleExit()
if h.layout.WerePositionsChanged() {
h.updateConfigFile()
}
return
case console.SignalResize:
payload := e.Payload.(ui.Resize)
@ -76,7 +78,7 @@ func (h *Handler) handleModeChange(m layout.Mode) {
}
}
func (h *Handler) handleExit() {
func (h *Handler) updateConfigFile() {
var settings []config.ComponentSettings
for _, c := range h.layout.Components {
settings = append(settings,