Пример #1
0
// New creates a DockTheme widget to load and save the main theme.
//
func New(data cftype.Source, log cdtype.Logger, switcher *pageswitch.Switcher) (cftype.Grouper, bool) {
	file := data.DirShareData(cdglobal.FileConfigThemes)
	build, ok := cfbuild.NewFromFileSafe(data, log, file, "", "")
	if !ok {
		return build, false
	}

	// Widget building.
	keyLoad := func(key *cftype.Key) {
		w := confapplets.NewLoaded(data, log, nil, confapplets.ListThemes)
		getValue := func() interface{} { return w.Selected().GetName() }
		key.PackKeyWidget(key, getValue, nil, w)
	}

	keySave := func(key *cftype.Key) {
		cfwidget.PackComboBoxWithListField(key, true, false, data.ListDockThemeSave)
	}

	build.BuildAll(switcher,
		cfbuild.TweakKeySetAlignedVertical(groupLoad, "chosen theme"),
		cfbuild.TweakKeyMakeWidget(groupLoad, "chosen theme", keyLoad),
		cfbuild.TweakKeyMakeWidget(groupSave, "theme name", keySave),
	)

	// Builder update keys.
	return &DockTheme{
		Grouper:  build,
		switcher: switcher,
		data:     data,
		log:      log,
	}, true
}
Пример #2
0
// onSelect acts as a row selected callback.
//
func (widget *ConfCore) onSelect(item *Item, e error) {
	if widget.log.Err(e, "onSelect: selection problem") {
		return
	}
	widget.switcher.Clear()

	if widget.config != nil {
		widget.config.Destroy()
		widget.config = nil
	}

	var w configWidget
	switch item.Key {

	// Custom widgets.

	case TabShortkeys:
		w = confshortkeys.New(widget.data, widget.log, widget.btn)
		widget.btn.SetGrab()

	case TabThemes:
		var ok bool
		w, ok = docktheme.New(widget.data, widget.log, widget.switcher)
		if ok {
			widget.btn.SetApply()
		} else {
			widget.btn.SetNone()
		}

	case TabDownload:
		w = confapplets.NewLoaded(widget.data, widget.log, nil, confapplets.ListExternal)
		widget.btn.SetNone()

	case TabHelp:
		w, _ = helpfile.New(widget.data, widget.log, widget.switcher)
		widget.btn.SetNone()

	case TabDev:
		w = devpage.New(widget.data, widget.log, widget.switcher)
		widget.btn.SetNone()

		// Custom file path.

	case confown.GuiGroup: // own config has a special path.
		w = widget.fromFile(item,
			confown.PathFile(),
			"", // no default.
			func() { confown.Settings.Load() }, // reload own conf if saved.
		)

		// Default file path.

	default:
		w = widget.fromFile(item,
			widget.data.MainConfigFile(),
			widget.data.MainConfigDefault(),
			func() {
				tokf, ok := interface{}(w).(saver)
				if !ok {
					widget.log.NewErr("bad config widget", "update confcore")
					return
				}
				kf := tokf.KeyFile()
				if kf == nil {
					conf, e := cfbuild.LoadFile(widget.data.MainConfigFile(), "")
					if widget.log.Err(e, "update confcore, reload conf file") {
						return
					}
					kf = &conf.KeyFile
					defer kf.Free()
				}

				for _, manager := range item.Managers {
					widget.data.ManagerReload(manager, true, kf)
				}
			})
	}

	widget.setCurrent(w)
}