Beispiel #1
0
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)"
	}
}
Beispiel #2
0
func (ed *Editor) save(appID int) error {
	pack := ed.packs[appID]

	if len(ed.edits) == 0 || pack == nil {
		return nil
	}

	group := pack.Source.Group()
	newver := ""

	// Update version first in applet config file.
	// When an upgrade is requested, we have to change versions in both files,
	// so the config upgrade becomes mandatory.
	if delta, upVer := ed.edits[fieldVersion]; upVer {
		var e error
		newver, e = packages.FormatNewVersion(pack.Version, delta.(int))
		if e != nil {
			return e
		}
		filename := filepath.Join(pack.Path, pack.DisplayedName+".conf")
		e = config.SetFileVersion(ed.log, filename, "Icon", pack.Version, newver)
		if e != nil {
			return e
		}
	}

	// Update edited fields.
	filename := filepath.Join(pack.Path, pack.Source.File())
	e := config.SetToFile(ed.log, filename, func(cfg cdtype.ConfUpdater) (e error) {
		for k, v := range ed.edits {
			switch k {
			case fieldVersion:
				e = cfg.Set(group, "version", newver)

			case fieldCategory:
				e = cfg.Set(group, "category", v.(int))

			case fieldActAsLauncher:
				e = cfg.Set(group, "act as launcher", v.(bool))

			case fieldMultiInstance:
				e = cfg.Set(group, "multi-instance", v.(bool))
			}
			if e != nil {
				return e
			}
		}
		return nil
	})
	if e != nil {
		return e
	}

	// Reload data from disk.
	pack, e = packages.NewAppletPackageUser(ed.log,
		filepath.Dir(pack.Path), filepath.Base(pack.Path),
		pack.Type, pack.Source)

	if e != nil {
		return e
	}
	ed.packs[appID] = pack
	ed.edits = nil
	return nil
}