Exemple #1
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),
}
Exemple #2
0
// Text just enlarges the widget label (nothing more intended).
//
func Text(key *cftype.Key) {
	key.Label().SetLineWrap(true)
	key.Label().SetJustify(gtk.JUSTIFY_FILL)
}