File: entry_completion.go

package info (click to toggle)
go-gir-generator 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,216 kB
  • sloc: ansic: 186; makefile: 44
file content (64 lines) | stat: -rw-r--r-- 1,687 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
63
64
// Entry/Entry Completion
//
// GtkEntryCompletion provides a mechanism for adding support for
// completion in GtkEntry.
package entry_completion

import "gobject/gtk-3.0"
import "gobject/gobject-2.0"

func create_completion_model() *gtk.TreeModel {
	store := gtk.NewListStore(gobject.String)

	// Append few words
	store.Append("GNOME")
	store.Append("total")
	store.Append("totally")
	return gtk.ToTreeModel(store)
}

var dialog *gtk.Dialog

func Do(mainwin *gtk.Window) *gtk.Window {
	if dialog == nil {
		dialog = gtk.NewDialogWithButtons("GtkEntryCompletion",
			mainwin, 0, gtk.StockClose, gtk.ResponseTypeNone)
		dialog.SetResizable(false)
		dialog.Connect("response", func() { dialog.Destroy() })
		dialog.Connect("destroy", func() { dialog = nil })

		content_area := gtk.ToBox(dialog.GetContentArea())

		vbox := gtk.NewBox(gtk.OrientationVertical, 5)
		content_area.PackStart(vbox, true, true, 0)
		vbox.SetBorderWidth(5)

		label := gtk.NewLabel(gobject.NilString)
		label.SetMarkup("Completion demo, try writing <b>total</b> or <b>gnome</b> for example.")
		vbox.PackStart(label, false, false, 0)

		// Create our entry
		entry := gtk.NewEntry()
		vbox.PackStart(entry, false, false, 0)

		// Create the completion object
		completion := gtk.NewEntryCompletion()

		// Assign the completion to the entry
		entry.SetCompletion(completion)

		// Create a tree model and use it as the completion model
		completion_model := create_completion_model()
		completion.SetModel(completion_model)

		// Use model column 0 as the text column
		completion.SetTextColumn(0)
	}

	if !dialog.GetVisible() {
		dialog.ShowAll()
	} else {
		dialog.Destroy()
	}
	return gtk.ToWindow(dialog)
}