|
|
|
@ -366,14 +366,44 @@ func (ct *Cointop) loadTableColumnsFromConfig() error {
|
|
|
|
|
// LoadShortcutsFromConfig loads keyboard shortcuts from config file to struct
|
|
|
|
|
func (ct *Cointop) loadShortcutsFromConfig() error {
|
|
|
|
|
log.Debug("loadShortcutsFromConfig()")
|
|
|
|
|
|
|
|
|
|
// Load the shortcut config into a key:action map (filtering to actions that exist). Keep track of actions.
|
|
|
|
|
config := make(map[string]string)
|
|
|
|
|
actions := make(map[string]bool)
|
|
|
|
|
for k, ifc := range ct.config.Shortcuts {
|
|
|
|
|
if v, ok := ifc.(string); ok {
|
|
|
|
|
if !ct.ActionExists(v) {
|
|
|
|
|
log.Debugf("Shortcut '%s'=>%s is not a valid action", k, v)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
ct.State.shortcutKeys[k] = v
|
|
|
|
|
config[k] = v
|
|
|
|
|
actions[v] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Count how many keys are configured per action.
|
|
|
|
|
actionCount := make(map[string]int)
|
|
|
|
|
for _, action := range ct.State.shortcutKeys {
|
|
|
|
|
actionCount[action] += 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// merge defaults into the loaded config - if the key is not defined, and the action is not found, add it
|
|
|
|
|
for key, action := range ct.State.shortcutKeys {
|
|
|
|
|
if _, ok := config[key]; ok {
|
|
|
|
|
// k is already in the config - ignore it
|
|
|
|
|
} else if _, ok := actions[action]; ok {
|
|
|
|
|
if actionCount[action] == 1 {
|
|
|
|
|
// action is already in the config - ignore it
|
|
|
|
|
} else {
|
|
|
|
|
// there are multiple bindings, add them anyway
|
|
|
|
|
config[key] = action // add action
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
config[key] = action // add action
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ct.State.shortcutKeys = config
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|