Beispiel #1
0
// PackReset adds a reset value button.
//
func PackReset(key *cftype.Key, value interface{}) *gtk.Button {
	fileDefault := key.Storage().FileDefault()
	if fileDefault == "" {
		return nil
	}

	back := newgtk.ButtonFromIconName("edit-clear", gtk.ICON_SIZE_MENU)
	back.Connect("clicked", func() { key.ValueSet(value) })
	key.PackSubWidget(back)
	return back
}
Beispiel #2
0
// New creates a GuiIcons widget to edit cairo-dock icons config.
//
func New(data cftype.Source, log cdtype.Logger, switcher *pageswitch.Switcher, btn btnaction.Tune) *GuiIcons {
	paned := newgtk.Paned(gtk.ORIENTATION_HORIZONTAL)
	widget := &GuiIcons{
		Paned:    *paned,
		switcher: switcher,
		btn:      btn,
		data:     data,
		log:      log,
	}
	widget.icons = NewList(widget, log)

	up := newgtk.ButtonFromIconName("go-up", gtk.ICON_SIZE_BUTTON)
	down := newgtk.ButtonFromIconName("go-down", gtk.ICON_SIZE_BUTTON)
	remove := newgtk.ButtonFromIconName("list-remove", gtk.ICON_SIZE_BUTTON)

	boxLeft := newgtk.Box(gtk.ORIENTATION_VERTICAL, 0)
	boxBtns := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	boxLeft.PackStart(widget.icons, true, true, 0)
	boxLeft.PackStart(boxBtns, false, false, 0)
	boxBtns.PackStart(up, false, false, 0)
	boxBtns.PackStart(down, false, false, 0)
	boxBtns.PackEnd(remove, false, false, 0)

	widget.Pack1(boxLeft, true, true)

	widget.SetPosition(listIconsWidth) // Paned position = list icons width.

	up.Connect("clicked", widget.actionSelected(datatype.Iconer.MoveBeforePrevious))
	down.Connect("clicked", widget.actionSelected(datatype.Iconer.MoveAfterNext))
	remove.Connect("clicked", widget.actionSelected(datatype.Iconer.RemoveFromDock))

	// widget.icons.Connect("row-inserted", func() { log.Info("row inserted") })
	// widget.icons.Connect("row-deleted", func() { log.Info("row deleted") })

	return widget
}
Beispiel #3
0
// LaunchCommand adds a launch command widget.
// HELP ONLY
//
func LaunchCommand(key *cftype.Key) {
	if len(key.AuthorizedValues) == 0 || key.AuthorizedValues[0] == "" {
		key.Log().NewErrf("command missing", "widget LaunchCommand: %s", key.Name)
		return
	}
	// log.Info(key.Name, key.AuthorizedValues)

	if key.IsType(cftype.KeyLaunchCmdIf) {

		if len(key.AuthorizedValues) < 2 {
			key.Label().SetSensitive(false)
			return
		}

		key.Log().Info("KeyLaunchCmdIf : disabled for now")
		return

		// key.Log().Info("test", key.AuthorizedValues[1])

		// key.Log().Err(key.Log().ExecShow(key.AuthorizedValues[1]), "exec test")

		// gchar *cSecondCommand = pAuthorizedValuesList[1];
		// gchar *cResult = cairo_dock_launch_command_sync (cSecondCommand);
		// cd_debug ("%s: %s => %s", __func__, cSecondCommand, cResult);
		// if (cResult == NULL || *cResult == '0' || *cResult == '\0')  // result is 'fail'
		// {
		// 	gtk_widget_set_sensitive (pLabel, FALSE);
		// 	g_free (cResult);
		// 	break ;
		// }
		// g_free (cResult);
	}

	spinner := newgtk.Spinner()
	spinner.SetNoShowAll(true)
	key.PackSubWidget(spinner)

	btn := newgtk.ButtonFromIconName("go-jump", gtk.ICON_SIZE_BUTTON)
	key.PackSubWidget(btn)

	btn.Connect("clicked", func() {
		cmd, e := key.Log().ExecShlex(key.AuthorizedValues[0])
		if key.Log().Err(e, "widget LaunchCommand parse command", key.Name, ":", key.AuthorizedValues[0]) {
			return
		}

		e = cmd.Start()
		if key.Log().Err(e, "widget LaunchCommand exec", key.AuthorizedValues[0]) {
			return
		}

		btn.Hide()
		spinner.Show()
		spinner.Start()

		// Wait the external program in a go routine.
		// When finished, restore buttons state in the gtk idle loop.
		go func() {
			cmd.Wait()

			glib.IdleAdd(func() {
				btn.Show()
				spinner.Hide()
				spinner.Stop()
			})
		}()
	})

	// 	G_CALLBACK (_cairo_dock_widget_launch_command),
}