2019-02-16 12:01:17 +02:00
|
|
|
package gui
|
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
func (gui *Gui) changeContext(context string) error {
|
|
|
|
oldContext := gui.State.Context
|
|
|
|
|
|
|
|
if gui.State.Context == context {
|
2019-02-16 12:01:17 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-02 06:11:53 +02:00
|
|
|
contextMap := gui.GetContextMap()
|
2019-02-16 12:01:17 +02:00
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
oldBindings := contextMap[oldContext]
|
|
|
|
for _, binding := range oldBindings {
|
|
|
|
if err := gui.g.DeleteKeybinding(binding.ViewName, binding.Key, binding.Modifier); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2019-02-16 12:01:17 +02:00
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
bindings := contextMap[context]
|
2019-02-16 12:01:17 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 07:33:31 +02:00
|
|
|
|
|
|
|
gui.State.Context = context
|
2019-11-10 07:20:35 +02:00
|
|
|
return nil
|
2019-02-16 12:01:17 +02:00
|
|
|
}
|
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
func (gui *Gui) setInitialContext() error {
|
2019-03-02 06:11:53 +02:00
|
|
|
contextMap := gui.GetContextMap()
|
2019-02-16 12:01:17 +02:00
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
initialContext := "normal"
|
2019-02-16 12:01:17 +02:00
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
bindings := contextMap[initialContext]
|
|
|
|
for _, binding := range bindings {
|
|
|
|
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
|
|
|
return err
|
2019-02-16 12:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 07:33:31 +02:00
|
|
|
gui.State.Context = initialContext
|
2019-02-16 12:01:17 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|