示例#1
0
文件: action.go 项目: joy999/walk
func setActionImage(action *walk.Action, image interface{}) (err error) {
	var img *walk.Bitmap

	switch image := image.(type) {
	case nil:
		return nil

	case *walk.Bitmap:
		img = image

	case string:
		if img, err = walk.NewBitmapFromFile(image); err != nil {
			return
		}

	default:
		return errors.New("invalid type for Image")
	}

	return action.SetImage(img)
}
示例#2
0
文件: action.go 项目: joy999/walk
func (m Menu) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
	subMenu, err := walk.NewMenu()
	if err != nil {
		return nil, err
	}

	var action *walk.Action
	if menu == nil {
		action = walk.NewMenuAction(subMenu)
	} else if action, err = menu.Actions().AddMenu(subMenu); err != nil {
		return nil, err
	}

	if err := action.SetText(m.Text); err != nil {
		return nil, err
	}
	if err := setActionImage(action, m.Image); err != nil {
		return nil, err
	}

	for _, item := range m.Items {
		if _, err := item.createAction(builder, subMenu); err != nil {
			return nil, err
		}
	}

	if m.OnTriggered != nil {
		action.Triggered().Attach(m.OnTriggered)
	}

	if m.AssignActionTo != nil {
		*m.AssignActionTo = action
	}
	if m.AssignTo != nil {
		*m.AssignTo = subMenu
	}

	return action, nil
}