Esempio n. 1
0
// ListScreens returns the list of screens.
//
func (Data) ListScreens() (list []datatype.Field) {
	nb := desktops.NbScreens()
	if nb <= 1 {
		return []datatype.Field{{Key: "0", Name: "Use all screens"}}
	}

	var xmax, ymax int
	for i := 0; i < nb; i++ {
		x, y := desktops.ScreenPosition(i)
		xmax = ternary.Max(x, xmax)
		ymax = ternary.Max(y, ymax)
	}

	for i := 0; i < nb; i++ {
		var xstr, ystr string
		x, y := desktops.ScreenPosition(i)
		if xmax > 0 { // at least 2 screens horizontally
			switch {
			case x == 0:
				xstr = "left"
			case x == xmax:
				xstr = "right"
			default:
				xstr = "middle"
			}
		}

		if ymax > 0 { // at least 2 screens vertically
			switch {
			case y == 0:
				ystr = "top"
			case y == ymax:
				ystr = "bottom"
			default:
				ystr = "middle"
			}
		}
		key := strconv.Itoa(i)
		sep := ternary.String(xstr != "" && ystr != "", " - ", "")
		name := "Screen" + " " + key + " (" + xstr + sep + ystr + ")"

		list = append(list, datatype.Field{Key: key, Name: name})
	}
	return list
}
Esempio n. 2
0
File: editui.go Progetto: sqp/godock
// SetField sets the current field number.
//
func (ed *Editor) SetField(id int) int {
	ed.fields.Items = make([]string, len(fields))
	for i, str := range fields {
		ed.fields.Items[i] = str
	}
	// Highlight selected.
	id = ternary.Max(1, ternary.Min(id, len(ed.fields.Items)-1))
	ed.fields.Items[id] = "[" + ed.fields.Items[id] + "](fg-white,bg-blue)"
	return id
}
Esempio n. 3
0
File: editui.go Progetto: sqp/godock
// SetPack sets the current package number.
//
func (ed *Editor) SetPack(appID int) int {
	appID = ternary.Max(0, ternary.Min(appID, len(ed.packs)-1))

	var names []string
	for _, pack := range ed.packs {
		names = append(names, pack.DisplayedName)
	}
	names[appID] = "[" + names[appID] + "](fg-white,bg-blue)"

	ed.applets.Items = names

	ed.showPack(appID)
	return appID
}
Esempio n. 4
0
func (ed *Editor) setInt(field, delta, def, min, max int) {
	val := -1
	old, ok := ed.edits[field]
	if ok {
		val = old.(int) + delta
		if val == def {
			delete(ed.edits, field)
			return
		}
	} else {
		val = def + delta
	}
	ed.edits[field] = ternary.Max(min, ternary.Min(val, max))
}
Esempio n. 5
0
File: editui.go Progetto: sqp/godock
func (ed *Editor) showPack(appID int) {
	appID = ternary.Max(0, ternary.Min(appID, len(ed.packs)-1))
	pack := ed.packs[appID]
	catstr, _ := packages.FormatCategory(pack.Category)

	ed.appinfo.BorderLabel = pack.Path
	ed.appinfo.Items = []string{
		"",
		pack.DisplayedName,
		pack.Author,
		pack.Version,
		strconv.Itoa(pack.Category) + " : " + catstr,
		formatBool(pack.ActAsLauncher),
		formatBool(pack.IsMultiInstance),
	}

	ed.locked.Text = "this\nis\ndetails"

	ed.desc.Text = strings.Replace(pack.Description, "\\n", "\n", -1)

	// Update edited fields.
	for k, v := range ed.edits {
		switch k {
		case fieldVersion:
			ed.appinfo.Items[k], _ = packages.FormatNewVersion(pack.Version, v.(int))
			switch v.(int) {
			case 2:
				ed.appinfo.Items[k] = "[" + ed.appinfo.Items[k] + "](fg-magenta)"
				continue

			case 3:
				ed.appinfo.Items[k] = "[" + ed.appinfo.Items[k] + "](fg-red)"
				continue
			}

		case fieldCategory:
			catstr, _ := packages.FormatCategory(v.(int))
			ed.appinfo.Items[k] = strconv.Itoa(v.(int)) + " : " + catstr

		case fieldActAsLauncher, fieldMultiInstance:
			ed.appinfo.Items[k] = formatBool(v.(bool))
		}

		// Add color to field to indicate it's modified.
		ed.appinfo.Items[k] = "[" + ed.appinfo.Items[k] + "](fg-green)"
	}
}
Esempio n. 6
0
File: cftype.go Progetto: sqp/godock
// ValueState starts the comparison between old and new values.
// Only compares the presence or absence of values, not the content.
//
func (key *Key) ValueState(previous valuer.Valuer) ValueStateList {
	sizeOld := previous.Count()
	sizeNew := key.Value().Count()

	if sizeOld == 0 && sizeNew == 0 {
		return ValueStateList{{State: StateBothEmpty}}
	}

	count := ternary.Max(sizeOld, sizeNew)
	if count > key.NbElements && !key.IsType(KeyTreeViewSortSimple, KeyTreeViewSortModify, KeyTreeViewMultiChoice) {
		println("key.ValueState higher dropped", key.Type.String(), key.Name, ":", count, "/", key.NbElements)
		return ValueStateList{valueCompare(previous.Sprint(), key.Value().Sprint())}
	}

	flags := make(ValueStateList, count)

	for i := range flags {
		switch {
		case sizeOld <= i: // Added fields at the end.
			flags[i] = ValueStateField{
				State: StateAdded,
				New:   key.Value().SprintI(i),
			}

		case sizeNew <= i: // Same with removed.
			flags[i] = ValueStateField{
				State: StateRemoved,
				Old:   previous.SprintI(i),
			}

		default: // Values in both lists, pack first, and leave untested here.
			flags[i] = valueCompare(previous.SprintI(i), key.Value().SprintI(i))
		}
	}

	return flags
}