From 2343f8e9708d2e889b376635a3b769155b178fbc Mon Sep 17 00:00:00 2001 From: sqshq Date: Tue, 4 Jun 2019 23:37:28 -0400 Subject: [PATCH] override config file only if components positions changed --- component/layout/layout.go | 8 ++++++++ event/handler.go | 6 ++++-- example-interactive-shell.yml => example_int_shell.yml | 0 3 files changed, 12 insertions(+), 2 deletions(-) rename example-interactive-shell.yml => example_int_shell.yml (100%) diff --git a/component/layout/layout.go b/component/layout/layout.go index bf69b5f..02e67fb 100644 --- a/component/layout/layout.go +++ b/component/layout/layout.go @@ -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 +} diff --git a/event/handler.go b/event/handler.go index e122efd..44b7091 100644 --- a/event/handler.go +++ b/event/handler.go @@ -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, diff --git a/example-interactive-shell.yml b/example_int_shell.yml similarity index 100% rename from example-interactive-shell.yml rename to example_int_shell.yml