Exemplo n.º 1
0
// NewFromFileSafe creates a config page builder from the file.
//
// If the load file failed, an error widget is returned with false.
//
func NewFromFileSafe(source cftype.Source, log cdtype.Logger, file, originalConf, gettextDomain string) (cftype.Grouper, bool) {
	build, e := NewFromFile(source, log, file, originalConf, gettextDomain)
	if !log.Err(e, "Load config file", file) {
		return build, true // Load ok, return it.
	}

	// Load failed. Build a warning widget from virtual source.

	conf := vstorage.NewVirtual(file, originalConf)
	build = newFromStorage(source, log, conf, originalConf, gettextDomain)

	group := "problem"
	build.AddGroup(group,
		newkey.Frame(group, "fail", "Load failed", "dialog-error"),
		newkey.TextLabel(group, "text", "Can't load the configuration file to build the interface."),
		newkey.TextLabel(group, "file", file),
	)

	hack := TweakKeyMakeWidget(group, "file", func(key *cftype.Key) {
		key.Label().SetLineWrap(true)
		// key.Label().SetJustify(gtk.JUSTIFY_FILL)
		key.Label().SetSelectable(true)
	})

	return build.BuildSingle(group, hack), false
}
Exemplo n.º 2
0
// Tweak prepares a build tweak to add desktop class informations for a launcher.
//
func Tweak(build cftype.Grouper, source datatype.Source, selected datatype.DesktopClasser) func(cftype.Builder) {
	return func(build cftype.Builder) {
		// Create a key for the hidden existing Origin entry.
		keyOrigin := newkey.EmptyFull(cftype.DesktopEntry, "Origin")

		// Check if a launcher origin has been set (as a desktop class file location).
		keyOrigin.SetBuilder(build)
		origins := keyOrigin.Value().String()
		if origins == "" {
			return
		}

		// Prepare the desktop class widget.
		keyOrigin.SetMakeWidget(func(key *cftype.Key) {
			w := Widget(source, selected, origins)
			key.PackWidget(w, false, false, 0)
		})

		// Add the key to the builder.
		build.AddKeys(cftype.DesktopEntry,
			newkey.Frame(cftype.DesktopEntry, "FrameOrigin", "", ""), // A frame to close the expander.
			keyOrigin)
	}
}