Ejemplo n.º 1
0
// Execute implements "../commander".Controller.
func (c *Controller) Execute(command commands.Command) {
	executed, _ := execRecursively(command, c)
	if !executed {
		panic(fmt.Errorf("Command %s ran without executing", command.Name()))
	}
	c.Editor().Focus()
}
Ejemplo n.º 2
0
func execRecursively(command commands.Command, element interface{}) (executed, consume bool) {
	executed, consume = command.Exec(element)
	var childExecuted bool
	if parent, ok := element.(gxui.Parent); ok && !consume {
		for _, child := range parent.Children() {
			childExecuted, consume = execRecursively(command, child.Control)
			executed = executed || childExecuted
			if consume {
				return
			}
		}
	}
	if elementer, ok := element.(Elementer); ok {
		for _, element := range elementer.Elements() {
			childExecuted, consume = execRecursively(command, element)
			executed = executed || childExecuted
			if consume {
				return
			}
		}
	}
	return
}