Beispiel #1
0
// addBoxItem adds an item to the list.
//
func (widget *List) addBoxItem(icon datatype.Iconer, indent int, bold bool) *gtk.ListBoxRow {
	row := newgtk.ListBoxRow()
	box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	row.Add(box)

	name, img := icon.DefaultNameIcon()

	box.Set("margin-start", 15*indent)
	if bold {
		name = common.Bold(name)
	}
	if img != "" {
		if pix, e := common.ImageNewFromFile(img, iconSize); !widget.log.Err(e, "Load icon") {
			box.PackStart(pix, false, false, 0)
		}
	}
	lbl := newgtk.Label(name)
	lbl.SetUseMarkup(true)
	box.PackStart(lbl, false, false, 0)

	widget.list.Add(row)
	widget.index[row] = icon

	return row
}
Beispiel #2
0
// OnSelect reacts when a row is selected. Creates a new config for the icon.
//
func (widget *GuiIcons) OnSelect(icon datatype.Iconer, e error) {
	widget.switcher.Clear()

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

	// Using the welcome widget as fallback for empty fields.
	if widget.log.Err(e, "OnSelect icon") || // shouldn't match.
		icon.ConfigPath() == "" { // for icon.ConfigGroup: datatype.KeyMainDock || datatype.GroupServices.

		widget.ShowWelcome(true)
		return
	}

	// Build a custom config widget from a dock config file.

	// Can be:
	//   field icon     Applet, Launcher, Subdock, Separator.
	//   field custom   TaskBar, Service (applet without icon).
	//   group          Desklets, Alt maindock.

	build, ok := cfbuild.NewFromFileSafe(
		widget.data,
		widget.log,
		icon.ConfigPath(),
		icon.OriginalConfigPath(),
		icon.GetGettextDomain())

	switch {
	case !ok: // Widget already build with an error message.
		widget.btn.SetNone()
		widget.setCurrent(build)
		return

	case icon.ConfigGroup() != "":
		build.BuildSingle(icon.ConfigGroup())

	case icon.IsLauncher():
		tweak := desktopclass.Tweak(build, widget.data, icon.GetClass())
		build.BuildAll(widget.switcher, tweak)

	default:
		build.BuildAll(widget.switcher)
	}

	widget.btn.SetSave()
	widget.setCurrent(build)
}