Esempio n. 1
0
func (lf *lineFeed) addTest(key *cftype.Key) {
	def, e := key.Storage().Default(key.Group, key.Name)
	if e != nil {
		println("default: ", e.Error())
		return
	}

	valStatus := key.ValueState(def)
	if !valStatus.IsChanged() {
		return
	}

	lf.countChanged++

	lf.valuePrint = func(key *cftype.Key, line tablist.Liner) {
		for i, st := range valStatus {
			curline := lf.testNewLine(line, i)
			switch {
			// case cftype.StateUnchanged:
			// 	curline.Set(RowOld, st.Old)

			case st.State == cftype.StateEdited && st.New != "":
				curline.Set(RowOld, st.New)

			case st.State == cftype.StateAdded:
				curline.Colored(RowOld, color.FgYellow, st.New)

			case st.State == cftype.StateEdited, st.State == cftype.StateRemoved:
				curline.Colored(RowOld, color.FgMagenta, "**EMPTY**")
			}
		}
	}

	lf.Add(key)
}
Esempio n. 2
0
// ColorSelector adds a color selector widget.
//
func ColorSelector(key *cftype.Key) {
	values := key.Value().ListFloat()
	if len(values) == 3 {
		values = append(values, 1) // no transparency.
	}
	gdkColor := gdk.NewRGBA(values...)
	widget := newgtk.ColorButtonWithRGBA(gdkColor)

	var getValue func() interface{}
	switch key.Type {
	case cftype.KeyColorSelectorRGB:
		key.NbElements = 3
		getValue = func() interface{} { return widget.GetRGBA().Floats()[:3] } // Need to trunk ?

	case cftype.KeyColorSelectorRGBA:
		key.NbElements = 4
		getValue = func() interface{} { return widget.GetRGBA().Floats() }
	}

	widget.Set("use-alpha", key.IsType(cftype.KeyColorSelectorRGBA))

	key.PackKeyWidget(key,
		getValue,
		func(uncast interface{}) { widget.SetRGBA(gdk.NewRGBA(uncast.([]float64)...)) },
		widget,
	)
	oldval, e := key.Storage().Default(key.Group, key.Name)
	if e == nil {
		PackReset(key, oldval.ListFloat())
	}
}
Esempio n. 3
0
File: others.go Progetto: sqp/godock
// PackValuerAsInt packs a valuer widget with its reset button (to given value).
// Values are get and set as int.
//
func PackValuerAsInt(key *cftype.Key, w gtk.IWidget, valuer WidgetValuer, value int) {
	key.PackKeyWidget(key,
		func() interface{} { return int(valuer.GetValue()) },
		func(uncast interface{}) { valuer.SetValue(float64(uncast.(int))) },
		w)

	oldval, e := key.Storage().Default(key.Group, key.Name)
	if e == nil {
		PackReset(key, oldval.Int())
	}
}
Esempio n. 4
0
File: others.go Progetto: sqp/godock
// PackReset adds a reset value button.
//
func PackReset(key *cftype.Key, value interface{}) *gtk.Button {
	fileDefault := key.Storage().FileDefault()
	if fileDefault == "" {
		return nil
	}

	back := newgtk.ButtonFromIconName("edit-clear", gtk.ICON_SIZE_MENU)
	back.Connect("clicked", func() { key.ValueSet(value) })
	key.PackSubWidget(back)
	return back
}
Esempio n. 5
0
File: others.go Progetto: sqp/godock
// PackComboBoxWithListField creates a combo box filled with the getList call.
//
func PackComboBoxWithListField(key *cftype.Key, withEntry, numbered bool, getList func() []datatype.Field) *gtk.ComboBox {
	var list []datatype.Field
	if getList != nil {
		list = getList()
	}
	current, _ := key.Storage().String(key.Group, key.Name)
	widget, _, getValue, setValue := NewComboBox(key, withEntry, numbered, current, list)

	key.PackKeyWidget(key, getValue, setValue, widget)
	return widget
}
Esempio n. 6
0
func (lf *lineFeed) valueDefault(key *cftype.Key, line tablist.Liner) {
	flag := false

	def, e := key.Storage().Default(key.Group, key.Name)
	if e != nil {
		println("default: ", e.Error())
	}

	valStatus := key.ValueState(def)

	for i, st := range valStatus {
		curline := lf.testNewLine(line, i)
		switch st.State {

		case cftype.StateBothEmpty:
			line.Set(RowOld, "**EMPTY**")

		case cftype.StateUnchanged:
			curline.Set(RowOld, st.Old)

		case cftype.StateEdited:
			curline.Set(RowOld, st.Old)
			if st.New == "" {
				curline.Colored(RowNew, color.FgMagenta, "**EMPTY**")
			} else {
				curline.Colored(RowNew, color.FgGreen, st.New)
			}
			flag = true

		case cftype.StateAdded:
			curline.Set(RowOld, "**EMPTY**")
			curline.Colored(RowNew, color.FgYellow, st.New)
			flag = true

		case cftype.StateRemoved:
			curline.Set(RowOld, st.Old)
			curline.Colored(RowNew, color.FgMagenta, "**EMPTY**")
			flag = true
		}
	}

	if flag {
		lf.countChanged++
	}
}
Esempio n. 7
0
func (lf *lineFeed) valueUpdated(key *cftype.Key, line tablist.Liner) {
	flag := false
	older := key.Storage().Valuer(key.Group, key.Name)
	valStatus := key.ValueState(older)

	for i, st := range valStatus {
		curline := lf.testNewLine(line, i)
		switch st.State {

		case cftype.StateBothEmpty:
			line.Colored(RowOld, color.FgMagenta, "**EMPTY**")
			line.Colored(RowNew, color.BgRed, "  ==  ")

		case cftype.StateUnchanged:
			curline.Set(RowOld, st.Old)
			curline.Colored(RowNew, color.BgRed, "  ==  ")

		case cftype.StateEdited:
			curline.Set(RowOld, st.Old)
			st.New = ternary.String(st.New == "", "**EMPTY**", st.New)
			curline.Colored(RowNew, color.FgGreen, st.New)
			flag = true

		case cftype.StateAdded:
			curline.Set(RowOld, "**EMPTY**")
			curline.Colored(RowNew, color.FgGreen, st.New)
			flag = true

		case cftype.StateRemoved:
			curline.Set(RowOld, st.Old)
			curline.Colored(RowNew, color.FgGreen, "**EMPTY**")
			flag = true
		}
	}

	if flag {
		lf.countChanged++
	}
}
Esempio n. 8
0
// ListDock adds a dock list widget.
//
func ListDock(key *cftype.Key) {
	// Get current Icon name if its a Subdock.
	iIconType, _ := key.Storage().Int(key.Group, "Icon Type")
	SubdockName := ""
	if iIconType == cftype.UserIconStack { // it's a stack-icon
		SubdockName, _ = key.Storage().String(key.Group, "Name") // It's a subdock, get its name to remove the selection of a recursive position (inside itself).
	}

	list := key.Source().ListDocks("", SubdockName) // Get the list of available docks. Keep parent, but remove itself from the list.
	list = append(list, datatype.Field{
		Key:  datatype.KeyNewDock,
		Name: tran.Slate("New main dock")},
	)

	model := newModelSimple()
	current := key.Value().String()

	if current == "" {
		current = datatype.KeyMainDock
	}

	model.SetSortColumnId(RowName, gtk.SORT_ASCENDING)
	widget := newgtk.ComboBoxWithModel(model)
	renderer := newgtk.CellRendererText()
	widget.PackStart(renderer, false)
	widget.AddAttribute(renderer, "text", RowName)

	saved := indexiter.NewByString(widget, key.Log())
	iter := fillModelWithFields(key, model, list, current, saved)
	widget.SetActiveIter(iter)

	key.PackKeyWidget(key,
		getValueListCombo(widget, model, key.Log()),
		func(uncast interface{}) { saved.SetActive(uncast.(string)) },
		widget)
}
Esempio n. 9
0
// Float adds a float selector widget. SpinButton or Horizontal Scale
//
func Float(key *cftype.Key) {
	if key.NbElements > 1 { // TODO: remove temp test
		key.Log().Info("Float multi", key.NbElements, key.Type.String())
	}

	values := key.Value().ListFloat()
	minValue, maxValue := minMaxValues(key)

	var valuers []WidgetValuer

	for k := 0; k < key.NbElements; k++ {
		var value float64
		if k < len(values) {
			value = values[k]
		}

		switch key.Type {
		case cftype.KeyFloatScale:
			adjustment := newgtk.Adjustment(
				value,
				minValue,
				maxValue,
				(maxValue-minValue)/20,
				(maxValue-minValue)/10, 0,
			)
			w := newgtk.Scale(gtk.ORIENTATION_HORIZONTAL, adjustment)
			w.Set("digits", 3)

			key.PackSubWidget(WrapKeyScale(key, w))
			valuers = append(valuers, w)

		case cftype.KeyFloatSpin:
			w := newgtk.SpinButtonWithRange(minValue, maxValue, 1)
			w.Set("digits", 3)
			w.SetValue(value)

			key.PackSubWidget(w)
			valuers = append(valuers, w)
		}
	}

	switch {
	case key.NbElements == 1:
		key.PackKeyWidget(key,
			func() interface{} { return valuers[0].GetValue() },
			func(uncast interface{}) { valuers[0].SetValue(uncast.(float64)) },
		)
		oldval, e := key.Storage().Default(key.Group, key.Name)
		if e == nil {
			PackReset(key, oldval.Float())
		}

	default:
		key.PackKeyWidget(key,
			func() interface{} { return listValuerGet(valuers) },
			func(uncast interface{}) { listValuerSet(valuers, uncast.([]float64)) },
		)
		oldval, e := key.Storage().Default(key.Group, key.Name)
		if e == nil {
			PackReset(key, oldval.ListFloat())
		}
	}
}
Esempio n. 10
0
// IntegerSize adds an integer selector widget.
//
func IntegerSize(key *cftype.Key) {
	if key.NbElements > 1 { // TODO: remove temp test
		key.Log().Info("IntegerSize multi", key.NbElements, key.Type.String())
	}

	toggle := newgtk.ToggleButton()
	img := newgtk.ImageFromIconName("media-playback-pause", gtk.ICON_SIZE_MENU) // get better image.
	toggle.SetImage(img)

	values := key.Value().ListInt()
	minValue, maxValue := minMaxValues(key)

	var valuers []WidgetValuer

	key.NbElements *= 2 // Two widgets to add.

	// Value pair data.
	var firstValue int
	var firstWidget *gtk.SpinButton
	var cbBlock func() func()

	for k := 0; k < key.NbElements; k++ {
		var value int
		if k < len(values) {
			value = values[k]
		}

		w := newgtk.SpinButtonWithRange(minValue, maxValue, 1)
		w.SetValue(float64(value))
		key.PackSubWidget(w)
		valuers = append(valuers, w)

		if k&1 == 0 { // first value, separator
			label := newgtk.Label("x")
			key.PackSubWidget(label)

			firstWidget = w
			firstValue = value

		} else { // second value. connect both spin values.
			if firstValue == value {
				toggle.SetActive(true)
			}

			cb0, e := firstWidget.Connect("value-changed", onValuePairChanged, &valuePair{
				linked: w,
				toggle: toggle})
			key.Log().Err(e, "IntegerSize connect value-changed 1")
			cb1, e := w.Connect("value-changed", onValuePairChanged, &valuePair{
				linked: firstWidget,
				toggle: toggle})
			key.Log().Err(e, "IntegerSize connect value-changed 2")

			cbBlock = func() func() {
				firstWidget.HandlerBlock(cb0)
				w.HandlerBlock(cb1)
				return func() {
					firstWidget.HandlerUnblock(cb0)
					w.HandlerUnblock(cb1)
				}
			}
		}
	}

	setValue := func(uncast interface{}) {
		if cbBlock == nil {
			key.Log().NewErr("no valuePair callbacks", "IntegerSize", key.Name)
		} else {
			defer cbBlock()() // This disables now and reenables during defer.
		}
		values := uncast.([]int)
		if len(values) < 2 {
			key.Log().NewErr("not enough values provided", "IntegerSize set value", key.Name, values)
			values = []int{0, 0}
		}

		listValuerSet(valuers, cast.IntsToFloats(values))
		toggle.SetActive(values[0] == values[1])
	}

	key.PackKeyWidget(key,
		func() interface{} { return cast.FloatsToInts(listValuerGet(valuers)) },
		setValue,
		toggle,
	)

	oldval, e := key.Storage().Default(key.Group, key.Name)
	key.Log().Err(e, "IntegerSize original value")
	if e == nil {
		PackReset(key, oldval.ListInt())
	}
}