2019-02-16 12:01:17 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
func (gui *Gui) changeContext(viewName, context string) error {
|
|
|
|
if gui.State.Contexts[viewName] == context {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-02 06:11:53 +02:00
|
|
|
contextMap := gui.GetContextMap()
|
2019-02-16 12:01:17 +02:00
|
|
|
|
|
|
|
gui.g.DeleteKeybindings(viewName)
|
|
|
|
|
|
|
|
bindings := contextMap[viewName][context]
|
|
|
|
for _, binding := range bindings {
|
2019-11-10 07:20:35 +02:00
|
|
|
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
2019-02-16 12:01:17 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gui.State.Contexts[viewName] = context
|
2019-11-10 07:20:35 +02:00
|
|
|
return nil
|
2019-02-16 12:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) setInitialContexts() error {
|
2019-03-02 06:11:53 +02:00
|
|
|
contextMap := gui.GetContextMap()
|
2019-02-16 12:01:17 +02:00
|
|
|
|
|
|
|
initialContexts := map[string]string{
|
2019-11-10 07:20:35 +02:00
|
|
|
"main": "normal",
|
|
|
|
"secondary": "normal",
|
2019-02-16 12:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for viewName, context := range initialContexts {
|
|
|
|
bindings := contextMap[viewName][context]
|
|
|
|
for _, binding := range bindings {
|
|
|
|
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.State.Contexts = initialContexts
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|