summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-08-28 13:18:58 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-09-04 17:50:49 +0200
commit1106981827f5730ae9e71ff38bde27751fc66213 (patch)
treeb0a12c4412706d428351ab7245726d66f7005649
parent1dac4158e9d8c8ab60203c76e9f86af409724823 (diff)
Extract a SaveAppStateAndLogError function
It seems that most actions that change a state option and resave the state want to just log the error.
-rw-r--r--pkg/gui/controllers/toggle_whitespace_action.go4
-rw-r--r--pkg/gui/extras_panel.go4
-rw-r--r--pkg/gui/gui_common.go6
-rw-r--r--pkg/gui/types/common.go1
4 files changed, 9 insertions, 6 deletions
diff --git a/pkg/gui/controllers/toggle_whitespace_action.go b/pkg/gui/controllers/toggle_whitespace_action.go
index 5e9c1bf1b..175738b59 100644
--- a/pkg/gui/controllers/toggle_whitespace_action.go
+++ b/pkg/gui/controllers/toggle_whitespace_action.go
@@ -24,9 +24,7 @@ func (self *ToggleWhitespaceAction) Call() error {
}
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
- if err := self.c.SaveAppState(); err != nil {
- self.c.Log.Errorf("error when saving app state: %v", err)
- }
+ self.c.SaveAppStateAndLogError()
return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{})
}
diff --git a/pkg/gui/extras_panel.go b/pkg/gui/extras_panel.go
index 5381823b9..1d42f3c92 100644
--- a/pkg/gui/extras_panel.go
+++ b/pkg/gui/extras_panel.go
@@ -24,9 +24,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
show := !gui.c.State().GetShowExtrasWindow()
gui.c.State().SetShowExtrasWindow(show)
gui.c.GetAppState().HideCommandLog = !show
- if err := gui.c.SaveAppState(); err != nil {
- gui.c.Log.Errorf("error when saving app state: %v", err)
- }
+ gui.c.SaveAppStateAndLogError()
return nil
},
},
diff --git a/pkg/gui/gui_common.go b/pkg/gui/gui_common.go
index e3e288c11..bad0957ec 100644
--- a/pkg/gui/gui_common.go
+++ b/pkg/gui/gui_common.go
@@ -92,6 +92,12 @@ func (self *guiCommon) SaveAppState() error {
return self.gui.Config.SaveAppState()
}
+func (self *guiCommon) SaveAppStateAndLogError() {
+ if err := self.gui.Config.SaveAppState(); err != nil {
+ self.gui.Log.Errorf("error when saving app state: %v", err)
+ }
+}
+
func (self *guiCommon) GetConfig() config.AppConfigurer {
return self.gui.Config
}
diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go
index df927e1b2..6eacd882b 100644
--- a/pkg/gui/types/common.go
+++ b/pkg/gui/types/common.go
@@ -73,6 +73,7 @@ type IGuiCommon interface {
GetConfig() config.AppConfigurer
GetAppState() *config.AppState
SaveAppState() error
+ SaveAppStateAndLogError()
// Runs the given function on the UI thread (this is for things like showing a popup asking a user for input).
// Only necessary to call if you're not already on the UI thread i.e. you're inside a goroutine.