File: application_since_3_12.go

package info (click to toggle)
golang-github-gotk3-gotk3 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,332 kB
  • sloc: ansic: 904; makefile: 4
file content (62 lines) | stat: -rw-r--r-- 1,636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// +build !gtk_3_6,!gtk_3_8,!gtk_3_10

// See: https://developer.gnome.org/gtk3/3.12/api-index-3-12.html

package gtk

// #include <gtk/gtk.h>
// #include "gtk.go.h"
import "C"
import "unsafe"

// GetAccelsForAction is a wrapper around gtk_application_get_accels_for_action().
func (v *Application) GetAccelsForAction(act string) []string {
	cstr1 := (*C.gchar)(C.CString(act))
	defer C.free(unsafe.Pointer(cstr1))

	var descs []string
	c := C.gtk_application_get_accels_for_action(v.native(), cstr1)
	originalc := c
	defer C.g_strfreev(originalc)

	for *c != nil {
		descs = append(descs, C.GoString((*C.char)(*c)))
		c = nextgcharptr(c)
	}

	return descs
}

// SetAccelsForAction is a wrapper around gtk_application_set_accels_for_action().
func (v *Application) SetAccelsForAction(act string, accels []string) {
	cstr1 := (*C.gchar)(C.CString(act))
	defer C.free(unsafe.Pointer(cstr1))

	caccels := C.make_strings(C.int(len(accels) + 1))
	defer C.destroy_strings(caccels)

	for i, accel := range accels {
		cstr := C.CString(accel)
		defer C.free(unsafe.Pointer(cstr))
		C.set_string(caccels, C.int(i), (*C.gchar)(cstr))
	}

	C.set_string(caccels, C.int(len(accels)), nil)

	C.gtk_application_set_accels_for_action(v.native(), cstr1, caccels)
}

// ListActionDescriptions is a wrapper around gtk_application_list_action_descriptions().
func (v *Application) ListActionDescriptions() []string {
	var descs []string
	c := C.gtk_application_list_action_descriptions(v.native())
	originalc := c
	defer C.g_strfreev(originalc)

	for *c != nil {
		descs = append(descs, C.GoString((*C.char)(*c)))
		c = nextgcharptr(c)
	}

	return descs
}